Created
December 18, 2019 15:44
-
-
Save jthuraisamy/61a4d5468087261711bfa1627868b730 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 os.path | |
import pefile | |
print('#pragma once') | |
target_dll = r'target.dll' | |
pe = pefile.PE(target_dll) | |
for export in pe.DIRECTORY_ENTRY_EXPORT.symbols: | |
if export.name: | |
name = export.name.decode() | |
ordinal = export.ordinal | |
basename = os.path.splitext(os.path.basename(target_dll))[0].replace('.', '_') | |
print(f'#pragma comment(linker, "/export:{name}={basename}0.{name},@{ordinal}")') | |
print(''' | |
VOID StartRoutine() { | |
} | |
BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved) | |
{ | |
switch (fdwReason) | |
{ | |
case DLL_PROCESS_ATTACH: | |
if (!::OpenMutexA(SYNCHRONIZE, TRUE, ".text$mm")) | |
{ | |
::CreateMutexA(NULL, TRUE, ".text$mm"); | |
::CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)StartRoutine, nullptr, 0, nullptr); | |
} | |
case DLL_THREAD_ATTACH: | |
case DLL_THREAD_DETACH: | |
case DLL_PROCESS_DETACH: | |
break; | |
} | |
return TRUE; | |
} | |
''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment