Impl GetContactByWxid

This commit is contained in:
Changhua 2023-11-26 17:50:31 +08:00
parent af477194b5
commit 79ad2f9653
6 changed files with 111 additions and 2 deletions

View File

@ -24,6 +24,7 @@ enum Functions {
FUNC_RECV_TRANSFER = 0x52;
FUNC_REFRESH_PYQ = 0x53;
FUNC_DOWNLOAD_ATTACH = 0x54;
FUNC_GET_CONTACT_INFO = 0x55;
FUNC_DECRYPT_IMAGE = 0x60;
FUNC_ADD_ROOM_MEMBERS = 0x70;
FUNC_DEL_ROOM_MEMBERS = 0x71;

View File

@ -141,3 +141,45 @@ int AcceptNewFriend(string v3, string v4, int scene)
return success; // 成功返回 1
}
/*没啥用,非好友获取不到*/
RpcContact_t GetContactByWxid(string wxid)
{
RpcContact_t contact;
char buff[0x440] = { 0 };
wstring wsWxid = String2Wstring(wxid);
WxString pri(wsWxid);
DWORD contact_mgr_addr = g_WeChatWinDllAddr + 0x75A4A0;
DWORD get_contact_addr = g_WeChatWinDllAddr + 0xC04E00;
DWORD free_contact_addr = g_WeChatWinDllAddr + 0xEA7880;
__asm {
PUSHAD
PUSHFD
CALL contact_mgr_addr
LEA ECX,buff
PUSH ECX
LEA ECX,pri
PUSH ECX
MOV ECX,EAX
CALL get_contact_addr
POPFD
POPAD
}
contact.wxid = wxid;
contact.code = GetStringByWstrAddr((DWORD)buff + g_WxCalls.contact.wxCode);
contact.remark = GetStringByWstrAddr((DWORD)buff + g_WxCalls.contact.wxRemark);
contact.name = GetStringByWstrAddr((DWORD)buff + g_WxCalls.contact.wxName);
contact.gender = GET_DWORD((DWORD)buff + 0x148);
__asm {
PUSHAD
PUSHFD
LEA ECX,buff
CALL free_contact_addr
POPFD
POPAD
}
return contact;
}

View File

@ -7,3 +7,5 @@
vector<RpcContact_t> GetContacts();
int AcceptNewFriend(std::string v3, std::string v4, int scene);
int AddFriendByWxid(std::string wxid, std::string msg);
RpcContact_t GetContactByWxid(std::string wxid);

View File

@ -534,6 +534,29 @@ bool func_download_attach(AttachMsg att, uint8_t *out, size_t *len)
return true;
}
bool func_get_contact_info(string wxid, uint8_t *out, size_t *len)
{
/*借用 Functions_FUNC_GET_CONTACTS */
Response rsp = Response_init_default;
rsp.func = Functions_FUNC_GET_CONTACT_INFO;
rsp.which_msg = Response_contacts_tag;
vector<RpcContact_t> contacts;
contacts.push_back(GetContactByWxid(wxid));
rsp.msg.contacts.contacts.funcs.encode = encode_contacts;
rsp.msg.contacts.contacts.arg = &contacts;
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_decrypt_image(char *src, char *dst, uint8_t *out, size_t *len)
{
Response rsp = Response_init_default;
@ -711,6 +734,11 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len
ret = func_download_attach(req.msg.att, out, out_len);
break;
}
case Functions_FUNC_GET_CONTACT_INFO: {
LOG_DEBUG("[Functions_FUNC_GET_CONTACT_INFO]");
ret = func_get_contact_info(req.msg.str, out, out_len);
break;
}
case Functions_FUNC_DECRYPT_IMAGE: {
LOG_DEBUG("[FUNCTIONS_FUNC_DECRYPT_IMAGE]");
ret = func_decrypt_image(req.msg.dec.src, req.msg.dec.dst, out, out_len);

View File

@ -599,6 +599,42 @@ class Wcf():
rsp = self._send_request(req)
return rsp.str
def get_info_by_wxid(self, wxid: str) -> dict:
"""通过 wxid 查询微信号昵称等信息
Args:
wxid (str): 联系人 wxid
Returns:
dict: {wxid, code, name, gender}
"""
req = wcf_pb2.Request()
req.func = wcf_pb2.FUNC_GET_CONTACT_INFO # FUNC_GET_CONTACT_INFO
req.str = wxid
rsp = self._send_request(req)
contacts = json_format.MessageToDict(rsp.contacts).get("contacts", [])
contact = {}
for cnt in contacts:
gender = cnt.get("gender", "")
if gender == 1:
gender = ""
elif gender == 2:
gender = ""
else:
gender = ""
contact = {
"wxid": cnt.get("wxid", ""),
"code": cnt.get("code", ""),
"remark": cnt.get("remark", ""),
"name": cnt.get("name", ""),
"country": cnt.get("country", ""),
"province": cnt.get("province", ""),
"city": cnt.get("city", ""),
"gender": gender}
return contact
def decrypt_image(self, src: str, dst: str) -> bool:
"""解密图片:

File diff suppressed because one or more lines are too long