From ffbef43d60af3cc39d3e5ed9f8a8473366bd739d Mon Sep 17 00:00:00 2001 From: Changhua Date: Sat, 18 Feb 2023 19:45:36 +0800 Subject: [PATCH] Refactor SendTextMessage and SendImageMessage --- spy/rpc_server.cpp | 4 ++-- spy/send_msg.cpp | 45 ++++++++++++++++++++++++++------------------- spy/send_msg.h | 6 +++--- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/spy/rpc_server.cpp b/spy/rpc_server.cpp index 2a7fdb4..e5bf95e 100644 --- a/spy/rpc_server.cpp +++ b/spy/rpc_server.cpp @@ -170,7 +170,7 @@ bool func_send_txt(TextMsg txt, uint8_t *out, size_t *len) string receiver(txt.receiver); string aters(txt.aters ? txt.aters : ""); - SendTextMessage(String2Wstring(receiver), String2Wstring(msg), String2Wstring(aters)); + SendTextMessage(receiver, msg, aters); } pb_ostream_t stream = pb_ostream_from_buffer(out, *len); @@ -193,7 +193,7 @@ bool func_send_img(char *path, char *receiver, uint8_t *out, size_t *len) if ((path == NULL) || (receiver == NULL)) { rsp.msg.status = -1; } else { - SendImageMessage(String2Wstring(receiver), String2Wstring(path)); + SendImageMessage(receiver, path); } pb_ostream_t stream = pb_ostream_from_buffer(out, *len); diff --git a/spy/send_msg.cpp b/spy/send_msg.cpp index 29fb288..f961d33 100644 --- a/spy/send_msg.cpp +++ b/spy/send_msg.cpp @@ -1,9 +1,10 @@ -#include -#include +#include "framework.h" +#include #include #include "send_msg.h" #include "spy_types.h" +#include "util.h" extern HANDLE g_hEvent; extern WxCalls_t g_WxCalls; @@ -15,7 +16,7 @@ typedef struct AtList { DWORD end2; } AtList_t; -void SendTextMessage(wstring wxid, wstring msg, wstring atWxids) +void SendTextMessage(string wxid, string msg, string atWxids) { char buffer[0x3B0] = { 0 }; AtList_t atList = { 0 }; @@ -26,17 +27,20 @@ void SendTextMessage(wstring wxid, wstring msg, wstring atWxids) // 发送消息Call地址 = 微信基址 + 偏移 DWORD sendCallAddress = g_WeChatWinDllAddr + g_WxCalls.sendTextMsg; - txtMsg.text = (wchar_t *)msg.c_str(); - txtMsg.size = msg.size(); - txtMsg.capacity = msg.capacity(); + wstring wsWxid = String2Wstring(wxid); + wstring wsMsg = String2Wstring(msg); - txtWxid.text = (wchar_t *)wxid.c_str(); - txtWxid.size = wxid.size(); - txtWxid.capacity = wxid.capacity(); + txtMsg.text = (wchar_t *)wsMsg.c_str(); + txtMsg.size = wsMsg.size(); + txtMsg.capacity = wsMsg.capacity(); - wstring tmp = atWxids; - if (!tmp.empty()) { - int i = 0; + txtWxid.text = (wchar_t *)wsWxid.c_str(); + txtWxid.size = wsWxid.size(); + txtWxid.capacity = wsWxid.capacity(); + + if (!atWxids.empty()) { + int i = 0; + wstring tmp = String2Wstring(atWxids); wstring wstr; vector vAtWxids; wstringstream wss(tmp); @@ -78,7 +82,7 @@ void SendTextMessage(wstring wxid, wstring msg, wstring atWxids) } } -void SendImageMessage(wstring wxid, wstring path) +void SendImageMessage(string wxid, string path) { if (g_WeChatWinDllAddr == 0) { return; @@ -89,13 +93,16 @@ void SendImageMessage(wstring wxid, wstring path) TextStruct_t imgWxid = { 0 }; TextStruct_t imgPath = { 0 }; - imgWxid.text = (wchar_t *)wxid.c_str(); - imgWxid.size = wxid.size(); - imgWxid.capacity = wxid.capacity(); + wstring wsWxid = String2Wstring(wxid); + wstring wspath = String2Wstring(path); - imgPath.text = (wchar_t *)path.c_str(); - imgPath.size = path.size(); - imgPath.capacity = path.capacity(); + imgWxid.text = (wchar_t *)wsWxid.c_str(); + imgWxid.size = wsWxid.size(); + imgWxid.capacity = wsWxid.capacity(); + + imgPath.text = (wchar_t *)wspath.c_str(); + imgPath.size = wspath.size(); + imgPath.capacity = wspath.capacity(); // 发送图片Call地址 = 微信基址 + 偏移 DWORD sendCall1 = g_WeChatWinDllAddr + g_WxCalls.sendImg.call1; diff --git a/spy/send_msg.h b/spy/send_msg.h index f38fe06..4f744c2 100644 --- a/spy/send_msg.h +++ b/spy/send_msg.h @@ -1,8 +1,8 @@ #pragma once -#include "framework.h" +#include using namespace std; -void SendTextMessage(wstring wxid, wstring msg, wstring atWxids); -void SendImageMessage(wstring wxid, wstring path); +void SendTextMessage(string wxid, string msg, string atWxids); +void SendImageMessage(string wxid, string path);