From e4a52ffe2ac17723705829d3e95380d3807eda17 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Mon, 8 Jul 2024 07:44:45 +0100 Subject: [PATCH] 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 --- renderdoc/os/win32/win32_hook.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/renderdoc/os/win32/win32_hook.cpp b/renderdoc/os/win32/win32_hook.cpp index 50db1a183..303f094cc 100644 --- a/renderdoc/os/win32/win32_hook.cpp +++ b/renderdoc/os/win32/win32_hook.cpp @@ -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;