From 878b1523967e4d4098adbef14b0f52934791646c Mon Sep 17 00:00:00 2001 From: Changhua Date: Sun, 25 Sep 2022 11:22:24 +0800 Subject: [PATCH] Impl get self wxid --- App/App.cpp | 4 ++++ Rpc/rpc.idl | 3 ++- SDK/rpc_client.cpp | 15 +++++++++++++++ SDK/rpc_client.h | 1 + SDK/sdk.cpp | 7 +++++++ SDK/sdk.def | 23 ++++++++++++----------- SDK/sdk.h | 1 + SDK/util.h | 2 +- SDKpy/sdkpy.cpp | 5 +++-- Spy/rpc_server.cpp | 3 +++ Spy/spy.cpp | 2 ++ 11 files changed, 51 insertions(+), 15 deletions(-) diff --git a/App/App.cpp b/App/App.cpp index c4dd8a0..5d7194f 100644 --- a/App/App.cpp +++ b/App/App.cpp @@ -106,6 +106,10 @@ int main() return 0; } + // 自己的 wxid + wstring selfWxid = WxGetSelfWxid(); + wprintf(L"本号WXID:%s\n", selfWxid.c_str()); + // 获取消息类型 wprintf(L"获取消息类型\n"); const MsgTypesMap_t WxMsgTypes = WxGetMsgTypes(); diff --git a/Rpc/rpc.idl b/Rpc/rpc.idl index 8da455e..351adca 100644 --- a/Rpc/rpc.idl +++ b/Rpc/rpc.idl @@ -55,7 +55,8 @@ interface ISpy typedef RpcSqlResult_t **PPRpcSqlResult; typedef RpcSqlResult_t ***PPPRpcSqlResult; - int IsLogin(); + int IsLogin(); + int GetSelfWxId([ out, string ] wchar_t wxid[20]); int SendTextMsg([ in, string ] const wchar_t *wxid, [ in, string ] const wchar_t *msg, [ in, unique, string ] const wchar_t *atWxids); int SendImageMsg([ in, string ] const wchar_t *wxid, [ in, string ] const wchar_t *path); diff --git a/SDK/rpc_client.cpp b/SDK/rpc_client.cpp index d5aff96..5e1ad3c 100644 --- a/SDK/rpc_client.cpp +++ b/SDK/rpc_client.cpp @@ -96,6 +96,21 @@ int RpcIsLogin() return loginFlag; } +int RpcGetSelfWxId(wchar_t wxid[20]) +{ + int ret = -1; + unsigned long ulCode = 0; + RpcTryExcept { ret = client_GetSelfWxId(wxid); } + RpcExcept(1) + { + ulCode = RpcExceptionCode(); + printf("RpcIsLogin exception 0x%lx = %ld\n", ulCode, ulCode); + } + RpcEndExcept; + + return ret; +} + int RpcSendTextMsg(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atWxids) { int ret = 0; diff --git a/SDK/rpc_client.h b/SDK/rpc_client.h index af12f04..b292e57 100644 --- a/SDK/rpc_client.h +++ b/SDK/rpc_client.h @@ -8,6 +8,7 @@ RPC_STATUS RpcDisconnectServer(); int RpcEnableReceiveMsg(); int RpcDisableReceiveMsg(); int RpcIsLogin(); +int RpcGetSelfWxId(wchar_t wxid[20]); int RpcSendTextMsg(const wchar_t *wxid, const wchar_t *msg, const wchar_t *atWxids); int RpcSendImageMsg(const wchar_t *wxid, const wchar_t *path); PPRpcIntBstrPair RpcGetMsgTypes(int *pNum); diff --git a/SDK/sdk.cpp b/SDK/sdk.cpp index 8dae896..e3628fb 100644 --- a/SDK/sdk.cpp +++ b/SDK/sdk.cpp @@ -157,6 +157,13 @@ static int getAddrHandle(DWORD *addr, HANDLE *handle) return 0; } +wstring WxGetSelfWxid() +{ + wchar_t wxid[20] = { 0 }; + RpcGetSelfWxId(wxid); + return wstring(wxid); +} + MsgTypesMap_t WxGetMsgTypes() { static MsgTypesMap_t WxMsgTypes; diff --git a/SDK/sdk.def b/SDK/sdk.def index dc1ba55..771843a 100644 --- a/SDK/sdk.def +++ b/SDK/sdk.def @@ -1,13 +1,14 @@ EXPORTS - WxInitSDK - WxDestroySDK - WxEnableRecvMsg - WxDisableRecvMsg - WxSendTextMsg - WxGetMsgTypes - WxSendImageMsg - WxGetContacts - WxGetDbNames - WxGetDbTables - WxExecDbQuery + WxInitSDK + WxDestroySDK + WxEnableRecvMsg + WxDisableRecvMsg + WxSendTextMsg + WxGetSelfWxid + WxGetMsgTypes + WxSendImageMsg + WxGetContacts + WxGetDbNames + WxGetDbTables + WxExecDbQuery WxAcceptNewFriend diff --git a/SDK/sdk.h b/SDK/sdk.h index a8d0e02..ad28923 100644 --- a/SDK/sdk.h +++ b/SDK/sdk.h @@ -51,6 +51,7 @@ int WxEnableRecvMsg(const std::function &onMsg); int WxDisableRecvMsg(); int WxSendTextMsg(wstring wxid, wstring msg, wstring vAtWxids); int WxSendImageMsg(wstring wxid, wstring path); +wstring WxGetSelfWxid(); ContactMap_t WxGetContacts(); MsgTypesMap_t WxGetMsgTypes(); vector WxGetDbNames(); diff --git a/SDK/util.h b/SDK/util.h index 7c52791..911be37 100644 --- a/SDK/util.h +++ b/SDK/util.h @@ -11,7 +11,7 @@ #define WECHATINJECTDLL L"Spy.dll" #define GET_DWORD(addr) ((DWORD) * (DWORD *)(addr)) -#define GET_STRING(addr) ((CHAR *)(addr)) +#define GET_STRING(addr) ((CHAR *)(*(DWORD *)(addr))) #define GET_WSTRING(addr) ((WCHAR *)(*(DWORD *)(addr))) int OpenWeChat(DWORD *pid); diff --git a/SDKpy/sdkpy.cpp b/SDKpy/sdkpy.cpp index a8daffb..d388e1a 100644 --- a/SDKpy/sdkpy.cpp +++ b/SDKpy/sdkpy.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -74,7 +74,8 @@ PYBIND11_MODULE(wcferry, m) m.def("WxDisableRecvMsg", &WxDisableRecvMsg, "Disable message receiving."); m.def("WxSendTextMsg", &WxSendTextMsg, "Send text message.", py::arg("wxid"), py::arg("msg"), py::arg("atWxids") = L""); - m.def("WxSendImageMsg", &WxSendImageMsg, "Send image message.", py::arg("wxid"), py::arg("path")); + m.def("WxSendImageMsg", &WxSendImageMsg, "Send image message.", py::arg("wxid"), py::arg("path")); + m.def("WxGetSelfWxid", &WxGetSelfWxid, "Get Self Wxid."); m.def("WxGetContacts", &WxGetContacts, py::return_value_policy::reference, "Get contact list."); m.def("WxGetMsgTypes", &WxGetMsgTypes, py::return_value_policy::reference, "Get message types."); m.def("WxGetDbNames", &WxGetDbNames, py::return_value_policy::reference, "Get DB names."); diff --git a/Spy/rpc_server.cpp b/Spy/rpc_server.cpp index f39103d..e6b1172 100644 --- a/Spy/rpc_server.cpp +++ b/Spy/rpc_server.cpp @@ -16,6 +16,7 @@ using namespace std; extern int IsLogin(void); // Defined in spy.cpp +extern wstring GetSelfWxid(); // Defined in spy.cpp extern HANDLE g_hEvent; // New message signal extern BOOL g_rpcKeepAlive; // Keep RPC server thread running extern MsgQueue_t g_MsgQueue; // Queue for message @@ -77,6 +78,8 @@ int RpcStopServer() int server_IsLogin() { return IsLogin(); } +int server_GetSelfWxId(wchar_t wxid[20]) { return wcscpy_s(wxid, 20, GetSelfWxid().c_str()); } + void server_EnableReceiveMsg() { unsigned long ulCode = 0; diff --git a/Spy/spy.cpp b/Spy/spy.cpp index 5c3eff1..c61093f 100644 --- a/Spy/spy.cpp +++ b/Spy/spy.cpp @@ -42,3 +42,5 @@ void DestroySpy(HMODULE hModule) } int IsLogin(void) { return (int)GET_DWORD(g_WeChatWinDllAddr + g_WxCalls.login); } + +wstring GetSelfWxid() { return String2Wstring(GET_STRING(g_WeChatWinDllAddr + g_WxCalls.ui.wxid)); }