冰楓論壇

 找回密碼
 立即註冊
ads_sugarbook
搜索
查看: 2737|回覆: 6
打印 上一主題 下一主題

kernel driver - NTHook

[複製鏈接]

46

主題

6

好友

144

積分

技術師

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

UID
15835
帖子
2025
主題
46
精華
0
積分
144
楓幣
2209
威望
125
存款
0
贊助金額
0
推廣
0
GP
164
閱讀權限
100
性別
保密
在線時間
371 小時
註冊時間
2012-10-23
最後登入
2022-4-21
跳轉到指定樓層
1
發表於 2015-1-10 22:15:55 |只看該作者 |倒序瀏覽
本帖最後由 kkmomo 於 2015-1-10 23:17 編輯

幾年前從一個自稱香港人的 alan 大大那得到的
只有小改一點點讓 vc 可以 compile
當時在 32bits os 測試是可以 work
不過很久沒去碰這個了,剛才整理東西時翻到 給想研究的人看看

2樓  entry.cpp
3樓  NtOpenProcess.h
4樓  NtProtectVirtualMemory.h
5樓  NtReadVirtualMemory.h
6樓  NtWriteVirtualMemory.h
收藏收藏0 推0 噓0


把本文推薦給朋友或其他網站上,每次被點擊增加您在本站積分: 1骰子
複製連結並發給好友,以賺取推廣點數
簡單兩步驟,註冊、分享網址,即可獲得獎勵! 一起推廣文章換商品、賺$$

46

主題

6

好友

144

積分

技術師

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

UID
15835
帖子
2025
主題
46
精華
0
積分
144
楓幣
2209
威望
125
存款
0
贊助金額
0
推廣
0
GP
164
閱讀權限
100
性別
保密
在線時間
371 小時
註冊時間
2012-10-23
最後登入
2022-4-21
2
發表於 2015-1-10 22:19:55 |只看該作者
  1. // Author : alan
  2. // entry.cpp

  3. #include <ntddk.h>
  4. #include "NtOpenProcess.h"
  5. #include "NtReadVirtualMemory.h"
  6. #include "NtProtectVirtualMemory.h"
  7. #include "NtWriteVirtualMemory.h"

  8. #define _Driver_name      L"\\Device\\NTHook"
  9. #define _Symbolic_name      L"\\DosDevices\\NTHook1"

  10. #define INITCODE code_seg("INIT")
  11. #define PAGECODE code_seg("PAGE")
  12. #pragma INITCODE

  13. VOID DriverUnLoad(PDRIVER_OBJECT driver);
  14. NTSTATUS DispatchIrp(PDEVICE_OBJECT driver,PIRP irp);

  15. extern "C"
  16. NTSTATUS DriverEntry(PDRIVER_OBJECT driver,PUNICODE_STRING driver_object_name)
  17. {
  18.   HookNtOpenProcess();
  19.   HookNtReadVirtualMemory();
  20.   HookNtProtectVirtualMemory();
  21.   HookNtWriteVirtualMemory();

  22.   NTSTATUS status=STATUS_SUCCESS;
  23.   driver->MajorFunction[IRP_MJ_CREATE]=DispatchIrp;
  24.   driver->MajorFunction[IRP_MJ_READ]=DispatchIrp;
  25.   driver->MajorFunction[IRP_MJ_WRITE]=DispatchIrp;
  26.   driver->MajorFunction[IRP_MJ_CLOSE]=DispatchIrp;
  27.   driver->MajorFunction[IRP_MJ_DEVICE_CONTROL]=DispatchIrp;
  28.   driver->DriverUnload=DriverUnLoad;
  29.   
  30.   UNICODE_STRING driver_name;
  31.   RtlInitUnicodeString(&driver_name,_Driver_name);
  32.   
  33.   PDEVICE_OBJECT device_object;
  34.   status=IoCreateDevice(driver,NULL,&driver_name,FILE_DEVICE_UNKNOWN,NULL,FALSE,&device_object);
  35.   if(!NT_SUCCESS(status))
  36.   {
  37.     KdPrint(("創建設備失敗!\n"));
  38.     return status;
  39.   }
  40.   KdPrint(("創建設備成功!\n"));
  41.   device_object->Flags |= DO_BUFFERED_IO;
  42.   
  43.   UNICODE_STRING symbolic_name;
  44.   RtlInitUnicodeString(&symbolic_name,_Symbolic_name);
  45.   status=IoCreateSymbolicLink(&symbolic_name,&driver_name);
  46.   if(!NT_SUCCESS(status))
  47.   {
  48.     IoDeleteDevice(device_object);
  49.     KdPrint(("創建符號鏈接失敗!\n"));
  50.     return status;
  51.   }
  52.   KdPrint(("創建符號鏈接成功!\n"));
  53.   return STATUS_SUCCESS;
  54. }

  55. #pragma PAGEDCODE
  56. VOID DriverUnLoad(PDRIVER_OBJECT driver)
  57. {
  58.   UNICODE_STRING symbol_name;
  59.   RtlInitUnicodeString(&symbol_name,_Symbolic_name);
  60.   IoDeleteSymbolicLink(&symbol_name);
  61.   IoDeleteDevice(driver->DeviceObject);
  62.   KdPrint(("刪除設備成功!\n"));
  63.   UnhookNtOpenProcess();
  64.   UnhookNtReadVirtualMemory();
  65.   UnhookNtProtectVirtualMemory();
  66.   UnhookNtWriteVirtualMemory();
  67. }

  68. #pragma PAGEDCODE
  69. NTSTATUS DispatchIrp(PDEVICE_OBJECT driver,PIRP irp)
  70. {
  71.   irp->IoStatus.Status=STATUS_SUCCESS;
  72.   irp->IoStatus.Information=0;
  73.   IoCompleteRequest(irp,IO_NO_INCREMENT);
  74.   KdPrint(("進入IRP例程!\n"));
  75.   return STATUS_SUCCESS;
  76. }
