From 2e691d482e599f6602931ffaa7d7514fdf838bf6 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Sun, 29 Oct 2023 23:14:10 +0100 Subject: [PATCH 1/2] Artemis x64 engine hook --- texthook/engine/match64.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index 859f746..86f6b0f 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -214,6 +214,35 @@ namespace Engine return false; } + bool InsertArtemisHook() { + //by Blu3train + /* + * Sample games: + * https://vndb.org/v45247 + */ + const BYTE bytes[] = { + 0xCC, // int 3 + 0x40, 0x57, // push rdi <- hook here + 0x48, 0x83, 0xEC, 0x40, // sub rsp,40 + 0x48, 0xC7, 0x44, 0x24, 0x30, XX4, // mov qword ptr [rsp+30],FFFFFFFFFFFFFFFE + 0x48, 0x89, 0x5C, 0x24, 0x50 // mov [rsp+50],rbx + }; + + ULONG64 range = min(processStopAddress - processStartAddress, X64_MAX_REL_ADDR); + for (auto addr : Util::SearchMemory(bytes, sizeof(bytes), PAGE_EXECUTE, processStartAddress, processStartAddress + range)) { + HookParam hp = {}; + hp.address = addr + 1; + hp.offset = -0x44 -4; //RDI + hp.type = USING_STRING | USING_UTF8 | NO_CONTEXT; + ConsoleOutput("vnreng: INSERT Artemis Hook "); + NewHook(hp, "Artemis"); + return true; + } + + ConsoleOutput("vnreng:Artemis: pattern not found"); + return false; + } + bool UnsafeDetermineEngineType() { if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true; @@ -228,6 +257,11 @@ namespace Engine return true; } + if (Util::CheckFile(L"*.pfs")) { + InsertArtemisHook(); + return true; + } + if (Util::CheckFile(L"*.py") && InsertRenpyHook()) return true; for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll" }) if (HMODULE module = GetModuleHandleW(monoName)) if (InsertMonoHooks(module)) return true; From 9c6383d9917d9c198618fb26e18c963d93e507b8 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Sun, 29 Oct 2023 23:27:31 +0100 Subject: [PATCH 2/2] fixed code --- texthook/engine/match64.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index 86f6b0f..4551a46 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -7,8 +7,13 @@ #include "engine.h" #include "util.h" +#define XX2 XX,XX // WORD +#define XX4 XX2,XX2 // DWORD +#define XX8 XX4,XX4 // QWORD + namespace Engine { + enum : DWORD { X64_MAX_REL_ADDR = 0x00300000 }; /** Artikash 6/7/2019 * PPSSPP JIT code has pointers, but they are all added to an offset before being used. Find that offset so that hook searching works properly.