From 3b3c903f212b8a4d65c0632523585cd55c21bdc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sat, 16 Nov 2024 22:41:34 +0800 Subject: [PATCH] fix --- cpp/LunaHook/LunaHook/engine32/WillPlus.cpp | 115 +++++++++++------- cpp/LunaHook/LunaHook/enginecontrol.cpp | 4 +- .../LunaHook/engines/pchooks/pchooks.cpp | 35 ++++-- 3 files changed, 94 insertions(+), 60 deletions(-) diff --git a/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp b/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp index 37463e30..df5345ca 100644 --- a/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp +++ b/cpp/LunaHook/LunaHook/engine32/WillPlus.cpp @@ -1666,40 +1666,8 @@ namespace WillPlusEngine namespace { - static bool InsertWillPlus4() + bool InsertWillPlus5() { - // by Blu3train - /* - * Sample games: - * https://vndb.org/r71235 - */ - const BYTE bytes[] = { - 0x33, 0xC9, // xor ecx,ecx <-- hook - 0x8B, 0xC7, // mov eax,edi - 0xC7, 0x84, 0x24, XX4, XX4, // mov [esp+000001E0],00000007 - 0x89, 0x9C, 0x24, XX4 // mov [esp+000001DC],ebx - }; - ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); - ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); - if (!addr) - { - ConsoleOutput("WillPlus4: pattern not found"); - return false; - } - - HookParam hp = {}; - hp.address = addr; - hp.offset = get_reg(regs::edi); - hp.type = CODEC_UTF16 | USING_STRING; - hp.filter_fun = WillPlus_extra_filter; - ConsoleOutput("INSERT WillPlus4"); - NewHook(hp, "WillPlus4"); - return true; - } - - static bool InsertWillPlus5() - { - // by Blu3train /* * Sample games: * https://vndb.org/v29881 @@ -1728,19 +1696,78 @@ namespace hp.type = CODEC_UTF16 | USING_STRING | NO_CONTEXT | USING_SPLIT; hp.filter_fun = WillPlus_extra_filter; ConsoleOutput("INSERT WillPlus5"); - NewHook(hp, "WillPlus5"); - return true; + return NewHook(hp, "WillPlus5"); } - bool _xxx() +} +namespace +{ + bool h7() { - bool ok = false; - ok = InsertWillPlus4() || ok; - ok = InsertWillPlus5() || ok; - return ok; + /* + v20 = *(unsigned __int16 *)v19; + sub_43B730((int)v37, a4, v20, &v33); + if ( v20 - 58942 > 0x119 ) + { + if ( v33.gmCellIncX ) + { + v24 = v39; + *a8 = v33.gmCellIncX; + a8[1] = v24; + goto LABEL_25; + } + gmCellIncX = v39; + gmCellIncY = v33.gmCellIncY; + } + else + { + sub_43B730((int)v37, a4, 0x8AADu, &v33); + */ + const BYTE bytes[] = { + 0x8d, XX, 0xc2, 0x19, 0xff, 0xff, // lea ecx, [edi-0xe63e] + 0x81, XX, 0x19, 0x01, 0x00, 0x00, // cmp ecx,0x119 + 0x77, XX, // ja xx + XX4, // lea edx,[esp+34] + XX, // push edx + XX, 0xad, 0x8a, 0x00, 0x00 // mov edi,0x8aad + }; + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress); + if (!addr) + return false; + int offset = 0; + switch ((*(BYTE *)(addr + 1)) & 0x7) + { + case 0x7: + offset = get_reg(regs::edi); + break; + case 0x6: + offset = get_reg(regs::esi); + break; + case 0x5: + offset = get_reg(regs::ebp); + break; + case 0x3: + offset = get_reg(regs::ebx); + break; + case 0x2: + offset = get_reg(regs::edx); + break; + case 0x1: + offset = get_reg(regs::ecx); + break; + case 0x0: + offset = get_reg(regs::eax); + break; + default: + return false; + } + HookParam hp = {}; + hp.address = addr; + hp.offset = offset; + hp.type = CODEC_UTF16 | USING_CHAR; + return NewHook(hp, "WillPlus7"); } } - bool WillPlus::attach_function() { bool succ = WillPlusEngine::attach(); @@ -1749,10 +1776,8 @@ bool WillPlus::attach_function() succ |= InsertWillPlus5Hook(); succ |= insertwillplus6(); succ |= willX(); - succ |= _xxx(); - PcHooks::hookGDIFunctions(GetGlyphOutlineA); - PcHooks::hookGDIFunctions(GetGlyphOutlineW); - return succ; + succ |= InsertWillPlus5(); + return succ || h7(); } bool Willold::attach_function() diff --git a/cpp/LunaHook/LunaHook/enginecontrol.cpp b/cpp/LunaHook/LunaHook/enginecontrol.cpp index 7acb3a5e..a278f5c5 100644 --- a/cpp/LunaHook/LunaHook/enginecontrol.cpp +++ b/cpp/LunaHook/LunaHook/enginecontrol.cpp @@ -86,8 +86,8 @@ bool checkengine() bool matched = safematch(m); bool attached = matched && safeattach(m); - // ConsoleOutput("Progress %d/%d, checked engine %s, %s",current,total,m->getenginename(),infomations[matched+attached]); - // ConsoleOutput("Progress %d/%d, %s",current,total,infomations[matched+attached]); + //ConsoleOutput("Progress %d/%d, checked engine %s, %s",current,engines.size(),m->getenginename(),infomations[matched+attached]); + //ConsoleOutput("Progress %d/%d, %s",current,engines.size(),infomations[matched+attached]); if (matched == false) continue; ConsoleOutput(MatchedEngine, m->getenginename()); diff --git a/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp b/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp index 853cdfc9..3d8dc15f 100644 --- a/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp +++ b/cpp/LunaHook/LunaHook/engines/pchooks/pchooks.cpp @@ -12,7 +12,8 @@ // #define LPASTE(s) L##s // #define L(s) LPASTE(s) -Synchronized> hookonce; +std::set hookonce; +std::mutex hookoncelock; #define NEW_HOOK(ptr, _dll, _fun, _data, _data_ind, _split_off, _split_ind, _type, _len_off) \ { \ HookParam hp; \ @@ -25,15 +26,19 @@ Synchronized> hookonce; hp.type = _type | MODULE_OFFSET | FUNCTION_OFFSET; \ hp.length_offset = _len_off; \ auto currptr = GetModuleHandle(hp.module) ? GetProcAddress(GetModuleHandle(hp.module), hp.function) : nullptr; \ - bool dohook = false; \ - if (ptr) \ - dohook = currptr == ptr; \ - else if (currptr) \ - dohook = hookonce->find(currptr) == hookonce->end(); \ - if (dohook) \ + if (currptr) \ { \ - NewHook(hp, #_fun); \ - hookonce->insert(currptr); \ + bool dohook = false; \ + std::lock_guard _(hookoncelock); \ + if (ptr) \ + dohook = currptr == ptr; \ + else \ + dohook = hookonce.find(currptr) == hookonce.end(); \ + if (dohook) \ + { \ + NewHook(hp, #_fun); \ + hookonce.insert(currptr); \ + } \ } \ } @@ -51,11 +56,15 @@ Synchronized> hookonce; hp.type = _type | MODULE_OFFSET | FUNCTION_OFFSET; \ hp.length_offset = _len_off; \ auto currptr = GetProcAddress(_module, hp.function); \ - auto dohook = currptr ? hookonce->find(currptr) == hookonce->end() : false; \ - if (dohook) \ + if (currptr) \ { \ - NewHook(hp, #_fun); \ - hookonce->insert(currptr); \ + std::lock_guard _(hookoncelock); \ + auto dohook = currptr ? hookonce.find(currptr) == hookonce.end() : false; \ + if (dohook) \ + { \ + NewHook(hp, #_fun); \ + hookonce.insert(currptr); \ + } \ } \ }