Refatoring
This commit is contained in:
parent
bc40b6e922
commit
f2c017de10
@ -49,10 +49,10 @@ QWORD MessageHandler::DispatchMsg(QWORD arg1, QWORD arg2)
|
||||
|
||||
if (wxMsg.roomid.find("@chatroom") != std::string::npos) {
|
||||
wxMsg.is_group = true;
|
||||
wxMsg.sender = wxMsg.is_self ? GetSelfWxid() : GetStringByWstrAddr(arg2 + OS_RECV_MSG_WXID);
|
||||
wxMsg.sender = wxMsg.is_self ? user_info::get_self_wxid() : GetStringByWstrAddr(arg2 + OS_RECV_MSG_WXID);
|
||||
} else {
|
||||
wxMsg.is_group = false;
|
||||
wxMsg.sender = wxMsg.is_self ? GetSelfWxid() : wxMsg.roomid;
|
||||
wxMsg.sender = wxMsg.is_self ? user_info::get_self_wxid() : wxMsg.roomid;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
LOG_ERROR(GB2312ToUtf8(e.what()));
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include "log.hpp"
|
||||
#include "send_msg.h"
|
||||
#include "spy_types.h"
|
||||
#include "user_info.h"
|
||||
#include "util.h"
|
||||
|
||||
extern HANDLE g_hEvent;
|
||||
extern QWORD g_WeChatWinDllAddr;
|
||||
extern string GetSelfWxid(); // Defined in spy.cpp
|
||||
|
||||
#define SRTM_SIZE 0x3F0
|
||||
|
||||
@ -263,7 +263,7 @@ void SendXmlMessage(string receiver, string xml, string path, QWORD type)
|
||||
WxString *pReceiver = NewWxStringFromStr(receiver);
|
||||
WxString *pXml = NewWxStringFromStr(xml);
|
||||
WxString *pPath = NewWxStringFromStr(path);
|
||||
WxString *pSender = NewWxStringFromStr(GetSelfWxid());
|
||||
WxString *pSender = NewWxStringFromStr(user_info::get_self_wxid());
|
||||
|
||||
sendXmlMsg(pBuf, (QWORD)pSender, (QWORD)pReceiver, (QWORD)pXml, (QWORD)pPath, (QWORD)(&nullBuf), type, 0x4, sign,
|
||||
pBuf2);
|
||||
|
@ -6,17 +6,17 @@
|
||||
#include "user_info.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace user_info
|
||||
{
|
||||
|
||||
extern UINT64 g_WeChatWinDllAddr;
|
||||
|
||||
namespace user_info
|
||||
{
|
||||
#define OS_USER_HOME 0x5932770
|
||||
#define OS_USER_WXID 0x595C270
|
||||
#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;
|
||||
@ -29,28 +29,34 @@ std::string get_home_path()
|
||||
return home_path;
|
||||
}
|
||||
|
||||
std::optional<std::string> get_self_wxid()
|
||||
std::string get_self_wxid()
|
||||
{
|
||||
UINT64 wxid_type = 0;
|
||||
try {
|
||||
wxid_type = GET_UINT64(g_WeChatWinDllAddr + OS_USER_WXID + 0x18);
|
||||
if (wxid_type == 0xF) {
|
||||
return GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
} else {
|
||||
return GET_STRING(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
static std::once_flag flag;
|
||||
static std::string wxid;
|
||||
|
||||
std::call_once(flag, [] {
|
||||
UINT64 wxid_type = 0;
|
||||
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);
|
||||
} else {
|
||||
wxid = GET_STRING(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||
}
|
||||
|
||||
} catch (...) {
|
||||
LOG_ERROR("Failed to get wxid, type: {:#x}", wxid_type);
|
||||
LOG_BUFFER(reinterpret_cast<uint8_t *>(g_WeChatWinDllAddr + OS_USER_WXID), 20);
|
||||
wxid = "获取wxid失败";
|
||||
}
|
||||
} catch (...) {
|
||||
LOG_ERROR("Failed to get wxid, type: {:#x}", wxid_type);
|
||||
LOG_BUFFER(reinterpret_cast<uint8_t *>(g_WeChatWinDllAddr + OS_USER_WXID), 20);
|
||||
return std::nullopt;
|
||||
}
|
||||
});
|
||||
return wxid;
|
||||
}
|
||||
|
||||
UserInfo_t get_user_info()
|
||||
{
|
||||
UserInfo_t ui;
|
||||
auto wxid = get_self_wxid();
|
||||
ui.wxid = wxid.value_or("unknown_wxid");
|
||||
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)
|
||||
@ -64,20 +70,18 @@ UserInfo_t get_user_info()
|
||||
|
||||
bool rpc_get_self_wxid(uint8_t *out, size_t *len)
|
||||
{
|
||||
return fill_response<Functions_FUNC_GET_SELF_WXID>(out, len, [](Response &rsp) {
|
||||
auto wxid = get_self_wxid();
|
||||
rsp.msg.str = wxid ? wxid->c_str() : "error";
|
||||
});
|
||||
return fill_response<Functions_FUNC_GET_SELF_WXID>(
|
||||
out, len, [](Response &rsp) { rsp.msg.str = (char *)get_self_wxid().c_str(); });
|
||||
}
|
||||
|
||||
bool rpc_get_user_info(uint8_t *out, size_t *len)
|
||||
{
|
||||
return fill_response<Functions_FUNC_GET_USER_INFO>(out, len, [](Response &rsp) {
|
||||
UserInfo_t ui = get_user_info();
|
||||
rsp.msg.ui.wxid = ui.wxid.c_str();
|
||||
rsp.msg.ui.name = ui.name.c_str();
|
||||
rsp.msg.ui.mobile = ui.mobile.c_str();
|
||||
rsp.msg.ui.home = ui.home.c_str();
|
||||
rsp.msg.ui.wxid = (char *)ui.wxid.c_str();
|
||||
rsp.msg.ui.name = (char *)ui.name.c_str();
|
||||
rsp.msg.ui.mobile = (char *)ui.mobile.c_str();
|
||||
rsp.msg.ui.home = (char *)ui.home.c_str();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace user_info
|
||||
std::string get_home_path();
|
||||
|
||||
// 获取自身 wxid
|
||||
std::optional<std::string> get_self_wxid();
|
||||
std::string get_self_wxid();
|
||||
|
||||
// 获取用户信息
|
||||
UserInfo_t get_user_info();
|
||||
|
Loading…
Reference in New Issue
Block a user