Page 1 of 1

Double hook issue

Posted: Wed Sep 07, 2022 7:17 am
by rr97
Hey madshi.

We have been trying to hook both "GetKeyState" and "GetAsyncKeyState" via the "HookApi" function and we are experiencing some weird behavior.
The hook order is : 1.GetKeyState, 2.GetAsyncKeyState , The first hook is placed fine but the second one (GetAsync..) is placed only to be immediately removed because of the "double hook" detection in the following code:

Image

(I have confirmed that this is the case by simply debugging it and stepping into it)
The machine is Win 10 X64 bit.

Both of this API's reside in the same module. (Which is USER32.dll)
If we only hook one of them then it works fine, but the combination of both leads to the undesired behavior (The second API is hooked only to be unhooked)

Any suggestions? are we missing something?

Thanks & good day.

Re: Double hook issue

Posted: Wed Sep 07, 2022 1:12 pm
by madshi
Can you please show me your "HookAPI()" call code? Are you using the same "NextHook" function variable for both API hooks? That's usually when the "double hook" error comes up. You need to use a separate "NextHook" variable for each and every API hook.

Re: Double hook issue

Posted: Wed Sep 07, 2022 7:28 pm
by rr97
Hey thanks for the fast reply, seems like that was the issue.
Fixed and working.

Highly appreciated.

Re: Double hook issue

Posted: Fri Sep 09, 2022 1:22 am
by iconic
Glad your issue is resolved by Madshi's suggestion, for future reference, see below please =]
6. Each API hook needs its own callback function and its own "NextHook" variable. Don't try to save code by using callback functions and/or NextHook variables twice.
Hooking rules can be located here: http://help.madshi.net/HookingRules.htm

--Iconic

Re: Double hook issue

Posted: Fri Sep 09, 2022 9:58 am
by madshi
Good point. The "hooking rules" are always worth a read... :D