From 74ac1c944eee1cfdf4e0b8d1c3c388c8d3921d0c Mon Sep 17 00:00:00 2001 From: ttttupup Date: Sat, 6 Apr 2024 23:37:50 +0800 Subject: [PATCH] feat: controller --- app/wxhelper/src/hook_controller.cc | 16 +++++++ app/wxhelper/src/hook_controller.h | 18 ++++++++ app/wxhelper/src/sync_msg_hook.cc | 67 +++++++++++++++++++++++++++++ app/wxhelper/src/sync_msg_hook.h | 15 +++++++ 4 files changed, 116 insertions(+) create mode 100644 app/wxhelper/src/hook_controller.cc create mode 100644 app/wxhelper/src/hook_controller.h create mode 100644 app/wxhelper/src/sync_msg_hook.cc create mode 100644 app/wxhelper/src/sync_msg_hook.h diff --git a/app/wxhelper/src/hook_controller.cc b/app/wxhelper/src/hook_controller.cc new file mode 100644 index 0000000..bdff1ce --- /dev/null +++ b/app/wxhelper/src/hook_controller.cc @@ -0,0 +1,16 @@ +#include "hook_controller.h" + +#include "json_utils.h" +#include "nlohmann/json.hpp" +#include "sync_msg_hook.h" + +namespace jsonutils = wxhelper::jsonutils; +namespace wxhelper { +std::string HookController::HookSyncMsg(std::string params) { + SyncMsgHook::GetInstance().Init(); + int success = SyncMsgHook::GetInstance().Hook(); + nlohmann::json ret_data = { + {"code", success}, {"data", {}}, {"msg", "success"}}; + return ret_data.dump(); +} +} // namespace wxhelper \ No newline at end of file diff --git a/app/wxhelper/src/hook_controller.h b/app/wxhelper/src/hook_controller.h new file mode 100644 index 0000000..771625a --- /dev/null +++ b/app/wxhelper/src/hook_controller.h @@ -0,0 +1,18 @@ +#ifndef WXHELPER_HOOK_CONTROLLER_H_ +#define WXHELPER_HOOK_CONTROLLER_H_ + +#include "http_controller.h" + +namespace wxhelper { +class HookController : public http::HttpController { + public: + PATHS_BEGIN + ADD_PATH("/api/hookSyncMsg", HookSyncMsg); + PATHS_END + + public: + static std::string HookSyncMsg(std::string params); +}; +} // namespace wxhelper + +#endif \ No newline at end of file diff --git a/app/wxhelper/src/sync_msg_hook.cc b/app/wxhelper/src/sync_msg_hook.cc new file mode 100644 index 0000000..6795a07 --- /dev/null +++ b/app/wxhelper/src/sync_msg_hook.cc @@ -0,0 +1,67 @@ +#include "sync_msg_hook.h" + +#include "base64.h" +#include "config.h" +#include "nlohmann/json.hpp" +#include "offset.h" +#include "spdlog/spdlog.h" +#include "thread_pool.h" +#include "utils.h" +#include "wechat_interface.h" +#include "wxutils.h" + +namespace wxhelper { + +void SyncMsgHook::Init() { + int64_t addr = wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg; + wechat::function::__DoAddMsg addMsg = (wechat::function::__DoAddMsg)addr; + origin_ = addMsg; + detour_ = &HandleSyncMsg; +} + +void SyncMsgHook::HandleSyncMsg(INT64 param1, INT64 param2, INT64 param3) { + nlohmann::json msg; + + msg["pid"] = GetCurrentProcessId(); + msg["fromUser"] = + wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x18)); + msg["toUser"] = + wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x28)); + msg["content"] = + wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x30)); + msg["signature"] = + wxhelper::wxutils::ReadWeChatStr(*(INT64 *)(param2 + 0x48)); + msg["msgId"] = *(INT64 *)(param2 + 0x60); + msg["msgSequence"] = *(DWORD *)(param2 + 0x5C); + msg["createTime"] = *(DWORD *)(param2 + 0x58); + msg["displayFullContent"] = + wxhelper::wxutils::ReadWeChatStr(*(INT64 *)(param2 + 0x50)); + DWORD type = *(DWORD *)(param2 + 0x24); + msg["type"] = type; + if (type == 3) { + std::string img = + wxhelper::wxutils::ReadSKBuiltinBuffer(*(INT64 *)(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 = wxhelper::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); + } + int64_t addr = + wxhelper::wxutils::GetWeChatWinBase() + wechat::offset::kDoAddMsg; + wechat::function::__DoAddMsg addMsg = (wechat::function::__DoAddMsg)addr; + addMsg(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 new file mode 100644 index 0000000..5a88be0 --- /dev/null +++ b/app/wxhelper/src/sync_msg_hook.h @@ -0,0 +1,15 @@ +#ifndef WXHELPER_SYNC_MSG_HOOK_H_ +#define WXHELPER_SYNC_MSG_HOOK_H_ +#include "hook.h" +#include "singleton.h" +namespace wxhelper{ +class SyncMsgHook : public hook::BaseHook,public base::Singleton { + public: + void Init(); + private: + static void HandleSyncMsg(INT64 param1, INT64 param2, INT64 param3); +}; + +} + +#endif \ No newline at end of file