UnhookCode blocks the process

c++ / delphi package - dll injection and api hooking
Post Reply
pisto
Posts: 2
Joined: Thu Mar 13, 2008 6:59 am

UnhookCode blocks the process

Post by pisto »

I coded a dll that hooks a function in the process that was injected into. The hooked function is a thiscall, but since I'm using gcc I declared the hooking function stdcall, and it works, because ecx isn't spoilt before I call the hooked function inside my hook.
The problem is that when I close the program, DllMain is called with reason==DLL_PROCESS_DETACH, and in this case I unhook the function of the main program where the dll is injected (i know it's useless since the program is going to exit, but the dll could be detached at anytime). When I call UnhookCode(), the thread blocks and doesn't let the process to exit, so I have to kill it with the taskmanager.

what's the problem?

edit: the same happens with UnhookAPI. I forgot to say that madchook is loaded by the launcher that either launch the process and inject the dll
Post Reply