Open AraHaan opened 3 months ago
Hello, is the above code the original version of MemoryModule? As far as I know, the original version does not support TLS. The missing functions such as MemoryGetProcAddress
you mentioned are required by the original version. The MemoryModule implemented in this repo is compatible with Win32 API, such as MemoryGetProcAddress
can be directly replaced by GetProcAddress
function.
Hello, is the above code the original version of MemoryModule? As far as I know, the original version does not support TLS. The missing functions such as
MemoryGetProcAddress
you mentioned are required by the original version. The MemoryModule implemented in this repo is compatible with Win32 API, such asMemoryGetProcAddress
can be directly replaced byGetProcAddress
function.
I think so, it is a copy of the one from py2exe.
If this is the case, you need to modify MemoryModule to call the unexported ntdll!LdrpHandleTlsData
function to handle TLS before calling DllMain. Since it is not exported, you need to locate it through signatures or debug symbols.
@bb107
If this is the case, you need to modify MemoryModule to call the unexported ntdll!LdrpHandleTlsData function to handle TLS before calling DllMain. Since it is not exported, you need to locate it through signatures or debug symbols.
I see that this project, Blackbone, jector, and probably many other all resorted to load this unexported symbol from ntdll
. Conversely, nobody tried to reimplement this function. Do you have any idea why? Is doing this so difficult? My uneducated guess is that the gist is easy but the devil lies in the details/in the peculiar cases...
@bb107
If this is the case, you need to modify MemoryModule to call the unexported ntdll!LdrpHandleTlsData function to handle TLS before calling DllMain. Since it is not exported, you need to locate it through signatures or debug symbols.
I see that this project, Blackbone, jector, and probably many other all resorted to load this unexported symbol from
ntdll
. Conversely, nobody tried to reimplement this function. Do you have any idea why? Is doing this so difficult? My uneducated guess is that the gist is easy but the devil lies in the details/in the peculiar cases...
For starters x64 cannot __asm
as I have tried to __declspec(naked)
it for inline ASM.
I could just paste the asm code inside of an asm file but it would require some fixups and probably dumping of even more internal only ntdll.dll symbols for it to work as well.
Also when I tried this I got an access violation instantly from inside the function call, and then I realized I had to fake up the __thiscall
because in C you do not have c++ classes and as such cannot use __thiscall
in non-member functions unless you use inline ASM to fake it. Oh wait Microsoft messed us over on using inline asm on x64 when needing to compile :joy:.
You can't use assembly code directly because it contains relocation code. Implementing this function requires hooking some functions to complete, which may bring uncertainty.
You can use asmjit for x64
I have a usecase forthese apis as drop in replacement for :
That implements full TLS support. The reason why is that I need to load python's core dll file (3.14) from a
void *
pointer obtained fromLockResource
, however since Python 3.12 the Python Core Developers force__declspec(thread)
in parts of their codebase so now when I go to load the dll it causes an access violation when it even attempts to call it'sDllMain
function.