Impl GetMsgTypes
This commit is contained in:
parent
7f934f6ea9
commit
6c42e328ae
66
rpc/pb_util.cpp
Normal file
66
rpc/pb_util.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "pb_util.h"
|
||||||
|
#include "wcf.pb.h"
|
||||||
|
|
||||||
|
#define BUF_SIZE (1024 * 1024)
|
||||||
|
static char buf[BUF_SIZE] = { 0 };
|
||||||
|
|
||||||
|
typedef std::map<int, std::string> MsgTypes_t;
|
||||||
|
|
||||||
|
void log_buffer(uint8_t *buffer, size_t len)
|
||||||
|
{
|
||||||
|
size_t j = sprintf_s(buf, BUF_SIZE, "Encoded message[%ld]: ", len);
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
j += sprintf_s(buf + j, BUF_SIZE, "%02X ", buffer[i]);
|
||||||
|
if (j > BUF_SIZE - 3) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_INFO(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void *const *arg)
|
||||||
|
{
|
||||||
|
const char *str = (const char *)*arg;
|
||||||
|
|
||||||
|
if (!pb_encode_tag_for_field(stream, field)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pb_encode_string(stream, (uint8_t *)str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool decode_string(pb_istream_t *stream, const pb_field_t *field, void **arg)
|
||||||
|
{
|
||||||
|
std::string *str = static_cast<std::string *>(*arg);
|
||||||
|
size_t len = stream->bytes_left;
|
||||||
|
str->resize(len);
|
||||||
|
if (!pb_read(stream, (uint8_t *)str->data(), len)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool encode_types(pb_ostream_t *stream, const pb_field_t *field, void *const *arg)
|
||||||
|
{
|
||||||
|
MsgTypes_t *m = (MsgTypes_t *)*arg;
|
||||||
|
MsgTypes_TypesEntry message = MsgTypes_TypesEntry_init_default;
|
||||||
|
|
||||||
|
for (auto it = m->begin(); it != m->end(); it++) {
|
||||||
|
message.key = it->first;
|
||||||
|
message.value.funcs.encode = &encode_string;
|
||||||
|
message.value.arg = (void *)it->second.c_str();
|
||||||
|
|
||||||
|
if (!pb_encode_tag_for_field(stream, field)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pb_encode_submessage(stream, MsgTypes_TypesEntry_fields, &message)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
9
rpc/pb_util.h
Normal file
9
rpc/pb_util.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pb_decode.h>
|
||||||
|
#include <pb_encode.h>
|
||||||
|
|
||||||
|
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);
|
@ -1,6 +1,5 @@
|
|||||||
# Generate all fields as pointers.
|
# Generate all fields as pointers.
|
||||||
* mangle_names:M_STRIP_PACKAGE
|
* mangle_names:M_STRIP_PACKAGE
|
||||||
* fallback_type:FT_POINTER
|
* fallback_type:FT_POINTER
|
||||||
MsgTypes.types max_count:10
|
MsgTypes* fallback_type:FT_CALLBACK
|
||||||
MsgTypes.TypesEntry.value max_size:16
|
RpcContact* fallback_type:FT_CALLBACK
|
||||||
# MsgTypes.* max_size:16
|
|
||||||
|
@ -55,14 +55,14 @@ message Response
|
|||||||
Functions func = 1;
|
Functions func = 1;
|
||||||
oneof msg
|
oneof msg
|
||||||
{
|
{
|
||||||
int32 status = 2;
|
int32 status = 2;
|
||||||
string str = 3;
|
string str = 3;
|
||||||
WxMsg wxmsg = 4;
|
WxMsg wxmsg = 4;
|
||||||
MsgTypes types = 5;
|
MsgTypes types = 5;
|
||||||
RpcContacts contacts = 6;
|
RpcContacts contacts = 6;
|
||||||
DbNames dbs = 7;
|
DbNames dbs = 7;
|
||||||
DbTables tables = 8;
|
DbTables tables = 8;
|
||||||
DbRows rows = 9;
|
DbRows rows = 9;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@
|
|||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>
|
||||||
</PrecompiledHeaderFile>
|
</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>$(SolutionDir)rpc\nanopb;$(SolutionDir)rpc\proto;C:\Tools\vcpkg\installed\x86-windows-static\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(SolutionDir)rpc;$(SolutionDir)rpc\nanopb;$(SolutionDir)rpc\proto;$(SolutionDir)spy;C:\Tools\vcpkg\installed\x86-windows-static\include</AdditionalIncludeDirectories>
|
||||||
<PrecompiledHeaderOutputFile />
|
<PrecompiledHeaderOutputFile />
|
||||||
<DisableSpecificWarnings>4251;4819</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4251;4819</DisableSpecificWarnings>
|
||||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
@ -194,6 +194,7 @@ C:\Tools\nanopb\protoc --nanopb_out=. wcf.proto
|
|||||||
<ClInclude Include="..\rpc\nanopb\pb_common.h" />
|
<ClInclude Include="..\rpc\nanopb\pb_common.h" />
|
||||||
<ClInclude Include="..\rpc\nanopb\pb_decode.h" />
|
<ClInclude Include="..\rpc\nanopb\pb_decode.h" />
|
||||||
<ClInclude Include="..\rpc\nanopb\pb_encode.h" />
|
<ClInclude Include="..\rpc\nanopb\pb_encode.h" />
|
||||||
|
<ClInclude Include="..\rpc\pb_util.h" />
|
||||||
<ClInclude Include="..\rpc\proto\wcf.pb.h" />
|
<ClInclude Include="..\rpc\proto\wcf.pb.h" />
|
||||||
<ClInclude Include="accept_new_friend.h" />
|
<ClInclude Include="accept_new_friend.h" />
|
||||||
<ClInclude Include="exec_sql.h" />
|
<ClInclude Include="exec_sql.h" />
|
||||||
@ -212,6 +213,7 @@ C:\Tools\nanopb\protoc --nanopb_out=. wcf.proto
|
|||||||
<ClCompile Include="..\rpc\nanopb\pb_common.c" />
|
<ClCompile Include="..\rpc\nanopb\pb_common.c" />
|
||||||
<ClCompile Include="..\rpc\nanopb\pb_decode.c" />
|
<ClCompile Include="..\rpc\nanopb\pb_decode.c" />
|
||||||
<ClCompile Include="..\rpc\nanopb\pb_encode.c" />
|
<ClCompile Include="..\rpc\nanopb\pb_encode.c" />
|
||||||
|
<ClCompile Include="..\rpc\pb_util.cpp" />
|
||||||
<ClCompile Include="..\rpc\proto\wcf.pb.c" />
|
<ClCompile Include="..\rpc\proto\wcf.pb.c" />
|
||||||
<ClCompile Include="accept_new_friend.cpp" />
|
<ClCompile Include="accept_new_friend.cpp" />
|
||||||
<ClCompile Include="dllmain.cpp" />
|
<ClCompile Include="dllmain.cpp" />
|
||||||
|
@ -69,6 +69,9 @@
|
|||||||
<ClInclude Include="..\rpc\proto\wcf.pb.h">
|
<ClInclude Include="..\rpc\proto\wcf.pb.h">
|
||||||
<Filter>nnrpc</Filter>
|
<Filter>nnrpc</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\rpc\pb_util.h">
|
||||||
|
<Filter>nnrpc</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
@ -116,6 +119,9 @@
|
|||||||
<ClCompile Include="..\rpc\proto\wcf.pb.c">
|
<ClCompile Include="..\rpc\proto\wcf.pb.c">
|
||||||
<Filter>nnrpc</Filter>
|
<Filter>nnrpc</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\rpc\pb_util.cpp">
|
||||||
|
<Filter>nnrpc</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="spy.def">
|
<None Include="spy.def">
|
||||||
|
@ -1,4 +1,31 @@
|
|||||||
#pragma execution_character_set("utf-8")
|
#pragma execution_character_set("utf-8")
|
||||||
|
|
||||||
|
#include "receive_msg.h"
|
||||||
|
|
||||||
|
MsgTypes_t GetMsgTypes()
|
||||||
|
{
|
||||||
|
const std::map<int32_t, std::string> m = { { 0x01, "文字" },
|
||||||
|
{ 0x03, "图片" },
|
||||||
|
{ 0x22, "语音" },
|
||||||
|
{ 0x25, "好友确认" },
|
||||||
|
{ 0x28, "POSSIBLEFRIEND_MSG" },
|
||||||
|
{ 0x2A, "名片" },
|
||||||
|
{ 0x2B, "视频" },
|
||||||
|
{ 0x2F, "石头剪刀布 | 表情图片" },
|
||||||
|
{ 0x30, "位置" },
|
||||||
|
{ 0x31, "共享实时位置、文件、转账、链接" },
|
||||||
|
{ 0x32, "VOIPMSG" },
|
||||||
|
{ 0x33, "微信初始化" },
|
||||||
|
{ 0x34, "VOIPNOTIFY" },
|
||||||
|
{ 0x35, "VOIPINVITE" },
|
||||||
|
{ 0x3E, "小视频" },
|
||||||
|
{ 0x270F, "SYSNOTICE" },
|
||||||
|
{ 0x2710, "红包、系统消息" },
|
||||||
|
{ 0x2712, "撤回消息" } };
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
@ -55,11 +82,11 @@ void GetMsgTypes(MsgTypes *types)
|
|||||||
|
|
||||||
void HookAddress(DWORD hookAddr, LPVOID funcAddr, CHAR recvMsgBackupCode[5])
|
void HookAddress(DWORD hookAddr, LPVOID funcAddr, CHAR recvMsgBackupCode[5])
|
||||||
{
|
{
|
||||||
//组装跳转数据
|
// 组装跳转数据
|
||||||
BYTE jmpCode[5] = { 0 };
|
BYTE jmpCode[5] = { 0 };
|
||||||
jmpCode[0] = 0xE9;
|
jmpCode[0] = 0xE9;
|
||||||
|
|
||||||
//计算偏移
|
// 计算偏移
|
||||||
*(DWORD *)&jmpCode[1] = (DWORD)funcAddr - hookAddr - 5;
|
*(DWORD *)&jmpCode[1] = (DWORD)funcAddr - hookAddr - 5;
|
||||||
|
|
||||||
// 备份原来的代码
|
// 备份原来的代码
|
||||||
@ -76,7 +103,7 @@ void UnHookAddress(DWORD hookAddr, CHAR restoreCode[5])
|
|||||||
void DispatchMsg(DWORD reg)
|
void DispatchMsg(DWORD reg)
|
||||||
{
|
{
|
||||||
WxMsg wxMsg;
|
WxMsg wxMsg;
|
||||||
DWORD *p = (DWORD *)reg; //消息结构基址
|
DWORD *p = (DWORD *)reg; // 消息结构基址
|
||||||
|
|
||||||
wxMsg.set_type(GET_DWORD(*p + g_WxCalls.recvMsg.type));
|
wxMsg.set_type(GET_DWORD(*p + g_WxCalls.recvMsg.type));
|
||||||
wxMsg.set_is_self(GET_DWORD(*p + g_WxCalls.recvMsg.isSelf));
|
wxMsg.set_is_self(GET_DWORD(*p + g_WxCalls.recvMsg.isSelf));
|
||||||
@ -106,7 +133,7 @@ void DispatchMsg(DWORD reg)
|
|||||||
__declspec(naked) void RecieveMsgFunc()
|
__declspec(naked) void RecieveMsgFunc()
|
||||||
{
|
{
|
||||||
__asm {
|
__asm {
|
||||||
mov reg_buffer, edi //把值复制出来
|
mov reg_buffer, edi // 把值复制出来
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchMsg(reg_buffer);
|
DispatchMsg(reg_buffer);
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
typedef std::map<int, std::string> MsgTypes_t;
|
||||||
|
|
||||||
|
MsgTypes_t GetMsgTypes();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#include "../proto/wcf.grpc.pb.h"
|
#include "../proto/wcf.grpc.pb.h"
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
#include <nng/nng.h>
|
#include <nng/nng.h>
|
||||||
#include <nng/protocol/pair1/pair.h>
|
#include <nng/protocol/pair1/pair.h>
|
||||||
#include <nng/supplemental/util/platform.h>
|
#include <nng/supplemental/util/platform.h>
|
||||||
#include <pb_decode.h>
|
|
||||||
#include <pb_encode.h>
|
|
||||||
|
|
||||||
#include "wcf.pb.h"
|
#include "wcf.pb.h"
|
||||||
|
|
||||||
@ -19,6 +17,7 @@
|
|||||||
#include "exec_sql.h"
|
#include "exec_sql.h"
|
||||||
#include "get_contacts.h"
|
#include "get_contacts.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "pb_util.h"
|
||||||
#include "receive_msg.h"
|
#include "receive_msg.h"
|
||||||
#include "rpc_server.h"
|
#include "rpc_server.h"
|
||||||
#include "send_msg.h"
|
#include "send_msg.h"
|
||||||
@ -26,6 +25,8 @@
|
|||||||
#include "spy_types.h"
|
#include "spy_types.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#define G_BUF_SIZE (1024 * 1024)
|
||||||
|
|
||||||
extern int IsLogin(void); // Defined in spy.cpp
|
extern int IsLogin(void); // Defined in spy.cpp
|
||||||
extern std::string GetSelfWxid(); // Defined in spy.cpp
|
extern std::string GetSelfWxid(); // Defined in spy.cpp
|
||||||
|
|
||||||
@ -39,18 +40,7 @@ bool gIsListening;
|
|||||||
static DWORD lThreadId = 0;
|
static DWORD lThreadId = 0;
|
||||||
static bool lIsRunning = false;
|
static bool lIsRunning = false;
|
||||||
static nng_socket sock;
|
static nng_socket sock;
|
||||||
static uint8_t gBuffer[1024 * 1024] = { 0 };
|
static uint8_t gBuffer[G_BUF_SIZE] = { 0 };
|
||||||
|
|
||||||
static void LogBuffer(uint8_t *buffer, size_t len)
|
|
||||||
{
|
|
||||||
int j = 0;
|
|
||||||
char buf[1024] = { 0 };
|
|
||||||
j = sprintf_s(buf, 1024, "Encoded message: ");
|
|
||||||
for (size_t i = 0; i < len; i++) {
|
|
||||||
j += sprintf_s(buf + j, 1024, "%02X ", buffer[i]);
|
|
||||||
}
|
|
||||||
LOG_INFO(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool func_is_login(uint8_t *out, size_t *len)
|
bool func_is_login(uint8_t *out, size_t *len)
|
||||||
{
|
{
|
||||||
@ -58,15 +48,13 @@ bool func_is_login(uint8_t *out, size_t *len)
|
|||||||
rsp.func = Functions_FUNC_IS_LOGIN;
|
rsp.func = Functions_FUNC_IS_LOGIN;
|
||||||
rsp.which_msg = Response_status_tag;
|
rsp.which_msg = Response_status_tag;
|
||||||
rsp.msg.status = IsLogin();
|
rsp.msg.status = IsLogin();
|
||||||
if (!pb_get_encoded_size(len, Response_fields, &rsp)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
||||||
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
||||||
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
|
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*len = stream.bytes_written;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -77,15 +65,33 @@ bool func_get_self_wxid(uint8_t *out, size_t *len)
|
|||||||
rsp.func = Functions_FUNC_IS_LOGIN;
|
rsp.func = Functions_FUNC_IS_LOGIN;
|
||||||
rsp.which_msg = Response_str_tag;
|
rsp.which_msg = Response_str_tag;
|
||||||
rsp.msg.str = (char *)GetSelfWxid().c_str();
|
rsp.msg.str = (char *)GetSelfWxid().c_str();
|
||||||
if (!pb_get_encoded_size(len, Response_fields, &rsp)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
|
||||||
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
if (!pb_encode(&stream, Response_fields, &rsp)) {
|
||||||
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
|
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*len = stream.bytes_written;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool func_get_msg_types(uint8_t *out, size_t *len)
|
||||||
|
{
|
||||||
|
Response rsp = Response_init_default;
|
||||||
|
rsp.func = Functions_FUNC_GET_MSG_TYPES;
|
||||||
|
rsp.which_msg = Response_types_tag;
|
||||||
|
|
||||||
|
MsgTypes_t types = GetMsgTypes();
|
||||||
|
rsp.msg.types.types.funcs.encode = encode_types;
|
||||||
|
rsp.msg.types.types.arg = &types;
|
||||||
|
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -113,6 +119,11 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len
|
|||||||
ret = func_get_self_wxid(out, out_len);
|
ret = func_get_self_wxid(out, out_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Functions_FUNC_GET_MSG_TYPES: {
|
||||||
|
LOG_INFO("[Functions_FUNC_GET_MSG_TYPES]");
|
||||||
|
ret = func_get_msg_types(out, out_len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
LOG_ERROR("[UNKNOW FUNCTION]");
|
LOG_ERROR("[UNKNOW FUNCTION]");
|
||||||
break;
|
break;
|
||||||
@ -145,14 +156,15 @@ static int RunServer()
|
|||||||
lIsRunning = true;
|
lIsRunning = true;
|
||||||
while (lIsRunning) {
|
while (lIsRunning) {
|
||||||
uint8_t *in = NULL;
|
uint8_t *in = NULL;
|
||||||
size_t in_len, out_len;
|
size_t in_len, out_len = G_BUF_SIZE;
|
||||||
if ((rv = nng_recv(sock, &in, &in_len, NNG_FLAG_ALLOC)) != 0) {
|
if ((rv = nng_recv(sock, &in, &in_len, NNG_FLAG_ALLOC)) != 0) {
|
||||||
LOG_ERROR("nng_recv: {}", rv);
|
LOG_ERROR("nng_recv: {}", rv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LogBuffer(in, in_len);
|
|
||||||
|
log_buffer(in, in_len);
|
||||||
if (dispatcher(in, in_len, gBuffer, &out_len)) {
|
if (dispatcher(in, in_len, gBuffer, &out_len)) {
|
||||||
LogBuffer(gBuffer, out_len);
|
log_buffer(gBuffer, out_len);
|
||||||
rv = nng_send(sock, gBuffer, out_len, 0);
|
rv = nng_send(sock, gBuffer, out_len, 0);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
LOG_ERROR("nng_send: {}", rv);
|
LOG_ERROR("nng_send: {}", rv);
|
||||||
|
Loading…
Reference in New Issue
Block a user