From 272d62b0e9e519b24353cd4ac97e619dfa4fe73a Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Sat, 1 Jul 2023 13:32:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A5=BD=E5=8F=8B=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http_server_callback.cc | 26 ++++++++++++++++++++++++-- src/manager.cc | 33 ++++++++++++++++++++++++++++++++- src/manager.h | 1 + src/utils.cc | 17 +++++++++++++++++ src/utils.h | 3 ++- src/wechat_function.h | 33 +++++++++++++++++++++++++++++++-- 6 files changed, 107 insertions(+), 6 deletions(-) diff --git a/src/http_server_callback.cc b/src/http_server_callback.cc index 6e54d98..0f46c16 100644 --- a/src/http_server_callback.cc +++ b/src/http_server_callback.cc @@ -157,12 +157,34 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) { {"code", success}, {"data", {}}, {"msg", "success"}}; ret = ret_data.dump(); return ret; - } else { + } else if (mg_http_match_uri(hm, "/api/getContactList")) { + std::vector vec; + INT64 success = wxhelper::GlobalContext::GetInstance().mgr->GetContacts(vec); + nlohmann::json ret_data = { + {"code", success}, {"data", {}}, {"msg", "success"}}; + for (unsigned int i = 0; i < vec.size(); i++) { + nlohmann::json item = { + {"customAccount", vec[i].custom_account}, + {"encryptName", vec[i].encrypt_name}, + {"type", vec[i].type}, + {"verifyFlag", vec[i].verify_flag}, + {"wxid", vec[i].wxid}, + {"nickname", vec[i].nickname}, + {"pinyin", vec[i].pinyin}, + {"pinyinAll", vec[i].pinyin_all}, + {"reserved1", vec[i].reserved1}, + {"reserved2", vec[i].reserved2}, + }; + ret_data["data"].push_back(item); + } + 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", "unreachable code."}}; ret = ret_data.dump(); diff --git a/src/manager.cc b/src/manager.cc index e87e07c..1bce95a 100644 --- a/src/manager.cc +++ b/src/manager.cc @@ -322,4 +322,35 @@ INT64 Manager::SendFileMsg(const std::wstring& wxid, const std::wstring& file_pa } -} // namespace wxhelper` \ No newline at end of file +INT64 Manager::GetContacts(std::vector &vec) { + INT64 success = -1; + UINT64 get_contact_mgr_addr = base_addr_ + offset::kGetContactMgr; + UINT64 get_contact_list_addr = base_addr_ + offset::kGetContactList; + func::__GetContactMgr get_contact_mgr = + (func::__GetContactMgr)get_contact_mgr_addr; + func::__GetContactList get_contact_list = + (func::__GetContactList)get_contact_list_addr; + UINT64 mgr = get_contact_mgr(); + UINT64 contact_vec[3] = {0, 0, 0}; + success = get_contact_list(mgr, reinterpret_cast(&contact_vec)); + + UINT64 start = contact_vec[0]; + UINT64 end = contact_vec[2]; + while (start < end) { + common::ContactInner temp; + temp.wxid = Utils::ReadWstringThenConvert(start + 0x10); + temp.custom_account = Utils::ReadWstringThenConvert(start + 0x30); + temp.encrypt_name = Utils::ReadWstringThenConvert(start + 0x50); + temp.nickname = Utils::ReadWstringThenConvert(start + 0xA0); + temp.pinyin = Utils::ReadWstringThenConvert(start + 0x108); + temp.pinyin_all = Utils::ReadWstringThenConvert(start + 0x128); + temp.verify_flag = *(DWORD *)(start + 0x70); + temp.type = *(DWORD *)(start + 0x74); + temp.reserved1 = *(DWORD *)(start + 0x1F0); + temp.reserved2 = *(DWORD *)(start + 0x1F4); + vec.push_back(temp); + start += 0x698; + } + return success; +} +} // namespace wxhelper` \ No newline at end of file diff --git a/src/manager.h b/src/manager.h index 3f40051..e971f02 100644 --- a/src/manager.h +++ b/src/manager.h @@ -12,6 +12,7 @@ class Manager { 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); + INT64 GetContacts(std::vector &vec); private: UINT64 base_addr_; }; diff --git a/src/utils.cc b/src/utils.cc index 2cd7310..de8484a 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -302,4 +302,21 @@ std::string Utils::ImageXor(std::string buf){ } return std::string(); } + +std::wstring Utils::ReadWstring(INT64 addr){ + DWORD len = *(DWORD *)(addr + 0x8); + if (len == 0) { + return std::wstring(); + } + wchar_t * str = *(wchar_t **)(addr); + if (str == NULL) { + return std::wstring(); + } + return std::wstring(str, len); + +} +std::string Utils::ReadWstringThenConvert(INT64 addr){ + std::wstring wstr = ReadWstring(addr); + return WstringToUTF8(wstr); +} } // namespace wxhelper \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 0226ffe..420f408 100644 --- a/src/utils.h +++ b/src/utils.h @@ -56,7 +56,8 @@ class Utils { static std::string ReadWeChatStr(INT64 addr); static std::string ImageXor(std::string buf); - + static std::wstring ReadWstring(INT64 addr); + static std::string ReadWstringThenConvert(INT64 addr); template static std::vector split(T1 str, T2 letter) { std::vector arr; diff --git a/src/wechat_function.h b/src/wechat_function.h index f22a169..9e46130 100644 --- a/src/wechat_function.h +++ b/src/wechat_function.h @@ -29,6 +29,31 @@ struct SelfInfoInner { std::string db_key; }; +struct ContactInner { + std::string wxid; + std::string custom_account; + std::string encrypt_name; + std::string nickname; + std::string pinyin; + std::string pinyin_all; + DWORD type; + DWORD verify_flag; + DWORD reserved1; + DWORD reserved2; + ContactInner(){ + wxid = ""; + custom_account = ""; + encrypt_name = ""; + nickname =""; + pinyin =""; + pinyin_all =""; + type = -1; + verify_flag = -1; + reserved1 = -1; + reserved2 = -1; + } +}; + } // namespace common namespace V3_9_5_81 { namespace function { @@ -44,9 +69,11 @@ 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(*__OperatorNew)(UINT64); -typedef UINT64(*Free)(); +typedef UINT64(*__Free)(); +typedef UINT64 (*__GetContactMgr)(); +typedef UINT64 (*__GetContactList)(UINT64,UINT64); } // namespace function namespace prototype { @@ -101,6 +128,8 @@ const UINT64 kSendImageMsg = 0xfc3d30; const UINT64 kChatMsgInstanceCounter = 0x8c7fd0; const UINT64 kSendFileMsg = 0xdd27f0; const UINT64 kGetAppMsgMgr = 0x8c33f0; +const UINT64 kGetContactMgr = 0x8ae3d0; +const UINT64 kGetContactList = 0xeab270; } // namespace offset } // namespace V3_9_5_81