首页
社区
课程
招聘
[原创] Hook Directx在游戏中显示自己的文字 代码加注解 MASM
2017-12-26 13:52 8365

[原创] Hook Directx在游戏中显示自己的文字 代码加注解 MASM

2017-12-26 13:52
8365
d3d9esp_s struct
 regEdi dd ?
 regEsi dd ?
 regEbp dd ?
 regEsp dd ?
 regEbx dd ?
 regEdx dd ?
 regEcx dd ?
 regEax dd ?
 call_ret dd ?
 arg1 dd ?
 arg2 dd ?
 arg3 dd ?
 arg4 dd ?
 arg5 dd ?
 arg6 dd ?
 arg7 dd ?
 arg8 dd ?
d3d9esp_s ends
D3DXFONT_DESCA struct
 height dd ?
 d3width dd ?
 Weight dd ?
 MipLevels dd ?
 Italic dd ?
 CharSet dd ?
 OutputPrecision dd ?
 Quality dd ?
 PitchAndFamily dd ?
 FaceName db 256 dup(?)
D3DXFONT_DESCA ends
.data
pDirect3DCreate9 dd ?
Direct3DCreate9_ret dd ?
pCreateDevice dd ?
CreateDevice_ret dd ?
pCreateDevice_jmp dd ?
pIDirect3DDevice9 dd ?
pDxdevice dd ?
pD3DXCreateFontIndirectA dd ?
pPresent dd ?
lrect RECT<?>
ID3DXFont dd ?
lf D3DXFONT_DESCA<?>
d3dbuf db 256 dup(?)
 
.code

 
d3dajmpb proc a_addr:dword,b_addr:dword
local OldProtect
 pushad
 invoke IsBadWritePtr,a_addr,8
 .if eax!=0
  invoke VirtualProtect,a_addr,8,PAGE_EXECUTE_READWRITE,addr OldProtect
 .endif
 mov eax,a_addr
 mov edx,b_addr
 sub edx,eax
 sub edx,5
 mov byte ptr[eax],0e9h
 xchg [eax+1],edx
 popad
 ret
d3dajmpb endp

lpfnBeginScene proc
 mov eax,pIDirect3DDevice9
 mov eax,dword ptr[eax]
 mov ecx,dword ptr[eax]
 mov eax,dword ptr[ecx+0a4h]
 push pDxdevice
 call eax
 ret
lpfnBeginScene endp

lpfnEndScene proc
 
 mov eax,pIDirect3DDevice9
 mov eax,dword ptr[eax]
 mov ecx,dword ptr[eax]
 mov eax,dword ptr[ecx+0a8h]
 push pDxdevice
 call eax
 ret
lpfnEndScene endp

formatstr proc
LOCAL lbuf[64]:byte
 
 invoke crt_sprintf,addr lbuf,SADD("[%0.4f  %0.4f  %0.4f]",0),pos_x,pos_y,pos_z
 invoke wsprintf,addr d3dbuf,SADD("%s",0),addr lbuf
 ret
formatstr endp
;ID3DXFont.38h==drawtext  要this指针
;INT DrawText(
;  [in] LPD3DXSPRITE pSprite,
;  [in] LPCTSTR      pString,
;  [in] INT          Count,
;  [in] LPRECT       pRect,
;  [in] DWORD        Format,
;  [in] D3DCOLOR     Color
;);

New_Present proc
 
 pushad
  
  invoke lpfnBeginScene
  
  ;在这里写字
  invoke formatstr
  .if ID3DXFont  ;
      push 0ff00ff00h
      push 0
      push offset lrect
      invoke szLen,addr d3dbuf
      push eax
      push offset d3dbuf
      push NULL
      push ID3DXFont          ;
      mov ecx,ID3DXFont
      mov ecx,dword ptr[ecx]
      call dword ptr[ecx+38h]   ;ID3DXFont.DrawText
  .endif
  invoke lpfnEndScene
 
 popad
 
 mov edi,edi
 push ebp
 mov ebp,esp
 
 mov eax,pPresent
 add eax,5
 jmp eax
 ret
