From 0bbba4a9020f23115ff36f78ba265222a2f1ad95 Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Wed, 28 Jun 2023 16:35:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E9=80=81=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http_server_callback.cc | 24 ++++++-- src/manager.cc | 109 +++++++++++++++++++++++++++++++++++- src/manager.h | 2 + src/pch.h | 1 + src/wechat_function.h | 20 +++++-- 5 files changed, 147 insertions(+), 9 deletions(-) diff --git a/src/http_server_callback.cc b/src/http_server_callback.cc index ff15f58..6e54d98 100644 --- a/src/http_server_callback.cc +++ b/src/http_server_callback.cc @@ -141,11 +141,27 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) { {"code", success}, {"data", {}}, {"msg", "success"}}; ret = ret_data.dump(); 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 { - nlohmann::json ret_data = { - {"code", 200}, {"data", {}}, {"msg", "not support url"}}; - ret = ret_data.dump(); - return ret; + nlohmann::json ret_data = { + {"code", 200}, {"data", {}}, {"msg", "not support url"}}; + ret = ret_data.dump(); + return ret; } nlohmann::json ret_data = { {"code", 200}, {"data", {}}, {"msg", "unreachable code."}}; diff --git a/src/manager.cc b/src/manager.cc index cf30eab..e87e07c 100644 --- a/src/manager.cc +++ b/src/manager.cc @@ -193,7 +193,6 @@ INT64 Manager::SendTextMsg(const std::wstring& wxid, const std::wstring& msg){ INT64 success = -1; prototype::WeChatString to_user(wxid); prototype::WeChatString text_msg(msg); - wchar_t** msg_pptr = &text_msg.ptr; UINT64 send_message_mgr_addr = base_addr_ + offset::kGetSendMessageMgr; UINT64 send_text_msg_addr = base_addr_ + offset::kSendTextMsg; 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; } +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(&chat_msg_temp)); + UINT64 temp1 =0; + UINT64 temp2 =0; + UINT64* flag[10] = {}; + flag[8] = &temp1; + flag[9] = &temp2; + flag[1] = reinterpret_cast(p_chat_msg_temp); + + UINT64 p_chat_msg = new_chat_msg(reinterpret_cast(&chat_msg)); + UINT64 send_mgr = mgr(); + send_img(send_mgr, p_chat_msg, + reinterpret_cast(&to_user), + reinterpret_cast(&image_full_path), + reinterpret_cast(&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(wxid.length()); + to_user->max_length = static_cast(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(file_path.length()); + image_full_path->max_length = static_cast(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(chat_msg)); + // send_file(app_mgr, p_chat_msg, reinterpret_cast(to_user), + // reinterpret_cast(image_full_path), 1, + // reinterpret_cast(temp1), 0x300, + // reinterpret_cast(temp2), 0, + // reinterpret_cast(temp3), + // reinterpret_cast(temp4), + // temp5); + + send_file(app_mgr, reinterpret_cast(chat_msg), + reinterpret_cast(to_user), + reinterpret_cast(image_full_path), 1, + reinterpret_cast(temp1), 0, reinterpret_cast(temp2), + 0, reinterpret_cast(temp3), 0, 0x0); + free(reinterpret_cast(chat_msg)); + HeapFree(GetProcessHeap(),0,temp1); + HeapFree(GetProcessHeap(),0,temp2); + HeapFree(GetProcessHeap(),0,temp3); + HeapFree(GetProcessHeap(),0,temp4); + success = 1; + return success; + +} + } // namespace wxhelper` \ No newline at end of file diff --git a/src/manager.h b/src/manager.h index 8e9d223..3f40051 100644 --- a/src/manager.h +++ b/src/manager.h @@ -10,6 +10,8 @@ class Manager { INT64 CheckLogin(); INT64 GetSelfInfo(common::SelfInfoInner& out); 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: UINT64 base_addr_; }; diff --git a/src/pch.h b/src/pch.h index a50ea93..df42aa6 100644 --- a/src/pch.h +++ b/src/pch.h @@ -21,6 +21,7 @@ #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" #include +#include #endif // PCH_H diff --git a/src/wechat_function.h b/src/wechat_function.h index 79ea888..f22a169 100644 --- a/src/wechat_function.h +++ b/src/wechat_function.h @@ -35,10 +35,18 @@ namespace function { typedef UINT64(*__GetAccountService)(); typedef UINT64(*__GetDataSavePath)(UINT64); typedef UINT64(*__GetCurrentDataPath)(UINT64); -typedef void(*__GetSendMessageMgr)(); +typedef UINT64(*__GetSendMessageMgr)(); typedef UINT64 (*__SendTextMsg)(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 prototype { @@ -57,7 +65,7 @@ struct WeChatString { WeChatString(const std::wstring &s) { ptr = (wchar_t *)(s.c_str()); length = static_cast(s.length()); - max_length = static_cast(s.length() * 2); + max_length = static_cast(s.length()); } WeChatString(const wchar_t *pStr) { WeChatString((wchar_t *)pStr); } WeChatString(int tmp) { @@ -68,7 +76,7 @@ struct WeChatString { WeChatString(wchar_t *pStr) { ptr = pStr; length = static_cast(wcslen(pStr)); - max_length = static_cast(wcslen(pStr) * 2); + max_length = static_cast(wcslen(pStr)); } void set_value(const wchar_t *pStr) { ptr = (wchar_t *)pStr; @@ -89,6 +97,10 @@ const UINT64 kSendTextMsg = 0xfcd8d0; const UINT64 kFreeChatMsg = 0x8aaa00; const UINT64 kDoAddMsg = 0x1010d80; +const UINT64 kSendImageMsg = 0xfc3d30; +const UINT64 kChatMsgInstanceCounter = 0x8c7fd0; +const UINT64 kSendFileMsg = 0xdd27f0; +const UINT64 kGetAppMsgMgr = 0x8c33f0; } // namespace offset } // namespace V3_9_5_81