複製代碼
點評回覆

使用道具 舉報

46

主題

6

好友

144

積分

技術師

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

UID
15835
帖子
2025
主題
46
精華
0
積分
144
楓幣
2209
威望
125
存款
0
贊助金額
0
推廣
0
GP
164
閱讀權限
100
性別
保密
在線時間
371 小時
註冊時間
2012-10-23
最後登入
2022-4-21
3
發表於 2015-1-10 22:20:41 |只看該作者
  1. // Author : alan
  2. // NtOpenProcess.h

  3. #include <ntddk.h>

  4. typedef struct _SERVICE_DESCRIPTOR_TABLE
  5. {
  6. PULONG ServiceTableBase;
  7. PULONG ServiceCounterTableBase;
  8. ULONG NumberOfService;
  9. ULONG ParamTableBase;
  10. }SERVICE_DESCRIPTOR_TABLE,*PSERVICE_DESCRIPTOR_TABLE;
  11. extern "C" PSERVICE_DESCRIPTOR_TABLE KeServiceDescriptorTable;

  12. VOID HookNtOpenProcess();
  13. VOID UnhookNtOpenProcess();

  14. PEPROCESS  processEPROCESS = NULL;  
  15. ANSI_STRING  p_str1,p_str2;      

  16. ULONG OldNtOpenProcessAddress = 0;
  17. ULONG Addr_NtOpenProcess;
  18. ULONG Addr_ObWatchHandles;      
  19. ULONG Addr_SEH_prolog;         
  20. ULONG Jmp_Addr_NtOpenProcess;   

  21. __declspec(naked) NTSTATUS __stdcall MyNtOpenProcess(
  22. OUT PHANDLE ProcessHandle,
  23. IN ACCESS_MASK AccessMask,
  24. IN POBJECT_ATTRIBUTES ObjectAttributes,
  25. IN PCLIENT_ID ClientId)
  26. {
  27. processEPROCESS = IoGetCurrentProcess();
  28. RtlInitAnsiString(&p_str1,(PCSZ)processEPROCESS+0x174);
  29. RtlInitAnsiString(&p_str2,"MapleStory.exe");
  30.    if (RtlCompareString(&p_str1,&p_str2,TRUE) == 0)
  31. {
  32. _asm
  33. {
  34. jmp OldNtOpenProcessAddress
  35. }  
  36. }
  37.    else
  38.    {
  39. _asm
  40. {
  41. push 0x0c4
  42. mov edx,Addr_ObWatchHandles
  43. push edx
  44. mov edx,Jmp_Addr_NtOpenProcess
  45. push edx
  46. mov edx,Addr_SEH_prolog
  47. jmp edx
  48.         }
  49.     }
  50. }

  51. VOID HookNtOpenProcess()
  52. {
  53.             
  54. ULONG NtOpenProcessIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  55. ULONG NtOpenProcessIndexAddress1 = NtOpenProcessIndexAddress + 0x7A*4;

  56. OldNtOpenProcessAddress = *(ULONG*)NtOpenProcessIndexAddress1;

  57. __asm{
  58. cli
  59. mov eax,cr0
  60. and eax,not 10000h
  61. mov cr0,eax

  62. mov ebx,NtOpenProcessIndexAddress1      
  63. mov eax,dword ptr [ebx]
  64. mov Addr_NtOpenProcess,eax   
  65.       
  66. add eax,0x0f
  67. mov Jmp_Addr_NtOpenProcess,eax      
  68.          
  69. mov ebx,Addr_NtOpenProcess        
  70. mov eax,dword ptr [ebx+6]           
  71. mov Addr_ObWatchHandles,eax

  72. mov eax,dword ptr [ebx+0x0b]        
  73. add eax,Addr_NtOpenProcess
  74. add eax,0x0a
  75. add eax,5
  76. mov Addr_SEH_prolog,eax
  77. }

  78. *(ULONG*)NtOpenProcessIndexAddress1 = (ULONG)MyNtOpenProcess;
  79. DbgPrint("Addr_ObWatchHandles is %x",Addr_ObWatchHandles);
  80. DbgPrint("Addr_NtOpenProcess is %x",Addr_NtOpenProcess);
  81. DbgPrint("Addr_SEH_prolog is %x",Addr_SEH_prolog);
  82. DbgPrint("Jmp_Addr_NtOpenProcess is %x",Jmp_Addr_NtOpenProcess);
  83. __asm{
  84. mov eax,cr0
  85. or eax,10000h
  86. mov cr0,eax
  87. sti
  88. }
  89. DbgPrint("HookNtOpenProcess");
  90. }

  91. VOID UnhookNtOpenProcess()
  92. {
  93. ULONG NtOpenProcessIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  94. ULONG NtOpenProcessIndexAddress1 = NtOpenProcessIndexAddress + 0x7A*4;

  95. _asm
  96. {
  97. cli
  98. pushad                  
  99. mov eax,cr0
  100. and eax,not 10000h
  101. mov cr0,eax
  102. }
  103. *(ULONG*)NtOpenProcessIndexAddress1 = (ULONG)OldNtOpenProcessAddress;
  104. _asm
  105. {     
  106. mov eax,cr0
  107. or eax,10000h
  108. mov cr0,eax
  109. popad
  110. sti
  111. }

  112. DbgPrint("UnhookNtOpenProcess");

  113. }
複製代碼
[發帖際遇]: kkmomo 發文時在路邊撿到 5 楓幣,偷偷放進了口袋 幸運榜 / 衰神榜
點評回覆

使用道具 舉報

46

主題

6

好友

144

積分

技術師

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

UID
15835
帖子
2025
主題
46
精華
0
積分
144
楓幣
2209
威望
125
存款
0
贊助金額
0
推廣
0
GP
164
閱讀權限
100
性別
保密
在線時間
371 小時
註冊時間
2012-10-23
最後登入
2022-4-21
4
發表於 2015-1-10 22:21:36 |只看該作者
  1. // Author : alan
  2. // NtProtectVirtualMemory.h

  3. #include <ntddk.h>

  4. VOID HookNtProtectVirtualMemory();
  5. VOID UnhookNtProtectVirtualMemory();

  6. ULONG JmpNtProtectVirtualMemory = 0;
  7. ULONG OldNtProtectVirtualMemoryAddress = 0;

  8. PEPROCESS  ProtectEPROCESS = NULL;
  9. ANSI_STRING pp_str1,pp_str2;

  10. ULONG Addr_NtProtectVirtualMemory;
  11. ULONG Addr_P_NoAccessPte;  
  12. ULONG Addr_P_SEH_prolog;        
  13. ULONG Jmp_Addr_NtProtectVirtualMemory = 0;   

  14. __declspec(naked) NTSTATUS __stdcall MyNtProtectVirtualMemory(
  15. IN HANDLE ProcessHandle,
  16. IN OUT PVOID *BaseAddress,
  17. IN OUT PULONG NumberOfBytesToProtect,
  18. IN ULONG NewAccessProtection,
  19. OUT PULONG OldAccessProtection
  20. )
  21. {
  22. ProtectEPROCESS = IoGetCurrentProcess();
  23. RtlInitAnsiString(&pp_str1,(PCSZ)ProtectEPROCESS+0x174);
  24. RtlInitAnsiString(&pp_str2,"MapleStory.exe");
  25.     if (RtlCompareString(&pp_str1,&pp_str2,TRUE) == 0)
  26.     {
  27. _asm
  28. {
  29. jmp OldNtProtectVirtualMemoryAddress
  30. }  
  31.     }
  32.     else
  33.     {
  34. _asm
  35. {
  36. push 0x44
  37. mov edx,Addr_P_NoAccessPte
  38. push edx
  39. mov edx,Jmp_Addr_NtProtectVirtualMemory
  40. push edx
  41. mov edx,Addr_P_SEH_prolog
  42. jmp edx
  43. }
  44.     }
  45. }

  46. VOID HookNtProtectVirtualMemory()
  47. {

  48. ULONG NtProtectVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  49. ULONG NtProtectVirtualMemoryIndexAddress1 = NtProtectVirtualMemoryIndexAddress + 0x89*4;

  50. OldNtProtectVirtualMemoryAddress = *(ULONG*)NtProtectVirtualMemoryIndexAddress1 ;
  51. /*
  52. JmpNtProtectVirtualMemory = OldNtProtectVirtualMemoryAddress + 7;
  53. Addr_P_NoAccessPte =  OldNtProtectVirtualMemoryAddress - 0xDE38E;
  54. Addr_P_SEH_prolog = OldNtProtectVirtualMemoryAddress - 0x7C7F6;
  55. Jmp_Addr_NtProtectVirtualMemory = OldNtProtectVirtualMemoryAddress + 0xC;
  56. */
  57. __asm{
  58. cli
  59. mov eax,cr0
  60. and eax,not 10000h
  61. mov cr0,eax

  62. mov ebx,NtProtectVirtualMemoryIndexAddress1   
  63. mov eax,dword ptr [ebx]
  64. mov Addr_NtProtectVirtualMemory,eax

  65. add eax,0x0c
  66. mov Jmp_Addr_NtProtectVirtualMemory,eax   
  67.          
  68. mov ebx,Addr_NtProtectVirtualMemory     
  69. mov eax,dword ptr [ebx+3]      
  70. mov Addr_P_NoAccessPte,eax   

  71. mov eax,dword ptr [ebx+8]
  72. add eax,Addr_NtProtectVirtualMemory
  73. add eax,7
  74. add eax,5
  75. mov Addr_P_SEH_prolog,eax           
  76. }
  77. DbgPrint("Addr_NtProtectVirtualMemory is %x",Addr_NtProtectVirtualMemory);
  78. DbgPrint("Addr_P_NoAccessPte is %x",Addr_P_NoAccessPte);
  79. DbgPrint("Addr_P_SEH_prolog is %x",Addr_P_SEH_prolog);
  80. DbgPrint("Jmp_Addr_NtProtectVirtualMemory is %x",Jmp_Addr_NtProtectVirtualMemory);

  81. *(ULONG*)NtProtectVirtualMemoryIndexAddress1 = (ULONG)MyNtProtectVirtualMemory;

  82. __asm{
  83. mov eax,cr0
  84. or eax,10000h
  85. mov cr0,eax
  86. sti
  87. }
  88. DbgPrint("HookNtProtectVirtualMemory");

  89. }

  90. VOID UnhookNtProtectVirtualMemory()
  91. {
  92. ULONG NtProtectVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  93. ULONG NtProtectVirtualMemoryIndexAddress1 = NtProtectVirtualMemoryIndexAddress + 0x89*4;
  94. _asm
  95. {
  96. cli
  97. pushad                  
  98. mov eax,cr0
  99. and eax,not 10000h
  100. mov cr0,eax
  101. }
  102. *(ULONG*)NtProtectVirtualMemoryIndexAddress1 = (ULONG)OldNtProtectVirtualMemoryAddress;
  103. _asm
  104. {     
  105. mov eax,cr0
  106. or eax,10000h
  107. mov cr0,eax
  108. popad
  109. sti
  110. }

  111. DbgPrint("UnhookNtProtectVirtualMemory");

  112. }
