Impl GetContacts
This commit is contained in:
parent
da9cae2f35
commit
33a5ed4033
@ -3,4 +3,16 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
typedef std::map<int, std::string> MsgTypes_t;
|
||||
using namespace std;
|
||||
|
||||
typedef map<int, string> MsgTypes_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t gender;
|
||||
string wxid;
|
||||
string code;
|
||||
string name;
|
||||
string country;
|
||||
string province;
|
||||
string city;
|
||||
} RpcContact_t;
|
||||
|
@ -61,3 +61,42 @@ bool encode_types(pb_ostream_t *stream, const pb_field_t *field, void *const *ar
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool encode_contacts(pb_ostream_t *stream, const pb_field_t *field, void *const *arg)
|
||||
{
|
||||
vector<RpcContact_t> *v = (vector<RpcContact_t> *)*arg;
|
||||
RpcContact message = RpcContact_init_default;
|
||||
|
||||
LOG_INFO("encode_contacts[{}]", v->size());
|
||||
for (auto it = v->begin(); it != v->end(); it++) {
|
||||
message.wxid.funcs.encode = &encode_string;
|
||||
message.wxid.arg = (void *)(*it).wxid.c_str();
|
||||
|
||||
message.code.funcs.encode = &encode_string;
|
||||
message.code.arg = (void *)(*it).code.c_str();
|
||||
|
||||
message.name.funcs.encode = &encode_string;
|
||||
message.name.arg = (void *)(*it).name.c_str();
|
||||
|
||||
message.country.funcs.encode = &encode_string;
|
||||
message.country.arg = (void *)(*it).country.c_str();
|
||||
|
||||
message.province.funcs.encode = &encode_string;
|
||||
message.province.arg = (void *)(*it).province.c_str();
|
||||
|
||||
message.city.funcs.encode = &encode_string;
|
||||
message.city.arg = (void *)(*it).city.c_str();
|
||||
|
||||
message.gender = (*it).gender;
|
||||
|
||||
if (!pb_encode_tag_for_field(stream, field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pb_encode_submessage(stream, RpcContact_fields, &message)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,3 +7,4 @@ void log_buffer(uint8_t *buffer, size_t len);
|
||||
bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void *const *arg);
|
||||
bool decode_string(pb_istream_t *stream, const pb_field_t *field, void **arg);
|
||||
bool encode_types(pb_ostream_t *stream, const pb_field_t *field, void *const *arg);
|
||||
bool encode_contacts(pb_ostream_t *stream, const pb_field_t *field, void *const *arg);
|
||||
|
@ -77,7 +77,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PreBuildEventUseInBuild>true</PreBuildEventUseInBuild>
|
||||
<PreBuildEventUseInBuild>false</PreBuildEventUseInBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
@ -194,6 +194,7 @@ C:\Tools\nanopb\protoc --nanopb_out=. wcf.proto
|
||||
<ClInclude Include="..\rpc\nanopb\pb_common.h" />
|
||||
<ClInclude Include="..\rpc\nanopb\pb_decode.h" />
|
||||
<ClInclude Include="..\rpc\nanopb\pb_encode.h" />
|
||||
<ClInclude Include="..\rpc\pb_types.h" />
|
||||
<ClInclude Include="..\rpc\pb_util.h" />
|
||||
<ClInclude Include="..\rpc\proto\wcf.pb.h" />
|
||||
<ClInclude Include="accept_new_friend.h" />
|
||||
|
@ -72,6 +72,9 @@
|
||||
<ClInclude Include="..\rpc\pb_util.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\rpc\pb_types.h">
|
||||
<Filter>nnrpc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma execution_character_set("utf-8")
|
||||
#if 0
|
||||
|
||||
#include "get_contacts.h"
|
||||
#include "load_calls.h"
|
||||
#include "util.h"
|
||||
@ -7,26 +7,26 @@
|
||||
extern WxCalls_t g_WxCalls;
|
||||
extern DWORD g_WeChatWinDllAddr;
|
||||
|
||||
bool GetContacts(wcf::Contacts *contacts)
|
||||
vector<RpcContact_t> GetContacts()
|
||||
{
|
||||
vector<RpcContact_t> contacts;
|
||||
DWORD baseAddr = g_WeChatWinDllAddr + g_WxCalls.contact.base;
|
||||
DWORD tempAddr = GET_DWORD(baseAddr);
|
||||
DWORD head = GET_DWORD(tempAddr + g_WxCalls.contact.head);
|
||||
DWORD node = GET_DWORD(head);
|
||||
|
||||
while (node != head) {
|
||||
wcf::Contact *cnt = contacts->add_contacts();
|
||||
cnt->set_wxid(GetStringByAddress(node + g_WxCalls.contact.wxId));
|
||||
cnt->set_code(GetStringByAddress(node + g_WxCalls.contact.wxCode));
|
||||
cnt->set_name(GetStringByAddress(node + g_WxCalls.contact.wxName));
|
||||
cnt->set_country(GetStringByAddress(node + g_WxCalls.contact.wxCountry));
|
||||
cnt->set_province(GetStringByAddress(node + g_WxCalls.contact.wxProvince));
|
||||
cnt->set_city(GetStringByAddress(node + g_WxCalls.contact.wxCity));
|
||||
cnt->set_gender(GET_DWORD(node + g_WxCalls.contact.wxGender));
|
||||
|
||||
RpcContact_t cnt;
|
||||
cnt.wxid = GetStringByAddress(node + g_WxCalls.contact.wxId);
|
||||
cnt.code = GetStringByAddress(node + g_WxCalls.contact.wxCode);
|
||||
cnt.name = GetStringByAddress(node + g_WxCalls.contact.wxName);
|
||||
cnt.country = GetStringByAddress(node + g_WxCalls.contact.wxCountry);
|
||||
cnt.province = GetStringByAddress(node + g_WxCalls.contact.wxProvince);
|
||||
cnt.city = GetStringByAddress(node + g_WxCalls.contact.wxCity);
|
||||
cnt.gender = GET_DWORD(node + g_WxCalls.contact.wxGender);
|
||||
contacts.push_back(cnt);
|
||||
node = GET_DWORD(node);
|
||||
}
|
||||
|
||||
return true;
|
||||
return contacts;
|
||||
}
|
||||
#endif
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#if 0
|
||||
#include "../proto/wcf.grpc.pb.h"
|
||||
|
||||
bool GetContacts(wcf::Contacts *contacts);
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
#include "pb_types.h"
|
||||
|
||||
vector<RpcContact_t> GetContacts();
|
||||
|
@ -96,6 +96,26 @@ bool func_get_msg_types(uint8_t *out, size_t *len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool func_get_contacts(uint8_t *out, size_t *len)
|
||||
{
|
||||
Response rsp = Response_init_default;
|
||||
rsp.func = Functions_FUNC_GET_CONTACTS;
|
||||
rsp.which_msg = Response_contacts_tag;
|
||||
|
||||
vector<RpcContact_t> contacts = GetContacts();
|
||||
rsp.msg.types.types.funcs.encode = encode_contacts;
|
||||
rsp.msg.types.types.arg = &contacts;
|
||||
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
||||
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
||||
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
|
||||
return false;
|
||||
}
|
||||
*len = stream.bytes_written;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)
|
||||
{
|
||||
bool ret = false;
|
||||
@ -124,6 +144,11 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len
|
||||
ret = func_get_msg_types(out, out_len);
|
||||
break;
|
||||
}
|
||||
case Functions_FUNC_GET_CONTACTS: {
|
||||
LOG_INFO("[Functions_FUNC_GET_CONTACTS]");
|
||||
ret = func_get_contacts(out, out_len);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
LOG_ERROR("[UNKNOW FUNCTION]");
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user