diff --git a/app/wxhelper/src/sync_msg_hook.cc b/app/wxhelper/src/sync_msg_hook.cc index aa5ba6e..2d0553b 100644 --- a/app/wxhelper/src/sync_msg_hook.cc +++ b/app/wxhelper/src/sync_msg_hook.cc @@ -10,54 +10,64 @@ #include "wxutils.h" -namespace wxhelper { +namespace wxhelper +{ -void SyncMsgHook::Init() { - int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg; - kDoAddMsg = (wechat::function::__DoAddMsg)addr; - origin_ = &kDoAddMsg; - detour_ = &HandleSyncMsg; - hook_flag_ = false; -} - -void SyncMsgHook::HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3) { - nlohmann::json msg; - - msg["pid"] = GetCurrentProcessId(); - msg["fromUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x18)); - msg["toUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x28)); - msg["content"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x30)); - msg["signature"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x48)); - msg["msgId"] = *(int64_t *)(param2 + 0x60); - msg["msgSequence"] = *(DWORD *)(param2 + 0x5C); - msg["createTime"] = *(DWORD *)(param2 + 0x58); - msg["displayFullContent"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x50)); - DWORD type = *(DWORD *)(param2 + 0x24); - msg["type"] = type; - if (type == 3) { - std::string img = wxutils::ReadSKBuiltinBuffer(*(int64_t *)(param2 + 0x40)); - SPDLOG_INFO("encode size:{}", img.size()); - msg["base64Img"] = base64_encode(img); - } - std::string jstr = msg.dump() + '\n'; - hook::InnerMessageStruct *inner_msg = new hook::InnerMessageStruct; - inner_msg->buffer = new char[jstr.size() + 1]; - memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1); - inner_msg->length = jstr.size(); - std::string mode = Config::GetInstance().GetRecvMessageMode(); - if (mode == "http") { - bool add = base::ThreadPool::GetInstance().AddWork( - hook::SendHttpMsgCallback, inner_msg); - SPDLOG_INFO("add http msg work:{}", add); - } else if (mode == "tcp") { - bool add = base::ThreadPool::GetInstance().AddWork(hook::SendTcpMsgCallback, - inner_msg); - SPDLOG_INFO("add tcp msg work:{}", add); - } - if (kDoAddMsg == nullptr){ + void SyncMsgHook::Init() + { int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg; kDoAddMsg = (wechat::function::__DoAddMsg)addr; + origin_ = &kDoAddMsg; + detour_ = &HandleSyncMsg; + hook_flag_ = false; } - kDoAddMsg(param1, param2, param3); -} -} // namespace wxhelper \ No newline at end of file + + void SyncMsgHook::HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3) + { + nlohmann::json msg; + + msg["pid"] = GetCurrentProcessId(); + msg["fromUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x18)); + msg["toUser"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x28)); + msg["content"] = wxutils::ReadSKBuiltinString(*(int64_t *)(param2 + 0x30)); + msg["signature"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x48)); + msg["msgId"] = *(int64_t *)(param2 + 0x60); + msg["msgSequence"] = *(DWORD *)(param2 + 0x5C); + msg["createTime"] = *(DWORD *)(param2 + 0x58); + msg["displayFullContent"] = wxutils::ReadWeChatStr(*(int64_t *)(param2 + 0x50)); + DWORD type = *(DWORD *)(param2 + 0x24); + msg["type"] = type; + if (type == 3) + { + std::string img = wxutils::ReadSKBuiltinBuffer(*(int64_t *)(param2 + 0x40)); + SPDLOG_INFO("encode size:{}", img.size()); + msg["base64Img"] = base64_encode(img); + } + std::string jstr = msg.dump() + '\n'; + hook::InnerMessageStruct *inner_msg = new hook::InnerMessageStruct; + inner_msg->buffer = new char[jstr.size() + 1]; + memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1); + inner_msg->length = jstr.size(); + std::string mode = Config::GetInstance().GetRecvMessageMode(); + if (mode == "http") + { + bool add = base::ThreadPool::GetInstance().AddWork( + hook::SendHttpMsgCallback, inner_msg); + SPDLOG_INFO("add http msg work:{}", add); + } + else if (mode == "tcp") + { + bool add = base::ThreadPool::GetInstance().AddWork(hook::SendTcpMsgCallback, + inner_msg); + wxhelper::wxutils::print_utf8_to_console("add tcp msg work:" + std::to_string(add)); + + SPDLOG_INFO("add tcp msg work:{}", add); + } + if (kDoAddMsg == nullptr) + { + int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg; + kDoAddMsg = (wechat::function::__DoAddMsg)addr; + } + kDoAddMsg(param1, param2, param3); + } +} // namespace wxhelper \ No newline at end of file diff --git a/app/wxhelper/src/sync_msg_hook.h b/app/wxhelper/src/sync_msg_hook.h index 9566e56..b1babb0 100644 --- a/app/wxhelper/src/sync_msg_hook.h +++ b/app/wxhelper/src/sync_msg_hook.h @@ -1,17 +1,36 @@ -#ifndef WXHELPER_SYNC_MSG_HOOK_H_ +// 防止头文件重复包含,确保整个程序中只被包含一次 +#ifndef WXHELPER_SYNC_MSG_HOOK_H_ #define WXHELPER_SYNC_MSG_HOOK_H_ -#include "hook.h" -#include "singleton.h" -#include "wechat_interface.h" -namespace wxhelper{ -static wechat::function::__DoAddMsg kDoAddMsg= nullptr; -class SyncMsgHook : public hook::BaseHook,public base::Singleton { - public: - void Init(); - private: - static void HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3); -}; +// 引入hook.h,该头文件定义了hook相关函数和类 +#include "hook.h" +// 引入singleton.h,该头文件提供了单例模式的实现 +#include "singleton.h" +// 引入wechat_interface.h,该头文件定义了微信相关接口 +#include "wechat_interface.h" + +// 定义wxhelper命名空间,用于组织wxhelper相关的代码和类 +namespace wxhelper { + // 声明一个静态成员变量kDoAddMsg,它是一个函数指针,指向微信的__DoAddMsg函数 + // 该变量初始值为nullptr,表示未设置指向任何函数 + static wechat::function::__DoAddMsg kDoAddMsg = nullptr; + + // 定义SyncMsgHook类,它继承自hook::BaseHook和base::Singleton + // BaseHook可能提供了hook相关的方法和属性 + // Singleton模板确保SyncMsgHook类只有一个实例 + class SyncMsgHook : public hook::BaseHook, public base::Singleton { + public: + // 定义一个公共成员函数Init,用于初始化SyncMsgHook类 + void Init(); + private: + // 定义一个私有静态成员函数HandleSyncMsg,用于处理同步消息 + // 该函数接收三个int64_t类型的参数param1、param2、param3 + static void HandleSyncMsg(int64_t param1, int64_t param2, int64_t param3); + }; + + // 通过Singleton模板,可以获取SyncMsgHook类的唯一实例 + // 例如:auto syncMsgHook = wxhelper::SyncMsgHook::GetInstance(); } +// 结束头文件的声明 #endif \ No newline at end of file