複製代碼
點評回覆

使用道具 舉報

46

主題

6

好友

144

積分

技術師

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

UID
15835
帖子
2025
主題
46
精華
0
積分
144
楓幣
2209
威望
125
存款
0
贊助金額
0
推廣
0
GP
164
閱讀權限
100
性別
保密
在線時間
371 小時
註冊時間
2012-10-23
最後登入
2022-4-21
5
發表於 2015-1-10 22:22:35 |只看該作者
  1. // Author : alan
  2. // NtReadVirtualMemory.h

  3. #include <ntddk.h>

  4. VOID HookNtReadVirtualMemory();
  5. VOID UnhookNtReadVirtualMemory();

  6. ULONG JmpNtReadVirtualMemory = 0;
  7. ULONG OldNtReadVirtualMemoryAddress = 0;

  8. PEPROCESS  ReadEPROCESS = NULL;
  9. ANSI_STRING r_str1,r_str2;

  10. ULONG Addr_NtReadVirtualMemory;
  11. ULONG Addr_MmClaimParameter;   
  12. ULONG Addr_R_SEH_prolog;        
  13. ULONG Jmp_Addr_NtReadVirtualMemory = 0;

  14. __declspec(naked) NTSTATUS __stdcall MyNtReadVirtualMemory(
  15. IN HANDLE ProcessHandle,
  16. IN PVOID BaseAddress,
  17. OUT PVOID Buffer,
  18. IN ULONG NumberOfBytesToRead,
  19. OUT PULONG NumberOfBytesReaded OPTIONAL
  20. )
  21. {
  22. ReadEPROCESS = IoGetCurrentProcess();
  23. RtlInitAnsiString(&r_str1,(PCSZ)ReadEPROCESS+0x174);
  24. RtlInitAnsiString(&r_str2,"MapleStory.exe");
  25.     if (RtlCompareString(&r_str1,&r_str2,TRUE) == 0)
  26.     {
  27. _asm
  28. {
  29. jmp OldNtReadVirtualMemoryAddress
  30. }  
  31.     }
  32.     else
  33. {
  34. _asm
  35. {
  36. push 0x1c
  37. mov edx,Addr_MmClaimParameter
  38. push edx
  39. mov edx,Jmp_Addr_NtReadVirtualMemory
  40. push edx
  41. mov edx,Addr_R_SEH_prolog
  42. jmp edx
  43. }
  44.     }
  45. }

  46. VOID HookNtReadVirtualMemory()
  47. {

  48. ULONG NtReadVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  49. ULONG NtReadVirtualMemoryIndexAddress1 = NtReadVirtualMemoryIndexAddress + 0xba*4;

  50. OldNtReadVirtualMemoryAddress = *(ULONG*)NtReadVirtualMemoryIndexAddress1 ;

  51. /*JmpNtReadVirtualMemory = OldNtReadVirtualMemoryAddress + 7;
  52. Addr_R_SEH_prolog = OldNtReadVirtualMemoryAddress - 0x7869A;
  53. Addr_MmClaimParameter = OldNtReadVirtualMemoryAddress - 0xDA3DA;
  54. Jmp_Addr_NtReadVirtualMemory = OldNtReadVirtualMemoryAddress + 0xC;
  55. */
  56. __asm{
  57. cli
  58. mov eax,cr0
  59. and eax,not 10000h
  60. mov cr0,eax

  61. mov ebx,NtReadVirtualMemoryIndexAddress1     
  62. mov eax,dword ptr [ebx]
  63. mov Addr_NtReadVirtualMemory,eax
  64.      
  65. add eax,0x0c        
  66. mov Jmp_Addr_NtReadVirtualMemory,eax
  67.          
  68. mov ebx,Addr_NtReadVirtualMemory
  69. mov eax,dword ptr [ebx+3]           
  70. mov Addr_MmClaimParameter,eax

  71. mov eax,dword ptr [ebx+8]
  72. add eax,Addr_NtReadVirtualMemory
  73. add eax,7
  74. add eax,5
  75. mov Addr_R_SEH_prolog,eax           
  76. }
  77. DbgPrint("Addr_NtReadVirtualMemory is %x",Addr_NtReadVirtualMemory);
  78. DbgPrint("Addr_R_SEH_prolog is %x",Addr_R_SEH_prolog);
  79. DbgPrint("Addr_MmClaimParameter is %x",Addr_MmClaimParameter);
  80. DbgPrint("Jmp_Addr_NtReadVirtualMemory is %x",Jmp_Addr_NtReadVirtualMemory);
  81. *(ULONG*)NtReadVirtualMemoryIndexAddress1 = (ULONG)MyNtReadVirtualMemory;

  82. __asm{
  83. mov eax,cr0
  84. or eax,10000h
  85. mov cr0,eax
  86. sti
  87. }
  88. DbgPrint("HookNtReadVirtualMemory");

  89. }

  90. VOID UnhookNtReadVirtualMemory()
  91. {
  92. ULONG NtReadVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  93. ULONG NtReadVirtualMemoryIndexAddress1 = NtReadVirtualMemoryIndexAddress + 0xba*4;
  94. _asm
  95. {
  96. cli
  97. pushad                  
  98. mov eax,cr0
  99. and eax,not 10000h
  100. mov cr0,eax
  101. }
  102. *(ULONG*)NtReadVirtualMemoryIndexAddress1 = (ULONG)OldNtReadVirtualMemoryAddress;
  103. _asm
  104. {     
  105. mov eax,cr0
  106. or eax,10000h
  107. mov cr0,eax
  108. popad
  109. sti
  110. }

  111. DbgPrint("UnhookNtReadVirtualMemory");

  112. }
