From 1ff56fc0557c1f938c438d4de0bd7e9e6a8cd9af Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Thu, 26 Oct 2023 22:16:31 +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 --- app/wxhelper/src/global_manager.cc | 3 +++ app/wxhelper/src/http_url_handler.cc | 30 +++++++++++++++++++++++++++ app/wxhelper/src/http_url_handler.h | 2 ++ app/wxhelper/src/wechat_function.h | 4 ++++ app/wxhelper/src/wechat_hook.cc | 20 +++++++++++++++++- app/wxhelper/src/wechat_service.cc | 31 +++++++++++++++++++++++++++- 6 files changed, 88 insertions(+), 2 deletions(-) diff --git a/app/wxhelper/src/global_manager.cc b/app/wxhelper/src/global_manager.cc index ad14e32..ce04c66 100644 --- a/app/wxhelper/src/global_manager.cc +++ b/app/wxhelper/src/global_manager.cc @@ -24,6 +24,9 @@ void GlobalManager::initialize(HMODULE module) { new http::HttpServer(config->GetPort())); http_server->AddHttpApiUrl("/api/sendTextMsg", SendTextMsg); http_server->AddHttpApiUrl("/api/hookSyncMsg", HookSyncMsg); + http_server->AddHttpApiUrl("/api/getContactList", GetContacts); + http_server->AddHttpApiUrl("/api/unhookSyncMsg", UnHookSyncMsg); + http_server->Start(); base::ThreadPool::GetInstance().Create(2, 8); diff --git a/app/wxhelper/src/http_url_handler.cc b/app/wxhelper/src/http_url_handler.cc index 57d673d..9128b13 100644 --- a/app/wxhelper/src/http_url_handler.cc +++ b/app/wxhelper/src/http_url_handler.cc @@ -66,4 +66,34 @@ std::string HookSyncMsg(mg_http_message* hm) { std::string ret = ret_data.dump(); return ret; } + +std::string GetContacts(mg_http_message* hm) { + std::vector vec; + INT64 success = WechatService::GetInstance().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); + } + std::string ret = ret_data.dump(); + return ret; +} +std::string UnHookSyncMsg(mg_http_message* hm) { + INT64 success = hook::WechatHook::GetInstance().UnHookSyncMsg(); + nlohmann::json ret_data = { + {"code", success}, {"data", {}}, {"msg", "success"}}; + return ret_data.dump(); +} } // namespace wxhelper \ No newline at end of file diff --git a/app/wxhelper/src/http_url_handler.h b/app/wxhelper/src/http_url_handler.h index 37ae834..3e281cb 100644 --- a/app/wxhelper/src/http_url_handler.h +++ b/app/wxhelper/src/http_url_handler.h @@ -6,6 +6,8 @@ namespace wxhelper { std::string SendTextMsg(struct mg_http_message *hm); std::string HookSyncMsg(struct mg_http_message *hm); +std::string GetContacts(struct mg_http_message *hm); +std::string UnHookSyncMsg(struct mg_http_message *hm); } #endif \ No newline at end of file diff --git a/app/wxhelper/src/wechat_function.h b/app/wxhelper/src/wechat_function.h index 4f0eb26..06c10ce 100644 --- a/app/wxhelper/src/wechat_function.h +++ b/app/wxhelper/src/wechat_function.h @@ -488,12 +488,16 @@ const UINT64 kGetSendMessageMgr = 0x8fe740; const UINT64 kFreeChatMsg = 0x8fffc0; const UINT64 kSendTextMsg = 0x1024370; const UINT64 kDoAddMsg = 0x106b810; +const UINT64 kGetContactMgr = 0x8ebfb0; +const UINT64 kGetContactList = 0xeff050; } // namespace offset namespace function { typedef UINT64 (*__GetSendMessageMgr)(); typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64); typedef UINT64 (*__FreeChatMsg)(UINT64); +typedef UINT64 (*__GetContactMgr)(); +typedef UINT64 (*__GetContactList)(UINT64, UINT64); } // namespace function } // namespace V3_9_7_29 } // namespace wxhelper diff --git a/app/wxhelper/src/wechat_hook.cc b/app/wxhelper/src/wechat_hook.cc index bbcc65c..edfe59f 100644 --- a/app/wxhelper/src/wechat_hook.cc +++ b/app/wxhelper/src/wechat_hook.cc @@ -184,4 +184,22 @@ int WechatHook::HookSyncMsg() { } return ret; } -} // namespace hook +int WechatHook::UnHookSyncMsg() { + if (!sync_msg_flag_) { + SPDLOG_INFO("call UnHookSyncMsg but no hooked "); + return NO_ERROR; + } + UINT64 base = wxhelper::wxutils::GetWeChatWinBase(); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourDetach(&(PVOID &)RealDoAddMsg, &HandleSyncMsg); + LONG ret = DetourTransactionCommit(); + if (ret == NO_ERROR) { + sync_msg_flag_ = false; + strcpy_s(kServerIp, "127.0.0.1"); + } + return ret; + } + int WechatHook::HookLog() { return 0; } + int WechatHook::UnHookLog() { return 0; } + } // namespace hook diff --git a/app/wxhelper/src/wechat_service.cc b/app/wxhelper/src/wechat_service.cc index 1ff05ce..3115512 100644 --- a/app/wxhelper/src/wechat_service.cc +++ b/app/wxhelper/src/wechat_service.cc @@ -1,4 +1,5 @@ #include "wechat_service.h" +#include "wxutils.h" namespace offset = wxhelper::V3_9_7_29::offset; namespace prototype = wxhelper::V3_9_7_29::prototype; namespace func = wxhelper::V3_9_7_29::function; @@ -46,7 +47,35 @@ INT64 WechatService::SendFileMsg(const std::wstring& wxid, } INT64 WechatService::GetContacts(std::vector& vec) { - return INT64(); + 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 = wxutils::ReadWstringThenConvert(start + 0x10); + temp.custom_account = wxutils::ReadWstringThenConvert(start + 0x30); + temp.encrypt_name = wxutils::ReadWstringThenConvert(start + 0x50); + temp.nickname = wxutils::ReadWstringThenConvert(start + 0xA0); + temp.pinyin = wxutils::ReadWstringThenConvert(start + 0x108); + temp.pinyin_all = wxutils::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 += 0x6A8; + } + return success; } INT64 WechatService::GetChatRoomDetailInfo(