In Win32 ApplyHooks get module baseAddress from the call to LoadLibrary

If the module is unloaded, reloaded during the hooking process the base address might have changed and the original baseAddress will be pointing to invalid memory
This commit is contained in:
Jake Turner
2024-07-08 07:44:45 +01:00
parent 94212f1488
commit e4a52ffe2a
+1 -2
View File
@@ -280,8 +280,6 @@ struct CachedHookData
if(ignores.find(lowername) != ignores.end())
return;
byte *baseAddress = (byte *)module;
// the module could have been unloaded after our toolhelp snapshot, especially if we spent a
// long time
// dealing with a previous module (like adding our hooks).
@@ -296,6 +294,7 @@ struct CachedHookData
// and FreeLibrary that I want to avoid. Worst case, we load a dll, hook it, then unload it
// again.
HMODULE refcountModHandle = LoadLibraryW(modpath);
byte *baseAddress = (byte *)refcountModHandle;
PIMAGE_DOS_HEADER dosheader = (PIMAGE_DOS_HEADER)baseAddress;