diff --git a/cpp/LunaHook/LunaHook/engine64/rpcs3.cpp b/cpp/LunaHook/LunaHook/engine64/rpcs3.cpp index c7e92861..2841dc7f 100644 --- a/cpp/LunaHook/LunaHook/engine64/rpcs3.cpp +++ b/cpp/LunaHook/LunaHook/engine64/rpcs3.cpp @@ -156,7 +156,7 @@ namespace struct emfuncinfo { uint64_t type; - int argidx; + int offset; int padding; decltype(HookParam::text_fun) hookfunc; decltype(HookParam::filter_fun) filterfun; @@ -192,7 +192,7 @@ namespace hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type; hpinternal.text_fun = op.hookfunc; hpinternal.filter_fun = op.filterfun; - hpinternal.argidx = op.argidx; + hpinternal.offset = op.offset; hpinternal.padding = op.padding; hpinternal.jittype = JITTYPE::RPCS3; NewHook(hpinternal, op._id); diff --git a/cpp/LunaHook/LunaHook/engine64/vita3k.cpp b/cpp/LunaHook/LunaHook/engine64/vita3k.cpp index 726a6f72..b1793496 100644 --- a/cpp/LunaHook/LunaHook/engine64/vita3k.cpp +++ b/cpp/LunaHook/LunaHook/engine64/vita3k.cpp @@ -30,7 +30,7 @@ namespace struct emfuncinfo { uint64_t type; - int argidx; + int offset; int padding; decltype(HookParam::text_fun) hookfunc; decltype(HookParam::filter_fun) filterfun; @@ -117,10 +117,12 @@ bool vita3k::attach_function() HookParam hpinternal; hpinternal.address = entrypoint; hpinternal.emu_addr = em_address; // 用于生成hcode - hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type; + hpinternal.type = NO_CONTEXT | BREAK_POINT | op.type; + if (!(op.type & USING_CHAR)) + hpinternal.type |= USING_STRING; hpinternal.text_fun = op.hookfunc; hpinternal.filter_fun = op.filterfun; - hpinternal.argidx = op.argidx; + hpinternal.offset = op.offset; hpinternal.padding = op.padding; hpinternal.jittype = JITTYPE::VITA3K; NewHook(hpinternal, op._id); @@ -245,6 +247,14 @@ namespace s = std::regex_replace(s, std::regex(R"(\\n)"), ""); buffer->from(s); } + void PCSG00530(TextBuffer *buffer, HookParam *) + { + StringFilter(buffer, "#n", 2); + } + void PCSG00833(TextBuffer *buffer, HookParam *) + { + StringFilter(buffer, u8" ", strlen(u8" ")); + } void PCSG00787(TextBuffer *buffer, HookParam *) { CharFilter(buffer, '\n'); @@ -301,6 +311,29 @@ namespace Trim(ws); buffer->from(WideStringToString(ws)); } + void PCSG01011(hook_stack *stack, HookParam *hp, TextBuffer *buffer, uintptr_t *split) + { + auto address = VITA3K::emu_arg(stack)[7]; + while (*(char *)(address - 1)) + address -= 1; + buffer->from((char *)address); + static std::string last; + auto s = buffer->strA(); + if (s == last) + { + buffer->clear(); + last = s; + } + else + { + last = s; + strReplace(s, "\n", ""); + auto pos = s.find(u8"×"); + if (pos != s.npos) + s = s.substr(pos + strlen(u8"×")); + buffer->from(s); + } + } void PCSG00912(hook_stack *stack, HookParam *hp, TextBuffer *buffer, uintptr_t *split) { auto address = VITA3K::emu_arg(stack)[1]; @@ -616,6 +649,15 @@ namespace {0x8002BB78, {CODEC_UTF8, 0, 0, 0, PCSG00787, "PCSG00787"}}, // zip安装版 // ニセコイ ヨメイリ!? {0x8189e60c, {CODEC_UTF8, 4, 0, 0, 0, "PCSG00397"}}, + // DIABOLIK LOVERS DARK FATE + {0x8002CF8E, {0, 1, 0, 0, PCSG00530, "PCSG00530"}}, + // DIABOLIK LOVERS LOST EDEN + {0x8007443E, {0, 0, 0, 0, 0, "PCSG00910"}}, + // NORN9 ACT TUNE + {0x8001E288, {CODEC_UTF8, 0, 0, 0, PCSG00833, "PCSG00833"}}, + // 空蝉の廻 + {0x82535242, {CODEC_UTF16 | USING_CHAR | DATA_INDIRECT, 1, 0, 0, 0, "PCSG01011"}}, // 后缀有人名,需要额外过滤 + {0x801AE35A, {CODEC_UTF8, 7, 0, PCSG01011, 0, "PCSG01011"}}, }; return 1; }(); diff --git a/cpp/LunaHook/LunaHook/engine64/yuzu.cpp b/cpp/LunaHook/LunaHook/engine64/yuzu.cpp index 6f99a8f8..c7ab5d49 100644 --- a/cpp/LunaHook/LunaHook/engine64/yuzu.cpp +++ b/cpp/LunaHook/LunaHook/engine64/yuzu.cpp @@ -46,7 +46,7 @@ namespace struct emfuncinfo { uint64_t type; - int argidx; + int offset; int padding; decltype(HookParam::text_fun) hookfunc; decltype(HookParam::filter_fun) filterfun; @@ -204,7 +204,7 @@ bool yuzu::attach_function() hpinternal.type |= USING_STRING; hpinternal.text_fun = op.hookfunc; hpinternal.filter_fun = op.filterfun; - hpinternal.argidx = op.argidx; + hpinternal.offset = op.offset; hpinternal.padding = op.padding; hpinternal.jittype = JITTYPE::YUZU; NewHook(hpinternal, ull2hex(op._id).c_str()); diff --git a/cpp/LunaHook/LunaHook/engines/mono/monocommon.hpp b/cpp/LunaHook/LunaHook/engines/mono/monocommon.hpp index 04a39ffd..2e5e0483 100644 --- a/cpp/LunaHook/LunaHook/engines/mono/monocommon.hpp +++ b/cpp/LunaHook/LunaHook/engines/mono/monocommon.hpp @@ -71,7 +71,7 @@ namespace monocommon const char *klassName; const char *name; int argsCount; - int argidx; + int offset; decltype(HookParam::text_fun) text_fun = nullptr; bool Embed = false; bool isstring = true; @@ -93,7 +93,7 @@ namespace monocommon HookParam hp; hp.address = addr; - hp.argidx = hook.argidx; + hp.offset = hook.offset; hp.text_fun = (decltype(hp.text_fun))hook.text_fun; if (hook.isstring) { diff --git a/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp b/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp index 5c75f1fd..b165bd6c 100644 --- a/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp +++ b/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp @@ -349,7 +349,7 @@ namespace ppsspp hpinternal.type = USING_STRING | NO_CONTEXT | BREAK_POINT | op.type; hpinternal.text_fun = op.hookfunc; hpinternal.filter_fun = op.filterfun; - hpinternal.argidx = op.argidx; + hpinternal.offset = op.offset; hpinternal.padding = op.padding; hpinternal.jittype = JITTYPE::PPSSPP; NewHook(hpinternal, op._id); diff --git a/cpp/LunaHook/LunaHook/engines/ppsspp/psputils.hpp b/cpp/LunaHook/LunaHook/engines/ppsspp/psputils.hpp index 6cd6630f..5750ae50 100644 --- a/cpp/LunaHook/LunaHook/engines/ppsspp/psputils.hpp +++ b/cpp/LunaHook/LunaHook/engines/ppsspp/psputils.hpp @@ -6,7 +6,7 @@ namespace ppsspp struct emfuncinfo { uint64_t type; - int argidx; + int offset; int padding; decltype(HookParam::text_fun) hookfunc; decltype(HookParam::filter_fun) filterfun; diff --git a/cpp/LunaHook/LunaHook/hookfinder.cc b/cpp/LunaHook/LunaHook/hookfinder.cc index ee0ac892..caaf1fca 100644 --- a/cpp/LunaHook/LunaHook/hookfinder.cc +++ b/cpp/LunaHook/LunaHook/hookfinder.cc @@ -1,6 +1,6 @@ #include "MinHook.h" -#define SEARCH_SJIS_UNSAFE 0 +#define DUMP_JIT_ADDR_MAP 0 namespace { SearchParam sp; @@ -10,7 +10,6 @@ namespace { uint64_t address = 0; uint64_t em_addr = 0; - int argidx = 0; intptr_t padding = 0; int offset = 0; JITTYPE jittype; @@ -134,7 +133,7 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty int length = 0, sum = 0; for (; *(uint16_t *)(str + length) && length < MAX_STRING_SIZE; length += sizeof(uint16_t)) sum += *(uint16_t *)(str + length); -#if SEARCH_SJIS_UNSAFE +#if DUMP_JIT_ADDR_MAP if (((length > STRING) || (IsDBCSLeadByteEx(932, *str))) && length < MAX_STRING_SIZE - 1) #else if (length > STRING && length < MAX_STRING_SIZE - 1) @@ -142,7 +141,7 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty { // many duplicate results with same address, offset, and third/fourth character will be found: filter them out uint64_t signature = ((uint64_t)i << 56) | ((uint64_t)(str[2] + str[3]) << 48) | address; -#if SEARCH_SJIS_UNSAFE +#if DUMP_JIT_ADDR_MAP #else if (signatureCache[signature % CACHE_SIZE] == signature) return; @@ -165,7 +164,7 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty else { records[n].em_addr = em_addr; - records[n].argidx = i; + records[n].offset = i; } for (int j = 0; j < length; ++j) @@ -290,12 +289,12 @@ void SearchForHooks_Return() hp.codepage = sp.codepage; hp.jittype = records[i].jittype; hp.padding = records[i].padding; + hp.offset = records[i].offset; if (records[i].jittype == JITTYPE::PC) { if (!records[i].address) continue; - hp.offset = records[i].offset; hp.type = CODEC_UTF16 | USING_STRING; hp.address = records[i].address; } @@ -305,7 +304,6 @@ void SearchForHooks_Return() continue; hp.emu_addr = records[i].em_addr; hp.type = CODEC_UTF16 | USING_STRING | BREAK_POINT | NO_CONTEXT; - hp.argidx = records[i].argidx; } NotifyHookFound(hp, (wchar_t *)records[i].text); if (++results % 100'000 == 0) @@ -479,7 +477,7 @@ void SearchForHooks(SearchParam spUser) } ConsoleOutput("%p %p",minemaddr,maxemaddr); ConsoleOutput("%p %p",sp.minAddress,sp.maxAddress); -#if SEARCH_SJIS_UNSAFE +#if DUMP_JIT_ADDR_MAP auto f=fopen("1.txt","a"); for(auto addr:jitaddr2emuaddr){ fprintf(f,"%llx => %llx\n", addr.second.second ,addr.first); diff --git a/cpp/LunaHook/LunaHook/texthook.cc b/cpp/LunaHook/LunaHook/texthook.cc index cebbfedf..4be4c6ed 100644 --- a/cpp/LunaHook/LunaHook/texthook.cc +++ b/cpp/LunaHook/LunaHook/texthook.cc @@ -190,20 +190,25 @@ uintptr_t queryrelativeret(HookParam &hp, uintptr_t retaddr) return relative; } -uintptr_t jitgetaddr(hook_stack *stack, HookParam *hp) +uintptr_t jitgetaddr(hook_stack *stack, HookParam *hp, bool offset) { + int off; + if (offset) + off = hp->offset; + else + off = hp->split; switch (hp->jittype) { #ifdef _WIN64 case JITTYPE::RPCS3: - return RPCS3::emu_arg(stack)[hp->argidx]; + return RPCS3::emu_arg(stack)[off]; case JITTYPE::VITA3K: - return VITA3K::emu_arg(stack)[hp->argidx]; + return VITA3K::emu_arg(stack)[off]; case JITTYPE::YUZU: - return YUZU::emu_arg(stack, hp->emu_addr)[hp->argidx]; + return YUZU::emu_arg(stack, hp->emu_addr)[off]; #endif case JITTYPE::PPSSPP: - return PPSSPP::emu_arg(stack)[hp->argidx]; + return PPSSPP::emu_arg(stack)[off]; default: return 0; } @@ -280,12 +285,12 @@ void TextHook::Send(uintptr_t lpDataBase) if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY) { - lpDataIn = jitgetaddr(stack, &hp); + lpDataIn = jitgetaddr(stack, &hp, true); plpdatain = (uintptr_t)&lpDataIn; } else if (hp.jittype == JITTYPE::UNITY) { - plpdatain = (uintptr_t)argidx(stack, hp.argidx); + plpdatain = (uintptr_t)argidx(stack, hp.offset); lpDataIn = *(uintptr_t *)plpdatain; } @@ -304,7 +309,10 @@ void TextHook::Send(uintptr_t lpDataBase) lpSplit = FIXED_SPLIT_VALUE; // fuse all threads, and prevent floating else if (hp.type & USING_SPLIT) { - lpSplit = *(uintptr_t *)(lpDataBase + hp.split); + if (hp.jittype != JITTYPE::PC && hp.jittype != JITTYPE::UNITY) + lpSplit = jitgetaddr(stack, &hp, false); + else + lpSplit = *(uintptr_t *)(lpDataBase + hp.split); if (hp.type & SPLIT_INDIRECT) lpSplit = *(uintptr_t *)(lpSplit + hp.split_index); } @@ -418,7 +426,7 @@ void TextHook::Send(uintptr_t lpDataBase) else if (hp.type & SPECIAL_JIT_STRING) { if (hp.jittype == JITTYPE::UNITY) - unity_ui_string_embed_fun(argidx(stack, hp.argidx), buff); + unity_ui_string_embed_fun(argidx(stack, hp.offset), buff); } } } diff --git a/cpp/LunaHook/include/hookcode.cpp b/cpp/LunaHook/include/hookcode.cpp index ce70cb90..a86d0cca 100644 --- a/cpp/LunaHook/include/hookcode.cpp +++ b/cpp/LunaHook/include/hookcode.cpp @@ -186,8 +186,6 @@ namespace return {}; HCode.erase(0, 1); HCode = HCode.substr(0, HCode.size() - wcslen(L":JIT:UNITY")); - hp.argidx = hp.offset; - hp.offset = 0; hp.address = 0; hp.type &= ~MODULE_OFFSET; hp.type &= ~FUNCTION_OFFSET; @@ -223,8 +221,6 @@ namespace if (hp.jittype != JITTYPE::PC) { hp.emu_addr = hp.address; - hp.argidx = hp.offset; - hp.offset = 0; hp.address = 0; hp.type &= ~MODULE_OFFSET; hp.type &= ~FUNCTION_OFFSET; @@ -363,14 +359,7 @@ namespace if (hp.split < 0) hp.split += 4; - if (hp.jittype == JITTYPE::PC) - { - HCode += HexString(hp.offset); - } - else - { - HCode += HexString(hp.argidx); - } + HCode += HexString(hp.offset); if (hp.type & DATA_INDIRECT) HCode += L'*' + HexString(hp.index); diff --git a/cpp/LunaHook/include/types.h b/cpp/LunaHook/include/types.h index 93dcbe5e..ecb80295 100644 --- a/cpp/LunaHook/include/types.h +++ b/cpp/LunaHook/include/types.h @@ -123,7 +123,6 @@ struct HookParam ZeroMemory(this, sizeof(HookParam)); } uint64_t emu_addr; - int argidx; JITTYPE jittype; char unityfunctioninfo[1024]; };