From b873ecbc96ade9a6e11da5e2e6d7898965dd8236 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sun, 27 Jan 2019 03:04:16 -0500 Subject: [PATCH] add d3dx hooks --- vnrhook/engine/match.cc | 5 ++++ vnrhook/engine/native/pchooks.cc | 46 ++++++++++++++++++++++++++++++++ vnrhook/engine/native/pchooks.h | 1 + 3 files changed, 52 insertions(+) diff --git a/vnrhook/engine/match.cc b/vnrhook/engine/match.cc index 3b154a6..ca4e9f0 100644 --- a/vnrhook/engine/match.cc +++ b/vnrhook/engine/match.cc @@ -84,6 +84,11 @@ bool DeterminePCEngine() // return true; //} + for (std::wstring DXVersion : { L"d3dx9", L"d3dx10" }) + if (HMODULE module = GetModuleHandleW(DXVersion.c_str())) PcHooks::hookD3DXFunctions(module); + else for (int i = 0; i < 50; ++i) + if (HMODULE module = GetModuleHandleW((DXVersion + L"_" + std::to_wstring(i)).c_str())) PcHooks::hookD3DXFunctions(module); + if (GetProcAddress((HMODULE)processStartAddress, "?Write@String@v8@@QBEHPAGHHH@Z")) InsertV8Hook((HMODULE)processStartAddress); if (HMODULE module = GetModuleHandleW(L"node.dll")) diff --git a/vnrhook/engine/native/pchooks.cc b/vnrhook/engine/native/pchooks.cc index e25d9d2..9665ca4 100644 --- a/vnrhook/engine/native/pchooks.cc +++ b/vnrhook/engine/native/pchooks.cc @@ -153,6 +153,52 @@ void PcHooks::hookGDIPlusFunctions() NEW_MODULE_HOOK(hModule, GdipMeasureDriverString, s_arg1, 0,s_arg3,0, USING_UNICODE|USING_STRING, s_arg2 / arg_sz) } + +bool PcHooks::hookD3DXFunctions(HMODULE d3dxModule) +{ + ConsoleOutput("Textractor: inserting Direct3D hooks (EXPERIMENTAL)"); + uintptr_t createFont = (uintptr_t)GetProcAddress(d3dxModule, "D3DXCreateFontIndirectA"); + if (!createFont) createFont = (uintptr_t)GetProcAddress(d3dxModule, "D3DX10CreateFontIndirectA"); + if (!createFont) + { + ConsoleOutput("Textractor: D3DX failed: couldn't find entry function"); + return false; + } + + struct D3DXFont + { + uintptr_t(*vtable)[20]; + DWORD data[2000]; + } font; + for (int i = 0, calls = 0; i < 100; ++i) + { + if (*(BYTE*)(createFont + i) == 0xe8) ++calls; + if (calls == 2) + { + union + { + void(D3DXFont::*ctor)(); + uintptr_t addr; + } fuckTheTypeSystem; + fuckTheTypeSystem.addr = *(uintptr_t*)(createFont + i + 1) + createFont + i + 5; + (font.*(fuckTheTypeSystem.ctor))(); + + HookParam hp = {}; + hp.address = (*font.vtable)[14]; + hp.offset = s_arg3; + hp.length_offset = s_arg4 / arg_sz; + hp.type = USING_STRING; + NewHook(hp, "ID3DXFont::DrawTextA"); + hp.address = (*font.vtable)[15]; + hp.type = USING_STRING | USING_UNICODE; + NewHook(hp, "ID3DXFont::DrawTextW"); + return true; + } + } + ConsoleOutput("Textractor: D3DX failed: couldn't find vtable"); + return false; +} + // jichi 10/2/2013 // Note: All functions does not have NO_CONTEXT attribute and will be filtered. void PcHooks::hookOtherPcFunctions() diff --git a/vnrhook/engine/native/pchooks.h b/vnrhook/engine/native/pchooks.h index 60eac25..2510a7b 100644 --- a/vnrhook/engine/native/pchooks.h +++ b/vnrhook/engine/native/pchooks.h @@ -7,6 +7,7 @@ namespace PcHooks { void hookGDIFunctions(); void hookGDIPlusFunctions(); +void hookD3DXFunctions(HMODULE d3dxModule); void hookOtherPcFunctions(); } // namespace PcHooks