New_Present endp
New_CreateDevice proc
 
 ;修改返回地址.
 pop eax
 mov CreateDevice_ret,eax
 push offset New_CreateDevice_sub
 
;--------------------------------------------------------------------------------
 
 pushad
 mov edi,esp
 assume edi:ptr d3d9esp_s
; 这里什么都不做可以输出
 
 mov eax,[edi].arg7
 mov pIDirect3DDevice9,eax  ;
 
 invoke wsprintf,addr szbuf,SADD("pIDirect3DDevice9:%08x"),pIDirect3DDevice9
 invoke OutputDebugString,addr szbuf
 invoke wsprintf,addr szbuf,SADD("CreateDevice_ret:%08x"),CreateDevice_ret
 invoke OutputDebugString,addr szbuf
 invoke OutputDebugString,SADD("New_CreateDevice_START")
 
 popad
;--------------------------------------------------------------------------------
 ;执行函数
 
 mov edi,edi
 push ebp
 mov ebp,esp
 
 push eax
 mov eax,pCreateDevice
 add eax,5
 mov pCreateDevice_jmp,eax
 pop eax
 jmp pCreateDevice_jmp
 
;--------------------------------------------------------------------------------
 
 
 New_CreateDevice_sub:
 pushad
 
 invoke wsprintf,addr szbuf,SADD("111pIDirect3DDevice9:%08x"),pIDirect3DDevice9
 invoke OutputDebugString,addr szbuf
 
 
 .if eax
  mov eax,pIDirect3DDevice9
  mov eax,dword ptr[eax]
  
  mov pDxdevice,eax
  
  mov eax,dword ptr[eax]
  mov eax,dword ptr[eax+44h]
  
  mov pPresent,eax
  
  invoke d3dajmpb,pPresent,offset New_Present
 
  invoke wsprintf,addr szbuf,SADD("pPresent:%08x  pDxdevice:%08x"),pPresent,pDxdevice
  invoke OutputDebugString,addr szbuf
 
 
  invoke OutputDebugString,SADD("New_Present hooked  New_CreateDevice_end")
  
  
  .if pD3DXCreateFontIndirectA
   push offset ID3DXFont
   push offset lf
   push pDxdevice
   call pD3DXCreateFontIndirectA
   
   invoke wsprintf,addr szbuf,SADD("ID3DXFont:%08x"),ID3DXFont
   invoke OutputDebugString,addr szbuf
  .endif
  
  
 .else
  invoke OutputDebugString,SADD("ERROR::New_CreateDevice_end")
 .endif
 popad
 jmp CreateDevice_ret
 ret
New_CreateDevice endp

New_Direct3DCreate9 proc
 
 
 ;修改返回地址.
 pop eax
 mov Direct3DCreate9_ret,eax
 push offset New_Direct3DCreate9_sub
 
;--------------------------------------------------------------------------------
 
 pushad
 mov edi,esp
 assume edi:ptr d3d9esp_s
; 这里什么都不做可以输出
 
 invoke OutputDebugString,SADD("New_Direct3DCreate9_START")
 
 popad
;--------------------------------------------------------------------------------
 
 ;执行函数
 
 mov edi,edi
 push ebp
 mov ebp,esp
 
 mov eax,pDirect3DCreate9
 add eax,5
 jmp eax
;--------------------------------------------------------------------------------
 
 New_Direct3DCreate9_sub:
 pushad
 .if eax
  mov eax,dword ptr[eax]
  mov eax,dword ptr[eax+40h]
  
  mov pCreateDevice,eax
  
  invoke d3dajmpb,pCreateDevice,offset New_CreateDevice
 
  invoke wsprintf,addr szbuf,SADD("pCreateDevice:%08x"),pCreateDevice
  invoke OutputDebugString,addr szbuf
 
  invoke OutputDebugString,SADD("New_CreateDevice hooked  New_Direct3DCreate9_end")
  
  
 .else
  invoke OutputDebugString,SADD("ERROR::New_Direct3DCreate9_end")
 .endif
 popad
 jmp Direct3DCreate9_ret
 ret
