From 68c65bbea6c28676d8f5921d2f75e87ee4ead61c Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 27 Jun 2019 12:41:15 +0530 Subject: [PATCH] x64 v8/javascript/tyranobuilder hook --- texthook/engine/match32.cc | 12 +++++++++++- texthook/engine/match64.cc | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index a0bd47a..c98e93e 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -65,12 +65,22 @@ bool DeterminePCEngine() 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")) + if (GetProcAddress((HMODULE)processStartAddress, "?Write@String@v8@@QBEHPAGHHH@Z")) + { InsertV8Hook((HMODULE)processStartAddress); + return true; + } if (HMODULE module = GetModuleHandleW(L"node.dll")) + { InsertV8Hook(module); + return true; + } + if (HMODULE module = GetModuleHandleW(L"nw.dll")) + { InsertV8Hook(module); + return true; + } if (InsertMonoHooks()) { return true; diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index d4a35a8..6a2144f 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -90,7 +90,7 @@ namespace Engine HookParam hp = {}; hp.address = addr; hp.type = USING_STRING | USING_UNICODE; - hp.offset = -0x20; + hp.offset = -0x20; // rcx hp.padding = 20; hp.length_fun = [](uintptr_t, uintptr_t data) { @@ -115,10 +115,35 @@ namespace Engine return ret; } + // Artikash 6/23/2019: V8 (JavaScript runtime) has rcx = string** at v8::String::Write + // sample game https://www.freem.ne.jp/dl/win/18963 + bool InsertV8Hook(HMODULE module) + { + if (uint64_t addr = (uint64_t)GetProcAddress(module, "?Write@String@v8@@QEBAHPEAGHHH@Z")) + { + HookParam hp = {}; + hp.type = USING_STRING | USING_UNICODE | DATA_INDIRECT; + hp.address = addr; + hp.offset = -0x20; // rcx + hp.index = 0; + hp.padding = 23; + hp.length_fun = [](uintptr_t, uintptr_t data) + { + int len = *(int*)(data - 4); + return len > 0 && len < 1000 ? len * 2 : 0; + }; + NewHook(hp, "JavaScript"); + return true; + } + return false; + } + bool UnsafeDetermineEngineType() { if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true; + for (const wchar_t* moduleName : { (const wchar_t*)NULL, L"node.dll", L"nw.dll" }) if (InsertV8Hook(GetModuleHandleW(moduleName))) return true; + for (const wchar_t* monoName : { L"mono", L"mono-2.0-bdwgc" }) if (HMODULE module = GetModuleHandleW(monoName)) if (InsertMonoHooks(module)) return true; for (std::wstring DXVersion : { L"d3dx9", L"d3dx10" })