在http://cache.baidu.com/c?word=%CF%DD%DA%E5%3B%CA%BD%3Bapihook&url=http%3A//www%2Eblogcn%2Ecom/user35/sundytu/blog/21666280%2Ehtml&p=c463c54ad2c402dd2aaac7710e1c91&user=baidu<br>看了一篇文章,发现和网上那些常见的文章有点区别,按照文中的办法试了试,竟然成功了<br>unit Unit4;<br><br>interface<br>uses<br> Windows;<br><br>type<br> mymsgboxa=function(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall;<br> Tjump=packed record<br> jumpcode:Byte;<br> addr:mymsgboxa;<br> MoveEAX:Word;<br> reservedbyte:Byte;<br> end;<br><br>var<br> old,jmp:Tjump;<br> processhandle:THandle;<br> oldmsgboxa
ointer;<br> dwsize
WORD;<br> hookhd:THandle;<br><br>procedure load;<br>implementation<br>function mybox(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall;<br>begin<br> MessageBoxW(hWnd,'APIHook成功,感谢各位高人相助','Hook OK',uType);<br>end; <br>procedure HookApi;<br>var<br> DllMoudle:THandle;<br>begin<br> processhandle:=GetCurrentProcess;<br> DllMoudle:=LoadLibrary('user32.dll');<br> oldmsgboxa:=GetProcAddress(DllMoudle,'MessageBoxA');<br> jmp.jumpcode:=$B8;<br> jmp.addr:=@mybox;<br> jmp.MoveEAX:=$E0FF;<br> ReadProcessMemory(processhandle,oldmsgboxa,@old,8,dwsize);<br> WriteProcessMemory(processhandle,oldmsgboxa,@jmp,8,dwsize);<br>end;<br>procedure HookEnd;<br>begin<br> WriteProcessMemory(processhandle,oldmsgboxa,@old,8,dwsize);<br>end;<br>function msghook(ncode,wparam,lparam:Integer):LRESULT;stdcall;<br>begin<br> hookapi;<br> Result:=CallNextHookEx(hookhd,ncode,wparam,lparam);<br>end;<br>procedure load;<br>begin<br> hookhd:=SetWindowsHookEx(WH_GETMESSAGE,@msghook,HInstance,0);<br>end;<br><br>end.