Well, it might not work for all cases, but it would for my hook dll. Perhaps you could add an API called IsSafeToHook(dllname, functionname) which checks the call stacks of running threads and if the API is found return FALSE. Then the caller (me) could decide whether to uninject the dll and try again later. Just an idea, it may not work, but providing guaranteed successful hooking, at least under some limited circumstances, could potentially be a valuable addition to madCodeHook. At any rate, please take it only as a suggestion.madshi wrote:In DllMain there could be lots of stuff which was already being executed before the HookAPI call finds out that the callstack of a thread is not ok. Simply unloading the dll is not really a good idea. What if all the other API hooks were already installed and are working just fine? And who guarantees that reinjection a few milliseconds later will solve the callstack problem? It might even be that the hook dll is written in a way that doesn't allow uninjection without crashing. I do have such a dll written myself. There's no problem with it, since I don't ever uninject it myself.
Cheers and Merry Christmas.
-- David