天马阁

 找回密码
 立即注册
                                        →→→→→→→→→→→→ 1点击查看所有VIP教程目录长列表(总教程数269个) 2办理VIP详情进入 ←←←←←←←←←←←←
1 x64CE与x64dbg入门基础教程 7课 已完结 2 x64汇编语言基础教程 16课 已完结 3 x64辅助入门基础教程 9课 已完结 4 C++x64内存辅助实战技术教程 149课 已完结
5 C++x64内存检测与过检测技术教程 10课 已完结 6 C+x64二叉树分析遍历与LUA自动登陆教程 19课已完结 7 C++BT功能原理与x64实战教程 29课 已完结 8 C+FPS框透视与自瞄x64实现原理及防护思路 30课完结
64驱?封? 9 64反驱? 10 64位V? 11 绝? 12 ???课?
13 64透 ? 14 64U ? 15 64Q ? 16 64功 ?
17 64U ? 18 64模 ? 19 64多 ? 20 64网 ?
21 64注 ? 22 64火 ? 23 64棋 ? 24 64自二链L?
25 64破 ? VIP会员办理QQ: 89986068   
【请先加好友,然后到好友列表双击联系客服办理,不然可能无法接受到信息。】
27 加入2000人交流群637034024 3 28 免责声明?
查看: 6154|回复: 0

IAT hook D3D透视源码 过检测的写法

[复制链接]

13

主题

0

回帖

16

积分

编程入门

Rank: 1

