Refactoring

This commit is contained in:
Changhua 2025-02-05 16:05:40 +08:00
parent 228ebbf4d1
commit 505eefd03c
14 changed files with 104 additions and 88 deletions

View File

@ -9,7 +9,7 @@
using namespace std; using namespace std;
extern QWORD g_WeChatWinDllAddr; extern QWORD g_WeChatWinDllAddr;
namespace chatroom_mgmt namespace chatroom
{ {
#define OS_GET_CHATROOM_MGR 0x1B83BD0 #define OS_GET_CHATROOM_MGR 0x1B83BD0
#define OS_ADD_MEMBERS 0x2155100 #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); }); out, len, [&](Response &rsp) { rsp.msg.status = invite_chatroom_member(roomid, wxids); });
} }
} // namespace chatroom_mgmt } // namespace chatroom

View File

@ -2,7 +2,7 @@
#include <string> #include <string>
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_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); bool rpc_invite_chatroom_member(const std::string &roomid, const std::string &wxids, uint8_t *out, size_t *len);
} // namespace chatroom_mgmt } // namespace chatroom

View File

@ -11,7 +11,7 @@ using namespace std;
extern QWORD g_WeChatWinDllAddr; extern QWORD g_WeChatWinDllAddr;
namespace contact_mgmt namespace contact
{ {
#define OS_GET_CONTACT_MGR 0x1B417A0 #define OS_GET_CONTACT_MGR 0x1B417A0
#define OS_GET_CONTACT_LIST 0x219ED10 #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); }); out, len, [&](Response &rsp) { rsp.msg.status = accept_new_friend(v3, v4, scene); });
} }
} // namespace contact_mgmt } // namespace contact

View File

@ -5,7 +5,7 @@
#include "pb_types.h" #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_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); 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

View File

@ -11,7 +11,7 @@
extern UINT64 g_WeChatWinDllAddr; extern UINT64 g_WeChatWinDllAddr;
namespace exec_sql namespace db
{ {
#define OFFSET_DB_INSTANCE 0x5902000 #define OFFSET_DB_INSTANCE 0x5902000
#define OFFSET_DB_MICROMSG 0xB8 #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

View File

@ -6,7 +6,7 @@
#include "pb_types.h" #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_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); bool rpc_exec_db_query(const std::string &db, const std::string &sql, uint8_t *out, size_t *len);
} // namespace exec_sql } // namespace db

View File

@ -33,7 +33,9 @@ extern QWORD g_WeChatWinDllAddr;
#define OS_PYQ_MSG_CALL 0x2E42C90 #define OS_PYQ_MSG_CALL 0x2E42C90
#define OS_WXLOG 0x2613D20 #define OS_WXLOG 0x2613D20
QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2) namespace message
{
QWORD Handler::DispatchMsg(QWORD arg1, QWORD arg2)
{ {
auto &handler = getInstance(); auto &handler = getInstance();
WxMsg_t wxMsg = {}; WxMsg_t wxMsg = {};
@ -50,10 +52,10 @@ QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2)
if (wxMsg.roomid.find("@chatroom") != std::string::npos) { if (wxMsg.roomid.find("@chatroom") != std::string::npos) {
wxMsg.is_group = true; wxMsg.is_group = true;
wxMsg.sender 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 { } else {
wxMsg.is_group = false; 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) { } catch (const std::exception &e) {
LOG_ERROR(util::gb2312_to_utf8(e.what())); LOG_ERROR(util::gb2312_to_utf8(e.what()));
@ -68,8 +70,8 @@ QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2)
return handler.realRecvMsg(arg1, 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 Handler::PrintWxLog(QWORD a1, QWORD a2, QWORD a3, QWORD a4, QWORD a5, QWORD a6, QWORD a7, QWORD a8, QWORD a9,
QWORD a9, QWORD a10, QWORD a11, QWORD a12) QWORD a10, QWORD a11, QWORD a12)
{ {
auto &handler = getInstance(); auto &handler = getInstance();
@ -82,7 +84,7 @@ QWORD MessageHandler::PrintWxLog(QWORD a1, QWORD a2, QWORD a3, QWORD a4, QWORD a
return p; return p;
} }
void MessageHandler::DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3) void Handler::DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3)
{ {
auto &handler = getInstance(); auto &handler = getInstance();
QWORD startAddr = *(QWORD *)(arg2 + OS_PYQ_MSG_START); 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; return instance;
} }
MessageHandler::MessageHandler() Handler::Handler()
{ {
isLogging = false; isLogging = false;
isListeningMsg = false; isListeningMsg = false;
isListeningPyq = false; isListeningPyq = false;
} }
MessageHandler::~MessageHandler() Handler::~Handler()
{ {
DisableLog(); DisableLog();
UnListenMsg(); UnListenMsg();
UnListenPyq(); UnListenPyq();
} }
MsgTypes_t MessageHandler::GetMsgTypes() MsgTypes_t Handler::GetMsgTypes()
{ {
return { { 0x00, "朋友圈消息" }, return { { 0x00, "朋友圈消息" },
{ 0x01, "文字" }, { 0x01, "文字" },
@ -171,7 +173,7 @@ MsgTypes_t MessageHandler::GetMsgTypes()
{ 0x41000031, "文件" } }; { 0x41000031, "文件" } };
} }
std::optional<WxMsg_t> MessageHandler::popMessage() std::optional<WxMsg_t> Handler::popMessage()
{ {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
if (msgQueue_.empty()) { if (msgQueue_.empty()) {
@ -182,7 +184,7 @@ std::optional<WxMsg_t> MessageHandler::popMessage()
return msg; return msg;
} }
int MessageHandler::EnableLog() int Handler::EnableLog()
{ {
if (isLogging) return 1; if (isLogging) return 1;
@ -196,7 +198,7 @@ int MessageHandler::EnableLog()
return 0; return 0;
} }
int MessageHandler::DisableLog() int Handler::DisableLog()
{ {
if (!isLogging) return 1; if (!isLogging) return 1;
if (MH_DisableHook(funcWxLog) != MH_OK) return -1; if (MH_DisableHook(funcWxLog) != MH_OK) return -1;
@ -205,7 +207,7 @@ int MessageHandler::DisableLog()
return 0; return 0;
} }
int MessageHandler::ListenMsg() int Handler::ListenMsg()
{ {
if (isListeningMsg) return 1; if (isListeningMsg) return 1;
@ -218,7 +220,7 @@ int MessageHandler::ListenMsg()
return 0; return 0;
} }
int MessageHandler::UnListenMsg() int Handler::UnListenMsg()
{ {
if (!isListeningMsg) return 1; if (!isListeningMsg) return 1;
if (MH_DisableHook(funcRecvMsg) != MH_OK) return -1; if (MH_DisableHook(funcRecvMsg) != MH_OK) return -1;
@ -227,7 +229,7 @@ int MessageHandler::UnListenMsg()
return 0; return 0;
} }
int MessageHandler::ListenPyq() int Handler::ListenPyq()
{ {
if (isListeningPyq) return 1; if (isListeningPyq) return 1;
@ -240,7 +242,7 @@ int MessageHandler::ListenPyq()
return 0; return 0;
} }
int MessageHandler::UnListenPyq() int Handler::UnListenPyq()
{ {
if (!isListeningPyq) return 1; if (!isListeningPyq) return 1;
if (MH_DisableHook(funcRecvPyq) != MH_OK) return -1; if (MH_DisableHook(funcRecvPyq) != MH_OK) return -1;
@ -249,7 +251,7 @@ int MessageHandler::UnListenPyq()
return 0; return 0;
} }
MH_STATUS MessageHandler::InitializeHook() MH_STATUS Handler::InitializeHook()
{ {
if (isMH_Initialized) return MH_OK; if (isMH_Initialized) return MH_OK;
MH_STATUS status = MH_Initialize(); MH_STATUS status = MH_Initialize();
@ -257,10 +259,11 @@ MH_STATUS MessageHandler::InitializeHook()
return status; return status;
} }
MH_STATUS MessageHandler::UninitializeHook() MH_STATUS Handler::UninitializeHook()
{ {
if (!isMH_Initialized || isLogging || isListeningMsg || isListeningPyq) return MH_OK; if (!isMH_Initialized || isLogging || isListeningMsg || isListeningPyq) return MH_OK;
MH_STATUS status = MH_Uninitialize(); MH_STATUS status = MH_Uninitialize();
if (status == MH_OK) isMH_Initialized = false; if (status == MH_OK) isMH_Initialized = false;
return status; return status;
} }
}

View File

@ -11,10 +11,12 @@
#include "pb_types.h" #include "pb_types.h"
#include "spy_types.h" #include "spy_types.h"
class MessageHandler namespace message {
class Handler
{ {
public: public:
static MessageHandler &getInstance(); static Handler &getInstance();
// 0: 成功, -1: 失败, 1: 已经开启 // 0: 成功, -1: 失败, 1: 已经开启
int EnableLog(); int EnableLog();
@ -35,8 +37,8 @@ public:
std::mutex &getMutex() { return mutex_; }; std::mutex &getMutex() { return mutex_; };
private: private:
MessageHandler(); Handler();
~MessageHandler(); ~Handler();
mutable std::mutex mutex_; mutable std::mutex mutex_;
std::condition_variable cv_; std::condition_variable cv_;
@ -64,3 +66,5 @@ private:
QWORD a10, QWORD a11, QWORD a12); QWORD a10, QWORD a11, QWORD a12);
static void DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3); static void DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3);
}; };
} // namespace message

