From fe9c9435c5270463d81180c9965f29ca3aa3a9bc Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Mon, 29 Jul 2019 01:50:20 -0400 Subject: [PATCH] more reliable shinario hook --- texthook/engine/engine.cc | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index c4bd6c2..9749b13 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -60,11 +60,12 @@ enum { VNR_TEXT_CAPACITY = 1500 }; // estimated max number of bytes allowed in V namespace { // unnamed helpers - template bool StackSearchingTrigger(LPVOID funcAddr, DWORD, DWORD stack) + template + bool StackSearchingTrigger(LPVOID funcAddr, DWORD, DWORD stack) { bool ret = false; if (funcAddr != funcA && funcAddr != funcW) return false; - for (int i = 0; i < 100; ++i) + for (int i = 0; i < depth; ++i) { // Address of text is somewhere on stack in call to func. Search for it. DWORD addr = *((DWORD*)stack + i); @@ -79,7 +80,7 @@ namespace { // unnamed helpers hp.address = addr; ConsoleOutput("Textractor: triggered: adding dynamic reader"); NewHook(hp, "READ"); - ret = true; + //ret = true; } }; } @@ -5788,6 +5789,12 @@ int GetShinaRioVersion() return ret; } +bool IsSJIS(char* text) +{ + for (int i = 0; i < 3; ++i) if (!IsDBCSLeadByte(text[i * 2])) return false; + return true; +} + } // unnamed namespace // jichi 8/24/2013: Rewrite ShinaRio logic. @@ -5797,7 +5804,31 @@ bool InsertShinaHook() int ver = GetShinaRioVersion(); if (ver >= 50) { SetTrigger(); - trigger_fun = StackSearchingTrigger; + //trigger_fun = StackSearchingTrigger; + trigger_fun = [](LPVOID funcAddr, DWORD, DWORD stack) + { + bool ret = false; + if (funcAddr != GetGlyphOutlineA) return false; + for (int i = 0; i < 100; ++i) + { + // Address of text is somewhere on stack in call to func. Search for it. + DWORD addr = *((DWORD*)stack + i); + //ConsoleOutput(std::to_string((DWORD)*addr).c_str()); + if (IthGetMemoryRange((void*)addr, nullptr, nullptr) && strlen((char*)addr) > 9) + { + if (IsSJIS((char*)addr) || strstr((char*)addr, "_r")) + { + HookParam hp = {}; + hp.type = DIRECT_READ; + hp.address = addr; + ConsoleOutput("Textractor: triggered: adding dynamic reader"); + NewHook(hp, "READ"); + ret = true; + } + }; + } + return ret; + }; ConsoleOutput("Textractor: ShinaRio 2.50+: adding trigger"); return true; }