Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions renderdoc/os/win32/win32_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -813,15 +816,15 @@ 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)
{
RDCERR("Unexpected ordinal - lower than ordinalbase %u for %s",
(uint32_t)it->second.OrdinalBase, it->first.c_str());

SetLastError(S_OK);
return GetProcAddress(mod, func);
return GetProcAddress(mod, originalRequest);
}

ordinal -= it->second.OrdinalBase;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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()
{
Expand Down
Loading