From 3658796a00fb415116337a293403cb9dd98ed67b Mon Sep 17 00:00:00 2001 From: Changhua Date: Mon, 17 Feb 2025 00:42:41 +0800 Subject: [PATCH] feat(message): impl wechat log --- WeChatFerry/spy/message_handler.cpp | 20 +++++++++++++------- WeChatFerry/spy/message_handler.h | 1 + WeChatFerry/spy/offsets.h | 5 +++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/WeChatFerry/spy/message_handler.cpp b/WeChatFerry/spy/message_handler.cpp index 3bf9882..2039525 100644 --- a/WeChatFerry/spy/message_handler.cpp +++ b/WeChatFerry/spy/message_handler.cpp @@ -6,10 +6,11 @@ #include "framework.h" +#include "account_manager.h" #include "log.hpp" +#include "offsets.h" #include "pb_util.h" #include "rpc_helper.h" -#include "account_manager.h" #include "util.h" extern QWORD g_WeChatWinDllAddr; @@ -37,6 +38,8 @@ extern QWORD g_WeChatWinDllAddr; namespace message { +namespace OsMsg = Offsets::Message; + QWORD Handler::DispatchMsg(QWORD arg1, QWORD arg2) { auto &handler = getInstance(); @@ -190,13 +193,15 @@ int Handler::EnableLog() { if (isLogging) return 1; - funcWxLog = reinterpret_cast(g_WeChatWinDllAddr + OS_WXLOG); + funcWxLog = reinterpret_cast(g_WeChatWinDllAddr + OsMsg::LOG); + pLogLevel = reinterpret_cast(g_WeChatWinDllAddr + OsMsg::LOG_LEVEL); if (InitializeHook() != MH_OK) return -1; - if (MH_CreateHook(funcWxLog, &PrintWxLog, reinterpret_cast(&realWxLog)) != MH_OK) return -1; - if (MH_EnableHook(funcWxLog) != MH_OK) return -1; + if (MH_CreateHook(funcWxLog, &PrintWxLog, reinterpret_cast(&realWxLog)) != MH_OK) return -2; + if (MH_EnableHook(funcWxLog) != MH_OK) return -3; - isLogging = true; + *pLogLevel = 0; + isLogging = true; return 0; } @@ -204,8 +209,9 @@ int Handler::DisableLog() { if (!isLogging) return 1; if (MH_DisableHook(funcWxLog) != MH_OK) return -1; - if (UninitializeHook() != MH_OK) return -1; - isLogging = false; + if (UninitializeHook() != MH_OK) return -2; + *pLogLevel = 6; + isLogging = false; return 0; } diff --git a/WeChatFerry/spy/message_handler.h b/WeChatFerry/spy/message_handler.h index c4227ec..2937b11 100644 --- a/WeChatFerry/spy/message_handler.h +++ b/WeChatFerry/spy/message_handler.h @@ -55,6 +55,7 @@ private: using funcWxLog_t = QWORD (*)(QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD); using funcRecvPyq_t = QWORD (*)(QWORD, QWORD, QWORD); + uint32_t *pLogLevel; funcWxLog_t funcWxLog, realWxLog; funcRecvMsg_t funcRecvMsg, realRecvMsg; funcRecvPyq_t funcRecvPyq, realRecvPyq; diff --git a/WeChatFerry/spy/offsets.h b/WeChatFerry/spy/offsets.h index 05f61e5..02625b9 100644 --- a/WeChatFerry/spy/offsets.h +++ b/WeChatFerry/spy/offsets.h @@ -16,6 +16,11 @@ namespace Account constexpr uint64_t LOGIN = 0x7F8; // 登录状态 } +namespace Message +{ + constexpr uint64_t LOG = 0x261B890; // 日志函数 + constexpr uint64_t LOG_LEVEL = 0x56E4244; // 日志级别 +} } #endif // OFFSETS_H