天马币
26
发表于 2024-3-6 09:22:44 | 显示全部楼层 |阅读模式

  1. #include "stdafx.h"
  2. #include <d3d9.h>
  3. #include <d3dx9.h>
  4. #pragma comment(lib, "d3d9.lib")
  5. #pragma comment(lib, "d3dx9.lib")
  6. bool bCompare(CONST BYTE *pData, CONST BYTE *bMask, CONST CHAR *szMask)
  7. {
  8.   for (; *szMask; ++szMask, ++pData, ++bMask)
  9.   if (*szMask == 'x' && *pData != *bMask)
  10.     return false;

  11.   return (*szMask) == NULL;
  12. }
  13. DWORD FindPattern(DWORD dwAddress, DWORD dwLen, BYTE* bMask, char* szMask)
  14. {
  15.   for (DWORD i = 0; i < dwLen; i++)
  16.   if (bCompare((BYTE *)(dwAddress + i), bMask, szMask))
  17.     return (DWORD)(dwAddress + i);

  18.   return 0;
  19. }



  20. void __cdecl nReset(void)
  21. {
  22.   _asm pushad

  23.   _asm popad
  24. }
  25. static DWORD PresentRetAddr;
  26. __declspec(naked) DWORD __stdcall Present_Return(LPDIRECT3DDEVICE9 pDevice, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
  27. {

  28.   __asm
  29.   {

  30.     MOV EDI, EDI
  31.       PUSH EBP
  32.       MOV EBP, ESP
  33.       jmp PresentRetAddr
  34.   }

  35. }

  36. static LPDIRECT3DDEVICE9 pDevice;
  37. LPD3DXFONT pFont = 0;
  38. #define TextRed     D3DCOLOR_ARGB(255,255,0,0)
  39. void WriteText(LPD3DXFONT g_pFont, INT x, INT y, D3DCOLOR Color, WCHAR *String)
  40. {
  41.   RECT Rect;
  42.   SetRect(&Rect, x, y, x, y);
  43.   g_pFont->DrawText(0, String, -1, &Rect, DT_LEFT | DT_NOCLIP, Color);
  44. }

  45. //这个函数用于取当前的指针,或许有更好的办法......
  46. HRESULT WINAPI Present_Detour(LPDIRECT3DDEVICE9 Device, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
  47. {
  48.   pDevice = Device; //这行代码执行后就可以恢复这个函数的钩子, 避免被检测//恢复的代码就自己写吧

  49.   return Present_Return(Device, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);

  50. }

  51. D3DVIEWPORT9 VPort;
  52. DWORD SCenterX, SCenterY;
  53. WCHAR Msg[256];
  54. void __cdecl nEndScene(void)
  55. {
  56.   static LPDIRECT3DDEVICE9 dwpDevice;
  57.   static DWORD dwEBP=0,offset=0;
  58.   __asm pushad
  59.   __asm MOV dwEBP, EBP
  60.   if (pDevice&&!offset)
  61.   {//遍历堆栈,取设备当前设备指针
  62.     for (int i = 0; i < 1024; i++)
  63.     {
  64.       if (*(DWORD*)(dwEBP + i) == (DWORD)pDevice)
  65.       {
  66.         offset = i;
  67.         break;
  68.       }
  69.     }
  70.   }
  71.   dwpDevice = *(LPDIRECT3DDEVICE9*)(dwEBP + offset);//取出指针
  72.   if (offset&&dwpDevice)
  73.   {//这个判断防止空指针,避免崩溃



  74.     /*
  75.     以下就可以进行菜单绘制等操作
  76.     */
  77.     static bool dwIPfos = 0;
  78.     if (pFont)
  79.     {
  80.       pFont->Release();
  81.       pFont = NULL;
  82.       dwIPfos = false;
  83.     }
  84.     if (!dwIPfos)
  85.     {
  86.       D3DXCreateFont(pDevice, 15, 0, 800, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &pFont);
  87.       dwIPfos = true;
  88.     }
  89.     WriteText(pFont, 150, 150, TextRed, L"德玛西亚");

  90.     dwpDevice->GetViewport(&VPort);
  91.     SCenterX = (float)VPort.Width / 2;
  92.     SCenterY = (float)VPort.Height / 2;
  93.     D3DRECT rec01 = { SCenterX - 2, SCenterY, SCenterX + 3, SCenterY + 1 };
  94.     D3DRECT rec02 = { SCenterX, SCenterY - 2, SCenterX + 1, SCenterY + 3 };
  95.     dwpDevice->Clear(1, &rec01, D3DCLEAR_TARGET, TextRed, 0, 0);
  96.     dwpDevice->Clear(1, &rec02, D3DCLEAR_TARGET, TextRed, 0, 0);
  97.   }
  98.   __asm popad
  99. }


  100. void __cdecl nDrawIndexedPrimitive(void)
  101. {
  102.   static LPDIRECT3DDEVICE9 dwpDevice;
  103.   static DWORD dwEBP = 0, offset = 0;
  104.   __asm pushad
  105.   __asm MOV dwEBP, EBP
  106.   if (pDevice&&!offset)
  107.   {
  108.     for (int i = 0; i < 1024; i++)
  109.     {//遍历堆栈,取设备当前设备指针
  110.       if (*(DWORD*)(dwEBP + i) == (DWORD)pDevice)
  111.       {
  112.         offset = i;
  113.         break;//取到就跳出
  114.       }

  115.     }
  116.   }
  117.   dwpDevice = *(LPDIRECT3DDEVICE9*)(dwEBP + offset);//取出指针
  118.   if (offset&&dwpDevice)
  119.   {//这个判断防止空指针,避免崩溃
  120.     LPDIRECT3DVERTEXBUFFER9   Stream = NULL;
  121.     UINT Offset = 0;
  122.     UINT Stride = 0;
  123.     if (dwpDevice->GetStreamSource(0, &Stream, &Offset, &Stride) == D3D_OK)
  124.       Stream->Release();
  125.     if (Stride == 44 || Stride == 40){
  126.       pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
  127.     }
  128.   }
  129.   _asm popad
  130. }
  131. static DWORD hHooking = NULL;
  132. static DWORD hEndScene = NULL;
  133. static DWORD hReset = NULL;
  134. static DWORD hDrawIndexPrimtive = NULL;


  135. typedef void (WINAPI * EnterCriticalSection_t) (LPCRITICAL_SECTION lpCriticalSection);
  136. EnterCriticalSection_t  pEnterCriticalSection;

  137. void WINAPI nEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
  138. {

  139.   _asm
  140.   {
  141.     MOV EAX, [EBP + 0x4]
  142.       MOV hHooking, EAX
  143.   }

  144.   // EndScene
  145.   if (hHooking == hEndScene)
  146.   {
  147.     __asm call[nEndScene]
  148.   }

  149.   //Reset
  150.   if (hHooking == hReset)
  151.   {
  152.     __asm call[nReset]
  153.   }

  154.   // DIP
  155.   if (hHooking == hDrawIndexPrimtive)
  156.   {
  157.     __asm call[nDrawIndexedPrimitive];
  158.   }


  159.   return pEnterCriticalSection(lpCriticalSection);
  160. }
  161. void* DetourCreate(BYTE *src, CONST BYTE *dst, CONST INT len)
  162. {
  163.   BYTE *jmp = (BYTE*)malloc(len + 5);

  164.   DWORD dwback;

  165.   VirtualProtect(src, len, PAGE_READWRITE, &dwback);

  166.   memcpy(jmp, src, len); jmp += len;

  167.   jmp[0] = 0xE9;

  168.   *(DWORD*)(jmp + 1) = (DWORD)(src + len - jmp) - 5;

  169.   src[0] = 0xE9;

  170.   *(DWORD*)(src + 1) = (DWORD)(dst - src) - 5;

  171.   //VirtualProtect(src, len, dwback, &dwback);

  172.   return (jmp - len);
  173. }
  174. void InitDevice(void)
  175. {

  176.   LPDIRECT3D9 pD3d9 = NULL;
  177.   DWORD oldflag;

  178.   LPDIRECT3DDEVICE9 pD3DDevice = NULL;
  179.   pD3d9 = Direct3DCreate9(D3D_SDK_VERSION);
  180.   if (pD3d9 == NULL)
  181.   {
  182.     MessageBox(NULL, L"[ERROR] Direct3DCreate9 失败", L" Error", MB_ICONERROR | MB_ICONSTOP);
  183.     return;
  184.   }
  185.   D3DPRESENT_PARAMETERS pPresentParms;
  186.   ZeroMemory(&pPresentParms, sizeof(pPresentParms));
  187.   pPresentParms.Windowed = TRUE;
  188.   pPresentParms.BackBufferFormat = D3DFMT_UNKNOWN;
  189.   pPresentParms.SwapEffect = D3DSWAPEFFECT_DISCARD;
  190.   if (FAILED(pD3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetDesktopWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pPresentParms, &pD3DDevice)))
  191.   {
  192.     MessageBox(NULL, L"[ERROR] CreateDevice Failed", L"Fatal Error", MB_ICONERROR | MB_ICONSTOP);
  193.     return;
  194.   }
  195.   DWORD * dwTable = (DWORD*)pD3DDevice;
  196.   dwTable = (DWORD*)dwTable[0];
  197.   PresentRetAddr = dwTable[17] + 5;
  198.   DetourCreate((PBYTE)dwTable[17], (PBYTE)&Present_Detour, 5);

  199. }
  200. void  WINAPI Start()
  201. {
  202.   
  203.   //
  204.   DWORD hD3D, hCriticalSection;
  205.   do
  206.   {
  207.     hD3D = (DWORD)GetModuleHandle(L"d3d9.dll");
  208.     Sleep(100);
  209.   } while (!hD3D);
  210.   hCriticalSection = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x74\x07\x00\xFF\x15\x00\x00\x00\x00\x8D\x00\x00", "xx?xx????x??")+5;
  211.   hCriticalSection =*(DWORD*)hCriticalSection;
  212.   if (!hCriticalSection)
  213.   {
  214.     MessageBox(NULL, L"Error Code (0)", L"Error", MB_ICONERROR);
  215.     exit(1);
  216.   }

  217.   //if (!hReset)
  218.   //  hReset = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\xFF\x15\x00\x00\x00\x00\x3B\x43\x20\x74\x1B\x8B\x46\x18\x85\xC0\x74\x07\x56", "xx????xxxxxxxxxxxxx");// Win XP
  219.   //if (!hReset)
  220.     hReset = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x57\xFF\x15\x00\x00\x00\x00\x8B\x45\x0C\x33\xF6\x39\x70\x20", "xxx????xxxxxxxx")+7;// Vista - Win7
  221.   if (!hReset)
  222.     hReset = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x33\xC9\x39\x4F\x20\x75\x79\x8D\x44\x24\x38\x89\x44\x24\x1C\x32\xC0\x8B\xDE", "xxxxxxxxxxxxxxxxxxx");// Win 8.0
  223.   if (!hReset)
  224.     hReset = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x8B\xCE\xE8\x00\x00\x00\x00\x8B\x4E\x0C\x48\xF7\xD8", "xxx????xxxxxx");// Win 8.1
  225.   if (!hReset)
  226.   {
  227.     MessageBox(NULL, L"Error Code (1)", L"Error", MB_ICONERROR);
  228.     exit(1);
  229.   }
  230. //  MessageBox(0, L"This", 0, 0);
  231.   //return;
  232.   //if (!hEndScene)
  233.     //hEndScene = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x57\xFF\x15\x00\x00\x00\x00\xF6\x46\x00\x00\x89\x5D\xFC\x75\x0E\x8B\x86\x00\x00\x00\x00\xA8\x01\xC6\x45\x00\x00\x75\x24", "xxx????xx??xxxxxxx????xxxx??xx")+7; // Win XP
  234.   //if (!hEndScene)
  235.     hEndScene = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x57\xFF\x15\x00\x00\x00\x00\xE9\x00\x00\x00\x00\x39\x5F\x18\x74\x07\x57\xFF\x15\x00\x00\x00\x00\xB8\x00\x00\x00\x00\x8B\x4D\xF4\x64\x89\x0D\x00\x00\x00\x00\x59\x5F\x5E\x5B\x8B\xE5\x5D\xC2\x04\x00\x68\xAD\x06\x00\x00", "xxx????x????xxxxxxxx????x????xxxxxx????xxxxxxxxxxxxx??")+7; // Vista Win7
  236.   if (!hEndScene)
  237.     hEndScene = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x33\xC0\xE8\x00\x00\x00\x00\xC2\x04\x00\x8B\xDF\xEB\x8E\x53\xFF\x15\x00\x00\x00\x00\xEB\x90", "xxx????xxxxxxxxxx????xx")+21;// Win8 8.0 + 8.1               
  238.   if (!hEndScene)
  239.   {
  240.     MessageBox(NULL, L"Error Code (2)", L"Error", MB_ICONERROR);
  241.     exit(1);
  242.   }

  243.   //if (!hDrawIndexPrimtive)
  244.     //hDrawIndexPrimtive = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x53\xFF\x15\x00\x00\x00\x00\xF6\x46\x00\x00\x89\x7D\xFC\x74\x24\x39\x7B\x18\x74\x07\x53\xFF\x15\x00\x00\x00\x00\xB8\x00\x00\x00\x00\x8B\x4D\xF4\x64\x89\x0D\x00\x00\x00\x00\x5F\x5E\x5B\x8B\xE5\x5D\xC2\x1C\x00", "xxx????xx??xxxxxxxxxxxxx????x????xxxxxx????xxxxxxxxx")+7;// Win XP
  245.   //if (!hDrawIndexPrimtive)
  246.     hDrawIndexPrimtive = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\x56\xFF\x15\x00\x00\x00\x00\xE9\x00\x00\x00\x00\x39\x5E\x18\x74\x07\x56\xFF\x15\x00\x00\x00\x00\xB8\x00\x00\x00\x00\x8B\x4D\xF4\x64\x89\x0D\x00\x00\x00\x00\x59\x5F\x5E\x5B\x8B\xE5\x5D\xC2\x1C\x00\x39\x9E\x00\x00\x00\x00", "xxx????x????xxxxxxxx????x????xxxxxx????xxxxxxxxxxxx????")+7;// Vista - Win7
  247.   if (!hDrawIndexPrimtive)
  248.     hDrawIndexPrimtive = FindPattern((DWORD)GetModuleHandle(L"d3d9.dll"), 0xffffff, (PBYTE)"\xE9\x00\x00\x00\x00\x00\xFF\x00\x00\x00\x00\x00\xE9\x00\x00\x00\x00\xC7\x45\x00\x00\x00\x00\x00\x8D\x4D\x00\xE8\x00\x00\x00\x00\xB8\x00\x00\x00\x00\xE9\x00\x00\x00\x00\x83\xBA\x00\x00\x00\x00\x00\x74\x00", "x?????x?????x????xx?????xx?x????x????x????xx?????x?")+12; // Win8 8.0 + 8.1
  249.   if (!hDrawIndexPrimtive)
  250.   {
  251.     MessageBox(NULL, L"Error Code (3)", L"Error", MB_ICONERROR);
  252.     exit(1);
  253.   }

  254.   if (hReset && hEndScene && hDrawIndexPrimtive)
  255.   {
  256.     DWORD dwBack;
  257.     VirtualProtect((void*)(hCriticalSection), 4, PAGE_EXECUTE_READWRITE, &dwBack);
  258.     pEnterCriticalSection = (EnterCriticalSection_t)*(DWORD*)(hCriticalSection);
  259.     *(DWORD*)(hCriticalSection) = (DWORD)nEnterCriticalSection;
  260.     VirtualProtect((void*)(hCriticalSection), 4, dwBack, &dwBack);
  261.     InitDevice();
  262.     return ;
  263.   }
  264.   
  265.   return ;
  266. }
  267. BOOL WINAPI DllMain(HMODULE hDll, DWORD dwReason, LPVOID lpReserved)
  268. {
  269.   if (dwReason == DLL_PROCESS_ATTACH)
  270.   {
  271.     CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Start, NULL, NULL, NULL);
  272.   }
  273.   return TRUE;
  274. }
复制代码
原创公布了 hook方法,但没使用方法, 主流射击游戏通用,此代码仅供学习研究,游戏公司尽早修复漏洞
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

天马阁|C/C++辅助教程|安卓逆向安全| 论坛导航|免责申明|Archiver||网站地图
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表天马阁立场!
任何人不得以任何方式翻录、盗版或出售本站视频,一经发现我们将追究其相关责任!
我们一直在努力成为最好的编程论坛!
Copyright© 2010-2021 All Right Reserved.
快速回复 返回顶部 返回列表