From c8d69685ecf0c06463c5fe4f7dc2d6351d0119d6 Mon Sep 17 00:00:00 2001 From: Wusiki Jeronii Date: Tue, 14 Apr 2026 13:10:42 +0300 Subject: [PATCH] win32_hook: preserve ordinal forwarding --- renderdoc/os/win32/win32_hook.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/renderdoc/os/win32/win32_hook.cpp b/renderdoc/os/win32/win32_hook.cpp index ca17c4be3..3a28bca7c 100644 --- a/renderdoc/os/win32/win32_hook.cpp +++ b/renderdoc/os/win32/win32_hook.cpp @@ -766,6 +766,9 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) if(mod == NULL || func == NULL || mod == s_HookData->ownmodule) return GetProcAddress(mod, func); + const LPCSTR originalRequest = func; + const bool requestIsOrdinal = OrdinalAsString((void *)originalRequest); + #if ENABLED(VERBOSE_DEBUG_HOOK) if(OrdinalAsString((void *)func)) RDCDEBUG("Hooked_GetProcAddress(%p, %p)", mod, func); @@ -813,7 +816,7 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) RDCDEBUG("Ordinal hook"); #endif - uint32_t ordinal = (uint16_t)(uintptr_t(func) & 0xffff); + uint32_t ordinal = (uint16_t)(uintptr_t(originalRequest) & 0xffff); if(ordinal < it->second.OrdinalBase) { @@ -821,7 +824,7 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) (uint32_t)it->second.OrdinalBase, it->first.c_str()); SetLastError(S_OK); - return GetProcAddress(mod, func); + return GetProcAddress(mod, originalRequest); } ordinal -= it->second.OrdinalBase; @@ -832,11 +835,17 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) (uint32_t)it->second.OrdinalNames.size(), it->first.c_str()); SetLastError(S_OK); - return GetProcAddress(mod, func); + return GetProcAddress(mod, originalRequest); } func = it->second.OrdinalNames[ordinal].c_str(); + if(func == NULL || func[0] == 0) + { + SetLastError(S_OK); + return GetProcAddress(mod, originalRequest); + } + #if ENABLED(VERBOSE_DEBUG_HOOK) RDCDEBUG("found ordinal %s", func); #endif @@ -848,7 +857,7 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) std::lower_bound(it->second.FunctionHooks.begin(), it->second.FunctionHooks.end(), search); if(found != it->second.FunctionHooks.end() && !(search < *found)) { - FARPROC realfunc = GetProcAddress(mod, func); + FARPROC realfunc = GetProcAddress(mod, requestIsOrdinal ? originalRequest : func); #if ENABLED(VERBOSE_DEBUG_HOOK) RDCDEBUG("Found hooked function, returning hook pointer %p", found->hook); @@ -870,7 +879,7 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) SetLastError(S_OK); - return GetProcAddress(mod, func); + return GetProcAddress(mod, requestIsOrdinal ? originalRequest : func); } static void InitHookData() {