Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when dll memory loadlibrary dll will be crash! #13

Open
warsark opened this issue Sep 7, 2022 · 1 comment
Open

when dll memory loadlibrary dll will be crash! #13

warsark opened this issue Sep 7, 2022 · 1 comment

Comments

@warsark
Copy link

warsark commented Sep 7, 2022

1.the test.exe memload a.dll
2.a.dll compile with memorymodulepp.lib
3.in a.dll dllmain DLL_PROCESS_ATTACH memload b.dll

if use test.exe memlod b.dll it's ok!
but use test.exe memload a.dll,in a.dll memload b.dll will crash in test.exe call a.dllmain

I comment //static const BOOL MmpStaticInitializer = MmpInitialize();
then call MmpInitialize before LdrLoadDllMemoryExW
the a.dll load successful, but a.dll call MmpInitialize crash
auto tls = CONTAINING_RECORD(NtCurrentTeb()->ThreadLocalStoragePointer, TLS_VECTOR, TLS_VECTOR::ModuleTlsData);
if (tls && tls->Length > MMP_START_TLS_INDEX) {
RtlRaiseStatus(STATUS_NOT_SUPPORTED);-->crash here
return FALSE;
}

@bb107
Copy link
Owner

bb107 commented Sep 7, 2022

Hi. MMP maintains a private TLS list internally to support TLS without locating the LdrpHandleTlsData routine by signature. The MMP will take over the TlsVector for all threads in the process, so it can only be initialized once. If you must link statically in a different module, use the previous version of MMP that did not handle TLS.
A good practice is to always link the MMP in the exe file and expose the MMP API as a function pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants