From 505eefd03ce3f1fe0311dc4adff7d20937d3b735 Mon Sep 17 00:00:00 2001 From: Changhua Date: Wed, 5 Feb 2025 16:05:40 +0800 Subject: [PATCH] Refactoring --- WeChatFerry/spy/chatroom_manager.cpp | 4 +- WeChatFerry/spy/chatroom_manager.h | 4 +- WeChatFerry/spy/contact_manager.cpp | 4 +- WeChatFerry/spy/contact_manager.h | 4 +- WeChatFerry/spy/database_executor.cpp | 4 +- WeChatFerry/spy/database_executor.h | 4 +- WeChatFerry/spy/message_handler.cpp | 43 +++++++++++---------- WeChatFerry/spy/message_handler.h | 12 ++++-- WeChatFerry/spy/message_sender.cpp | 54 ++++++++++++++------------- WeChatFerry/spy/message_sender.h | 17 ++++++--- WeChatFerry/spy/misc_manager.cpp | 8 ++-- WeChatFerry/spy/rpc_server.cpp | 26 ++++++------- WeChatFerry/spy/userinfo_manager.cpp | 4 +- WeChatFerry/spy/userinfo_manager.h | 4 +- 14 files changed, 104 insertions(+), 88 deletions(-) diff --git a/WeChatFerry/spy/chatroom_manager.cpp b/WeChatFerry/spy/chatroom_manager.cpp index c8b2042..00a9bf7 100644 --- a/WeChatFerry/spy/chatroom_manager.cpp +++ b/WeChatFerry/spy/chatroom_manager.cpp @@ -9,7 +9,7 @@ using namespace std; extern QWORD g_WeChatWinDllAddr; -namespace chatroom_mgmt +namespace chatroom { #define OS_GET_CHATROOM_MGR 0x1B83BD0 #define OS_ADD_MEMBERS 0x2155100 @@ -106,4 +106,4 @@ bool rpc_invite_chatroom_member(const string &roomid, const string &wxids, uint8 out, len, [&](Response &rsp) { rsp.msg.status = invite_chatroom_member(roomid, wxids); }); } -} // namespace chatroom_mgmt +} // namespace chatroom diff --git a/WeChatFerry/spy/chatroom_manager.h b/WeChatFerry/spy/chatroom_manager.h index 2f9b9a6..9791ed7 100644 --- a/WeChatFerry/spy/chatroom_manager.h +++ b/WeChatFerry/spy/chatroom_manager.h @@ -2,7 +2,7 @@ #include -namespace chatroom_mgmt +namespace chatroom { // 添加成员到群聊 @@ -19,4 +19,4 @@ bool rpc_add_chatroom_member(const std::string &roomid, const std::string &wxids bool rpc_del_chatroom_member(const std::string &roomid, const std::string &wxids, uint8_t *out, size_t *len); bool rpc_invite_chatroom_member(const std::string &roomid, const std::string &wxids, uint8_t *out, size_t *len); -} // namespace chatroom_mgmt +} // namespace chatroom diff --git a/WeChatFerry/spy/contact_manager.cpp b/WeChatFerry/spy/contact_manager.cpp index 17cc7f8..bb4efe8 100644 --- a/WeChatFerry/spy/contact_manager.cpp +++ b/WeChatFerry/spy/contact_manager.cpp @@ -11,7 +11,7 @@ using namespace std; extern QWORD g_WeChatWinDllAddr; -namespace contact_mgmt +namespace contact { #define OS_GET_CONTACT_MGR 0x1B417A0 #define OS_GET_CONTACT_LIST 0x219ED10 @@ -218,4 +218,4 @@ bool rpc_accept_friend(const string &v3, const string &v4, int scene, uint8_t *o out, len, [&](Response &rsp) { rsp.msg.status = accept_new_friend(v3, v4, scene); }); } -} // namespace contact_mgmt +} // namespace contact diff --git a/WeChatFerry/spy/contact_manager.h b/WeChatFerry/spy/contact_manager.h index 0fb8091..5b330c0 100644 --- a/WeChatFerry/spy/contact_manager.h +++ b/WeChatFerry/spy/contact_manager.h @@ -5,7 +5,7 @@ #include "pb_types.h" -namespace contact_mgmt +namespace contact { // 获取所有联系人 @@ -25,4 +25,4 @@ bool rpc_get_contacts(uint8_t *out, size_t *len); bool rpc_get_contact_info(const std::string &wxid, uint8_t *out, size_t *len); bool rpc_accept_friend(const std::string &v3, const std::string &v4, int scene, uint8_t *out, size_t *len); -} // namespace contact_mgmt +} // namespace contact diff --git a/WeChatFerry/spy/database_executor.cpp b/WeChatFerry/spy/database_executor.cpp index 7ff8290..3f850a3 100644 --- a/WeChatFerry/spy/database_executor.cpp +++ b/WeChatFerry/spy/database_executor.cpp @@ -11,7 +11,7 @@ extern UINT64 g_WeChatWinDllAddr; -namespace exec_sql +namespace db { #define OFFSET_DB_INSTANCE 0x5902000 #define OFFSET_DB_MICROMSG 0xB8 @@ -287,4 +287,4 @@ bool rpc_exec_db_query(const std::string &db, const std::string &sql, uint8_t *o }); } -} // namespace exec_sql +} // namespace db diff --git a/WeChatFerry/spy/database_executor.h b/WeChatFerry/spy/database_executor.h index 411c338..4f2752d 100644 --- a/WeChatFerry/spy/database_executor.h +++ b/WeChatFerry/spy/database_executor.h @@ -6,7 +6,7 @@ #include "pb_types.h" -namespace exec_sql +namespace db { // 获取数据库名称列表 @@ -29,4 +29,4 @@ bool rpc_get_db_names(uint8_t *out, size_t *len); bool rpc_get_db_tables(const std::string &db, uint8_t *out, size_t *len); bool rpc_exec_db_query(const std::string &db, const std::string &sql, uint8_t *out, size_t *len); -} // namespace exec_sql +} // namespace db diff --git a/WeChatFerry/spy/message_handler.cpp b/WeChatFerry/spy/message_handler.cpp index cf8b884..849382e 100644 --- a/WeChatFerry/spy/message_handler.cpp +++ b/WeChatFerry/spy/message_handler.cpp @@ -33,7 +33,9 @@ extern QWORD g_WeChatWinDllAddr; #define OS_PYQ_MSG_CALL 0x2E42C90 #define OS_WXLOG 0x2613D20 -QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2) +namespace message +{ +QWORD Handler::DispatchMsg(QWORD arg1, QWORD arg2) { auto &handler = getInstance(); WxMsg_t wxMsg = {}; @@ -50,10 +52,10 @@ QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2) if (wxMsg.roomid.find("@chatroom") != std::string::npos) { wxMsg.is_group = true; wxMsg.sender - = wxMsg.is_self ? user_info::get_self_wxid() : util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_WXID); + = wxMsg.is_self ? userinfo::get_self_wxid() : util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_WXID); } else { wxMsg.is_group = false; - wxMsg.sender = wxMsg.is_self ? user_info::get_self_wxid() : wxMsg.roomid; + wxMsg.sender = wxMsg.is_self ? userinfo::get_self_wxid() : wxMsg.roomid; } } catch (const std::exception &e) { LOG_ERROR(util::gb2312_to_utf8(e.what())); @@ -68,8 +70,8 @@ QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2) return handler.realRecvMsg(arg1, arg2); } -QWORD MessageHandler::PrintWxLog(QWORD a1, QWORD a2, QWORD a3, QWORD a4, QWORD a5, QWORD a6, QWORD a7, QWORD a8, - QWORD a9, QWORD a10, QWORD a11, QWORD a12) +QWORD Handler::PrintWxLog(QWORD a1, QWORD a2, QWORD a3, QWORD a4, QWORD a5, QWORD a6, QWORD a7, QWORD a8, QWORD a9, + QWORD a10, QWORD a11, QWORD a12) { auto &handler = getInstance(); @@ -82,7 +84,7 @@ QWORD MessageHandler::PrintWxLog(QWORD a1, QWORD a2, QWORD a3, QWORD a4, QWORD a return p; } -void MessageHandler::DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3) +void Handler::DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3) { auto &handler = getInstance(); QWORD startAddr = *(QWORD *)(arg2 + OS_PYQ_MSG_START); @@ -114,27 +116,27 @@ void MessageHandler::DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3) } } -MessageHandler &MessageHandler::getInstance() +Handler &Handler::getInstance() { - static MessageHandler instance; + static Handler instance; return instance; } -MessageHandler::MessageHandler() +Handler::Handler() { isLogging = false; isListeningMsg = false; isListeningPyq = false; } -MessageHandler::~MessageHandler() +Handler::~Handler() { DisableLog(); UnListenMsg(); UnListenPyq(); } -MsgTypes_t MessageHandler::GetMsgTypes() +MsgTypes_t Handler::GetMsgTypes() { return { { 0x00, "朋友圈消息" }, { 0x01, "文字" }, @@ -171,7 +173,7 @@ MsgTypes_t MessageHandler::GetMsgTypes() { 0x41000031, "文件" } }; } -std::optional MessageHandler::popMessage() +std::optional Handler::popMessage() { std::lock_guard lock(mutex_); if (msgQueue_.empty()) { @@ -182,7 +184,7 @@ std::optional MessageHandler::popMessage() return msg; } -int MessageHandler::EnableLog() +int Handler::EnableLog() { if (isLogging) return 1; @@ -196,7 +198,7 @@ int MessageHandler::EnableLog() return 0; } -int MessageHandler::DisableLog() +int Handler::DisableLog() { if (!isLogging) return 1; if (MH_DisableHook(funcWxLog) != MH_OK) return -1; @@ -205,7 +207,7 @@ int MessageHandler::DisableLog() return 0; } -int MessageHandler::ListenMsg() +int Handler::ListenMsg() { if (isListeningMsg) return 1; @@ -218,7 +220,7 @@ int MessageHandler::ListenMsg() return 0; } -int MessageHandler::UnListenMsg() +int Handler::UnListenMsg() { if (!isListeningMsg) return 1; if (MH_DisableHook(funcRecvMsg) != MH_OK) return -1; @@ -227,7 +229,7 @@ int MessageHandler::UnListenMsg() return 0; } -int MessageHandler::ListenPyq() +int Handler::ListenPyq() { if (isListeningPyq) return 1; @@ -240,7 +242,7 @@ int MessageHandler::ListenPyq() return 0; } -int MessageHandler::UnListenPyq() +int Handler::UnListenPyq() { if (!isListeningPyq) return 1; if (MH_DisableHook(funcRecvPyq) != MH_OK) return -1; @@ -249,7 +251,7 @@ int MessageHandler::UnListenPyq() return 0; } -MH_STATUS MessageHandler::InitializeHook() +MH_STATUS Handler::InitializeHook() { if (isMH_Initialized) return MH_OK; MH_STATUS status = MH_Initialize(); @@ -257,10 +259,11 @@ MH_STATUS MessageHandler::InitializeHook() return status; } -MH_STATUS MessageHandler::UninitializeHook() +MH_STATUS Handler::UninitializeHook() { if (!isMH_Initialized || isLogging || isListeningMsg || isListeningPyq) return MH_OK; MH_STATUS status = MH_Uninitialize(); if (status == MH_OK) isMH_Initialized = false; return status; } +} \ No newline at end of file diff --git a/WeChatFerry/spy/message_handler.h b/WeChatFerry/spy/message_handler.h index a2559ef..1fb06ee 100644 --- a/WeChatFerry/spy/message_handler.h +++ b/WeChatFerry/spy/message_handler.h @@ -11,10 +11,12 @@ #include "pb_types.h" #include "spy_types.h" -class MessageHandler +namespace message { + +class Handler { public: - static MessageHandler &getInstance(); + static Handler &getInstance(); // 0: 成功, -1: 失败, 1: 已经开启 int EnableLog(); @@ -35,8 +37,8 @@ public: std::mutex &getMutex() { return mutex_; }; private: - MessageHandler(); - ~MessageHandler(); + Handler(); + ~Handler(); mutable std::mutex mutex_; std::condition_variable cv_; @@ -64,3 +66,5 @@ private: QWORD a10, QWORD a11, QWORD a12); static void DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3); }; + +} // namespace message diff --git a/WeChatFerry/spy/message_sender.cpp b/WeChatFerry/spy/message_sender.cpp index 36b4d5f..0c79503 100644 --- a/WeChatFerry/spy/message_sender.cpp +++ b/WeChatFerry/spy/message_sender.cpp @@ -29,13 +29,16 @@ extern QWORD g_WeChatWinDllAddr; #define OS_XML_BUFSIGN 0x24F0D70 #define OS_SEND_XML 0x20CF360 -SendMsgManager &SendMsgManager::get_instance() +namespace message { - static SendMsgManager instance; + +Sender &Sender::get_instance() +{ + static Sender instance; return instance; } -SendMsgManager::SendMsgManager() +Sender::Sender() { func_new = reinterpret_cast(g_WeChatWinDllAddr + OS_NEW); func_free = reinterpret_cast(g_WeChatWinDllAddr + OS_FREE); @@ -50,16 +53,16 @@ SendMsgManager::SendMsgManager() func_send_xml = reinterpret_cast(g_WeChatWinDllAddr + OS_SEND_XML); } -std::unique_ptr SendMsgManager::new_wx_string(const char *str) +std::unique_ptr Sender::new_wx_string(const char *str) { return new_wx_string(str ? std::string(str) : std::string()); } -std::unique_ptr SendMsgManager::new_wx_string(const std::string &str) +std::unique_ptr Sender::new_wx_string(const std::string &str) { return std::make_unique(util::s2w(str)); } -std::vector SendMsgManager::parse_wxids(const string &wxids) +std::vector Sender::parse_wxids(const string &wxids) { vector wx_members; wstringstream wss(util::s2w(wxids)); @@ -70,7 +73,7 @@ std::vector SendMsgManager::parse_wxids(const string &wxids) return wx_members; } -void SendMsgManager::send_text(const std::string &wxid, const std::string &msg, const std::string &at_wxids) +void Sender::send_text(const std::string &wxid, const std::string &msg, const std::string &at_wxids) { auto wxWxid = new_wx_string(wxid); auto wxMsg = new_wx_string(msg); @@ -91,7 +94,7 @@ void SendMsgManager::send_text(const std::string &wxid, const std::string &msg, func_free(reinterpret_cast(&buffer)); } -void SendMsgManager::send_image(const std::string &wxid, const std::string &path) +void Sender::send_image(const std::string &wxid, const std::string &path) { auto wxWxid = new_wx_string(wxid); auto wxPath = new_wx_string(path); @@ -116,7 +119,7 @@ void SendMsgManager::send_image(const std::string &wxid, const std::string &path func_free(pMsgTmp); } -void SendMsgManager::send_file(const std::string &wxid, const std::string &path) +void Sender::send_file(const std::string &wxid, const std::string &path) { auto wxWxid = new_wx_string(wxid); auto wxPath = new_wx_string(path); @@ -135,8 +138,7 @@ void SendMsgManager::send_file(const std::string &wxid, const std::string &path) func_free(pMsg); } -void SendMsgManager::send_xml(const std::string &receiver, const std::string &xml, const std::string &path, - uint64_t type) +void Sender::send_xml(const std::string &receiver, const std::string &xml, const std::string &path, uint64_t type) { std::unique_ptr buff(new char[0x500]()); std::unique_ptr buff2(new char[0x500]()); @@ -151,7 +153,7 @@ void SendMsgManager::send_xml(const std::string &receiver, const std::string &xm auto wxReceiver = new_wx_string(receiver); auto wxXml = new_wx_string(xml); auto wxPath = new_wx_string(path); - auto wxSender = new_wx_string(user_info::get_self_wxid()); + auto wxSender = new_wx_string(userinfo::get_self_wxid()); func_send_xml(reinterpret_cast(buff.get()), reinterpret_cast(wxSender.get()), reinterpret_cast(wxReceiver.get()), reinterpret_cast(wxXml.get()), @@ -162,7 +164,7 @@ void SendMsgManager::send_xml(const std::string &receiver, const std::string &xm func_free(reinterpret_cast(buff2.get())); } -void SendMsgManager::send_emotion(const std::string &wxid, const std::string &path) +void Sender::send_emotion(const std::string &wxid, const std::string &path) { auto wxWxid = new_wx_string(wxid); auto wxPath = new_wx_string(path); @@ -180,7 +182,7 @@ void SendMsgManager::send_emotion(const std::string &wxid, const std::string &pa reinterpret_cast(buff.get())); } -int SendMsgManager::send_rich_text(const RichText &rt) +int Sender::send_rich_text(const RichText &rt) { #define SRTM_SIZE 0x3F0 QWORD status = -1; @@ -216,7 +218,7 @@ int SendMsgManager::send_rich_text(const RichText &rt) return static_cast(status); } -int SendMsgManager::send_pat(const std::string &roomid, const std::string &wxid) +int Sender::send_pat(const std::string &roomid, const std::string &wxid) { QWORD status = -1; @@ -228,12 +230,12 @@ int SendMsgManager::send_pat(const std::string &roomid, const std::string &wxid) return static_cast(status); } -int SendMsgManager::forward(QWORD msgid, const std::string &receiver) +int Sender::forward(QWORD msgid, const std::string &receiver) { uint32_t dbIdx = 0; QWORD localId = 0; - if (exec_sql::get_local_id_and_dbidx(msgid, &localId, &dbIdx) != 0) { + if (db::get_local_id_and_dbidx(msgid, &localId, &dbIdx) != 0) { LOG_ERROR("Failed to get localId, Please check id: {}", msgid); return -1; } @@ -247,7 +249,7 @@ int SendMsgManager::forward(QWORD msgid, const std::string &receiver) } // RPC 方法 -bool SendMsgManager::rpc_send_text(const TextMsg &text, uint8_t *out, size_t *len) +bool Sender::rpc_send_text(const TextMsg &text, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (text.msg == nullptr || text.receiver == nullptr || strlen(text.msg) == 0 || strlen(text.receiver) == 0) { @@ -260,7 +262,7 @@ bool SendMsgManager::rpc_send_text(const TextMsg &text, uint8_t *out, size_t *le }); } -bool SendMsgManager::rpc_send_image(const std::string &path, const std::string &receiver, uint8_t *out, size_t *len) +bool Sender::rpc_send_image(const std::string &path, const std::string &receiver, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (path.empty() || receiver.empty()) { @@ -273,7 +275,7 @@ bool SendMsgManager::rpc_send_image(const std::string &path, const std::string & }); } -bool SendMsgManager::rpc_send_file(const std::string &path, const std::string &receiver, uint8_t *out, size_t *len) +bool Sender::rpc_send_file(const std::string &path, const std::string &receiver, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (path.empty() || receiver.empty()) { @@ -286,7 +288,7 @@ bool SendMsgManager::rpc_send_file(const std::string &path, const std::string &r }); } -bool SendMsgManager::rpc_send_emotion(const std::string &path, const std::string &receiver, uint8_t *out, size_t *len) +bool Sender::rpc_send_emotion(const std::string &path, const std::string &receiver, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (path.empty() || receiver.empty()) { @@ -299,7 +301,7 @@ bool SendMsgManager::rpc_send_emotion(const std::string &path, const std::string }); } -bool SendMsgManager::rpc_send_xml(const XmlMsg &xml, uint8_t *out, size_t *len) +bool Sender::rpc_send_xml(const XmlMsg &xml, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (xml.content == nullptr || xml.receiver == nullptr) { @@ -312,7 +314,7 @@ bool SendMsgManager::rpc_send_xml(const XmlMsg &xml, uint8_t *out, size_t *len) }); } -bool SendMsgManager::rpc_send_rich_text(const RichText &rt, uint8_t *out, size_t *len) +bool Sender::rpc_send_rich_text(const RichText &rt, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (rt.receiver == nullptr) { @@ -324,7 +326,7 @@ bool SendMsgManager::rpc_send_rich_text(const RichText &rt, uint8_t *out, size_t }); } -bool SendMsgManager::rpc_send_pat(const std::string &roomid, const std::string &wxid, uint8_t *out, size_t *len) +bool Sender::rpc_send_pat(const std::string &roomid, const std::string &wxid, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (roomid.empty() || wxid.empty()) { @@ -336,7 +338,7 @@ bool SendMsgManager::rpc_send_pat(const std::string &roomid, const std::string & }); } -bool SendMsgManager::rpc_forward(uint64_t msgid, const std::string &receiver, uint8_t *out, size_t *len) +bool Sender::rpc_forward(uint64_t msgid, const std::string &receiver, uint8_t *out, size_t *len) { return fill_response(out, len, [&](Response &rsp) { if (receiver.empty()) { @@ -347,3 +349,5 @@ bool SendMsgManager::rpc_forward(uint64_t msgid, const std::string &receiver, ui } }); } + +} \ No newline at end of file diff --git a/WeChatFerry/spy/message_sender.h b/WeChatFerry/spy/message_sender.h index 66908d6..e528065 100644 --- a/WeChatFerry/spy/message_sender.h +++ b/WeChatFerry/spy/message_sender.h @@ -7,10 +7,13 @@ #include "spy_types.h" #include "wcf.pb.h" -class SendMsgManager +namespace message +{ + +class Sender { public: - static SendMsgManager &get_instance(); + static Sender &get_instance(); void send_text(const std::string &wxid, const std::string &msg, const std::string &at_wxids = ""); void send_image(const std::string &wxid, const std::string &path); @@ -32,11 +35,11 @@ public: bool rpc_forward(uint64_t msgid, const std::string &receiver, uint8_t *out, size_t *len); private: - SendMsgManager(); - ~SendMsgManager() = default; + Sender(); + ~Sender() = default; - SendMsgManager(const SendMsgManager &) = delete; - SendMsgManager &operator=(const SendMsgManager &) = delete; + Sender(const Sender &) = delete; + Sender &operator=(const Sender &) = delete; using New_t = QWORD (*)(QWORD); using Free_t = QWORD (*)(QWORD); @@ -73,3 +76,5 @@ private: std::unique_ptr new_wx_string(const std::string &str); std::vector parse_wxids(const std::string &wxids); }; + +} \ No newline at end of file diff --git a/WeChatFerry/spy/misc_manager.cpp b/WeChatFerry/spy/misc_manager.cpp index f6f252f..6454c0b 100644 --- a/WeChatFerry/spy/misc_manager.cpp +++ b/WeChatFerry/spy/misc_manager.cpp @@ -172,7 +172,7 @@ static int GetNextPage(QWORD id) int RefreshPyq(QWORD id) { - auto &msgHandler = MessageHandler::getInstance(); + auto &msgHandler = message::Handler::getInstance(); if (!msgHandler.isPyqListening()) { LOG_ERROR("没有启动朋友圈消息接收,参考:enable_receiving_msg"); return -1; @@ -203,7 +203,7 @@ int DownloadAttach(QWORD id, string thumb, string extra) return 0; } - if (exec_sql::get_local_id_and_dbidx(id, &localId, &dbIdx) != 0) { + if (db::get_local_id_and_dbidx(id, &localId, &dbIdx) != 0) { LOG_ERROR("Failed to get localId, Please check id: {}", to_string(id)); return status; } @@ -286,7 +286,7 @@ string GetAudio(QWORD id, string dir) return mp3path; } - vector silk = exec_sql::get_audio_data(id); + vector silk = db::get_audio_data(id); if (silk.size() == 0) { LOG_ERROR("Empty audio data."); return ""; @@ -306,7 +306,7 @@ string GetPCMAudio(uint64_t id, string dir, int32_t sr) return pcmpath; } vector pcm; - vector silk = exec_sql::get_audio_data(id); + vector silk = db::get_audio_data(id); if (silk.size() == 0) { LOG_ERROR("Empty audio data."); return ""; diff --git a/WeChatFerry/spy/rpc_server.cpp b/WeChatFerry/spy/rpc_server.cpp index 96e71f7..dbbbf36 100644 --- a/WeChatFerry/spy/rpc_server.cpp +++ b/WeChatFerry/spy/rpc_server.cpp @@ -45,8 +45,8 @@ static HANDLE msgThread = NULL; static nng_socket cmdSock = NNG_SOCKET_INITIALIZER; // TODO: 断开检测 static nng_socket msgSock = NNG_SOCKET_INITIALIZER; // TODO: 断开检测 -auto &msgHandler = MessageHandler::getInstance(); -auto &sendMgr = SendMsgManager::get_instance(); +auto &msgHandler = message::Handler::getInstance(); +auto &sendMgr = message::Sender::get_instance(); static std::string BuildUrl(int port) { return "tcp://0.0.0.0:" + std::to_string(port); } @@ -77,7 +77,7 @@ static bool func_is_login(uint8_t *out, size_t *len) static bool func_get_self_wxid(uint8_t *out, size_t *len) { return FillResponse(Response_str_tag, out, len, [](Response &rsp) { - std::string wxid = user_info::get_self_wxid(); + std::string wxid = userinfo::get_self_wxid(); rsp.msg.str = wxid.empty() ? nullptr : (char *)wxid.c_str(); }); } @@ -85,7 +85,7 @@ static bool func_get_self_wxid(uint8_t *out, size_t *len) static bool func_get_user_info(uint8_t *out, size_t *len) { return FillResponse(Response_ui_tag, out, len, [](Response &rsp) { - UserInfo_t ui = user_info::get_user_info(); + UserInfo_t ui = userinfo::get_user_info(); rsp.msg.ui.wxid = (char *)ui.wxid.c_str(); rsp.msg.ui.name = (char *)ui.name.c_str(); rsp.msg.ui.mobile = (char *)ui.mobile.c_str(); @@ -105,7 +105,7 @@ static bool func_get_msg_types(uint8_t *out, size_t *len) static bool func_get_contacts(uint8_t *out, size_t *len) { return FillResponse(Response_contacts_tag, out, len, [](Response &rsp) { - std::vector contacts = contact_mgmt::get_contacts(); + std::vector contacts = contact::get_contacts(); rsp.msg.contacts.contacts.funcs.encode = encode_contacts; rsp.msg.contacts.contacts.arg = &contacts; }); @@ -114,7 +114,7 @@ static bool func_get_contacts(uint8_t *out, size_t *len) static bool func_get_db_names(uint8_t *out, size_t *len) { return FillResponse(Response_dbs_tag, out, len, [](Response &rsp) { - static DbNames_t dbnames = exec_sql::get_db_names(); + static DbNames_t dbnames = db::get_db_names(); rsp.msg.dbs.names.funcs.encode = encode_dbnames; rsp.msg.dbs.names.arg = &dbnames; }); @@ -123,7 +123,7 @@ static bool func_get_db_names(uint8_t *out, size_t *len) static bool func_get_db_tables(char *db, uint8_t *out, size_t *len) { return FillResponse(Response_tables_tag, out, len, [db](Response &rsp) { - static DbTables_t tables = exec_sql::get_db_tables(db); + static DbTables_t tables = db::get_db_tables(db); rsp.msg.tables.tables.funcs.encode = encode_tables; rsp.msg.tables.tables.arg = &tables; }); @@ -355,7 +355,7 @@ static bool func_exec_db_query(char *db, char *sql, uint8_t *out, size_t *len) if ((db == nullptr) || (sql == nullptr)) { LOG_ERROR("Empty db or sql."); } else { - rows = exec_sql::exec_db_query(db, sql); + rows = db::exec_db_query(db, sql); } rsp.msg.rows.rows.arg = &rows; rsp.msg.rows.rows.funcs.encode = encode_rows; @@ -410,7 +410,7 @@ static bool func_accept_friend(char *v3, char *v4, int32_t scene, uint8_t *out, LOG_ERROR("Empty V3 or V4."); rsp.msg.status = -1; } else { - rsp.msg.status = contact_mgmt::accept_new_friend(v3, v4, scene); + rsp.msg.status = contact::accept_new_friend(v3, v4, scene); } }); } @@ -418,7 +418,7 @@ static bool func_accept_friend(char *v3, char *v4, int32_t scene, uint8_t *out, static bool func_get_contact_info(std::string wxid, uint8_t *out, size_t *len) { return FillResponse(Response_contacts_tag, out, len, [wxid](Response &rsp) { - std::vector contacts = { contact_mgmt::get_contact_by_wxid(wxid) }; + std::vector contacts = { contact::get_contact_by_wxid(wxid) }; rsp.msg.contacts.contacts.funcs.encode = encode_contacts; rsp.msg.contacts.contacts.arg = &contacts; }); @@ -458,7 +458,7 @@ static bool func_add_room_members(char *roomid, char *wxids, uint8_t *out, size_ LOG_ERROR("Empty roomid or wxids."); rsp.msg.status = -1; } else { - rsp.msg.status = chatroom_mgmt::add_chatroom_member(roomid, wxids); + rsp.msg.status = chatroom::add_chatroom_member(roomid, wxids); } }); } @@ -470,7 +470,7 @@ static bool func_del_room_members(char *roomid, char *wxids, uint8_t *out, size_ LOG_ERROR("Empty roomid or wxids."); rsp.msg.status = -1; } else { - rsp.msg.status = chatroom_mgmt::del_chatroom_member(roomid, wxids); + rsp.msg.status = chatroom::del_chatroom_member(roomid, wxids); } }); } @@ -482,7 +482,7 @@ static bool func_invite_room_members(char *roomid, char *wxids, uint8_t *out, si LOG_ERROR("Empty roomid or wxids."); rsp.msg.status = -1; } else { - rsp.msg.status = chatroom_mgmt::invite_chatroom_member(roomid, wxids); + rsp.msg.status = chatroom::invite_chatroom_member(roomid, wxids); } }); } diff --git a/WeChatFerry/spy/userinfo_manager.cpp b/WeChatFerry/spy/userinfo_manager.cpp index b8720ef..eddf0d5 100644 --- a/WeChatFerry/spy/userinfo_manager.cpp +++ b/WeChatFerry/spy/userinfo_manager.cpp @@ -9,7 +9,7 @@ extern UINT64 g_WeChatWinDllAddr; -namespace user_info +namespace userinfo { #define OS_USER_HOME 0x5932770 #define OS_USER_WXID 0x595C270 @@ -85,4 +85,4 @@ bool rpc_get_user_info(uint8_t *out, size_t *len) }); } -} // namespace user_info +} // namespace userinfo diff --git a/WeChatFerry/spy/userinfo_manager.h b/WeChatFerry/spy/userinfo_manager.h index f248ba7..6868817 100644 --- a/WeChatFerry/spy/userinfo_manager.h +++ b/WeChatFerry/spy/userinfo_manager.h @@ -5,7 +5,7 @@ #include "pb_types.h" -namespace user_info +namespace userinfo { // 获取 WeChat 数据存储路径 @@ -21,4 +21,4 @@ UserInfo_t get_user_info(); bool rpc_get_self_wxid(uint8_t *out, size_t *len); bool rpc_get_user_info(uint8_t *out, size_t *len); -} // namespace user_info +} // namespace userinfo