View File

@ -29,13 +29,16 @@ extern QWORD g_WeChatWinDllAddr;
#define OS_XML_BUFSIGN 0x24F0D70 #define OS_XML_BUFSIGN 0x24F0D70
#define OS_SEND_XML 0x20CF360 #define OS_SEND_XML 0x20CF360
SendMsgManager &SendMsgManager::get_instance() namespace message
{ {
static SendMsgManager instance;
Sender &Sender::get_instance()
{
static Sender instance;
return instance; return instance;
} }
SendMsgManager::SendMsgManager() Sender::Sender()
{ {
func_new = reinterpret_cast<New_t>(g_WeChatWinDllAddr + OS_NEW); func_new = reinterpret_cast<New_t>(g_WeChatWinDllAddr + OS_NEW);
func_free = reinterpret_cast<Free_t>(g_WeChatWinDllAddr + OS_FREE); func_free = reinterpret_cast<Free_t>(g_WeChatWinDllAddr + OS_FREE);
@ -50,16 +53,16 @@ SendMsgManager::SendMsgManager()
func_send_xml = reinterpret_cast<SendXml_t>(g_WeChatWinDllAddr + OS_SEND_XML); func_send_xml = reinterpret_cast<SendXml_t>(g_WeChatWinDllAddr + OS_SEND_XML);
} }
std::unique_ptr<WxString> SendMsgManager::new_wx_string(const char *str) std::unique_ptr<WxString> Sender::new_wx_string(const char *str)
{ {
return new_wx_string(str ? std::string(str) : std::string()); return new_wx_string(str ? std::string(str) : std::string());
} }
std::unique_ptr<WxString> SendMsgManager::new_wx_string(const std::string &str) std::unique_ptr<WxString> Sender::new_wx_string(const std::string &str)
{ {
return std::make_unique<WxString>(util::s2w(str)); return std::make_unique<WxString>(util::s2w(str));
} }
std::vector<WxString> SendMsgManager::parse_wxids(const string &wxids) std::vector<WxString> Sender::parse_wxids(const string &wxids)
{ {
vector<WxString> wx_members; vector<WxString> wx_members;
wstringstream wss(util::s2w(wxids)); wstringstream wss(util::s2w(wxids));
@ -70,7 +73,7 @@ std::vector<WxString> SendMsgManager::parse_wxids(const string &wxids)
return wx_members; 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 wxWxid = new_wx_string(wxid);
auto wxMsg = new_wx_string(msg); 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<QWORD>(&buffer)); func_free(reinterpret_cast<QWORD>(&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 wxWxid = new_wx_string(wxid);
auto wxPath = new_wx_string(path); 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); 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 wxWxid = new_wx_string(wxid);
auto wxPath = new_wx_string(path); 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); func_free(pMsg);
} }
void SendMsgManager::send_xml(const std::string &receiver, const std::string &xml, const std::string &path, void Sender::send_xml(const std::string &receiver, const std::string &xml, const std::string &path, uint64_t type)
uint64_t type)
{ {
std::unique_ptr<char[]> buff(new char[0x500]()); std::unique_ptr<char[]> buff(new char[0x500]());
std::unique_ptr<char[]> buff2(new char[0x500]()); std::unique_ptr<char[]> 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 wxReceiver = new_wx_string(receiver);
auto wxXml = new_wx_string(xml); auto wxXml = new_wx_string(xml);
auto wxPath = new_wx_string(path); 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<QWORD>(buff.get()), reinterpret_cast<QWORD>(wxSender.get()), func_send_xml(reinterpret_cast<QWORD>(buff.get()), reinterpret_cast<QWORD>(wxSender.get()),
reinterpret_cast<QWORD>(wxReceiver.get()), reinterpret_cast<QWORD>(wxXml.get()), reinterpret_cast<QWORD>(wxReceiver.get()), reinterpret_cast<QWORD>(wxXml.get()),
@ -162,7 +164,7 @@ void SendMsgManager::send_xml(const std::string &receiver, const std::string &xm
func_free(reinterpret_cast<QWORD>(buff2.get())); func_free(reinterpret_cast<QWORD>(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 wxWxid = new_wx_string(wxid);
auto wxPath = new_wx_string(path); auto wxPath = new_wx_string(path);
@ -180,7 +182,7 @@ void SendMsgManager::send_emotion(const std::string &wxid, const std::string &pa
reinterpret_cast<QWORD>(buff.get())); reinterpret_cast<QWORD>(buff.get()));
} }
int SendMsgManager::send_rich_text(const RichText &rt) int Sender::send_rich_text(const RichText &rt)
{ {
#define SRTM_SIZE 0x3F0 #define SRTM_SIZE 0x3F0
QWORD status = -1; QWORD status = -1;
@ -216,7 +218,7 @@ int SendMsgManager::send_rich_text(const RichText &rt)
return static_cast<int>(status); return static_cast<int>(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; QWORD status = -1;
@ -228,12 +230,12 @@ int SendMsgManager::send_pat(const std::string &roomid, const std::string &wxid)
return static_cast<int>(status); return static_cast<int>(status);
} }
int SendMsgManager::forward(QWORD msgid, const std::string &receiver) int Sender::forward(QWORD msgid, const std::string &receiver)
{ {
uint32_t dbIdx = 0; uint32_t dbIdx = 0;
QWORD localId = 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); LOG_ERROR("Failed to get localId, Please check id: {}", msgid);
return -1; return -1;
} }
@ -247,7 +249,7 @@ int SendMsgManager::forward(QWORD msgid, const std::string &receiver)
} }
// RPC 方法 // 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<Functions_FUNC_SEND_TXT>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_TXT>(out, len, [&](Response &rsp) {
if (text.msg == nullptr || text.receiver == nullptr || strlen(text.msg) == 0 || strlen(text.receiver) == 0) { 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<Functions_FUNC_SEND_IMG>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_IMG>(out, len, [&](Response &rsp) {
if (path.empty() || receiver.empty()) { 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<Functions_FUNC_SEND_FILE>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_FILE>(out, len, [&](Response &rsp) {
if (path.empty() || receiver.empty()) { 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<Functions_FUNC_SEND_EMOTION>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_EMOTION>(out, len, [&](Response &rsp) {
if (path.empty() || receiver.empty()) { 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<Functions_FUNC_SEND_XML>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_XML>(out, len, [&](Response &rsp) {
if (xml.content == nullptr || xml.receiver == nullptr) { 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<Functions_FUNC_SEND_RICH_TXT>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_RICH_TXT>(out, len, [&](Response &rsp) {
if (rt.receiver == nullptr) { 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<Functions_FUNC_SEND_PAT_MSG>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_SEND_PAT_MSG>(out, len, [&](Response &rsp) {
if (roomid.empty() || wxid.empty()) { 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<Functions_FUNC_FORWARD_MSG>(out, len, [&](Response &rsp) { return fill_response<Functions_FUNC_FORWARD_MSG>(out, len, [&](Response &rsp) {
if (receiver.empty()) { if (receiver.empty()) {
@ -347,3 +349,5 @@ bool SendMsgManager::rpc_forward(uint64_t msgid, const std::string &receiver, ui
} }
}); });
} }
}

View File

@ -7,10 +7,13 @@
#include "spy_types.h" #include "spy_types.h"
#include "wcf.pb.h" #include "wcf.pb.h"
class SendMsgManager namespace message
{
class Sender
{ {
public: 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_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); 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); bool rpc_forward(uint64_t msgid, const std::string &receiver, uint8_t *out, size_t *len);
private: private:
SendMsgManager(); Sender();
~SendMsgManager() = default; ~Sender() = default;
SendMsgManager(const SendMsgManager &) = delete; Sender(const Sender &) = delete;
SendMsgManager &operator=(const SendMsgManager &) = delete; Sender &operator=(const Sender &) = delete;
using New_t = QWORD (*)(QWORD); using New_t = QWORD (*)(QWORD);
using Free_t = QWORD (*)(QWORD); using Free_t = QWORD (*)(QWORD);
@ -73,3 +76,5 @@ private:
std::unique_ptr<WxString> new_wx_string(const std::string &str); std::unique_ptr<WxString> new_wx_string(const std::string &str);
std::vector<WxString> parse_wxids(const std::string &wxids); std::vector<WxString> parse_wxids(const std::string &wxids);
}; };
}

View File

@ -172,7 +172,7 @@ static int GetNextPage(QWORD id)
int RefreshPyq(QWORD id) int RefreshPyq(QWORD id)
{ {
auto &msgHandler = MessageHandler::getInstance(); auto &msgHandler = message::Handler::getInstance();
if (!msgHandler.isPyqListening()) { if (!msgHandler.isPyqListening()) {
LOG_ERROR("没有启动朋友圈消息接收参考enable_receiving_msg"); LOG_ERROR("没有启动朋友圈消息接收参考enable_receiving_msg");
return -1; return -1;
@ -203,7 +203,7 @@ int DownloadAttach(QWORD id, string thumb, string extra)
return 0; 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)); LOG_ERROR("Failed to get localId, Please check id: {}", to_string(id));
return status; return status;
} }
@ -286,7 +286,7 @@ string GetAudio(QWORD id, string dir)
return mp3path; return mp3path;
} }
vector<uint8_t> silk = exec_sql::get_audio_data(id); vector<uint8_t> silk = db::get_audio_data(id);
if (silk.size() == 0) { if (silk.size() == 0) {
LOG_ERROR("Empty audio data."); LOG_ERROR("Empty audio data.");
return ""; return "";
@ -306,7 +306,7 @@ string GetPCMAudio(uint64_t id, string dir, int32_t sr)
return pcmpath; return pcmpath;
} }
vector<uint8_t> pcm; vector<uint8_t> pcm;
vector<uint8_t> silk = exec_sql::get_audio_data(id); vector<uint8_t> silk = db::get_audio_data(id);
if (silk.size() == 0) { if (silk.size() == 0) {
LOG_ERROR("Empty audio data."); LOG_ERROR("Empty audio data.");
return ""; return "";

View File

@ -45,8 +45,8 @@ static HANDLE msgThread = NULL;
static nng_socket cmdSock = NNG_SOCKET_INITIALIZER; // TODO: 断开检测 static nng_socket cmdSock = NNG_SOCKET_INITIALIZER; // TODO: 断开检测
static nng_socket msgSock = NNG_SOCKET_INITIALIZER; // TODO: 断开检测 static nng_socket msgSock = NNG_SOCKET_INITIALIZER; // TODO: 断开检测
auto &msgHandler = MessageHandler::getInstance(); auto &msgHandler = message::Handler::getInstance();
auto &sendMgr = SendMsgManager::get_instance(); auto &sendMgr = message::Sender::get_instance();
static std::string BuildUrl(int port) { return "tcp://0.0.0.0:" + std::to_string(port); } 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) static bool func_get_self_wxid(uint8_t *out, size_t *len)
{ {
return FillResponse<Functions_FUNC_GET_SELF_WXID>(Response_str_tag, out, len, [](Response &rsp) { return FillResponse<Functions_FUNC_GET_SELF_WXID>(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(); 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) static bool func_get_user_info(uint8_t *out, size_t *len)
{ {
return FillResponse<Functions_FUNC_GET_USER_INFO>(Response_ui_tag, out, len, [](Response &rsp) { return FillResponse<Functions_FUNC_GET_USER_INFO>(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.wxid = (char *)ui.wxid.c_str();
rsp.msg.ui.name = (char *)ui.name.c_str(); rsp.msg.ui.name = (char *)ui.name.c_str();
rsp.msg.ui.mobile = (char *)ui.mobile.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) static bool func_get_contacts(uint8_t *out, size_t *len)
{ {
return FillResponse<Functions_FUNC_GET_CONTACTS>(Response_contacts_tag, out, len, [](Response &rsp) { return FillResponse<Functions_FUNC_GET_CONTACTS>(Response_contacts_tag, out, len, [](Response &rsp) {
std::vector<RpcContact_t> contacts = contact_mgmt::get_contacts(); std::vector<RpcContact_t> contacts = contact::get_contacts();
rsp.msg.contacts.contacts.funcs.encode = encode_contacts; rsp.msg.contacts.contacts.funcs.encode = encode_contacts;
rsp.msg.contacts.contacts.arg = &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) static bool func_get_db_names(uint8_t *out, size_t *len)
{ {
return FillResponse<Functions_FUNC_GET_DB_NAMES>(Response_dbs_tag, out, len, [](Response &rsp) { return FillResponse<Functions_FUNC_GET_DB_NAMES>(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.funcs.encode = encode_dbnames;
rsp.msg.dbs.names.arg = &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) static bool func_get_db_tables(char *db, uint8_t *out, size_t *len)
{ {
return FillResponse<Functions_FUNC_GET_DB_TABLES>(Response_tables_tag, out, len, [db](Response &rsp) { return FillResponse<Functions_FUNC_GET_DB_TABLES>(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.funcs.encode = encode_tables;
rsp.msg.tables.tables.arg = &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)) { if ((db == nullptr) || (sql == nullptr)) {
LOG_ERROR("Empty db or sql."); LOG_ERROR("Empty db or sql.");
} else { } 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.arg = &rows;
rsp.msg.rows.rows.funcs.encode = encode_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."); LOG_ERROR("Empty V3 or V4.");
rsp.msg.status = -1; rsp.msg.status = -1;
} else { } 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) static bool func_get_contact_info(std::string wxid, uint8_t *out, size_t *len)
{ {
return FillResponse<Functions_FUNC_GET_CONTACT_INFO>(Response_contacts_tag, out, len, [wxid](Response &rsp) { return FillResponse<Functions_FUNC_GET_CONTACT_INFO>(Response_contacts_tag, out, len, [wxid](Response &rsp) {
std::vector<RpcContact_t> contacts = { contact_mgmt::get_contact_by_wxid(wxid) }; std::vector<RpcContact_t> contacts = { contact::get_contact_by_wxid(wxid) };
rsp.msg.contacts.contacts.funcs.encode = encode_contacts; rsp.msg.contacts.contacts.funcs.encode = encode_contacts;
rsp.msg.contacts.contacts.arg = &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."); LOG_ERROR("Empty roomid or wxids.");
rsp.msg.status = -1; rsp.msg.status = -1;
} else { } 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."); LOG_ERROR("Empty roomid or wxids.");
rsp.msg.status = -1; rsp.msg.status = -1;
} else { } 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."); LOG_ERROR("Empty roomid or wxids.");
rsp.msg.status = -1; rsp.msg.status = -1;
} else { } else {
rsp.msg.status = chatroom_mgmt::invite_chatroom_member(roomid, wxids); rsp.msg.status = chatroom::invite_chatroom_member(roomid, wxids);
} }
}); });
} }

View File

@ -9,7 +9,7 @@
extern UINT64 g_WeChatWinDllAddr; extern UINT64 g_WeChatWinDllAddr;
namespace user_info namespace userinfo
{ {
#define OS_USER_HOME 0x5932770 #define OS_USER_HOME 0x5932770
#define OS_USER_WXID 0x595C270 #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

View File

@ -5,7 +5,7 @@
#include "pb_types.h" #include "pb_types.h"
namespace user_info namespace userinfo
{ {
// 获取 WeChat 数据存储路径 // 获取 WeChat 数据存储路径
@ -21,4 +21,4 @@ UserInfo_t get_user_info();
bool rpc_get_self_wxid(uint8_t *out, size_t *len); bool rpc_get_self_wxid(uint8_t *out, size_t *len);
bool rpc_get_user_info(uint8_t *out, size_t *len); bool rpc_get_user_info(uint8_t *out, size_t *len);
} // namespace user_info } // namespace userinfo