From b39ab1e5e4efa31cf1f5a912187824ad487f03c2 Mon Sep 17 00:00:00 2001 From: Changhua Date: Tue, 11 Apr 2023 23:26:38 +0800 Subject: [PATCH] Impl GetUserInfo --- python/wcferry/client.py | 9 +++++++++ rpc/pb_types.h | 7 +++++++ rpc/proto/wcf.proto | 26 ++++++++++++++++++-------- spy/rpc_server.cpp | 27 +++++++++++++++++++++++++++ spy/user_info.cpp | 12 ++++++++++++ spy/user_info.h | 4 ++++ 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/python/wcferry/client.py b/python/wcferry/client.py index 1dc34f5..f1895da 100644 --- a/python/wcferry/client.py +++ b/python/wcferry/client.py @@ -238,6 +238,15 @@ class Wcf(): return tables + def get_user_info(self) -> dict: + """获取个人信息""" + req = wcf_pb2.Request() + req.func = wcf_pb2.FUNC_GET_USER_INFO # FUNC_GET_USER_INFO + rsp = self._send_request(req) + ui = json_format.MessageToDict(rsp.ui) + + return ui + def send_text(self, msg: str, receiver: str, aters: Optional[str] = "") -> int: """发送文本消息""" req = wcf_pb2.Request() diff --git a/rpc/pb_types.h b/rpc/pb_types.h index 216cb73..a9a74ca 100644 --- a/rpc/pb_types.h +++ b/rpc/pb_types.h @@ -46,3 +46,10 @@ typedef struct { string thumb; string extra; } WxMsg_t; + +typedef struct { + string wxid; + string name; + string mobile; + string home; +} UserInfo_t; diff --git a/rpc/proto/wcf.proto b/rpc/proto/wcf.proto index b9dc8bf..af52d80 100644 --- a/rpc/proto/wcf.proto +++ b/rpc/proto/wcf.proto @@ -11,6 +11,7 @@ enum Functions { FUNC_GET_CONTACTS = 0x12; FUNC_GET_DB_NAMES = 0x13; FUNC_GET_DB_TABLES = 0x14; + FUNC_GET_USER_INFO = 0x15; FUNC_SEND_TXT = 0x20; FUNC_SEND_IMG = 0x21; FUNC_SEND_FILE = 0x22; @@ -44,14 +45,15 @@ message Response Functions func = 1; oneof msg { - int32 status = 2; - string str = 3; - WxMsg wxmsg = 4; - MsgTypes types = 5; - RpcContacts contacts = 6; - DbNames dbs = 7; - DbTables tables = 8; - DbRows rows = 9; + int32 status = 2; // Int 状态,通用 + string str = 3; // 字符串 + WxMsg wxmsg = 4; // 微信消息 + MsgTypes types = 5; // 消息类型 + RpcContacts contacts = 6; // 联系人 + DbNames dbs = 7; // 数据库列表 + DbTables tables = 8; // 表列表 + DbRows rows = 9; // 行列表 + UserInfo ui = 10; // 个人信息 }; } @@ -141,3 +143,11 @@ message AddMembers string roomid = 1; // 要加的群ID string wxids = 2; // 要加群的人列表,逗号分隔 } + +message UserInfo +{ + string wxid = 1; // 微信ID + string name = 2; // 昵称 + string mobile = 3; // 手机号 + string home = 4; // 文件/图片等父路径 +} diff --git a/spy/rpc_server.cpp b/spy/rpc_server.cpp index 176b135..863ce08 100644 --- a/spy/rpc_server.cpp +++ b/spy/rpc_server.cpp @@ -163,6 +163,28 @@ bool func_get_db_tables(char *db, uint8_t *out, size_t *len) return true; } +bool func_get_user_info(uint8_t *out, size_t *len) +{ + Response rsp = Response_init_default; + rsp.func = Functions_FUNC_GET_USER_INFO; + rsp.which_msg = Response_ui_tag; + + UserInfo_t ui = GetUserInfo(); + 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(); + + pb_ostream_t stream = pb_ostream_from_buffer(out, *len); + if (!pb_encode(&stream, Response_fields, &rsp)) { + LOG_ERROR("Encoding failed: {}", PB_GET_ERROR(&stream)); + return false; + } + *len = stream.bytes_written; + + return true; +} + bool func_send_txt(TextMsg txt, uint8_t *out, size_t *len) { Response rsp = Response_init_default; @@ -506,6 +528,11 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len ret = func_get_db_tables(req.msg.str, out, out_len); break; } + case Functions_FUNC_GET_USER_INFO: { + LOG_DEBUG("[Functions_FUNC_GET_USER_INFO]"); + ret = func_get_user_info(out, out_len); + break; + } case Functions_FUNC_SEND_TXT: { LOG_DEBUG("[Functions_FUNC_SEND_TXT]"); ret = func_send_txt(req.msg.txt, out, out_len); diff --git a/spy/user_info.cpp b/spy/user_info.cpp index 68b6301..3797e45 100644 --- a/spy/user_info.cpp +++ b/spy/user_info.cpp @@ -25,3 +25,15 @@ string GetSelfWxid() return "empty_wxid"; } } + +UserInfo_t GetUserInfo() +{ + UserInfo_t ui; + + ui.wxid = GetSelfWxid(); + ui.name = GET_STRING_FROM_P(g_WeChatWinDllAddr + g_WxCalls.ui.nickName); + ui.mobile = GET_STRING_FROM_P(g_WeChatWinDllAddr + g_WxCalls.ui.mobile); + ui.home = GET_STRING(g_WeChatWinDllAddr + g_WxCalls.ui.home); + + return ui; +} diff --git a/spy/user_info.h b/spy/user_info.h index 8a7131f..8d70dc7 100644 --- a/spy/user_info.h +++ b/spy/user_info.h @@ -2,7 +2,11 @@ #include +#include "pb_types.h" + using namespace std; string GetHomePath(); string GetSelfWxid(); + +UserInfo_t GetUserInfo();