Created
September 1, 2016 16:15
-
-
Save Cauterite/b190e62891c773703d0de3a1d99df362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- */ | |
import Dll_ = core.sys.windows.dll; | |
import W32_ = core.sys.windows.windows; | |
/* -------------------------------------------------------------------------- */ | |
/* --- runtime initialisation --- */ | |
version (CRuntime_DigitalMars) {} else {static assert(0);}; | |
pragma(mangle, `__acrtused_dll`) extern __gshared void* CrtData; | |
pragma(startaddress, raw_entrypoint); | |
void raw_entrypoint() { | |
asm { | |
naked; | |
/* jump to _DllMainCRTStartup */ | |
lea EAX, CrtData; | |
mov EAX, [EAX + 12]; | |
sub EAX, 0x4e; | |
jmp EAX; | |
}; | |
}; | |
/* this will be called by _DllMainCRTStartup */ | |
pragma(mangle, `DllMain`) extern(Windows) int dll_entrypoint( | |
void* Inst, uint Reason, void* | |
) { | |
switch (Reason) { | |
case W32_.DLL_PROCESS_ATTACH : { | |
Dll_.dll_process_attach(Inst, true); | |
}; break; | |
case W32_.DLL_PROCESS_DETACH : { | |
Dll_.dll_process_detach(Inst, true); | |
}; break; | |
case W32_.DLL_THREAD_ATTACH : { | |
Dll_.dll_thread_attach( true, true); | |
}; break; | |
case W32_.DLL_THREAD_DETACH : { | |
Dll_.dll_thread_detach(true, true); | |
}; break; | |
default : break; | |
}; | |
return 1; | |
}; | |
/* -------------------------------------------------------------------------- */ | |
/+ | |
+/ | |
/* -------------------------------------------------------------------------- */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment