API HOOK代码写在EXE和写在DLL中的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 sy0116
  • 开始时间 开始时间
S

sy0116

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟最近学习API&nbsp;HOOK,在http://www.itchina8.com/bbs/viewthread.php?tid=12995发现一篇讲API&nbsp;HOOK的文章,但是,小弟看了半天没有完全弄懂,程序的原理我基本上都弄清了,但是,文章中“第一个程序”、“第二个程序”、“第三个程序”之间的关系我没有弄清楚,我把第一个程序&nbsp;Unit&nbsp;mess全部写到一个EXE中,程序运行正常,但是,当我把unit&nbsp;mess中的代码写到DLL中然后<br>exports<br>API_Hookup,Un_API_Hook;&nbsp;<br>再到EXE中调用API_Hookup却没有用,不知道应该如何解决
 
能不能简明的说一下你是怎么调用那个dll和(注意是“和”)怎么调用dll里的hook函数的
 
我用的是这种方法,不知有何问题:<br>procedure&nbsp;API_Hookup;stdcall;external&nbsp;'project1.dll';//API_Hookup在projet1.dll<br>然后再在Button1的oncick中写<br>API_Hookup<br>我还用过这种方法:<br>写一个GetMessage钩子在project2.dll,然后再HooProc中调用API_Hookup(静态调用)
 
在http://cache.baidu.com/c?word=%CF%DD%DA%E5%3B%CA%BD%3Bapihook&amp;url=http%3A//www%2Eblogcn%2Ecom/user35/sundytu/blog/21666280%2Ehtml&amp;p=c463c54ad2c402dd2aaac7710e1c91&amp;user=baidu<br>看了一篇文章,发现和网上那些常见的文章有点区别,按照文中的办法试了试,竟然成功了<br>unit&nbsp;Unit4;<br><br>interface<br>uses<br>&nbsp;&nbsp;Windows;<br><br>type<br>&nbsp;&nbsp;mymsgboxa=function(hWnd:&nbsp;HWND;&nbsp;lpText,&nbsp;lpCaption:&nbsp;PAnsiChar;&nbsp;uType:&nbsp;UINT):&nbsp;Integer;&nbsp;stdcall;<br>&nbsp;&nbsp;Tjump=packed&nbsp;record<br>&nbsp;&nbsp;&nbsp;&nbsp;jumpcode:Byte;<br>&nbsp;&nbsp;&nbsp;&nbsp;addr:mymsgboxa;<br>&nbsp;&nbsp;&nbsp;&nbsp;MoveEAX:Word;<br>&nbsp;&nbsp;&nbsp;&nbsp;reservedbyte:Byte;<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;old,jmp:Tjump;<br>&nbsp;&nbsp;processhandle:THandle;<br>&nbsp;&nbsp;oldmsgboxa:Pointer;<br>&nbsp;&nbsp;dwsize:DWORD;<br>&nbsp;&nbsp;hookhd:THandle;<br><br>procedure&nbsp;load;<br>implementation<br>function&nbsp;mybox(hWnd:&nbsp;HWND;&nbsp;lpText,&nbsp;lpCaption:&nbsp;PAnsiChar;&nbsp;uType:&nbsp;UINT):&nbsp;Integer;&nbsp;stdcall;<br>begin<br>&nbsp;&nbsp;MessageBoxW(hWnd,'APIHook成功,感谢各位高人相助','Hook&nbsp;OK',uType);<br>end;&nbsp;&nbsp;<br>procedure&nbsp;HookApi;<br>var<br>&nbsp;&nbsp;DllMoudle:THandle;<br>begin<br>&nbsp;&nbsp;processhandle:=GetCurrentProcess;<br>&nbsp;&nbsp;DllMoudle:=LoadLibrary('user32.dll');<br>&nbsp;&nbsp;oldmsgboxa:=GetProcAddress(DllMoudle,'MessageBoxA');<br>&nbsp;&nbsp;jmp.jumpcode:=$B8;<br>&nbsp;&nbsp;jmp.addr:=@mybox;<br>&nbsp;&nbsp;jmp.MoveEAX:=$E0FF;<br>&nbsp;&nbsp;ReadProcessMemory(processhandle,oldmsgboxa,@old,8,dwsize);<br>&nbsp;&nbsp;WriteProcessMemory(processhandle,oldmsgboxa,@jmp,8,dwsize);<br>end;<br>procedure&nbsp;HookEnd;<br>begin<br>&nbsp;&nbsp;WriteProcessMemory(processhandle,oldmsgboxa,@old,8,dwsize);<br>end;<br>function&nbsp;msghook(ncode,wparam,lparam:Integer):LRESULT;stdcall;<br>begin<br>&nbsp;&nbsp;hookapi;<br>&nbsp;&nbsp;Result:=CallNextHookEx(hookhd,ncode,wparam,lparam);<br>end;<br>procedure&nbsp;load;<br>begin<br>&nbsp;&nbsp;hookhd:=SetWindowsHookEx(WH_GETMESSAGE,@msghook,HInstance,0);<br>end;<br><br>end.
 
接受答案了.
 

Similar threads

后退
顶部