New_Direct3DCreate9 endp

gamed3d_hook proc
 
 ;查找 Direct3DCreate9函数
 
 .while TRUE
  invoke GetModuleHandle,SADD("d3d9.dll")
  .break .if eax
  invoke Sleep,500
 .endw
 
 invoke GetProcAddress,eax,SADD("Direct3DCreate9")
 mov pDirect3DCreate9,eax
 
 
 ;HOOK Direct3DCreate9函数
 invoke d3dajmpb,pDirect3DCreate9,offset New_Direct3DCreate9
 
 invoke OutputDebugString,SADD("gamed3d_hook hooked")
 
 ;查找 D3DXCreateFontIndirectA 创键字体要用
 ;此处 D3DX9_37 是游戏加载的DLL。可以使用其它dll
 
 
 .while TRUE
  invoke GetModuleHandle,SADD("D3DX9_37.dll")
  .break .if eax
  invoke Sleep,500
 .endw
 
 invoke GetProcAddress,eax,SADD("D3DXCreateFontIndirectA")
 mov pD3DXCreateFontIndirectA,eax
 
 ;RECT  初始化结构
 mov lrect.left,0
 mov lrect.top,0
 mov lrect.right,1024
 mov lrect.bottom,100
 
 ;D3DXFONT_DESCA  初始化结构
 mov lf.height,12
 mov lf.d3width,8
 mov lf.Weight,100
 mov lf.Italic,0
 mov lf.CharSet,1
 invoke wsprintf,addr lf.FaceName,SADD("%s"),SADD("Times New Roman")
 
 
 ret
gamed3d_hook endp

[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞1
打赏
分享
最新回复 (12)
雪    币: 350
活跃值: (87)
能力值: ( LV7,RANK:110 )
在线值:
发帖
回帖
粉丝
czcqq 2 2017-12-26 14:53
2
0
使用汇编?牛了!不过使用汇编感觉有点不太友好,能不能关键部分使用汇编,别的部分使用C\C++代替呢?
雪    币: 614
活跃值: (1112)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
qqwawzymu 2017-12-26 16:58
3
0
主要是为何全用汇编呢?楼主高人。。。。
雪    币: 53
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
CoderJF 2017-12-26 18:05
4
0
恕我直言,使用汇编就有点故意装b之嫌。为了达到你的目标,这玩意基本没什么技术含量,更谈不上需要逆向
雪    币: 606
活跃值: (40)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yzlong 2017-12-26 18:31
5
0
情怀啊,  真是不累
雪    币: 6660
活跃值: (942)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
kingswb 2017-12-28 06:56
6
0
我喜欢,win32汇编。
雪    币: 140
活跃值: (70)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
流哥 2017-12-29 13:40
7
0
装逼啊!
雪    币: 123
活跃值: (316)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
taizhong 2018-2-14 01:39
8
0
CoderJF 恕我直言,使用汇编就有点故意装b之嫌。为了达到你的目标,这玩意基本没什么技术含量,更谈不上需要逆向
用远线程注入汇编代码到游戏,稳定,过检测
雪    币: 161
活跃值: (40)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
miWusn 2018-2-19 19:32
9
0
楼上说的对
雪    币: 433
活跃值: (1805)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
萌克力 2018-2-19 22:22
10
0
taizhong 用远线程注入汇编代码到游戏,稳定,过检测
你为啥会有这种错觉?
雪    币: 123
活跃值: (316)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
taizhong 2018-2-23 03:18
11
0
罗云彬的win32汇编编程,用汇编写个窗口程序,远线程注入,除了多出一个线程之外,几乎不留任何痕迹,可以看看



雪    币: 123
活跃值: (316)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
taizhong 2018-2-23 03:18
12
0
萌克力 你为啥会有这种错觉?
         
雪    币: 53
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
CoderJF 2018-3-1 18:52
13
0
不管是汇编代码还是C代码,注进去的都是二进制程序。
游客
登录 | 注册 方可回帖
返回