feat: 发送图片

This commit is contained in:
hugy 2023-06-28 16:35:53 +08:00
parent 5a9f91b425
commit 0bbba4a902
5 changed files with 147 additions and 9 deletions

View File

@ -141,6 +141,22 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) {
{"code", success}, {"data", {}}, {"msg", "success"}}; {"code", success}, {"data", {}}, {"msg", "success"}};
ret = ret_data.dump(); ret = ret_data.dump();
return ret; return ret;
} else if (mg_http_match_uri(hm, "/api/sendImagesMsg")) {
std::wstring wxid = GetWStringParam(j_param, "wxid");
std::wstring path = GetWStringParam(j_param, "imagePath");
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->SendImageMsg(wxid, path);
nlohmann::json ret_data = {
{"code", success}, {"data", {}}, {"msg", "success"}};
ret = ret_data.dump();
return ret;
} else if (mg_http_match_uri(hm, "/api/sendFileMsg")) {
std::wstring wxid = GetWStringParam(j_param, "wxid");
std::wstring path = GetWStringParam(j_param, "filePath");
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->SendFileMsg(wxid, path);
nlohmann::json ret_data = {
{"code", success}, {"data", {}}, {"msg", "success"}};
ret = ret_data.dump();
return ret;
} else { } else {
nlohmann::json ret_data = { nlohmann::json ret_data = {
{"code", 200}, {"data", {}}, {"msg", "not support url"}}; {"code", 200}, {"data", {}}, {"msg", "not support url"}};

View File

@ -193,7 +193,6 @@ INT64 Manager::SendTextMsg(const std::wstring& wxid, const std::wstring& msg){
INT64 success = -1; INT64 success = -1;
prototype::WeChatString to_user(wxid); prototype::WeChatString to_user(wxid);
prototype::WeChatString text_msg(msg); prototype::WeChatString text_msg(msg);
wchar_t** msg_pptr = &text_msg.ptr;
UINT64 send_message_mgr_addr = base_addr_ + offset::kGetSendMessageMgr; UINT64 send_message_mgr_addr = base_addr_ + offset::kGetSendMessageMgr;
UINT64 send_text_msg_addr = base_addr_ + offset::kSendTextMsg; UINT64 send_text_msg_addr = base_addr_ + offset::kSendTextMsg;
UINT64 free_chat_msg_addr = base_addr_ + offset::kFreeChatMsg; UINT64 free_chat_msg_addr = base_addr_ + offset::kFreeChatMsg;
@ -215,4 +214,112 @@ INT64 Manager::SendTextMsg(const std::wstring& wxid, const std::wstring& msg){
return success; return success;
} }
INT64 Manager::SendImageMsg(const std::wstring& wxid, const std::wstring& image_path){
INT64 success = -1;
prototype::WeChatString to_user(wxid);
prototype::WeChatString image_full_path(image_path);
UINT64 send_message_mgr_addr = base_addr_ + offset::kGetSendMessageMgr;
UINT64 send_img_addr = base_addr_ + offset::kSendImageMsg;
UINT64 new_chat_msg_addr = base_addr_ + offset::kChatMsgInstanceCounter;
UINT64 free_chat_msg_addr = base_addr_ + offset::kFreeChatMsg;
func::__NewChatMsg new_chat_msg = (func::__NewChatMsg)new_chat_msg_addr;
func::__GetSendMessageMgr mgr =
(func::__GetSendMessageMgr)send_message_mgr_addr;
func::__SendImageMsg send_img = (func::__SendImageMsg)send_img_addr;
func::__FreeChatMsg free = (func::__FreeChatMsg)free_chat_msg_addr;
char chat_msg[0x460] = {0};
char chat_msg_temp[0x460] = {0};
UINT64 p_chat_msg_temp = new_chat_msg(reinterpret_cast<UINT64>(&chat_msg_temp));
UINT64 temp1 =0;
UINT64 temp2 =0;
UINT64* flag[10] = {};
flag[8] = &temp1;
flag[9] = &temp2;
flag[1] = reinterpret_cast<UINT64*>(p_chat_msg_temp);
UINT64 p_chat_msg = new_chat_msg(reinterpret_cast<UINT64>(&chat_msg));
UINT64 send_mgr = mgr();
send_img(send_mgr, p_chat_msg,
reinterpret_cast<UINT64>(&to_user),
reinterpret_cast<UINT64>(&image_full_path),
reinterpret_cast<UINT64>(&flag));
free(p_chat_msg);
free(p_chat_msg_temp);
success = 1;
return success;
}
// todo bug 9/10
INT64 Manager::SendFileMsg(const std::wstring& wxid, const std::wstring& file_path){
INT64 success = -1;
prototype::WeChatString* to_user= (prototype::WeChatString*)HeapAlloc(GetProcessHeap(),0,sizeof(prototype::WeChatString));
wchar_t * ptr_wxid = (wchar_t*)HeapAlloc(GetProcessHeap(),0,wxid.length()+1);
wmemcpy(ptr_wxid,wxid.c_str(),wxid.length()+1);
to_user->ptr = ptr_wxid;
to_user->length = static_cast<DWORD>(wxid.length());
to_user->max_length = static_cast<DWORD>(wxid.length());
to_user->c_len=0;
to_user->c_ptr=0;
prototype::WeChatString* image_full_path= (prototype::WeChatString*)HeapAlloc(GetProcessHeap(),0,sizeof(prototype::WeChatString));
wchar_t * ptr_path = (wchar_t*)HeapAlloc(GetProcessHeap(),0,file_path.length()+1);
wmemcpy(ptr_path,file_path.c_str(),file_path.length()+1);
image_full_path->ptr = ptr_path;
image_full_path->length = static_cast<DWORD>(file_path.length());
image_full_path->max_length = static_cast<DWORD>(file_path.length());
image_full_path->c_len = 0;
image_full_path->c_ptr = 0;
UINT64 get_app_msg_mgr_addr = base_addr_ + offset::kGetAppMsgMgr;
UINT64 send_file_addr = base_addr_ + offset::kSendFileMsg;
UINT64 new_chat_msg_addr = base_addr_ + offset::kChatMsgInstanceCounter;
UINT64 free_chat_msg_addr = base_addr_ + offset::kFreeChatMsg;
func::__NewChatMsg new_chat_msg = (func::__NewChatMsg)new_chat_msg_addr;
func::__GetAppMsgMgr get_app_mgr =
(func::__GetAppMsgMgr)get_app_msg_mgr_addr;
func::__SendFile send_file = (func::__SendFile)send_file_addr;
func::__FreeChatMsg free = (func::__FreeChatMsg)free_chat_msg_addr;
char* chat_msg= (char*)HeapAlloc(GetProcessHeap(),0,0x460);
UINT64* temp1 = (UINT64*)HeapAlloc(GetProcessHeap(),0,sizeof(UINT64)*4);
UINT64* temp2 = (UINT64*)HeapAlloc(GetProcessHeap(),0,sizeof(UINT64)*4);
UINT64* temp3 = (UINT64*)HeapAlloc(GetProcessHeap(),0,sizeof(UINT64)*4);
UINT64* temp4 = (UINT64*)HeapAlloc(GetProcessHeap(),0,sizeof(UINT64)*4);
ZeroMemory(temp1,sizeof(UINT64)*4);
ZeroMemory(temp2,sizeof(UINT64)*4);
ZeroMemory(temp3,sizeof(UINT64)*4);
ZeroMemory(temp4,sizeof(UINT64)*4);
*temp4=0x1F;
UINT64 temp5 = 0xC;
UINT64 app_mgr = get_app_mgr();
// UINT64 p_chat_msg = new_chat_msg(reinterpret_cast<UINT64>(chat_msg));
// send_file(app_mgr, p_chat_msg, reinterpret_cast<UINT64>(to_user),
// reinterpret_cast<UINT64>(image_full_path), 1,
// reinterpret_cast<UINT64>(temp1), 0x300,
// reinterpret_cast<UINT64>(temp2), 0,
// reinterpret_cast<UINT64>(temp3),
// reinterpret_cast<UINT64>(temp4),
// temp5);
send_file(app_mgr, reinterpret_cast<UINT64>(chat_msg),
reinterpret_cast<UINT64>(to_user),
reinterpret_cast<UINT64>(image_full_path), 1,
reinterpret_cast<UINT64>(temp1), 0, reinterpret_cast<UINT64>(temp2),
0, reinterpret_cast<UINT64>(temp3), 0, 0x0);
free(reinterpret_cast<UINT64>(chat_msg));
HeapFree(GetProcessHeap(),0,temp1);
HeapFree(GetProcessHeap(),0,temp2);
HeapFree(GetProcessHeap(),0,temp3);
HeapFree(GetProcessHeap(),0,temp4);
success = 1;
return success;
}
} // namespace wxhelper` } // namespace wxhelper`

