From b32d3278425da5cf72663cd9114fbd7475452b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:30:04 +0800 Subject: [PATCH] fix --- LunaHook/main.cc | 11 ++++++++++- LunaHost/host.cpp | 5 ++++- include/hookcode.cpp | 2 +- include/stringutils.cpp | 4 ++-- include/stringutils.h | 4 ++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/LunaHook/main.cc b/LunaHook/main.cc index bd26932..4dca0b2 100644 --- a/LunaHook/main.cc +++ b/LunaHook/main.cc @@ -104,7 +104,16 @@ void ConsoleOutput(LPCSTR text, ...) void NotifyHookFound(HookParam hp, wchar_t *text) { - wcscpy_s(hp.hookcode, HOOKCODE_LEN, HookCode::Generate(hp, GetCurrentProcessId()).c_str()); + if (hp.jittype == JITTYPE::PC) + if (!(hp.type & MODULE_OFFSET)) + if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId())) + if (MEMORY_BASIC_INFORMATION info = {}; VirtualQueryEx(process, (LPCVOID)hp.address, &info, sizeof(info))) + { + + hp.type |= MODULE_OFFSET; + hp.address -= (uint64_t)info.AllocationBase; + wcsncpy_s(hp.module, processName, ARRAYSIZE(hp.module)); + } HookFoundNotif buffer(hp, text); WriteFile(hookPipe, &buffer, sizeof(buffer), DUMMY, nullptr); } diff --git a/LunaHost/host.cpp b/LunaHost/host.cpp index 484abf0..0de8010 100644 --- a/LunaHost/host.cpp +++ b/LunaHost/host.cpp @@ -102,7 +102,10 @@ namespace auto info = *(HookFoundNotif*)buffer; auto OnHookFound = processRecordsByIds->at(processId).OnHookFound; std::wstring wide = info.text; - if (wide.size() > STRING) OnHookFound(info.hp, std::move(info.text)); + if (wide.size() > STRING) { + wcscpy_s(info.hp.hookcode,HOOKCODE_LEN, HookCode::Generate(info.hp, processId).c_str()); + OnHookFound(info.hp, std::move(info.text)); + } info.hp.type &= ~CODEC_UTF16; if (auto converted = StringToWideString((char*)info.text, info.hp.codepage)) if (converted->size() > STRING) diff --git a/include/hookcode.cpp b/include/hookcode.cpp index 11c516f..12455ec 100644 --- a/include/hookcode.cpp +++ b/include/hookcode.cpp @@ -394,7 +394,7 @@ namespace if (hp.type & MODULE_OFFSET) HCode += L':' + std::wstring(hp.module); if (hp.type & FUNCTION_OFFSET) - HCode += L':' + StringToWideString(hp.function); + HCode += L':' + acastw(hp.function); } else { diff --git a/include/stringutils.cpp b/include/stringutils.cpp index 5d25c16..54d755b 100644 --- a/include/stringutils.cpp +++ b/include/stringutils.cpp @@ -215,7 +215,7 @@ size_t u32strlen(uint32_t *data) return s; } -std::string wcasta(const std::wstring x) +std::string wcasta(const std::wstring& x) { std::string xx; for (auto c : x) @@ -223,7 +223,7 @@ std::string wcasta(const std::wstring x) return xx; } -std::wstring acastw(const std::string x) +std::wstring acastw(const std::string& x) { std::wstring xx; for (auto c : x) diff --git a/include/stringutils.h b/include/stringutils.h index 60bb4f9..e8bd909 100644 --- a/include/stringutils.h +++ b/include/stringutils.h @@ -33,8 +33,8 @@ std::string WideStringToString(const std::wstring &text, UINT cp = CP_UTF8); std::wstring StringToWideString(const std::string &text); std::optional StringToWideString(const std::string &text, UINT encoding); -std::string wcasta(const std::wstring x); -std::wstring acastw(const std::string x); +std::string wcasta(const std::wstring& x); +std::wstring acastw(const std::string& x); size_t u32strlen(uint32_t *data); inline bool disable_mbwc = false; inline bool disable_wcmb = false;