From 48091b85268fe3bb2abc214ff4fe34cd69cc8183 Mon Sep 17 00:00:00 2001 From: Changhua Date: Sun, 7 Aug 2022 20:08:54 +0800 Subject: [PATCH] Fix WxMsgTypes --- App/App.cpp | 15 ++++++++------- Rpc/rpc.idl | 10 +++++++++- SDK/rpc_client.cpp | 21 +++++++++++++++++++++ SDK/rpc_client.h | 1 + SDK/sdk.cpp | 35 ++++++++++++++++------------------- SDK/util.cpp | 8 ++++---- SDK/util.h | 3 ++- Spy/receive_msg.cpp | 21 ++++++++++++++++++++- Spy/rpc_server.cpp | 34 +++++++++++++++++++++++++++++++--- 9 files changed, 112 insertions(+), 36 deletions(-) diff --git a/App/App.cpp b/App/App.cpp index 0008770..67fda28 100644 --- a/App/App.cpp +++ b/App/App.cpp @@ -39,19 +39,20 @@ int main() _wsetlocale(LC_ALL, L"chs"); // 这是个大坑,不设置中文直接不见了。。。 - // 获取消息类型 - const MsgTypesMap_t WxMsgTypes = WxGetMsgTypes(); - for (auto it = WxMsgTypes.begin(); it != WxMsgTypes.end(); ++it) { - wprintf(L"%d: %s\n", it->first, it->second.c_str()); - } - wprintf(L"WxInitSDK: "); status = WxInitSDK(); wcout << status << endl; wprintf(L"%d\n", status); if (status != 0) { return 0; - } + } + + // 获取消息类型 + wprintf(L"获取消息类型\n"); + const MsgTypesMap_t WxMsgTypes = WxGetMsgTypes(); + for (auto it = WxMsgTypes.begin(); it != WxMsgTypes.end(); ++it) { + wprintf(L"%d: %s\n", it->first, it->second.c_str()); + } wprintf(L"Message: 接收通知中......\n"); WxSetTextMsgCb(onTextMsg); diff --git a/Rpc/rpc.idl b/Rpc/rpc.idl index 34b56aa..2ec1d8d 100644 --- a/Rpc/rpc.idl +++ b/Rpc/rpc.idl @@ -17,11 +17,19 @@ interface ISpy BSTR wxId; // 发送人微信ID BSTR roomId; // 群ID BSTR content; // 消息内容,MAC版最大:16384,即16KB - } RpcMessage_t; + } RpcMessage_t; + + typedef struct RpcIntBstrPair { + int key; + BSTR value; + } RpcIntBstrPair_t; + typedef RpcIntBstrPair_t* PRpcIntBstrPair_t; + typedef RpcIntBstrPair_t** PPRpcIntBstrPair_t; int IsLogin(); int SendTextMsg([ in, string ] const wchar_t *wxid, [ in, string ] const wchar_t *at_wxid, [ in, string ] const wchar_t *msg); int SendImageMsg([ in, string ] const wchar_t *wxid, [ in, string ] const wchar_t *path); + int GetMsgTypes([ out ] int *pNum, [ out, size_is(, *pNum) ] PPRpcIntBstrPair_t *msgTypes); void EnableReceiveMsg(); [callback] int ReceiveMsg([ in ] RpcMessage_t rpcMsg); diff --git a/SDK/rpc_client.cpp b/SDK/rpc_client.cpp index ce2517b..c6d247d 100644 --- a/SDK/rpc_client.cpp +++ b/SDK/rpc_client.cpp @@ -113,6 +113,27 @@ int RpcSendImageMsg(const wchar_t *wxid, const wchar_t *path) return ret; } +PPRpcIntBstrPair_t RpcGetMsgTypes(int *pNum) +{ + int ret = 0; + unsigned long ulCode = 0; + PPRpcIntBstrPair_t ppRpcMsgTypes = NULL; + + RpcTryExcept{ ret = client_GetMsgTypes(pNum, &ppRpcMsgTypes); } + RpcExcept(1) + { + ulCode = RpcExceptionCode(); + printf("RpcGetMsgTypes exception 0x%lx = %ld\n", ulCode, ulCode); + } + RpcEndExcept; + if (ret != 0) { + printf("GetMsgTypes Failed: %d\n", ret); + return NULL; + } + + return ppRpcMsgTypes; +} + int server_ReceiveMsg(RpcMessage_t rpcMsg) { WxMessage_t msg; diff --git a/SDK/rpc_client.h b/SDK/rpc_client.h index f958d5f..5587f99 100644 --- a/SDK/rpc_client.h +++ b/SDK/rpc_client.h @@ -9,3 +9,4 @@ unsigned int __stdcall RpcSetTextMsgCb(void *p); int RpcIsLogin(); int RpcSendTextMsg(const wchar_t *wxid, const wchar_t *at_wxid, const wchar_t *msg); int RpcSendImageMsg(const wchar_t *wxid, const wchar_t *path); +RpcIntBstrPair_t** RpcGetMsgTypes(int *pNum); diff --git a/SDK/sdk.cpp b/SDK/sdk.cpp index 9428289..0af3228 100644 --- a/SDK/sdk.cpp +++ b/SDK/sdk.cpp @@ -13,24 +13,6 @@ #include "util.h" std::function g_cbReceiveTextMsg; -static const MsgTypesMap_t WxMsgTypes = MsgTypesMap_t { { 0x01, L"文字" }, - { 0x03, L"图片" }, - { 0x22, L"语音" }, - { 0x25, L"好友确认" }, - { 0x28, L"POSSIBLEFRIEND_MSG" }, - { 0x2A, L"名片" }, - { 0x2B, L"视频" }, - { 0x2F, L"石头剪刀布 | 表情图片" }, - { 0x30, L"位置" }, - { 0x31, L"共享实时位置、文件、转账、链接" }, - { 0x32, L"VOIPMSG" }, - { 0x33, L"微信初始化" }, - { 0x34, L"VOIPNOTIFY" }, - { 0x35, L"VOIPINVITE" }, - { 0x3E, L"小视频" }, - { 0x270F, L"SYSNOTICE" }, - { 0x2710, L"红包、系统消息" }, - { 0x2712, L"撤回消息" } }; int WxInitSDK() { @@ -187,4 +169,19 @@ ContactMap_t WxGetContacts() return mContact; } -MsgTypesMap_t WxGetMsgTypes() { return WxMsgTypes; } +MsgTypesMap_t WxGetMsgTypes() +{ + static MsgTypesMap_t WxMsgTypes; + if (WxMsgTypes.empty()) { + int size = 0; + PPRpcIntBstrPair_t pp = RpcGetMsgTypes(&size); + for (int i = 0; i < size; i++) { + WxMsgTypes.insert(make_pair(pp[i]->key, GetWstringFromBstr(pp[i]->value))); + midl_user_free(pp[i]); + } + midl_user_free(pp); + } + + return WxMsgTypes; +} + diff --git a/SDK/util.cpp b/SDK/util.cpp index 2445bb0..e153ea8 100644 --- a/SDK/util.cpp +++ b/SDK/util.cpp @@ -169,14 +169,14 @@ int GetWstringByAddress(DWORD address, wchar_t *buffer, DWORD buffer_size) BSTR GetBstrByAddress(DWORD address) { return SysAllocStringLen(GET_WSTRING(address), GET_DWORD(address + 4)); } -static wstring GetWstringFromBstr(BSTR p) +wstring GetWstringFromBstr(BSTR p) { - wstring ret = L""; + wstring ws = L""; if (p != nullptr) { - ret = wstring(p); + ws = wstring(p); SysFreeString(p); } - return ret; + return ws; } void GetRpcMessage(WxMessage_t *wxMsg, RpcMessage_t rpcMsg) diff --git a/SDK/util.h b/SDK/util.h index c61a6b1..0579361 100644 --- a/SDK/util.h +++ b/SDK/util.h @@ -22,5 +22,6 @@ bool GetFileVersion(const wchar_t *filePath, wchar_t *version); int GetWstringByAddress(DWORD address, wchar_t *buffer, DWORD buffer_size); BSTR GetBstrByAddress(DWORD address); void GetRpcMessage(WxMessage_t *wxMsg, RpcMessage_t rpcMsg); -DWORD GetMemoryIntByAddress(HANDLE hProcess, DWORD address); +DWORD GetMemoryIntByAddress(HANDLE hProcess, DWORD address); +std::wstring GetWstringFromBstr(BSTR p); std::wstring GetUnicodeInfoByAddress(HANDLE hProcess, DWORD address); diff --git a/Spy/receive_msg.cpp b/Spy/receive_msg.cpp index 714b09d..ac0f7af 100644 --- a/Spy/receive_msg.cpp +++ b/Spy/receive_msg.cpp @@ -1,4 +1,4 @@ -#include "framework.h" +#include "framework.h" #include "load_calls.h" #include "receive_msg.h" @@ -15,6 +15,25 @@ DWORD reg_buffer = 0; DWORD recvMsgCallAddr = 0; DWORD recvMsgJumpBackAddr = 0; RpcMessage_t lMsg = { 0 }; + +extern const MsgTypesMap_t g_WxMsgTypes = MsgTypesMap_t { { 0x01, L"文字" }, + { 0x03, L"图片" }, + { 0x22, L"语音" }, + { 0x25, L"好友确认" }, + { 0x28, L"POSSIBLEFRIEND_MSG" }, + { 0x2A, L"名片" }, + { 0x2B, L"视频" }, + { 0x2F, L"石头剪刀布 | 表情图片" }, + { 0x30, L"位置" }, + { 0x31, L"共享实时位置、文件、转账、链接" }, + { 0x32, L"VOIPMSG" }, + { 0x33, L"微信初始化" }, + { 0x34, L"VOIPNOTIFY" }, + { 0x35, L"VOIPINVITE" }, + { 0x3E, L"小视频" }, + { 0x270F, L"SYSNOTICE" }, + { 0x2710, L"红包、系统消息" }, + { 0x2712, L"撤回消息" } }; void DispatchMsg(DWORD reg) { diff --git a/Spy/rpc_server.cpp b/Spy/rpc_server.cpp index daeed03..9c340d8 100644 --- a/Spy/rpc_server.cpp +++ b/Spy/rpc_server.cpp @@ -4,13 +4,15 @@ #include "monitor.h" #include "rpc_server.h" #include "send_msg.h" -#include "spy_types.h" +#include "spy_types.h" +#include "sdk.h" -#include "../Rpc/rpc_h.h" -#pragma comment(lib, "Rpcrt4.lib") +#include "rpc_h.h" +#pragma comment(lib, "Rpcrt4.lib") extern HANDLE g_hEvent; extern MsgQueue_t g_MsgQueue; +extern const MsgTypesMap_t g_WxMsgTypes; int server_IsLogin() { return IsLogin(); } @@ -52,6 +54,32 @@ int server_SendImageMsg(const wchar_t *wxid, const wchar_t *path) return 0; } + +int server_GetMsgTypes(int *pNum, PPRpcIntBstrPair_t *msgTypes) +{ + *pNum = g_WxMsgTypes.size(); + PPRpcIntBstrPair_t pp = (PPRpcIntBstrPair_t)midl_user_allocate(*pNum * sizeof(RpcIntBstrPair_t)); + if (pp == NULL) { + printf("server_GetMsgTypes midl_user_allocate Failed for pp\n"); + return -2; + } + int index = 0; + for (auto it = g_WxMsgTypes.begin(); it != g_WxMsgTypes.end(); ++it) { + PRpcIntBstrPair_t p = (PRpcIntBstrPair_t)midl_user_allocate(sizeof(RpcIntBstrPair_t)); + if (p == NULL) { + printf("server_GetMsgTypes midl_user_allocate Failed for p\n"); + return -3; + } + + p->key = it->first; + p->value = SysAllocString(it->second.c_str()); + pp[index++] = p; + } + + *msgTypes = pp; + + return 0; +} RPC_STATUS CALLBACK SecurityCallback(RPC_IF_HANDLE /*hInterface*/, void * /*pBindingHandle*/) {