From bede8f7150e9ceb99584a6fec7962ca317f1b4f4 Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Wed, 1 Nov 2023 21:57:03 +0800 Subject: [PATCH] feat: check login and self info --- app/base/src/include/utils.h | 2 + app/base/src/utils.cc | 14 +++ app/wxhelper/src/global_manager.cc | 2 + app/wxhelper/src/http_url_handler.cc | 37 +++++- app/wxhelper/src/http_url_handler.h | 4 +- app/wxhelper/src/wechat_function.h | 8 ++ app/wxhelper/src/wechat_service.cc | 175 ++++++++++++++++++++++++++- app/wxhelper/src/wxutils.cc | 3 + 8 files changed, 240 insertions(+), 5 deletions(-) diff --git a/app/base/src/include/utils.h b/app/base/src/include/utils.h index f7c6803..5b83ff5 100644 --- a/app/base/src/include/utils.h +++ b/app/base/src/include/utils.h @@ -58,6 +58,8 @@ void CloseConsole(); void HideModule(HMODULE module); bool IsDigit(const std::string &str); + +std::string Bytes2Hex(const BYTE *bytes, const int length); } // namespace utils } // namespace base #endif \ No newline at end of file diff --git a/app/base/src/utils.cc b/app/base/src/utils.cc index b663b58..af605a2 100644 --- a/app/base/src/utils.cc +++ b/app/base/src/utils.cc @@ -167,5 +167,19 @@ bool IsDigit(const std::string &str) { return true; } +std::string Bytes2Hex(const BYTE *bytes, const int length) { + if (bytes == NULL) { + return ""; + } + std::string buff; + const int len = length; + for (int j = 0; j < len; j++) { + int high = bytes[j] / 16, low = bytes[j] % 16; + buff += (high < 10) ? ('0' + high) : ('a' + high - 10); + buff += (low < 10) ? ('0' + low) : ('a' + low - 10); + } + return buff; +} + } // namespace utils } // namespace base diff --git a/app/wxhelper/src/global_manager.cc b/app/wxhelper/src/global_manager.cc index ce04c66..585694b 100644 --- a/app/wxhelper/src/global_manager.cc +++ b/app/wxhelper/src/global_manager.cc @@ -26,6 +26,8 @@ void GlobalManager::initialize(HMODULE module) { http_server->AddHttpApiUrl("/api/hookSyncMsg", HookSyncMsg); http_server->AddHttpApiUrl("/api/getContactList", GetContacts); http_server->AddHttpApiUrl("/api/unhookSyncMsg", UnHookSyncMsg); + http_server->AddHttpApiUrl("/api/checkLogin", CheckLogin); + http_server->AddHttpApiUrl("/api/userInfo", GetSelfInfo); 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 9128b13..baa9121 100644 --- a/app/wxhelper/src/http_url_handler.cc +++ b/app/wxhelper/src/http_url_handler.cc @@ -3,8 +3,8 @@ #include #include "utils.h" -#include "wechat_service.h" #include "wechat_hook.h" +#include "wechat_service.h" #define STR2ULL(str) (base::utils::IsDigit(str) ? stoull(str) : 0) #define STR2LL(str) (base::utils::IsDigit(str) ? stoll(str) : 0) @@ -69,7 +69,7 @@ std::string HookSyncMsg(mg_http_message* hm) { std::string GetContacts(mg_http_message* hm) { std::vector vec; - INT64 success = WechatService::GetInstance().GetContacts(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++) { @@ -90,10 +90,43 @@ std::string GetContacts(mg_http_message* hm) { 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(); } + +std::string CheckLogin(mg_http_message* hm) { + INT64 success = WechatService::GetInstance().CheckLogin(); + nlohmann::json ret_data = { + {"code", success}, {"data", {}}, {"msg", "success"}}; + return ret_data.dump(); +} + +std::string GetSelfInfo(mg_http_message* hm) { + common::SelfInfoInner self_info; + INT64 success = WechatService::GetInstance().GetSelfInfo(self_info); + nlohmann::json ret_data = { + {"code", success}, {"data", {}}, {"msg", "success"}}; + if (success) { + nlohmann::json j_info = { + {"name", self_info.name}, + {"city", self_info.city}, + {"province", self_info.province}, + {"country", self_info.country}, + {"account", self_info.account}, + {"wxid", self_info.wxid}, + {"mobile", self_info.mobile}, + {"headImage", self_info.head_img}, + {"signature", self_info.signature}, + {"dataSavePath", self_info.data_save_path}, + {"currentDataPath", self_info.current_data_path}, + {"dbKey", self_info.db_key}, + }; + ret_data["data"] = j_info; + } + 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 3e281cb..7b4ef20 100644 --- a/app/wxhelper/src/http_url_handler.h +++ b/app/wxhelper/src/http_url_handler.h @@ -8,6 +8,8 @@ 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); -} +std::string CheckLogin(struct mg_http_message *hm); +std::string GetSelfInfo(struct mg_http_message *hm); +} // namespace wxhelper #endif \ No newline at end of file diff --git a/app/wxhelper/src/wechat_function.h b/app/wxhelper/src/wechat_function.h index 06c10ce..5e0c5fe 100644 --- a/app/wxhelper/src/wechat_function.h +++ b/app/wxhelper/src/wechat_function.h @@ -490,6 +490,11 @@ const UINT64 kSendTextMsg = 0x1024370; const UINT64 kDoAddMsg = 0x106b810; const UINT64 kGetContactMgr = 0x8ebfb0; const UINT64 kGetContactList = 0xeff050; +const UINT64 kGetAccountServiceMgr = 0x8fff40; +const UINT64 kGetAppDataSavePath = 0x1336c60; +const UINT64 kGetCurrentDataPath = 0xfacb50; + + } // namespace offset namespace function { typedef UINT64 (*__GetSendMessageMgr)(); @@ -498,6 +503,9 @@ typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, typedef UINT64 (*__FreeChatMsg)(UINT64); typedef UINT64 (*__GetContactMgr)(); typedef UINT64 (*__GetContactList)(UINT64, UINT64); +typedef UINT64(*__GetAccountService)(); +typedef UINT64 (*__GetDataSavePath)(UINT64); +typedef UINT64 (*__GetCurrentDataPath)(UINT64); } // namespace function } // namespace V3_9_7_29 } // namespace wxhelper diff --git a/app/wxhelper/src/wechat_service.cc b/app/wxhelper/src/wechat_service.cc index 3115512..140b94f 100644 --- a/app/wxhelper/src/wechat_service.cc +++ b/app/wxhelper/src/wechat_service.cc @@ -1,14 +1,185 @@ #include "wechat_service.h" #include "wxutils.h" +#include "utils.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; namespace wxhelper { WechatService::~WechatService() {} -INT64 WechatService::CheckLogin() { return INT64(); } +INT64 WechatService::CheckLogin() { + INT64 success = -1; + UINT64 accout_service_addr = base_addr_ + offset::kGetAccountServiceMgr; + func::__GetAccountService GetSevice = + (func::__GetAccountService)accout_service_addr; + UINT64 service_addr = GetSevice(); + if (service_addr) { + success = *(UINT64*)(service_addr + 0x7F8); + } + return success; +} -INT64 WechatService::GetSelfInfo(common::SelfInfoInner& out) { return INT64(); } +INT64 WechatService::GetSelfInfo(common::SelfInfoInner& out) { + INT64 success = -1; + UINT64 accout_service_addr = base_addr_ + offset::kGetAccountServiceMgr; + UINT64 get_app_data_save_path_addr = base_addr_ + offset::kGetAppDataSavePath; + UINT64 get_current_data_path_addr = base_addr_ + offset::kGetCurrentDataPath; + func::__GetAccountService GetSevice = (func::__GetAccountService)accout_service_addr; + func::__GetDataSavePath GetDataSavePath = (func::__GetDataSavePath)get_app_data_save_path_addr; + func::__GetCurrentDataPath GetCurrentDataPath = (func::__GetCurrentDataPath)get_current_data_path_addr; + + UINT64 service_addr = GetSevice(); + if (service_addr) { + if (*(INT64 *)(service_addr + 0x80) == 0 || + *(INT64 *)(service_addr + 0x80 + 0x10) == 0) { + out.wxid = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x80 + 0x18) == 0xF) { + out.wxid = std::string((char *)(service_addr + 0x80), + *(INT64 *)(service_addr + 0x80 + 0x10)); + } else { + out.wxid = std::string(*(char **)(service_addr + 0x80), + *(INT64 *)(service_addr + 0x80 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x108) == 0 || + *(INT64 *)(service_addr + 0x108 + 0x10) == 0) { + out.account = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x108 + 0x18) == 0xF) { + out.account = std::string((char *)(service_addr + 0x108), + *(INT64 *)(service_addr + 0x108 + 0x10)); + } else { + out.account = std::string(*(char **)(service_addr + 0x108), + *(INT64 *)(service_addr + 0x108 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x128) == 0 || + *(INT64 *)(service_addr + 0x128 + 0x10) == 0) { + out.mobile = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x128 + 0x18) == 0xF) { + out.mobile = std::string((char *)(service_addr + 0x128), + *(INT64 *)(service_addr + 0x128 + 0x10)); + } else { + out.mobile = std::string(*(char **)(service_addr + 0x128), + *(INT64 *)(service_addr + 0x128 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x148) == 0 || + *(INT64 *)(service_addr + 0x148 + 0x10) == 0) { + out.signature = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x148 + 0x18) == 0xF) { + out.signature = std::string((char *)(service_addr + 0x148), + *(INT64 *)(service_addr + 0x148 + 0x10)); + } else { + out.signature = std::string(*(char **)(service_addr + 0x148), + *(INT64 *)(service_addr + 0x148 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x168) == 0 || + *(INT64 *)(service_addr + 0x168 + 0x10) == 0) { + out.country = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x168 + 0x18) == 0xF) { + out.country = std::string((char *)(service_addr + 0x168), + *(INT64 *)(service_addr + 0x168 + 0x10)); + } else { + out.country = std::string(*(char **)(service_addr + 0x168), + *(INT64 *)(service_addr + 0x168 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x188) == 0 || + *(INT64 *)(service_addr + 0x188 + 0x10) == 0) { + out.province = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x188 + 0x18) == 0xF) { + out.province = std::string((char *)(service_addr + 0x188), + *(INT64 *)(service_addr + 0x188 + 0x10)); + } else { + out.province = std::string(*(char **)(service_addr + 0x188), + *(INT64 *)(service_addr + 0x188 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x1A8) == 0 || + *(INT64 *)(service_addr + 0x1A8 + 0x10) == 0) { + out.city = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x1A8 + 0x18) == 0xF) { + out.city = std::string((char *)(service_addr + 0x1A8), + *(INT64 *)(service_addr + 0x1A8 + 0x10)); + } else { + out.city = std::string(*(char **)(service_addr + 0x1A8), + *(INT64 *)(service_addr + 0x1A8 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x1E8) == 0 || + *(INT64 *)(service_addr + 0x1E8 + 0x10) == 0) { + out.name = std::string(); + } else { + if (*(INT64 *)(service_addr + 0x1E8 + 0x18) == 0xF) { + out.name = std::string((char *)(service_addr + 0x1E8), + *(INT64 *)(service_addr + 0x1E8 + 0x10)); + } else { + out.name = std::string(*(char **)(service_addr + 0x1E8), + *(INT64 *)(service_addr + 0x1E8 + 0x10)); + } + } + + if (*(INT64 *)(service_addr + 0x450) == 0 || + *(INT64 *)(service_addr + 0x450 + 0x10) == 0) { + out.head_img = std::string(); + } else { + out.head_img = std::string(*(char **)(service_addr + 0x450), + *(INT64 *)(service_addr + 0x450 + 0x10)); + } + + if (*(INT64 *)(service_addr + 0x6E0) == 0 || + *(INT64 *)(service_addr + 0x6E8) == 0) { + out.db_key = std::string(); + } else { + INT64 byte_addr = *(INT64 *)(service_addr + 0x6E0); + INT64 len = *(INT64 *)(service_addr + 0x6E8); + out.db_key = base::utils::Bytes2Hex((BYTE *)byte_addr, static_cast(len)); + } + + UINT64 flag = *(UINT64 *)(service_addr + 0x7F8); + if (flag == 1) { + prototype::WeChatString current_data_path; + // _GetCurrentDataPath(get_current_data_path_addr, + // reinterpret_cast(¤t_data_path)); + GetCurrentDataPath(reinterpret_cast(¤t_data_path)); + if (current_data_path.ptr) { + out.current_data_path = base::utils::WstringToUtf8( + std::wstring(current_data_path.ptr, current_data_path.length)); + } else { + out.current_data_path = std::string(); + } + } + } + + prototype::WeChatString data_save_path; + // _GetDataSavePath(get_app_data_save_path_addr, + // reinterpret_cast(&data_save_path)); + GetCurrentDataPath(reinterpret_cast(&data_save_path)); + if (data_save_path.ptr) { + out.data_save_path = base::utils::WstringToUtf8( + std::wstring(data_save_path.ptr, data_save_path.length)); + } else { + out.data_save_path = std::string(); + } + + success = 1; + return success; + } INT64 WechatService::SendTextMsg(const std::wstring& wxid, const std::wstring& msg) { diff --git a/app/wxhelper/src/wxutils.cc b/app/wxhelper/src/wxutils.cc index 7c6211d..855b1eb 100644 --- a/app/wxhelper/src/wxutils.cc +++ b/app/wxhelper/src/wxutils.cc @@ -92,5 +92,8 @@ std::string ReadWstringThenConvert(INT64 addr) { std::wstring wstr = ReadWstring(addr); return base::utils::WstringToUtf8(wstr); } + + + } // namespace wxutils } // namespace wxhelper