From f8874bf8a0564c4545b1bc72b76d878541c2bd21 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 30 Jun 2021 20:59:07 -0600 Subject: [PATCH] add rpg maker mz hook --- texthook/engine/match64.cc | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index d743cd6..9ab8545 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -132,26 +132,44 @@ namespace Engine // 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")) + auto getV8Length = [](uintptr_t, uintptr_t data) + { + int len = *(int*)(data - 4); + return len > 0 && len < PIPE_BUFFER_SIZE ? len * 2 : 0; + }; + + uint64_t addr1 = (uint64_t)GetProcAddress(module, "?Write@String@v8@@QEBAHPEAGHHH@Z"), + // Artikash 6/7/2021: Add new hook for new version of V8 used by RPG Maker MZ + addr2 = (uint64_t)GetProcAddress(module, "??$WriteToFlat@G@String@internal@v8@@SAXV012@PEAGHH@Z"); + + if (addr1 || addr2) { std::tie(spDefault.minAddress, spDefault.maxAddress) = Util::QueryModuleLimits(module); spDefault.maxRecords = Util::SearchMemory(spDefault.pattern, spDefault.length, PAGE_EXECUTE, spDefault.minAddress, spDefault.maxAddress).size() * 20; ConsoleOutput("Textractor: JavaScript hook is known to be low quality: try searching for hooks if you don't like it"); + } + if (addr1) + { HookParam hp = {}; hp.type = USING_STRING | USING_UNICODE | DATA_INDIRECT; - hp.address = addr; + hp.address = addr1; 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 < PIPE_BUFFER_SIZE ? len * 2 : 0; - }; + hp.length_fun = getV8Length; NewHook(hp, "JavaScript"); - return true; } - return false; + if (addr2) + { + HookParam hp = {}; + hp.type = USING_STRING | USING_UNICODE; + hp.address = addr2; + hp.offset = -0x20; // rcx + hp.padding = 11; + hp.length_fun = getV8Length; + NewHook(hp, "JavaScript"); + } + return addr1 || addr2; } /** Artikash 8/10/2018: Ren'py