Impl GetMsgTypes

This commit is contained in:
Changhua
2023-02-16 22:04:31 +08:00
parent 7f934f6ea9
commit 6c42e328ae
9 changed files with 167 additions and 38 deletions
+3 -1
View File
@@ -115,7 +115,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<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 />
<DisableSpecificWarnings>4251;4819</DisableSpecificWarnings>
<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_decode.h" />
<ClInclude Include="..\rpc\nanopb\pb_encode.h" />
<ClInclude Include="..\rpc\pb_util.h" />
<ClInclude Include="..\rpc\proto\wcf.pb.h" />
<ClInclude Include="accept_new_friend.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_decode.c" />
<ClCompile Include="..\rpc\nanopb\pb_encode.c" />
<ClCompile Include="..\rpc\pb_util.cpp" />
<ClCompile Include="..\rpc\proto\wcf.pb.c" />
<ClCompile Include="accept_new_friend.cpp" />
<ClCompile Include="dllmain.cpp" />
+6
View File
@@ -69,6 +69,9 @@
<ClInclude Include="..\rpc\proto\wcf.pb.h">
<Filter>nnrpc</Filter>
</ClInclude>
<ClInclude Include="..\rpc\pb_util.h">
<Filter>nnrpc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@@ -116,6 +119,9 @@
<ClCompile Include="..\rpc\proto\wcf.pb.c">
<Filter>nnrpc</Filter>
</ClCompile>
<ClCompile Include="..\rpc\pb_util.cpp">
<Filter>nnrpc</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="spy.def">
+31 -4
View File
@@ -1,4 +1,31 @@
#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
#include <queue>
@@ -55,11 +82,11 @@ void GetMsgTypes(MsgTypes *types)
void HookAddress(DWORD hookAddr, LPVOID funcAddr, CHAR recvMsgBackupCode[5])
{
//组装跳转数据
// 组装跳转数据
BYTE jmpCode[5] = { 0 };
jmpCode[0] = 0xE9;
//计算偏移
// 计算偏移
*(DWORD *)&jmpCode[1] = (DWORD)funcAddr - hookAddr - 5;
// 备份原来的代码
@@ -76,7 +103,7 @@ void UnHookAddress(DWORD hookAddr, CHAR restoreCode[5])
void DispatchMsg(DWORD reg)
{
WxMsg wxMsg;
DWORD *p = (DWORD *)reg; //消息结构基址
DWORD *p = (DWORD *)reg; // 消息结构基址
wxMsg.set_type(GET_DWORD(*p + g_WxCalls.recvMsg.type));
wxMsg.set_is_self(GET_DWORD(*p + g_WxCalls.recvMsg.isSelf));
@@ -106,7 +133,7 @@ void DispatchMsg(DWORD reg)
__declspec(naked) void RecieveMsgFunc()
{
__asm {
mov reg_buffer, edi //把值复制出来
mov reg_buffer, edi // 把值复制出来
}
DispatchMsg(reg_buffer);
+8
View File
@@ -1,4 +1,12 @@
#pragma once
#include <map>
#include <string>
typedef std::map<int, std::string> MsgTypes_t;
MsgTypes_t GetMsgTypes();
#if 0
#include "../proto/wcf.grpc.pb.h"
+35 -23
View File
@@ -10,8 +10,6 @@
#include <nng/nng.h>
#include <nng/protocol/pair1/pair.h>
#include <nng/supplemental/util/platform.h>
#include <pb_decode.h>
#include <pb_encode.h>
#include "wcf.pb.h"
@@ -19,6 +17,7 @@
#include "exec_sql.h"
#include "get_contacts.h"
#include "log.h"
#include "pb_util.h"
#include "receive_msg.h"
#include "rpc_server.h"
#include "send_msg.h"
@@ -26,6 +25,8 @@
#include "spy_types.h"
#include "util.h"
#define G_BUF_SIZE (1024 * 1024)
extern int IsLogin(void); // Defined in spy.cpp
extern std::string GetSelfWxid(); // Defined in spy.cpp
@@ -39,18 +40,7 @@ bool gIsListening;
static DWORD lThreadId = 0;
static bool lIsRunning = false;
static nng_socket sock;
static uint8_t gBuffer[1024 * 1024] = { 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);
}
static uint8_t gBuffer[G_BUF_SIZE] = { 0 };
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.which_msg = Response_status_tag;
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);
if (!pb_encode(&stream, Response_fields, &rsp)) {
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
return false;
}
*len = stream.bytes_written;
return true;
}
@@ -77,15 +65,33 @@ bool func_get_self_wxid(uint8_t *out, size_t *len)
rsp.func = Functions_FUNC_IS_LOGIN;
rsp.which_msg = Response_str_tag;
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);
if (!pb_encode(&stream, Response_fields, &rsp)) {
printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
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;
}
@@ -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);
break;
}
case Functions_FUNC_GET_MSG_TYPES: {
LOG_INFO("[Functions_FUNC_GET_MSG_TYPES]");
ret = func_get_msg_types(out, out_len);
break;
}
default: {
LOG_ERROR("[UNKNOW FUNCTION]");
break;
@@ -145,14 +156,15 @@ static int RunServer()
lIsRunning = true;
while (lIsRunning) {
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) {
LOG_ERROR("nng_recv: {}", rv);
break;
}
LogBuffer(in, in_len);
log_buffer(in, in_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);
if (rv != 0) {
LOG_ERROR("nng_send: {}", rv);