refactoring
This commit is contained in:
parent
bfe3336753
commit
86a55cf00c
@ -75,7 +75,7 @@ static bool func_is_login(uint8_t *out, size_t *len)
|
|||||||
static bool func_get_self_wxid(uint8_t *out, size_t *len)
|
static bool func_get_self_wxid(uint8_t *out, size_t *len)
|
||||||
{
|
{
|
||||||
return FillResponse<Functions_FUNC_GET_SELF_WXID>(Response_str_tag, out, len, [](Response &rsp) {
|
return FillResponse<Functions_FUNC_GET_SELF_WXID>(Response_str_tag, out, len, [](Response &rsp) {
|
||||||
std::string wxid = GetSelfWxid();
|
std::string wxid = user_info::get_self_wxid();
|
||||||
rsp.msg.str = wxid.empty() ? nullptr : (char *)wxid.c_str();
|
rsp.msg.str = wxid.empty() ? nullptr : (char *)wxid.c_str();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ static bool func_get_self_wxid(uint8_t *out, size_t *len)
|
|||||||
static bool func_get_user_info(uint8_t *out, size_t *len)
|
static bool func_get_user_info(uint8_t *out, size_t *len)
|
||||||
{
|
{
|
||||||
return FillResponse<Functions_FUNC_GET_USER_INFO>(Response_ui_tag, out, len, [](Response &rsp) {
|
return FillResponse<Functions_FUNC_GET_USER_INFO>(Response_ui_tag, out, len, [](Response &rsp) {
|
||||||
UserInfo_t ui = GetUserInfo();
|
UserInfo_t ui = user_info::get_user_info();
|
||||||
rsp.msg.ui.wxid = (char *)ui.wxid.c_str();
|
rsp.msg.ui.wxid = (char *)ui.wxid.c_str();
|
||||||
rsp.msg.ui.name = (char *)ui.name.c_str();
|
rsp.msg.ui.name = (char *)ui.name.c_str();
|
||||||
rsp.msg.ui.mobile = (char *)ui.mobile.c_str();
|
rsp.msg.ui.mobile = (char *)ui.mobile.c_str();
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
#include "user_info.h"
|
#include <filesystem>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "fill_response.h"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
#include "user_info.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
namespace user_info
|
||||||
|
{
|
||||||
|
|
||||||
extern UINT64 g_WeChatWinDllAddr;
|
extern UINT64 g_WeChatWinDllAddr;
|
||||||
|
|
||||||
#define OS_USER_HOME 0x5932770
|
#define OS_USER_HOME 0x5932770
|
||||||
@ -9,50 +16,69 @@ extern UINT64 g_WeChatWinDllAddr;
|
|||||||
#define OS_USER_NAME 0x595C3D8
|
#define OS_USER_NAME 0x595C3D8
|
||||||
#define OS_USER_MOBILE 0x595C318
|
#define OS_USER_MOBILE 0x595C318
|
||||||
|
|
||||||
static char home[MAX_PATH] = { 0 };
|
std::string get_home_path()
|
||||||
|
|
||||||
string GetHomePath()
|
|
||||||
{
|
{
|
||||||
if (home[0] == 0) {
|
static std::once_flag flag;
|
||||||
string path = Wstring2String(GET_WSTRING(g_WeChatWinDllAddr + OS_USER_HOME)) + "\\WeChat Files\\";
|
static std::string home_path;
|
||||||
strncpy_s(home, path.c_str(), path.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(home);
|
std::call_once(flag, [] {
|
||||||
|
std::string path = Wstring2String(GET_WSTRING(g_WeChatWinDllAddr + OS_USER_HOME)) + "\\WeChat Files\\";
|
||||||
|
home_path = std::filesystem::absolute(path).string();
|
||||||
|
});
|
||||||
|
|
||||||
|
return home_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetSelfWxid()
|
std::optional<std::string> get_self_wxid()
|
||||||
{
|
{
|
||||||
UINT64 wxidType = 0;
|
UINT64 wxid_type = 0;
|
||||||
try {
|
try {
|
||||||
wxidType = GET_UINT64(g_WeChatWinDllAddr + OS_USER_WXID + 0x18);
|
wxid_type = GET_UINT64(g_WeChatWinDllAddr + OS_USER_WXID + 0x18);
|
||||||
if (wxidType == 0xF) {
|
if (wxid_type == 0xF) {
|
||||||
return GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_WXID);
|
return GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||||
} else {
|
} else {
|
||||||
return GET_STRING(g_WeChatWinDllAddr + OS_USER_WXID);
|
return GET_STRING(g_WeChatWinDllAddr + OS_USER_WXID);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LOG_ERROR("wxid type: {:#x}", wxidType);
|
LOG_ERROR("Failed to get wxid, type: {:#x}", wxid_type);
|
||||||
LOG_BUFFER((uint8_t *)(g_WeChatWinDllAddr + OS_USER_WXID), 20);
|
LOG_BUFFER(reinterpret_cast<uint8_t *>(g_WeChatWinDllAddr + OS_USER_WXID), 20);
|
||||||
return "empty_wxid";
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInfo_t GetUserInfo()
|
UserInfo_t get_user_info()
|
||||||
{
|
{
|
||||||
UserInfo_t ui;
|
UserInfo_t ui;
|
||||||
|
auto wxid = get_self_wxid();
|
||||||
|
ui.wxid = wxid.value_or("unknown_wxid");
|
||||||
|
|
||||||
ui.wxid = GetSelfWxid();
|
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)
|
||||||
UINT64 nameType = GET_UINT64(g_WeChatWinDllAddr + OS_USER_NAME + 0x18);
|
: GET_STRING(g_WeChatWinDllAddr + OS_USER_NAME);
|
||||||
if (nameType == 0xF) {
|
|
||||||
ui.name = GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_NAME);
|
|
||||||
} else { // 0x1F
|
|
||||||
ui.name = GET_STRING(g_WeChatWinDllAddr + OS_USER_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.mobile = GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_MOBILE);
|
ui.mobile = GET_STRING_FROM_P(g_WeChatWinDllAddr + OS_USER_MOBILE);
|
||||||
ui.home = GetHomePath();
|
ui.home = get_home_path();
|
||||||
|
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace user_info
|
||||||
|
@ -1,12 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "pb_types.h"
|
#include "pb_types.h"
|
||||||
|
|
||||||
using namespace std;
|
namespace user_info
|
||||||
|
{
|
||||||
|
|
||||||
string GetHomePath();
|
// 获取 WeChat 数据存储路径
|
||||||
string GetSelfWxid();
|
std::string get_home_path();
|
||||||
|
|
||||||
UserInfo_t GetUserInfo();
|
// 获取自身 wxid
|
||||||
|
std::optional<std::string> get_self_wxid();
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
UserInfo_t get_user_info();
|
||||||
|
|
||||||
|
// RPC 方法
|
||||||
|
bool rpc_get_self_wxid(uint8_t *out, size_t *len);
|
||||||
|
bool rpc_get_user_info(uint8_t *out, size_t *len);
|
||||||
|
|
||||||
|
} // namespace user_info
|
||||||
|
Loading…
Reference in New Issue
Block a user