aboutsummaryrefslogtreecommitdiff
path: root/primedev/windows
diff options
context:
space:
mode:
Diffstat (limited to 'primedev/windows')
-rw-r--r--primedev/windows/libsys.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/primedev/windows/libsys.cpp b/primedev/windows/libsys.cpp
index 501eae68..0aff820b 100644
--- a/primedev/windows/libsys.cpp
+++ b/primedev/windows/libsys.cpp
@@ -18,15 +18,31 @@ ILoadLibraryExW o_LoadLibraryExW = nullptr;
//-----------------------------------------------------------------------------
void LibSys_RunModuleCallbacks(HMODULE hModule)
{
+ // Modules that we have already ran callbacks for.
+ // Note: If we ever hook unloading modules, then this will need updating to handle removal etc.
+ static std::vector<HMODULE> vCalledModules;
+
if (!hModule)
{
return;
}
+ // If we have already ran callbacks for this module, don't run them again.
+ if (std::find(vCalledModules.begin(), vCalledModules.end(), hModule) != vCalledModules.end())
+ {
+ return;
+ }
+ vCalledModules.push_back(hModule);
+
// Get module base name in ASCII as noone wants to deal with unicode
CHAR szModuleName[MAX_PATH];
GetModuleBaseNameA(GetCurrentProcess(), hModule, szModuleName, MAX_PATH);
+ // Run calllbacks for all imported modules
+ CModule cModule(hModule);
+ for (const std::string& svImport : cModule.GetImportedModules())
+ LibSys_RunModuleCallbacks(GetModuleHandleA(svImport.c_str()));
+
// DevMsg(eLog::NONE, "%s\n", szModuleName);
// Call callbacks