From 1e703f0f64dc6ae557c79e0240f9141bfa07a53c Mon Sep 17 00:00:00 2001 From: Changhua Date: Tue, 25 Feb 2025 00:50:50 +0800 Subject: [PATCH] feat(message): impl send image --- WeChatFerry/spy/message_sender.cpp | 52 +++++++++++++++--------------- WeChatFerry/spy/message_sender.h | 4 +-- WeChatFerry/spy/rpc_server.cpp | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/WeChatFerry/spy/message_sender.cpp b/WeChatFerry/spy/message_sender.cpp index bc6cad5..64256d5 100644 --- a/WeChatFerry/spy/message_sender.cpp +++ b/WeChatFerry/spy/message_sender.cpp @@ -40,11 +40,11 @@ Sender &Sender::get_instance() Sender::Sender() { - func_new = reinterpret_cast(g_WeChatWinDllAddr + OS_NEW); - func_free = reinterpret_cast(g_WeChatWinDllAddr + OsSend::FREE); + func_get_instance = reinterpret_cast(g_WeChatWinDllAddr + OsSend::INSTANCE); + func_free_chat_msg = reinterpret_cast(g_WeChatWinDllAddr + OsSend::FREE); func_send_msg_mgr = reinterpret_cast(g_WeChatWinDllAddr + OsSend::MGR); func_send_text = reinterpret_cast(g_WeChatWinDllAddr + OsSend::TEXT); - func_send_image = reinterpret_cast(g_WeChatWinDllAddr + OS_SEND_IMAGE); + func_send_image = reinterpret_cast(g_WeChatWinDllAddr + OsSend::IMAGE); func_send_file = reinterpret_cast(g_WeChatWinDllAddr + OS_SEND_FILE); func_send_rich_text = reinterpret_cast(g_WeChatWinDllAddr + OS_SEND_RICH_TEXT); func_send_pat = reinterpret_cast(g_WeChatWinDllAddr + OS_SEND_PAT_MSG); @@ -98,32 +98,32 @@ void Sender::send_text(const std::string &wxid, const std::string &msg, const st func_send_msg_mgr(); func_send_text(reinterpret_cast(&buffer), reinterpret_cast(&holderWxid.wx), reinterpret_cast(&holderMsg.wx), pWxAtWxids, 1, 1, 0, 0); - func_free(reinterpret_cast(&buffer)); + func_free_chat_msg(reinterpret_cast(&buffer)); } void Sender::send_image(const std::string &wxid, const std::string &path) { - auto wxWxid = new_wx_string(wxid); - auto wxPath = new_wx_string(path); + WxStringHolder holderWxid(wxid); + WxStringHolder holderPath(path); - char msg[0x460] = { 0 }; - char msgTmp[0x460] = { 0 }; - QWORD *flag[10] = { nullptr }; + char msg[1192] = { 0 }; + char msgTmp[1192] = { 0 }; + QWORD *flag[10] = { 0 }; - QWORD tmp1 = 0, tmp2 = 0; - QWORD pMsgTmp = func_new(reinterpret_cast(&msgTmp)); - flag[8] = &tmp1; - flag[9] = &tmp2; + QWORD tmp1 = 1, tmp2 = 0, tmp3 = 0; + QWORD pMsgTmp = func_get_instance((QWORD)(&msgTmp)); + flag[0] = reinterpret_cast(tmp1); flag[1] = reinterpret_cast(pMsgTmp); + flag[8] = &tmp2; + flag[9] = &tmp3; - QWORD pMsg = func_new(reinterpret_cast(&msg)); + QWORD pMsg = func_get_instance((QWORD)(&msg)); QWORD sendMgr = func_send_msg_mgr(); - - func_send_image(sendMgr, pMsg, reinterpret_cast(wxWxid.get()), reinterpret_cast(wxPath.get()), + func_send_image(sendMgr, pMsg, reinterpret_cast(&holderWxid.wx), reinterpret_cast(&holderPath.wx), reinterpret_cast(&flag)); - func_free(pMsg); - func_free(pMsgTmp); + func_free_chat_msg(pMsg); + func_free_chat_msg(pMsgTmp); } void Sender::send_file(const std::string &wxid, const std::string &path) @@ -136,13 +136,13 @@ void Sender::send_file(const std::string &wxid, const std::string &path) QWORD tmp2[4] = { 0 }; QWORD tmp3[4] = { 0 }; - QWORD pMsg = func_new(reinterpret_cast(&msg)); + QWORD pMsg = func_get_instance(reinterpret_cast(&msg)); QWORD appMgr = func_get_app_mgr(); func_send_file(appMgr, pMsg, reinterpret_cast(wxWxid.get()), reinterpret_cast(wxPath.get()), 1, tmp1, 0, tmp2, 0, tmp3, 0, 0); - func_free(pMsg); + func_free_chat_msg(pMsg); } void Sender::send_xml(const std::string &receiver, const std::string &xml, const std::string &path, uint64_t type) @@ -151,8 +151,8 @@ void Sender::send_xml(const std::string &receiver, const std::string &xml, const std::unique_ptr buff2(new char[0x500]()); char nullBuf[0x1C] = { 0 }; - func_new(reinterpret_cast(buff.get())); - func_new(reinterpret_cast(buff2.get())); + func_get_instance(reinterpret_cast(buff.get())); + func_get_instance(reinterpret_cast(buff2.get())); QWORD sbuf[4] = { 0, 0, 0, 0 }; QWORD sign = func_xml_buf_sign(reinterpret_cast(buff2.get()), reinterpret_cast(sbuf), 0x1); @@ -167,8 +167,8 @@ void Sender::send_xml(const std::string &receiver, const std::string &xml, const reinterpret_cast(wxPath.get()), reinterpret_cast(nullBuf), type, 0x4, sign, reinterpret_cast(buff2.get())); - func_free(reinterpret_cast(buff.get())); - func_free(reinterpret_cast(buff2.get())); + func_free_chat_msg(reinterpret_cast(buff.get())); + func_free_chat_msg(reinterpret_cast(buff2.get())); } void Sender::send_emotion(const std::string &wxid, const std::string &path) @@ -201,7 +201,7 @@ int Sender::send_rich_text(const RichText &rt) } memset(buff, 0, SRTM_SIZE); - func_new(reinterpret_cast(buff)); + func_get_instance(reinterpret_cast(buff)); auto pReceiver = new_wx_string(rt.receiver); auto pTitle = new_wx_string(rt.title); @@ -220,7 +220,7 @@ int Sender::send_rich_text(const RichText &rt) QWORD mgr = func_get_app_mgr(); status = func_send_rich_text(mgr, reinterpret_cast(pReceiver.get()), reinterpret_cast(buff)); - func_free(reinterpret_cast(buff)); + func_free_chat_msg(reinterpret_cast(buff)); return static_cast(status); } diff --git a/WeChatFerry/spy/message_sender.h b/WeChatFerry/spy/message_sender.h index 4453ba9..8ebfc46 100644 --- a/WeChatFerry/spy/message_sender.h +++ b/WeChatFerry/spy/message_sender.h @@ -58,8 +58,8 @@ private: using XmlBufSign_t = QWORD (*)(QWORD, QWORD, QWORD); using SendXml_t = QWORD (*)(QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD, QWORD); - New_t func_new; - Free_t func_free; + New_t func_get_instance; + Free_t func_free_chat_msg; SendMsgMgr_t func_send_msg_mgr; GetAppMgr_t func_get_app_mgr; SendText_t func_send_text; diff --git a/WeChatFerry/spy/rpc_server.cpp b/WeChatFerry/spy/rpc_server.cpp index 6590897..c090b86 100644 --- a/WeChatFerry/spy/rpc_server.cpp +++ b/WeChatFerry/spy/rpc_server.cpp @@ -249,7 +249,7 @@ const std::unordered_map RpcServer::rpcFu // { Functions_FUNC_GET_DB_TABLES, [](const Request &r, uint8_t *out, size_t *len) { return db::rpc_get_db_tables(r.msg.str, out, len); } }, // { Functions_FUNC_GET_AUDIO_MSG, [](const Request &r, uint8_t *out, size_t *len) { return misc::rpc_get_audio(r.msg.am, out, len); } }, { Functions_FUNC_SEND_TXT, [](const Request &r, uint8_t *out, size_t *len) { return RpcServer::getInstance().sender_.rpc_send_text(r.msg.txt, out, len); } }, - // { Functions_FUNC_SEND_IMG, [](const Request &r, uint8_t *out, size_t *len) { return sender.rpc_send_image(r.msg.file, out, len); } }, + { Functions_FUNC_SEND_IMG, [](const Request &r, uint8_t *out, size_t *len) { return RpcServer::getInstance().sender_.rpc_send_image(r.msg.file, out, len); } }, // { Functions_FUNC_SEND_FILE, [](const Request &r, uint8_t *out, size_t *len) { return sender.rpc_send_file(r.msg.file, out, len); } }, // { Functions_FUNC_SEND_XML, [](const Request &r, uint8_t *out, size_t *len) { return sender.rpc_send_xml(r.msg.xml, out, len); } }, // { Functions_FUNC_SEND_EMOTION, [](const Request &r, uint8_t *out, size_t *len) { return sender.rpc_send_emotion(r.msg.file, out, len); } },