The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: InfamousBytes on July 28, 2008, 11:36:40 PM

Title: API Hooking
Post by: InfamousBytes on July 28, 2008, 11:36:40 PM
Well, trying to hook MessageBoxA more for the hell of it than anything else, and I have narrowed down the problem to my generic hook function. The problem is that instead of writing the address ot my own proc after writing the jmp, it writes the totally wrong address. Here's my code:

HookFxn proc AddrFxn:DWORD, AddrNewFxn:DWORD, AddrStoreVar:DWORD

mov ebx, AddrFxn
mov AddrStoreVar, ebx
invoke WriteMem, AddrFxn, addr JmpByte, 1
mov ebx, AddrFxn
inc ebx
invoke WriteMem, ebx, AddrFxn, 4
ret

HookFxn endp


Thanks for any suggestions.
Title: Re: API Hooking
Post by: PBrennick on July 30, 2008, 03:24:14 AM
InfamousBytes,

For hooking a Message Box, use the MessageProc API with the MSGF_DIALOGBOX for the hook code. This hook code is used when the input event occurred in a message box or dialog box.

Hope this helps,
-- Paul
Title: Re: API Hooking
Post by: Vortex on July 31, 2008, 05:05:16 PM
Hi InfamousBytes,

Here, you can find how to hook a message box :

http://www.masm32.com/board/index.php?topic=7375.0