From d6633c3aed8c43e60bb562ee147b04f9d377234c Mon Sep 17 00:00:00 2001 From: Changhua Date: Sat, 18 Feb 2023 09:08:27 +0800 Subject: [PATCH] Impl SendTextMessage and SendImageMessage --- spy/rpc_server.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ spy/send_msg.cpp | 39 ++++++++++++------------------ spy/send_msg.h | 8 +++++-- 3 files changed, 81 insertions(+), 26 deletions(-) diff --git a/spy/rpc_server.cpp b/spy/rpc_server.cpp index f6ad262..2a7fdb4 100644 --- a/spy/rpc_server.cpp +++ b/spy/rpc_server.cpp @@ -156,6 +156,56 @@ bool func_get_db_tables(char *db, uint8_t *out, size_t *len) return true; } +bool func_send_txt(TextMsg txt, uint8_t *out, size_t *len) +{ + Response rsp = Response_init_default; + rsp.func = Functions_FUNC_SEND_TXT; + rsp.which_msg = Response_status_tag; + rsp.msg.status = 0; + + if ((txt.msg == NULL) || (txt.receiver == NULL)) { + rsp.msg.status = -1; // Empty message or empty receiver + } else { + string msg(txt.msg); + string receiver(txt.receiver); + string aters(txt.aters ? txt.aters : ""); + + SendTextMessage(String2Wstring(receiver), String2Wstring(msg), String2Wstring(aters)); + } + + pb_ostream_t stream = pb_ostream_from_buffer(out, *len); + if (!pb_encode(&stream, Response_fields, &rsp)) { + LOG_ERROR("Encoding failed: {}", PB_GET_ERROR(&stream)); + return false; + } + *len = stream.bytes_written; + + return true; +} + +bool func_send_img(char *path, char *receiver, uint8_t *out, size_t *len) +{ + Response rsp = Response_init_default; + rsp.func = Functions_FUNC_SEND_IMG; + rsp.which_msg = Response_status_tag; + rsp.msg.status = 0; + + if ((path == NULL) || (receiver == NULL)) { + rsp.msg.status = -1; + } else { + SendImageMessage(String2Wstring(receiver), String2Wstring(path)); + } + + pb_ostream_t stream = pb_ostream_from_buffer(out, *len); + if (!pb_encode(&stream, Response_fields, &rsp)) { + LOG_ERROR("Encoding failed: {}", PB_GET_ERROR(&stream)); + return false; + } + *len = stream.bytes_written; + + return true; +} + bool func_exec_db_query(char *db, char *sql, uint8_t *out, size_t *len) { Response rsp = Response_init_default; @@ -219,6 +269,16 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len ret = func_get_db_tables(req.msg.str, out, out_len); break; } + case Functions_FUNC_SEND_TXT: { + LOG_INFO("[Functions_FUNC_SEND_TXT]"); + ret = func_send_txt(req.msg.txt, out, out_len); + break; + } + case Functions_FUNC_SEND_IMG: { + LOG_INFO("[Functions_FUNC_SEND_IMG]"); + ret = func_send_img(req.msg.img.path, req.msg.txt.receiver, out, out_len); + break; + } case Functions_FUNC_EXEC_DB_QUERY: { LOG_INFO("[Functions_FUNC_EXEC_DB_QUERY]"); ret = func_exec_db_query(req.msg.query.db, req.msg.query.sql, out, out_len); diff --git a/spy/send_msg.cpp b/spy/send_msg.cpp index 5405838..29fb288 100644 --- a/spy/send_msg.cpp +++ b/spy/send_msg.cpp @@ -1,5 +1,4 @@ -#include "framework.h" -#include +#include #include #include @@ -10,15 +9,13 @@ extern HANDLE g_hEvent; extern WxCalls_t g_WxCalls; extern DWORD g_WeChatWinDllAddr; -using namespace std; - typedef struct AtList { DWORD start; DWORD end1; DWORD end2; } AtList_t; -void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atWxids) +void SendTextMessage(wstring wxid, wstring msg, wstring atWxids) { char buffer[0x3B0] = { 0 }; AtList_t atList = { 0 }; @@ -26,19 +23,16 @@ void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atW TextStruct_t txtWxid = { 0 }; TextStruct_t *tsArray = NULL; - wstring wsMsg = msg; - wstring wsWxid = wxid; - // 发送消息Call地址 = 微信基址 + 偏移 DWORD sendCallAddress = g_WeChatWinDllAddr + g_WxCalls.sendTextMsg; - txtMsg.text = (wchar_t *)wsMsg.c_str(); - txtMsg.size = wsMsg.size(); - txtMsg.capacity = wsMsg.capacity(); + txtMsg.text = (wchar_t *)msg.c_str(); + txtMsg.size = msg.size(); + txtMsg.capacity = msg.capacity(); - txtWxid.text = (wchar_t *)wsWxid.c_str(); - txtWxid.size = wsWxid.size(); - txtWxid.capacity = wsWxid.capacity(); + txtWxid.text = (wchar_t *)wxid.c_str(); + txtWxid.size = wxid.size(); + txtWxid.capacity = wxid.capacity(); wstring tmp = atWxids; if (!tmp.empty()) { @@ -84,7 +78,7 @@ void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atW } } -void SendImageMessage(const wchar_t *wxid, const wchar_t *path) +void SendImageMessage(wstring wxid, wstring path) { if (g_WeChatWinDllAddr == 0) { return; @@ -95,16 +89,13 @@ void SendImageMessage(const wchar_t *wxid, const wchar_t *path) TextStruct_t imgWxid = { 0 }; TextStruct_t imgPath = { 0 }; - wstring wsWxid = wxid; - wstring wsPath = path; + imgWxid.text = (wchar_t *)wxid.c_str(); + imgWxid.size = wxid.size(); + imgWxid.capacity = wxid.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(); + imgPath.text = (wchar_t *)path.c_str(); + imgPath.size = path.size(); + imgPath.capacity = path.capacity(); // 发送图片Call地址 = 微信基址 + 偏移 DWORD sendCall1 = g_WeChatWinDllAddr + g_WxCalls.sendImg.call1; diff --git a/spy/send_msg.h b/spy/send_msg.h index f68e5e6..f38fe06 100644 --- a/spy/send_msg.h +++ b/spy/send_msg.h @@ -1,4 +1,8 @@ #pragma once -void SendTextMessage(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atWxids); -void SendImageMessage(const wchar_t *wxid, const wchar_t *path); +#include "framework.h" + +using namespace std; + +void SendTextMessage(wstring wxid, wstring msg, wstring atWxids); +void SendImageMessage(wstring wxid, wstring path);