複製代碼
點評回覆

使用道具 舉報

46

主題

6

好友

144

積分

技術師

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

UID
15835
帖子
2025
主題
46
精華
0
積分
144
楓幣
2209
威望
125
存款
0
贊助金額
0
推廣
0
GP
164
閱讀權限
100
性別
保密
在線時間
371 小時
註冊時間
2012-10-23
最後登入
2022-4-21
6
發表於 2015-1-10 22:23:15 |只看該作者
  1. // Author : alan
  2. // NtWriteVirtualMemory.h

  3. #include <ntddk.h>

  4. VOID HookNtWriteVirtualMemory();
  5. VOID UnhookNtWriteVirtualMemory();

  6. ULONG JmpNtWriteVirtualMemory = 0;
  7. ULONG OldWriteVirtualMemoryAddress = 0;

  8. PEPROCESS  WriteEPROCESS = NULL;
  9. ANSI_STRING w_str1,w_str2;

  10. ULONG Addr_NtWriteVirtualMemory;
  11. ULONG Addr_W_MmClaimParameter;  
  12. ULONG Addr_W_SEH_prolog;        
  13. ULONG Jmp_Addr_NtWriteVirtualMemory = 0;   

  14. __declspec(naked) NTSTATUS __stdcall MyNtWriteVirtualMemory(
  15. IN HANDLE ProcessHandle,
  16. IN PVOID BaseAddress,
  17. IN PVOID Buffer,
  18. IN ULONG NumberOfBytesToWrite,
  19. OUT PULONG NumberOfBytesWritten OPTIONAL)
  20. {
  21. WriteEPROCESS = IoGetCurrentProcess();
  22. RtlInitAnsiString(&w_str1,(PCSZ)WriteEPROCESS+0x174);
  23. RtlInitAnsiString(&w_str2,"MapleStory.exe");
  24.     if (RtlCompareString(&w_str1,&w_str2,TRUE) == 0)
  25.     {
  26. _asm
  27. {
  28. jmp OldWriteVirtualMemoryAddress
  29. }  
  30.     }
  31.     else
  32.     {
  33. _asm
  34. {
  35. push 0x1C
  36. mov edx,Addr_W_MmClaimParameter
  37. push edx
  38. mov edx,Jmp_Addr_NtWriteVirtualMemory
  39. push edx
  40. mov edx,Addr_W_SEH_prolog
  41. jmp edx
  42. }
  43.     }
  44. }

  45. VOID HookNtWriteVirtualMemory()
  46. {

  47. ULONG NtWriteVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  48. ULONG NtWriteVirtualMemoryIndexAddress1 = NtWriteVirtualMemoryIndexAddress + 0x115*4;

  49. OldWriteVirtualMemoryAddress = *(ULONG*)NtWriteVirtualMemoryIndexAddress1;
  50. /*
  51. JmpNtWriteVirtualMemory = OldWriteVirtualMemoryAddress + 7;
  52. Addr_W_MmClaimParameter =  OldWriteVirtualMemoryAddress - 0xDA4CC;
  53. Addr_W_SEH_prolog = OldWriteVirtualMemoryAddress - 0x787A4;
  54. Jmp_Addr_NtWriteVirtualMemory = OldWriteVirtualMemoryAddress + 0xC;
  55. */
  56. __asm{
  57. cli
  58. mov eax,cr0
  59. and eax,not 10000h
  60. mov cr0,eax

  61. mov ebx,NtWriteVirtualMemoryIndexAddress1   
  62. mov eax,dword ptr [ebx]
  63. mov Addr_NtWriteVirtualMemory,eax

  64. add eax,0x0c
  65. mov Jmp_Addr_NtWriteVirtualMemory,eax   
  66.          
  67. mov ebx,Addr_NtWriteVirtualMemory     
  68. mov eax,dword ptr [ebx+3]      
  69. mov Addr_W_MmClaimParameter,eax   

  70. mov eax,dword ptr [ebx+8]
  71. add eax,Addr_NtWriteVirtualMemory
  72. add eax,7
  73. add eax,5
  74. mov Addr_W_SEH_prolog,eax           
  75. }
  76. DbgPrint("Addr_NtWriteVirtualMemory is %x",Addr_NtWriteVirtualMemory);
  77. DbgPrint("Addr_W_MmClaimParameter is %x",Addr_W_MmClaimParameter);
  78. DbgPrint("Addr_W_SEH_prolog is %x",Addr_W_SEH_prolog);
  79. DbgPrint("Jmp_Addr_NtWriteVirtualMemory is %x",Jmp_Addr_NtWriteVirtualMemory);

  80. *(ULONG*)NtWriteVirtualMemoryIndexAddress1 = (ULONG)MyNtWriteVirtualMemory;

  81. __asm{
  82. mov eax,cr0
  83. or eax,10000h
  84. mov cr0,eax
  85. sti
  86. }
  87. DbgPrint("HookNtWriteVirtualMemory");

  88. }

  89. VOID UnhookNtWriteVirtualMemory()
  90. {
  91. ULONG NtWriteVirtualMemoryIndexAddress = (ULONG)(KeServiceDescriptorTable->ServiceTableBase);
  92. ULONG NtWriteVirtualMemoryIndexAddress1 = NtWriteVirtualMemoryIndexAddress + 0x115*4;
  93. _asm
  94. {
  95. cli
  96. pushad                  
  97. mov eax,cr0
  98. and eax,not 10000h
  99. mov cr0,eax
  100. }
  101. *(ULONG*)NtWriteVirtualMemoryIndexAddress1 = (ULONG)OldWriteVirtualMemoryAddress;
  102. _asm
  103. {     
  104. mov eax,cr0
  105. or eax,10000h
  106. mov cr0,eax
  107. popad
  108. sti
  109. }

  110. DbgPrint("UnhookNtWriteVirtualMemory");

  111. }
複製代碼
[發帖際遇]: kkmomo 於2011年購買2498股票100張被套牢,今年度發放現金股利每股 8 楓幣 幸運榜 / 衰神榜
點評回覆

使用道具 舉報

0

主題

0

好友

1

積分

新手上路

Rank: 1

UID
90167
帖子
33
主題
0
精華
0
積分
1
楓幣
36
威望
1
存款
0
贊助金額
0
推廣
0
GP
0
閱讀權限
10
性別
保密
在線時間
9 小時
註冊時間
2015-1-26
最後登入
2015-2-7
7
發表於 2015-1-27 15:17:28 |只看該作者
好多的API阿~~
也許學習外褂這是必經的過程XD
點評回覆

使用道具 舉報

高級模式
B Color Image Link Quote Code Smilies |上傳

廣告刊登意見回饋關於我們管群招募本站規範DMCA隱私權政策

Copyright © 2011-2024 冰楓論壇, All rights reserved

免責聲明:本網站是以即時上載留言的方式運作,本站對所有留言的真實性、完整性及立場等,不負任何法律責任。

而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。

小黑屋|手機版|冰楓論壇

GMT+8, 2024-5-14 11:49

回頂部