Impl get self wxid

This commit is contained in:
Changhua 2022-09-25 11:22:24 +08:00
parent fdcb9cc54c
commit 878b152396
11 changed files with 51 additions and 15 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -51,6 +51,7 @@ int WxEnableRecvMsg(const std::function<int(WxMessage_t)> &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<wstring> WxGetDbNames();

View File

@ -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);

View File

@ -1,4 +1,4 @@
#include <pybind11/functional.h>
#include <pybind11/functional.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
@ -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.");

View File

@ -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;

View File

@ -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)); }