From 90733bf2f2354b6c375e7dacdad6412b61471379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1871535768@qq.com> Date: Wed, 28 Feb 2024 23:33:52 +0800 Subject: [PATCH] 5pb? and fix --- LunaHook/embed_util.cc | 25 ++++++++++++++++---- LunaHook/engine32/5pb.cpp | 48 +++++++++++++++++++++++++++++++++++---- LunaHook/texthook.cc | 9 ++++---- include/texthook.h | 1 + 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/LunaHook/embed_util.cc b/LunaHook/embed_util.cc index df2deee..4402b62 100644 --- a/LunaHook/embed_util.cc +++ b/LunaHook/embed_util.cc @@ -6,6 +6,7 @@ #include"hijackfuns.h" #include"winevent.hpp" #include"defs.h" +#include"stringfilters.h" DynamicShiftJISCodec *dynamiccodec=new DynamicShiftJISCodec(932); @@ -201,16 +202,30 @@ bool waitforevent(UINT32 timems,const ThreadParam& tp,const std::wstring &origin } return false; } + +void TextHook::parsenewlineseperator(void*data ,size_t*len) +{ + if(!(hp.type&EMBED_ABLE && hp.newlineseperator))return; + + if (hp.type & CODEC_UTF16) + { + StringReplacer((wchar_t*)data,len,hp.newlineseperator,wcslen(hp.newlineseperator),L"\n",1); + } + else if(hp.type&CODEC_UTF32) return; + else + { + //ansi/utf8,newlineseperator都是简单字符 + std::string newlineseperatorA; + for(int i=0;icodepage)) origin=t.value(); else return false; if(origin.size()>1000)return false; - if(hp.newlineseperator){ - strReplace(origin,hp.newlineseperator,L"\n"); - cast_back(hp,data,len,origin,true); - } - TextOutput(tp, buffer, *len); std::wstring translate; if(translatecache.find(origin)!=translatecache.end()){ diff --git a/LunaHook/engine32/5pb.cpp b/LunaHook/engine32/5pb.cpp index 41eebb2..8e56b9f 100644 --- a/LunaHook/engine32/5pb.cpp +++ b/LunaHook/engine32/5pb.cpp @@ -519,10 +519,7 @@ bool InsertKaleidoHook() ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); - if (!addr) { - ConsoleOutput("Kaleido: pattern not found"); - return false; - } + if (!addr) return false; HookParam hp; hp.address = addr + addr_offset; @@ -605,9 +602,52 @@ namespace return NewHook(hp, "5bp"); } } // namespace name +namespace{ + bool __2() + { + //レヱル・ロマネスク origin 多国語版 + //https://vndb.org/r119877 + //char __thiscall sub_426B70(float *this, int a2, int a3, int a4, int a5, char a6, char a7) + BYTE bytes[]={ + 0x0f,0xb7,0x04,0x72, + 0x46, + 0x89,0x85,XX4, + 0x0f,0xb7,0xc0, + 0x83,0xc0,0xf6, + 0x83,0xf8,0x52, + 0x0f,0x87 + }; + auto addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress); + if(!addr)return false; + addr=MemDbg::findEnclosingAlignedFunction_strict(addr); + if(!addr)return false; + HookParam hp; + hp.address = addr; + hp.offset=get_stack(1); + hp.split=get_stack(2); + hp.type = USING_SPLIT|USING_STRING | CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE|EMBED_AFTER_NEW;//中文显示不出来 + hp.filter_fun = [](LPVOID data, size_t* size, HookParam*) { + //そうして、[おひとよ,2]御一夜――\n眼下に広がるこの町も、僕を間違いなく救ってくれた。 + //「行政に関しての最大の変化は、市長です。\n現在の市長には[ひない,1]雛衣・ポーレットが就任しています」 + //「なるほど。それゆえ、御一夜は衰退し、\n\x%lエアクラ;#00ffc040;エアクラ%l;#;工場の誘致話が持ち上がったわけか?」 + //「ナビ。お前も\x%lエアクラ;#00ffc040;エアクラ%l;#;の仲間だったな。\n気を悪くしたか?」 + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + auto xx=std::wstring(text,*len/2); + xx = std::regex_replace(xx, std::wregex(L"\\[(.*?),\\d\\]"), L"$1"); + xx = std::regex_replace(xx, std::wregex(L"\\\\x%l(.*?);(.*?);(.*?);#;"), L"$1"); + *len=xx.size()*2; + wcscpy(text,xx.c_str()); + return true; + }; + hp.newlineseperator=L"\\n"; + return NewHook(hp, "5bp"); + } +} bool _5pb_2::attach_function() { bool ___1 = __1() || __(); + ___1|=__2(); return InsertKaleidoHook() || ___1; } \ No newline at end of file diff --git a/LunaHook/texthook.cc b/LunaHook/texthook.cc index a51405d..2119a43 100644 --- a/LunaHook/texthook.cc +++ b/LunaHook/texthook.cc @@ -193,6 +193,11 @@ void TextHook::Send(uintptr_t lpDataBase) buffer->type=hp.type; ThreadParam tp{ GetCurrentProcessId(), address, lpRetn, lpSplit }; + + parsenewlineseperator(pbData, &lpCount); + + TextOutput(tp, buffer, lpCount); + if((hp.type&EMBED_ABLE)&&(check_embed_able(tp))) { auto lpCountsave=lpCount; @@ -216,10 +221,6 @@ void TextHook::Send(uintptr_t lpDataBase) hp.hook_after(stack,pbData,lpCount); } } - else - { - TextOutput(tp, buffer, lpCount); - } } __except (EXCEPTION_EXECUTE_HANDLER) { diff --git a/include/texthook.h b/include/texthook.h index 2758dd9..eec49f3 100644 --- a/include/texthook.h +++ b/include/texthook.h @@ -55,6 +55,7 @@ private: void RemoveHookCode(); void RemoveReadCode(); bool waitfornotify(TextOutput_T* buffer,void*data ,size_t*len,ThreadParam tp); + void parsenewlineseperator(void*data ,size_t*len); volatile DWORD useCount; ALIGNPTR(uint64_t __1,HANDLE readerThread); ALIGNPTR(uint64_t __2,HANDLE readerEvent);