Refactoring
This commit is contained in:
@@ -24,7 +24,7 @@ using invite_member_to_chatroom_t = QWORD (*)(QWORD, QWORD, QWORD, QWORD);
|
||||
static vector<WxString> parse_wxids(const string &wxids)
|
||||
{
|
||||
vector<WxString> wx_members;
|
||||
wstringstream wss(String2Wstring(wxids));
|
||||
wstringstream wss(util::s2w(wxids));
|
||||
wstring wstr;
|
||||
while (getline(wss, wstr, L',')) {
|
||||
wx_members.emplace_back(wstr);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include "contact_mgmt.h"
|
||||
|
||||
#include "fill_response.h"
|
||||
#include "log.hpp"
|
||||
#include "pb_util.h"
|
||||
@@ -55,7 +56,7 @@ static string get_cnt_string(QWORD start, QWORD end, const uint8_t *feat, size_t
|
||||
return "";
|
||||
}
|
||||
|
||||
return Wstring2String(wstring(GET_WSTRING_FROM_P(pfeat + FEAT_LEN + 4), lfeat));
|
||||
return util::w2s(util::get_p_wstring(pfeat + FEAT_LEN + 4, lfeat));
|
||||
}
|
||||
|
||||
vector<RpcContact_t> get_contacts()
|
||||
@@ -80,10 +81,10 @@ vector<RpcContact_t> get_contacts()
|
||||
QWORD pbin = GET_QWORD(pstart + OS_CONTACT_BIN);
|
||||
QWORD lenbin = GET_DWORD(pstart + OS_CONTACT_BIN_LEN);
|
||||
|
||||
cnt.wxid = GetStringByWstrAddr(pstart + OS_CONTACT_WXID);
|
||||
cnt.code = GetStringByWstrAddr(pstart + OS_CONTACT_CODE);
|
||||
cnt.remark = GetStringByWstrAddr(pstart + OS_CONTACT_REMARK);
|
||||
cnt.name = GetStringByWstrAddr(pstart + OS_CONTACT_NAME);
|
||||
cnt.wxid = util::get_str_by_wstr_addr(pstart + OS_CONTACT_WXID);
|
||||
cnt.code = util::get_str_by_wstr_addr(pstart + OS_CONTACT_CODE);
|
||||
cnt.remark = util::get_str_by_wstr_addr(pstart + OS_CONTACT_REMARK);
|
||||
cnt.name = util::get_str_by_wstr_addr(pstart + OS_CONTACT_NAME);
|
||||
|
||||
cnt.country = get_cnt_string(pbin, pbin + lenbin, FEAT_COUNTRY, FEAT_LEN);
|
||||
cnt.province = get_cnt_string(pbin, pbin + lenbin, FEAT_PROVINCE, FEAT_LEN);
|
||||
@@ -112,8 +113,8 @@ int accept_new_friend(const std::string &v3, const std::string &v4, int scene)
|
||||
|
||||
LOG_DEBUG("\nv3: {}\nv4: {}\nscene: {}", v3, v4, scene);
|
||||
|
||||
wstring ws_v3 = String2Wstring(v3);
|
||||
wstring ws_v4 = String2Wstring(v4);
|
||||
wstring ws_v3 = util::s2w(v3);
|
||||
wstring ws_v4 = util::s2w(v4);
|
||||
WxString wx_v3(ws_v3);
|
||||
WxString wx_v4(ws_v4);
|
||||
|
||||
@@ -154,7 +155,7 @@ RpcContact_t get_contact_by_wxid(const string &wxid)
|
||||
RpcContact_t contact;
|
||||
#if 0
|
||||
char buff[0x440] = { 0 };
|
||||
wstring ws_wxid = String2Wstring(wxid);
|
||||
wstring ws_wxid = util::s2w(wxid);
|
||||
WxString pri(ws_wxid);
|
||||
|
||||
DWORD contact_mgr_addr = g_WeChatWinDllAddr + 0x75A4A0;
|
||||
@@ -176,9 +177,9 @@ RpcContact_t get_contact_by_wxid(const string &wxid)
|
||||
}
|
||||
|
||||
contact.wxid = wxid;
|
||||
contact.code = GetStringByWstrAddr(reinterpret_cast<DWORD>(buff) + g_WxCalls.contact.wxCode);
|
||||
contact.remark = GetStringByWstrAddr(reinterpret_cast<DWORD>(buff) + g_WxCalls.contact.wxRemark);
|
||||
contact.name = GetStringByWstrAddr(reinterpret_cast<DWORD>(buff) + g_WxCalls.contact.wxName);
|
||||
contact.code = util::get_str_by_wstr_addr(reinterpret_cast<DWORD>(buff) + g_WxCalls.contact.wxCode);
|
||||
contact.remark = util::get_str_by_wstr_addr(reinterpret_cast<DWORD>(buff) + g_WxCalls.contact.wxRemark);
|
||||
contact.name = util::get_str_by_wstr_addr(reinterpret_cast<DWORD>(buff) + g_WxCalls.contact.wxName);
|
||||
contact.gender = GET_DWORD(reinterpret_cast<DWORD>(buff) + 0x148);
|
||||
|
||||
__asm {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <algorithm>
|
||||
#include "exec_sql.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "exec_sql.h"
|
||||
#include "fill_response.h"
|
||||
#include "log.hpp"
|
||||
#include "pb_util.h"
|
||||
@@ -29,7 +30,7 @@ static db_map_t db_map;
|
||||
static void get_db_handle(QWORD base, QWORD offset)
|
||||
{
|
||||
auto *wsp = reinterpret_cast<wchar_t *>(*(QWORD *)(base + offset + OFFSET_DB_NAME));
|
||||
std::string dbname = Wstring2String(std::wstring(wsp));
|
||||
std::string dbname = util::w2s(std::wstring(wsp));
|
||||
db_map[dbname] = GET_QWORD(base + offset);
|
||||
}
|
||||
|
||||
@@ -41,12 +42,12 @@ static void get_msg_db_handle(QWORD msg_mgr_addr)
|
||||
QWORD db_addr = GET_QWORD(p_start + i * 0x08);
|
||||
if (db_addr) {
|
||||
// MSGi.db
|
||||
std::string dbname = Wstring2String(GET_WSTRING(db_addr));
|
||||
std::string dbname = util::w2s(get_pp_wstring(db_addr));
|
||||
db_map[dbname] = GET_QWORD(db_addr + 0x78);
|
||||
|
||||
// MediaMsgi.db
|
||||
QWORD mmdb_addr = GET_QWORD(db_addr + 0x20);
|
||||
std::string mmdbname = Wstring2String(GET_WSTRING(mmdb_addr + 0x78));
|
||||
std::string mmdbname = util::w2s(get_pp_wstring(mmdb_addr + 0x78));
|
||||
db_map[mmdbname] = GET_QWORD(mmdb_addr + 0x50);
|
||||
}
|
||||
}
|
||||
@@ -199,7 +200,7 @@ int get_local_id_and_dbidx(uint64_t id, uint64_t *local_id, uint32_t *db_idx)
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string dbname = Wstring2String(GET_WSTRING(db_addr));
|
||||
std::string dbname = util::w2s(get_pp_wstring(db_addr));
|
||||
db_map[dbname] = GET_QWORD(db_addr + 0x78);
|
||||
|
||||
std::string sql = "SELECT localId FROM MSG WHERE MsgSvrID=" + std::to_string(id) + ";";
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#pragma warning(disable : 4244)
|
||||
#include "funcs.h"
|
||||
|
||||
#include "framework.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include "framework.h"
|
||||
|
||||
#include "codec.h"
|
||||
#include "exec_sql.h"
|
||||
#include "funcs.h"
|
||||
#include "log.hpp"
|
||||
#include "receive_msg.h"
|
||||
#include "spy_types.h"
|
||||
@@ -342,7 +343,7 @@ OcrResult_t GetOcrResult(string path)
|
||||
QWORD *pUnk1 = &unk1;
|
||||
QWORD *pUnk2 = &unk2;
|
||||
// 路径分隔符有要求,必须为 `\`
|
||||
wstring wsPath = String2Wstring(fs::path(path).make_preferred().string());
|
||||
wstring wsPath = util::s2w(fs::path(path).make_preferred().string());
|
||||
WxString wxPath(wsPath);
|
||||
vector<QWORD> *pv = (vector<QWORD> *)HeapAlloc(GetProcessHeap(), 0, 0x20);
|
||||
RawVector_t *pRv = (RawVector_t *)pv;
|
||||
@@ -358,7 +359,7 @@ OcrResult_t GetOcrResult(string path)
|
||||
QWORD header = GET_QWORD(buff);
|
||||
for (QWORD i = 0; i < count; i++) {
|
||||
QWORD content = GET_QWORD(header);
|
||||
ret.result += Wstring2String(GET_WSTRING(content + 0x28));
|
||||
ret.result += util::w2s(get_pp_wstring(content + 0x28));
|
||||
ret.result += "\n";
|
||||
header = content;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
#include "receive_msg.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
@@ -6,7 +7,6 @@
|
||||
#include "framework.h"
|
||||
|
||||
#include "log.hpp"
|
||||
#include "receive_msg.h"
|
||||
#include "user_info.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -42,20 +42,21 @@ QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2)
|
||||
wxMsg.type = GET_DWORD(arg2 + OS_RECV_MSG_TYPE);
|
||||
wxMsg.is_self = GET_DWORD(arg2 + OS_RECV_MSG_SELF);
|
||||
wxMsg.ts = GET_DWORD(arg2 + OS_RECV_MSG_TS);
|
||||
wxMsg.content = GetStringByWstrAddr(arg2 + OS_RECV_MSG_CONTENT);
|
||||
wxMsg.sign = GetStringByWstrAddr(arg2 + OS_RECV_MSG_SIGN);
|
||||
wxMsg.xml = GetStringByWstrAddr(arg2 + OS_RECV_MSG_XML);
|
||||
wxMsg.roomid = GetStringByWstrAddr(arg2 + OS_RECV_MSG_ROOMID);
|
||||
wxMsg.content = util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_CONTENT);
|
||||
wxMsg.sign = util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_SIGN);
|
||||
wxMsg.xml = util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_XML);
|
||||
wxMsg.roomid = util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_ROOMID);
|
||||
|
||||
if (wxMsg.roomid.find("@chatroom") != std::string::npos) {
|
||||
wxMsg.is_group = true;
|
||||
wxMsg.sender = wxMsg.is_self ? user_info::get_self_wxid() : GetStringByWstrAddr(arg2 + OS_RECV_MSG_WXID);
|
||||
wxMsg.sender
|
||||
= wxMsg.is_self ? user_info::get_self_wxid() : util::get_str_by_wstr_addr(arg2 + OS_RECV_MSG_WXID);
|
||||
} else {
|
||||
wxMsg.is_group = false;
|
||||
wxMsg.sender = wxMsg.is_self ? user_info::get_self_wxid() : wxMsg.roomid;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
LOG_ERROR(GB2312ToUtf8(e.what()));
|
||||
LOG_ERROR(util::gb2312_to_utf8(e.what()));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -77,7 +78,7 @@ QWORD MessageHandler::PrintWxLog(QWORD a1, QWORD a2, QWORD a3, QWORD a4, QWORD a
|
||||
return p;
|
||||
}
|
||||
|
||||
LOG_INFO("【WX】\n{}", GB2312ToUtf8((char *)p));
|
||||
LOG_INFO("【WX】\n{}", util::gb2312_to_utf8((char *)p));
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -99,9 +100,9 @@ void MessageHandler::DispatchPyq(QWORD arg1, QWORD arg2, QWORD arg3)
|
||||
wxMsg.is_group = false;
|
||||
wxMsg.id = GET_QWORD(startAddr);
|
||||
wxMsg.ts = GET_DWORD(startAddr + OS_PYQ_MSG_TS);
|
||||
wxMsg.xml = GetStringByWstrAddr(startAddr + OS_PYQ_MSG_XML);
|
||||
wxMsg.sender = GetStringByWstrAddr(startAddr + OS_PYQ_MSG_SENDER);
|
||||
wxMsg.content = GetStringByWstrAddr(startAddr + OS_PYQ_MSG_CONTENT);
|
||||
wxMsg.xml = util::get_str_by_wstr_addr(startAddr + OS_PYQ_MSG_XML);
|
||||
wxMsg.sender = util::get_str_by_wstr_addr(startAddr + OS_PYQ_MSG_SENDER);
|
||||
wxMsg.content = util::get_str_by_wstr_addr(startAddr + OS_PYQ_MSG_CONTENT);
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(handler.mutex_);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma warning(disable : 4251)
|
||||
|
||||
#include "rpc_server.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <filesystem>
|
||||
@@ -26,7 +28,6 @@
|
||||
#include "pb_types.h"
|
||||
#include "pb_util.h"
|
||||
#include "receive_msg.h"
|
||||
#include "rpc_server.h"
|
||||
#include "send_msg.h"
|
||||
#include "spy.h"
|
||||
#include "spy_types.h"
|
||||
@@ -158,7 +159,7 @@ static bool func_send_img(char *path, char *receiver, uint8_t *out, size_t *len)
|
||||
if ((path == NULL) || (receiver == NULL)) {
|
||||
LOG_ERROR("Empty path or receiver.");
|
||||
rsp.msg.status = -1;
|
||||
} else if (!fs::exists(String2Wstring(path))) {
|
||||
} else if (!fs::exists(util::s2w(path))) {
|
||||
LOG_ERROR("Path does not exist: {}", path);
|
||||
rsp.msg.status = -2;
|
||||
} else {
|
||||
@@ -174,7 +175,7 @@ static bool func_send_file(char *path, char *receiver, uint8_t *out, size_t *len
|
||||
if ((path == nullptr) || (receiver == nullptr)) {
|
||||
LOG_ERROR("Empty path or receiver.");
|
||||
rsp.msg.status = -1;
|
||||
} else if (!fs::exists(String2Wstring(path))) {
|
||||
} else if (!fs::exists(util::s2w(path))) {
|
||||
LOG_ERROR("Path does not exist: {}", path);
|
||||
rsp.msg.status = -2;
|
||||
} else {
|
||||
@@ -685,7 +686,7 @@ static int RunRpcServer()
|
||||
}
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
LOG_ERROR(GB2312ToUtf8(e.what()));
|
||||
LOG_ERROR(util::gb2312_to_utf8(e.what()));
|
||||
} catch (...) {
|
||||
LOG_ERROR("Unknow exception.");
|
||||
}
|
||||
|
||||
@@ -56,13 +56,13 @@ std::unique_ptr<WxString> SendMsgManager::new_wx_string(const char *str)
|
||||
}
|
||||
std::unique_ptr<WxString> SendMsgManager::new_wx_string(const std::string &str)
|
||||
{
|
||||
return std::make_unique<WxString>(String2Wstring(str));
|
||||
return std::make_unique<WxString>(util::s2w(str));
|
||||
}
|
||||
|
||||
std::vector<WxString> SendMsgManager::parse_wxids(const string &wxids)
|
||||
{
|
||||
vector<WxString> wx_members;
|
||||
wstringstream wss(String2Wstring(wxids));
|
||||
wstringstream wss(util::s2w(wxids));
|
||||
wstring wstr;
|
||||
while (getline(wss, wstr, L',')) {
|
||||
wx_members.emplace_back(wstr);
|
||||
|
||||
+17
-24
@@ -1,44 +1,37 @@
|
||||
#include <filesystem>
|
||||
#include "spy.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
|
||||
#include "log.hpp"
|
||||
#include "rpc_server.h"
|
||||
#include "spy.h"
|
||||
#include "util.h"
|
||||
|
||||
constexpr std::string_view SUPPORT_VERSION = "3.9.11.25";
|
||||
|
||||
UINT64 g_WeChatWinDllAddr = 0;
|
||||
|
||||
static bool IsWxVersionMatched(const wchar_t *version)
|
||||
{
|
||||
if (wcscmp(version, SUPPORT_VERSION) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void InitSpy(LPVOID args)
|
||||
{
|
||||
|
||||
wchar_t version[16] = { 0 };
|
||||
PortPath_t *pp = (PortPath_t *)args;
|
||||
auto *pp = static_cast<PortPath_t *>(args);
|
||||
|
||||
Log::InitLogger(pp->path);
|
||||
g_WeChatWinDllAddr = (UINT64)GetModuleHandle(L"WeChatWin.dll"); // 获取wechatWin模块地址
|
||||
if (g_WeChatWinDllAddr == 0) {
|
||||
LOG_ERROR("获取 wechatWin.dll 模块地址失败");
|
||||
if (auto dll_addr = GetModuleHandle(L"WeChatWin.dll")) {
|
||||
g_WeChatWinDllAddr = reinterpret_cast<UINT64>(dll_addr);
|
||||
} else {
|
||||
LOG_ERROR("获取 WeChatWin.dll 模块地址失败");
|
||||
return; // TODO: 退出进程,避免后面操作失败
|
||||
}
|
||||
|
||||
if (!GetWeChatVersion(version)) { // 获取微信版本
|
||||
LOG_ERROR("获取微信版本失败");
|
||||
return;
|
||||
}
|
||||
LOG_INFO("WeChat version: {}", Wstring2String(version).c_str());
|
||||
if (!IsWxVersionMatched(version)) {
|
||||
LOG_ERROR("不支持当前版本");
|
||||
MessageBox(NULL, L"不支持当前版本", L"错误", 0);
|
||||
std::string version = util::get_wechat_version();
|
||||
std::string msg = "WCF 支持版本: " + SUPPORT_VERSION + ",当前版本: " + version;
|
||||
if (version != SUPPORT_VERSION) {
|
||||
LOG_ERROR(msg);
|
||||
MessageBoxA(NULL, msg.c_str(), "错误", MB_ICONERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO(msg);
|
||||
RpcStartServer(pp->port);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,5 @@
|
||||
|
||||
#include "framework.h"
|
||||
|
||||
#define SUPPORT_VERSION L"3.9.11.25"
|
||||
|
||||
void InitSpy(int port);
|
||||
void CleanupSpy();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <filesystem>
|
||||
#include "user_info.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
|
||||
#include "fill_response.h"
|
||||
#include "log.hpp"
|
||||
#include "user_info.h"
|
||||
#include "util.h"
|
||||
|
||||
extern UINT64 g_WeChatWinDllAddr;
|
||||
@@ -15,14 +16,13 @@ namespace user_info
|
||||
#define OS_USER_NAME 0x595C3D8
|
||||
#define OS_USER_MOBILE 0x595C318
|
||||
|
||||
std::string
|
||||
get_home_path()
|
||||
std::string get_home_path()
|
||||
{
|
||||
static std::once_flag flag;
|
||||
static std::string home_path;
|
||||
|
||||
std::call_once(flag, [] {
|
||||
std::string path = Wstring2String(GET_WSTRING(g_WeChatWinDllAddr + OS_USER_HOME)) + "\\WeChat Files\\";
|
||||
std::string path = util::w2s(get_pp_wstring(g_WeChatWinDllAddr + OS_USER_HOME)) + "\\WeChat Files\\";
|
||||
home_path = std::filesystem::absolute(path).string();
|
||||
});
|
||||
|
||||
@@ -39,9 +39,9 @@ std::string get_self_wxid()
|
||||
try {
|
||||
wxid_type = GET_UINT64(g_WeChatWinDllAddr + OS_USER_WXID + 0x18);
|
||||
if (wxid_type == 0xF) {
|
||||
wxid = GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
wxid = util::get_p_string(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
} else {
|
||||
wxid = GET_STRING(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
wxid = util::get_pp_string(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
}
|
||||
|
||||
} catch (...) {
|
||||
@@ -59,10 +59,10 @@ UserInfo_t get_user_info()
|
||||
ui.wxid = get_self_wxid();
|
||||
|
||||
UINT64 name_type = GET_UINT64(g_WeChatWinDllAddr + OS_USER_NAME + 0x18);
|
||||
ui.name = (name_type == 0xF) ? GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_NAME)
|
||||
: GET_STRING(g_WeChatWinDllAddr + OS_USER_NAME);
|
||||
ui.name = (name_type == 0xF) ? util::get_p_string(g_WeChatWinDllAddr + OS_USER_NAME)
|
||||
: util::get_pp_string(g_WeChatWinDllAddr + OS_USER_NAME);
|
||||
|
||||
ui.mobile = GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_MOBILE);
|
||||
ui.mobile = util::get_p_string(g_WeChatWinDllAddr + OS_USER_MOBILE);
|
||||
ui.home = get_home_path();
|
||||
|
||||
return ui;
|
||||
|
||||
Reference in New Issue
Block a user