1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Fixed a crash in IAT hooking when encountering imports by ordinals

See issue #149.
This commit is contained in:
narzoul 2022-10-05 19:38:09 +02:00
parent 7a59458d58
commit 19899f81c9
2 changed files with 21 additions and 11 deletions

View File

@ -70,12 +70,13 @@ namespace
auto origThunk = reinterpret_cast<PIMAGE_THUNK_DATA>(moduleBase + desc->OriginalFirstThunk);
while (0 != thunk->u1.AddressOfData && 0 != origThunk->u1.AddressOfData)
{
auto origImport = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(
moduleBase + origThunk->u1.AddressOfData);
if (0 == strcmp(origImport->Name, procName))
if (!(origThunk->u1.Ordinal & IMAGE_ORDINAL_FLAG))
{
return reinterpret_cast<FARPROC*>(&thunk->u1.Function);
auto origImport = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(moduleBase + origThunk->u1.AddressOfData);
if (0 == strcmp(origImport->Name, procName))
{
return reinterpret_cast<FARPROC*>(&thunk->u1.Function);
}
}
++thunk;

View File

@ -416,11 +416,6 @@ namespace D3dDdi
void installHooks()
{
g_origSubmitPresentBltToHwQueue = reinterpret_cast<decltype(&D3DKMTSubmitPresentBltToHwQueue)>(
GetProcAddress(GetModuleHandle("gdi32"), "D3DKMTSubmitPresentBltToHwQueue"));
g_origSubmitPresentToHwQueue = reinterpret_cast<decltype(&D3DKMTSubmitPresentToHwQueue)>(
GetProcAddress(GetModuleHandle("gdi32"), "D3DKMTSubmitPresentToHwQueue"));
Compat::hookIatFunction(Dll::g_origDDrawModule, "CreateDCA", ddrawCreateDcA);
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTCloseAdapter", closeAdapter);
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTCreateDCFromMemory", createDcFromMemory);
@ -431,7 +426,21 @@ namespace D3dDdi
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTReleaseProcessVidPnSourceOwners", releaseProcessVidPnSourceOwners);
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTSetGammaRamp", setGammaRamp);
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTSetVidPnSourceOwner", setVidPnSourceOwner);
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTSubmitPresentToHwQueue", submitPresentToHwQueue);
auto gdi32 = GetModuleHandle("gdi32");
g_origSubmitPresentBltToHwQueue = reinterpret_cast<decltype(&D3DKMTSubmitPresentBltToHwQueue)>(
GetProcAddress(gdi32, "D3DKMTSubmitPresentBltToHwQueue"));
if (g_origSubmitPresentBltToHwQueue)
{
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTSubmitPresentBltToHwQueue", submitPresentBltToHwQueue);
}
g_origSubmitPresentToHwQueue = reinterpret_cast<decltype(&D3DKMTSubmitPresentToHwQueue)>(
GetProcAddress(gdi32, "D3DKMTSubmitPresentToHwQueue"));
if (g_origSubmitPresentToHwQueue)
{
Compat::hookIatFunction(Dll::g_origDDrawModule, "D3DKMTSubmitPresentToHwQueue", submitPresentToHwQueue);
}
Dll::createThread(&vsyncThreadProc, nullptr, THREAD_PRIORITY_TIME_CRITICAL);
}