Hooking problem
-
I need to hook the user32.dll function for my process only. My application is running multiple worker threads which are hosting 3rd party STA component which is calling hooked function where I need to override it's default implementation. I've tried to do this: - created my function using exactly same parameters and definition as original function - save originl function's address - created critical section cs - saved first 5 bytes of original code and replaced by jmp _my_function (5 bytes code) my finction:
LONG retVal;
EnterCriticalSection(&cs);
// restore original code at original function
retVal = CallOriginal();
// restore jmp inftruction
LeaveCriticalSection(&cs);
return retVal;The problem is that when I'm running more than one workng threads, it will crash after some random time. Do you have idea what could be wrong? Is there some problem with this design? Thank you! PS. EnterCriticalSection() seems to be working, because when I remove LeaveCriticalSection(), there is a deadlock.
rrrado