Skip to content

Commit

Permalink
Pin real dll module and current module
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 11, 2024
1 parent bf1bcad commit cf3c659
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7137
#define BUILD_NUMBER 7138
12 changes: 8 additions & 4 deletions Dllmain/Dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
// Get handle
hModule_dll = hModule;

// Pin current module
HMODULE dummy = nullptr;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCSTR>(DllMain), &dummy);

// Initialize config
Config.Init();

Expand Down Expand Up @@ -235,6 +231,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
HMODULE dll = Wrapper::CreateWrapper((Config.RealDllPath.size()) ? Config.RealDllPath.c_str() : nullptr, (Config.WrapperMode.size()) ? Config.WrapperMode.c_str() : nullptr, Config.WrapperName.c_str());
if (dll)
{
// Pin real dll module
HMODULE dummy = nullptr;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCSTR>(dll), &dummy);

Utils::AddHandleToVector(dll, Config.WrapperName.c_str());

// Hook GetProcAddress to handle wrapped functions that are missing or not available in the OS
Expand All @@ -247,6 +247,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
}
}

// Pin current module
HMODULE dummy = nullptr;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCSTR>(DllMain), &dummy);

// Launch processes
if (!Config.RunProcess.empty())
{
Expand Down

0 comments on commit cf3c659

Please sign in to comment.