Check out my newly published blog post about DLL injection, thread local storage, TLS callbacks, and the problems that all these can cause. The blog post also shows how a thread can avoid invoking TLS callbacks, and that it can lead to other problems.
Conversation
Well, the WriteProcessMemory + CreateRemoteThread + LoadLibrary combo worked fairly well for me so far. What I describe in the blog post is an exceptional incompatibility, but generally I'm not sure there's a better alternative with the same level of flexibility.
1
I meant, flexible on the side of what I can inject. Windhawk is a modular customization framework, anyone can write mods to any programs. I wouldn't want to constrain devs to using ntdll, forcing to adhere to the DllMain limits, etc. But it might be a good tradeoff for others.
1
BTW regarding "an exceptional incompatibility", I'm no longer sure about that. Just today, a user showed a similar crash in a TLS callback. My findings (from the Windhawk Discord channel) are below. Seems that it's sometimes not safe to create threads before CRT is initialized.
1
1
Except that here, unlike DllMain, I can't know when I'm in this (CRT initialization) context, can I? It's just non-remarkable code that runs at the beginning, no locks/mutexts I can grab and use. The best I can do is wait a bit before CreateThread and hope for the best.
1
Show replies