View File

@ -10,6 +10,8 @@ class Manager {
INT64 CheckLogin(); INT64 CheckLogin();
INT64 GetSelfInfo(common::SelfInfoInner& out); INT64 GetSelfInfo(common::SelfInfoInner& out);
INT64 SendTextMsg(const std::wstring& wxid, const std::wstring& msg); INT64 SendTextMsg(const std::wstring& wxid, const std::wstring& msg);
INT64 SendImageMsg(const std::wstring& wxid, const std::wstring& image_path);
INT64 SendFileMsg(const std::wstring& wxid, const std::wstring& file_path);
private: private:
UINT64 base_addr_; UINT64 base_addr_;
}; };

View File

@ -21,6 +21,7 @@
#include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
#include <detours/detours.h> #include <detours/detours.h>
#include <heapapi.h>
#endif // PCH_H #endif // PCH_H

View File

@ -35,10 +35,18 @@ namespace function {
typedef UINT64(*__GetAccountService)(); typedef UINT64(*__GetAccountService)();
typedef UINT64(*__GetDataSavePath)(UINT64); typedef UINT64(*__GetDataSavePath)(UINT64);
typedef UINT64(*__GetCurrentDataPath)(UINT64); typedef UINT64(*__GetCurrentDataPath)(UINT64);
typedef void(*__GetSendMessageMgr)(); typedef UINT64(*__GetSendMessageMgr)();
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
UINT64, UINT64); UINT64, UINT64);
typedef void (*__FreeChatMsg)(UINT64); typedef UINT64 (*__FreeChatMsg)(UINT64);
typedef UINT64 (*__SendImageMsg)(UINT64, UINT64, UINT64, UINT64, UINT64);
typedef UINT64 (*__NewChatMsg)(UINT64);
typedef UINT64 (*__SendFile)(UINT64, UINT64, UINT64, UINT64, UINT64,UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64);
typedef UINT64(*__GetAppMsgMgr)();
typedef UINT64(*operator_new)(UINT64);
typedef UINT64(*Free)();
} // namespace function } // namespace function
namespace prototype { namespace prototype {
@ -57,7 +65,7 @@ struct WeChatString {
WeChatString(const std::wstring &s) { WeChatString(const std::wstring &s) {
ptr = (wchar_t *)(s.c_str()); ptr = (wchar_t *)(s.c_str());
length = static_cast<DWORD>(s.length()); length = static_cast<DWORD>(s.length());
max_length = static_cast<DWORD>(s.length() * 2); max_length = static_cast<DWORD>(s.length());
} }
WeChatString(const wchar_t *pStr) { WeChatString((wchar_t *)pStr); } WeChatString(const wchar_t *pStr) { WeChatString((wchar_t *)pStr); }
WeChatString(int tmp) { WeChatString(int tmp) {
@ -68,7 +76,7 @@ struct WeChatString {
WeChatString(wchar_t *pStr) { WeChatString(wchar_t *pStr) {
ptr = pStr; ptr = pStr;
length = static_cast<DWORD>(wcslen(pStr)); length = static_cast<DWORD>(wcslen(pStr));
max_length = static_cast<DWORD>(wcslen(pStr) * 2); max_length = static_cast<DWORD>(wcslen(pStr));
} }
void set_value(const wchar_t *pStr) { void set_value(const wchar_t *pStr) {
ptr = (wchar_t *)pStr; ptr = (wchar_t *)pStr;
@ -89,6 +97,10 @@ const UINT64 kSendTextMsg = 0xfcd8d0;
const UINT64 kFreeChatMsg = 0x8aaa00; const UINT64 kFreeChatMsg = 0x8aaa00;
const UINT64 kDoAddMsg = 0x1010d80; const UINT64 kDoAddMsg = 0x1010d80;
const UINT64 kSendImageMsg = 0xfc3d30;
const UINT64 kChatMsgInstanceCounter = 0x8c7fd0;
const UINT64 kSendFileMsg = 0xdd27f0;
const UINT64 kGetAppMsgMgr = 0x8c33f0;
} // namespace offset } // namespace offset
} // namespace V3_9_5_81 } // namespace V3_9_5_81