- UID
- 15835
- 帖子
- 2025
- 主題
- 46
- 精華
- 0
- 積分
- 144
- 楓幣
- 2209
- 威望
- 125
- 存款
- 0
- 贊助金額
- 0
- 推廣
- 0
- GP
- 164
- 閱讀權限
- 100
- 性別
- 保密
- 在線時間
- 371 小時
- 註冊時間
- 2012-10-23
- 最後登入
- 2022-4-21
|
- // Author : alan
- // NtProtectVirtualMemory.h
- #include <ntddk.h>
- VOID HookNtProtectVirtualMemory();
- VOID UnhookNtProtectVirtualMemory();
- ULONG JmpNtProtectVirtualMemory = 0;
- ULONG OldNtProtectVirtualMemoryAddress = 0;
- PEPROCESS ProtectEPROCESS = NULL;
- ANSI_STRING pp_str1,pp_str2;
- ULONG Addr_NtProtectVirtualMemory;
- ULONG Addr_P_NoAccessPte;
- ULONG Addr_P_SEH_prolog;
- ULONG Jmp_Addr_NtProtectVirtualMemory = 0;
- __declspec(naked) NTSTATUS __stdcall MyNtProtectVirtualMemory(
- IN HANDLE ProcessHandle,
- IN OUT PVOID *BaseAddress,
- IN OUT PULONG NumberOfBytesToProtect,
- IN ULONG NewAccessProtection,
- OUT PULONG OldAccessProtection
- )
- {
- ProtectEPROCESS = IoGetCurrentProcess();
- RtlInitAnsiString(&pp_str1,(PCSZ)ProtectEPROCESS+0x174);
- RtlInitAnsiString(&pp_str2,"MapleStory.exe");
- if (RtlCompareString(&pp_str1,&pp_str2,TRUE) == 0)
- {
- _asm
- {
- jmp OldNtProtectVirtualMemoryAddress
- }
- }
- else
- {
- _asm
- {
- push 0x44
- mov edx,Addr_P_NoAccessPte
- push edx
- mov edx,Jmp_Addr_NtProtectVirtualMemory
- push edx
- mov edx,Addr_P_SEH_prolog
- jmp edx
- }
- }
- }
- VOID HookNtProtectVirtualMemory()
- {
- ULONG NtProtectVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
- ULONG NtProtectVirtualMemoryIndexAddress1 = NtProtectVirtualMemoryIndexAddress + 0x89*4;
- OldNtProtectVirtualMemoryAddress = *(ULONG*)NtProtectVirtualMemoryIndexAddress1 ;
- /*
- JmpNtProtectVirtualMemory = OldNtProtectVirtualMemoryAddress + 7;
- Addr_P_NoAccessPte = OldNtProtectVirtualMemoryAddress - 0xDE38E;
- Addr_P_SEH_prolog = OldNtProtectVirtualMemoryAddress - 0x7C7F6;
- Jmp_Addr_NtProtectVirtualMemory = OldNtProtectVirtualMemoryAddress + 0xC;
- */
- __asm{
- cli
- mov eax,cr0
- and eax,not 10000h
- mov cr0,eax
- mov ebx,NtProtectVirtualMemoryIndexAddress1
- mov eax,dword ptr [ebx]
- mov Addr_NtProtectVirtualMemory,eax
- add eax,0x0c
- mov Jmp_Addr_NtProtectVirtualMemory,eax
-
- mov ebx,Addr_NtProtectVirtualMemory
- mov eax,dword ptr [ebx+3]
- mov Addr_P_NoAccessPte,eax
- mov eax,dword ptr [ebx+8]
- add eax,Addr_NtProtectVirtualMemory
- add eax,7
- add eax,5
- mov Addr_P_SEH_prolog,eax
- }
- DbgPrint("Addr_NtProtectVirtualMemory is %x",Addr_NtProtectVirtualMemory);
- DbgPrint("Addr_P_NoAccessPte is %x",Addr_P_NoAccessPte);
- DbgPrint("Addr_P_SEH_prolog is %x",Addr_P_SEH_prolog);
- DbgPrint("Jmp_Addr_NtProtectVirtualMemory is %x",Jmp_Addr_NtProtectVirtualMemory);
- *(ULONG*)NtProtectVirtualMemoryIndexAddress1 = (ULONG)MyNtProtectVirtualMemory;
- __asm{
- mov eax,cr0
- or eax,10000h
- mov cr0,eax
- sti
- }
- DbgPrint("HookNtProtectVirtualMemory");
- }
- VOID UnhookNtProtectVirtualMemory()
- {
- ULONG NtProtectVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
- ULONG NtProtectVirtualMemoryIndexAddress1 = NtProtectVirtualMemoryIndexAddress + 0x89*4;
- _asm
- {
- cli
- pushad
- mov eax,cr0
- and eax,not 10000h
- mov cr0,eax
- }
- *(ULONG*)NtProtectVirtualMemoryIndexAddress1 = (ULONG)OldNtProtectVirtualMemoryAddress;
- _asm
- {
- mov eax,cr0
- or eax,10000h
- mov cr0,eax
- popad
- sti
- }
- DbgPrint("UnhookNtProtectVirtualMemory");
- }
複製代碼 |
|