Skip to content

Commit d6a7e60

Browse files
wusikijeroniibaldurk
authored andcommitted
win32_hook: use local search name in Hooked_GetProcAddress ordinal path
1 parent 5461f52 commit d6a7e60

1 file changed

Lines changed: 29 additions & 42 deletions

File tree

renderdoc/os/win32/win32_hook.cpp

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,11 @@ static bool OrdinalAsString(void *func)
761761
return uint64_t(func) <= 0xffff;
762762
}
763763

764-
FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR const func)
764+
FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, const LPCSTR func)
765765
{
766766
if(mod == NULL || func == NULL || mod == s_HookData->ownmodule)
767767
return GetProcAddress(mod, func);
768768

769-
const LPCSTR originalRequest = func;
770-
const bool requestIsOrdinal = OrdinalAsString((void *)originalRequest);
771-
772769
#if ENABLED(VERBOSE_DEBUG_HOOK)
773770
if(OrdinalAsString((void *)func))
774771
RDCDEBUG("Hooked_GetProcAddress(%p, %p)", mod, func);
@@ -818,63 +815,53 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR const func)
818815
RDCDEBUG("Ordinal hook");
819816
#endif
820817

821-
uint32_t ordinal = (uint16_t)(uintptr_t(originalRequest) & 0xffff);
818+
uint32_t ordinal = (uint16_t)(uintptr_t(func) & 0xffff);
822819

823820
if(ordinal < it->second.OrdinalBase)
824821
{
825822
RDCERR("Unexpected ordinal - lower than ordinalbase %u for %s",
826823
(uint32_t)it->second.OrdinalBase, it->first.c_str());
827-
searchFunc = NULL;
824+
825+
SetLastError(S_OK);
826+
return GetProcAddress(mod, func);
828827
}
829-
else
828+
829+
ordinal -= it->second.OrdinalBase;
830+
831+
if(ordinal >= it->second.OrdinalNames.size())
830832
{
831-
ordinal -= it->second.OrdinalBase;
833+
RDCERR("Unexpected ordinal - higher than fetched ordinal names (%u) for %s",
834+
(uint32_t)it->second.OrdinalNames.size(), it->first.c_str());
832835

833-
if(ordinal >= it->second.OrdinalNames.size())
834-
{
835-
RDCERR("Unexpected ordinal - higher than fetched ordinal names (%u) for %s",
836-
(uint32_t)it->second.OrdinalNames.size(), it->first.c_str());
837-
searchFunc = NULL;
838-
}
839-
else
840-
{
841-
searchFunc = it->second.OrdinalNames[ordinal].c_str();
836+
SetLastError(S_OK);
837+
return GetProcAddress(mod, func);
838+
}
839+
840+
searchFunc = it->second.OrdinalNames[ordinal].c_str();
842841

843-
if(searchFunc && searchFunc[0] != 0)
844-
{
845842
#if ENABLED(VERBOSE_DEBUG_HOOK)
846-
RDCDEBUG("found ordinal %s", searchFunc);
843+
RDCDEBUG("found ordinal %s", searchFunc);
847844
#endif
848-
}
849-
else
850-
{
851-
searchFunc = NULL;
852-
}
853-
}
854-
}
855845
}
856846

857-
if(searchFunc && searchFunc[0] != 0)
858-
{
859-
FunctionHook search(searchFunc, NULL, NULL);
847+
FunctionHook search(searchFunc, NULL, NULL);
860848

861-
auto found = std::lower_bound(it->second.FunctionHooks.begin(),
862-
it->second.FunctionHooks.end(), search);
863-
if(found != it->second.FunctionHooks.end() && !(search < *found))
864-
{
865-
FARPROC realfunc = GetProcAddress(mod, requestIsOrdinal ? originalRequest : searchFunc);
849+
auto found =
850+
std::lower_bound(it->second.FunctionHooks.begin(), it->second.FunctionHooks.end(), search);
851+
if(found != it->second.FunctionHooks.end() && !(search < *found))
852+
{
853+
FARPROC realfunc = GetProcAddress(mod, func);
866854

867855
#if ENABLED(VERBOSE_DEBUG_HOOK)
868-
RDCDEBUG("Found hooked function, returning hook pointer %p", found->hook);
856+
RDCDEBUG("Found hooked function, returning hook pointer %p", found->hook);
869857
#endif
870858

871-
SetLastError(S_OK);
859+
SetLastError(S_OK);
872860

873-
if(realfunc == NULL)
874-
return NULL;
861+
if(realfunc == NULL)
862+
return NULL;
875863

876-
return (FARPROC)found->hook;
877-
}
864+
return (FARPROC)found->hook;
878865
}
879866
}
880867
}
@@ -885,7 +872,7 @@ FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR const func)
885872

886873
SetLastError(S_OK);
887874

888-
return GetProcAddress(mod, requestIsOrdinal ? originalRequest : func);
875+
return GetProcAddress(mod, func);
889876
}
890877
static void InitHookData()
891878
{

0 commit comments

Comments
 (0)