diff --git a/CWeChatRobot/SelfInfo.cpp b/CWeChatRobot/SelfInfo.cpp index 0e6268318cbf8a29974f93d1f8df59a91ec5d2fd..5e860906a64f6a12e5e775ce0a357d1b8663414c 100644 --- a/CWeChatRobot/SelfInfo.cpp +++ b/CWeChatRobot/SelfInfo.cpp @@ -47,4 +47,18 @@ std::wstring GetSelfInfo() { DeleteSelfInfoCache(); return SelfInfoString; +} + +BOOL isWxLogin() { + if (!hProcess) + return false; + DWORD isWxLoginAddr = GetWeChatRobotBase() + isWxLoginOffset; + DWORD dwId, dwRet = 0; + HANDLE hThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)isWxLoginAddr, NULL, 0, &dwId); + if (hThread) { + WaitForSingleObject(hThread, INFINITE); + GetExitCodeThread(hThread, &dwRet); + CloseHandle(hThread); + } + return dwRet == 1; } \ No newline at end of file diff --git a/CWeChatRobot/SelfInfo.h b/CWeChatRobot/SelfInfo.h index 01c9d1c8ea3b0814d36a5ea025b65e433fed4ddf..b29b86e0e5e585b561c069c5ff05d241781ceeab 100644 --- a/CWeChatRobot/SelfInfo.h +++ b/CWeChatRobot/SelfInfo.h @@ -2,4 +2,5 @@ #include #include using namespace std; -std::wstring GetSelfInfo(); \ No newline at end of file +std::wstring GetSelfInfo(); +BOOL isWxLogin(); \ No newline at end of file diff --git a/CWeChatRobot/WeChatRobot.cpp b/CWeChatRobot/WeChatRobot.cpp index 98e75590015fda550ae31e8b254fdb7ecb6cc7da..b4f4f6c2fda5aa3334531f53d08358bb9665bd2b 100644 --- a/CWeChatRobot/WeChatRobot.cpp +++ b/CWeChatRobot/WeChatRobot.cpp @@ -341,9 +341,17 @@ STDMETHODIMP CWeChatRobot::CSendAppMsg(BSTR wxid,BSTR appid,int* __result) { /* * 参数1:要删除的人wxid -* 参数3:预返回的值,调用时无需提供 +* 参数2:预返回的值,调用时无需提供 */ STDMETHODIMP CWeChatRobot::CDeleteUser(BSTR wxid, int* __result) { *__result = DeleteUser(wxid); return S_OK; +} + +/* +* 参数1:预返回的值,调用时无需提供 +*/ +STDMETHODIMP CWeChatRobot::CIsWxLogin(int* __result) { + *__result = isWxLogin(); + return S_OK; } \ No newline at end of file diff --git a/CWeChatRobot/WeChatRobot.h b/CWeChatRobot/WeChatRobot.h index d73ca52d07c9d79afc4139e8a1d5472277612dfe..c1841f8ef9793a8e691c797a418cadf6a24540fe 100644 --- a/CWeChatRobot/WeChatRobot.h +++ b/CWeChatRobot/WeChatRobot.h @@ -85,6 +85,7 @@ public: STDMETHODIMP CChangeWeChatVer(BSTR verStr, int* __result); STDMETHODIMP CSendAppMsg(BSTR wxid, BSTR appid, int* __result); STDMETHODIMP CDeleteUser(BSTR wxid, int* __result); + STDMETHODIMP CIsWxLogin(int* __result); }; OBJECT_ENTRY_AUTO(__uuidof(WeChatRobot), CWeChatRobot) diff --git a/CWeChatRobot/WeChatRobotCOM.idl b/CWeChatRobot/WeChatRobotCOM.idl index da9bdca129391110fd7b5cc2e09ee57470c84541..76cfb9cc4c68599cb4d2df9bf03a6c8176b21d2d 100644 --- a/CWeChatRobot/WeChatRobotCOM.idl +++ b/CWeChatRobot/WeChatRobotCOM.idl @@ -50,6 +50,7 @@ interface IWeChatRobot : IDispatch [id(35), helpstring("修改微信版本号")] HRESULT CChangeWeChatVer([in] BSTR verStr, [out, retval] int* __result); [id(36), helpstring("发送小程序")] HRESULT CSendAppMsg([in] BSTR wxid, [in] BSTR appid, [out, retval] int* __result); [id(37), helpstring("删除好友")] HRESULT CDeleteUser([in] BSTR wxid, [out, retval] int* __result); + [id(38), helpstring("获取登录状态")] HRESULT CIsWxLogin([out, retval] int* __result); }; [ object, diff --git a/CWeChatRobot/WeChatRobotCOM_i.h b/CWeChatRobot/WeChatRobotCOM_i.h index cc9a06a562fde5545be491c80c6e31c3d1903877..0bd5e73adac0437f45c3194147e95c736c0d8c0c 100644 --- a/CWeChatRobot/WeChatRobotCOM_i.h +++ b/CWeChatRobot/WeChatRobotCOM_i.h @@ -257,6 +257,9 @@ EXTERN_C const IID IID_IWeChatRobot; /* [in] */ BSTR wxid, /* [retval][out] */ int *__result) = 0; + virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CIsWxLogin( + /* [retval][out] */ int *__result) = 0; + }; @@ -492,6 +495,10 @@ EXTERN_C const IID IID_IWeChatRobot; /* [in] */ BSTR wxid, /* [retval][out] */ int *__result); + /* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *CIsWxLogin )( + IWeChatRobot * This, + /* [retval][out] */ int *__result); + END_INTERFACE } IWeChatRobotVtbl; @@ -630,6 +637,9 @@ EXTERN_C const IID IID_IWeChatRobot; #define IWeChatRobot_CDeleteUser(This,wxid,__result) \ ( (This)->lpVtbl -> CDeleteUser(This,wxid,__result) ) +#define IWeChatRobot_CIsWxLogin(This,__result) \ + ( (This)->lpVtbl -> CIsWxLogin(This,__result) ) + #endif /* COBJMACROS */ diff --git a/CWeChatRobot/WeChatRobotCOM_p.c b/CWeChatRobot/WeChatRobotCOM_p.c index 2bb797640d5da5eaeea0f372c9630ef53f47d77e..5994dad527c06e37256a7b5fa189c9c2aead4c75 100644 --- a/CWeChatRobot/WeChatRobotCOM_p.c +++ b/CWeChatRobot/WeChatRobotCOM_p.c @@ -49,7 +49,7 @@ #include "WeChatRobotCOM_i.h" #define TYPE_FORMAT_STRING_SIZE 1239 -#define PROC_FORMAT_STRING_SIZE 1513 +#define PROC_FORMAT_STRING_SIZE 1549 #define EXPR_FORMAT_STRING_SIZE 1 #define TRANSMIT_AS_TABLE_SIZE 0 #define WIRE_MARSHAL_TABLE_SIZE 2 @@ -1409,41 +1409,72 @@ static const WeChatRobotCOM_MIDL_PROC_FORMAT_STRING WeChatRobotCOM__MIDL_ProcFor /* 1468 */ 0x8, /* FC_LONG */ 0x0, /* 0 */ - /* Procedure CPostMessage */ + /* Procedure CIsWxLogin */ /* 1470 */ 0x33, /* FC_AUTO_HANDLE */ 0x6c, /* Old Flags: object, Oi2 */ /* 1472 */ NdrFcLong( 0x0 ), /* 0 */ -/* 1476 */ NdrFcShort( 0x7 ), /* 7 */ -/* 1478 */ NdrFcShort( 0x10 ), /* x86 Stack size/offset = 16 */ +/* 1476 */ NdrFcShort( 0x29 ), /* 41 */ +/* 1478 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */ /* 1480 */ NdrFcShort( 0x0 ), /* 0 */ /* 1482 */ NdrFcShort( 0x24 ), /* 36 */ -/* 1484 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */ - 0x3, /* 3 */ +/* 1484 */ 0x44, /* Oi2 Flags: has return, has ext, */ + 0x2, /* 2 */ /* 1486 */ 0x8, /* 8 */ - 0x45, /* Ext Flags: new corr desc, srv corr check, has range on conformance */ + 0x41, /* Ext Flags: new corr desc, has range on conformance */ /* 1488 */ NdrFcShort( 0x0 ), /* 0 */ -/* 1490 */ NdrFcShort( 0x1 ), /* 1 */ +/* 1490 */ NdrFcShort( 0x0 ), /* 0 */ /* 1492 */ NdrFcShort( 0x0 ), /* 0 */ - /* Parameter msg */ + /* Parameter __result */ -/* 1494 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */ +/* 1494 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */ /* 1496 */ NdrFcShort( 0x4 ), /* x86 Stack size/offset = 4 */ -/* 1498 */ NdrFcShort( 0x4cc ), /* Type Offset=1228 */ +/* 1498 */ 0x8, /* FC_LONG */ + 0x0, /* 0 */ - /* Parameter __result */ + /* Return value */ -/* 1500 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */ +/* 1500 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */ /* 1502 */ NdrFcShort( 0x8 ), /* x86 Stack size/offset = 8 */ /* 1504 */ 0x8, /* FC_LONG */ 0x0, /* 0 */ + /* Procedure CPostMessage */ + +/* 1506 */ 0x33, /* FC_AUTO_HANDLE */ + 0x6c, /* Old Flags: object, Oi2 */ +/* 1508 */ NdrFcLong( 0x0 ), /* 0 */ +/* 1512 */ NdrFcShort( 0x7 ), /* 7 */ +/* 1514 */ NdrFcShort( 0x10 ), /* x86 Stack size/offset = 16 */ +/* 1516 */ NdrFcShort( 0x0 ), /* 0 */ +/* 1518 */ NdrFcShort( 0x24 ), /* 36 */ +/* 1520 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */ + 0x3, /* 3 */ +/* 1522 */ 0x8, /* 8 */ + 0x45, /* Ext Flags: new corr desc, srv corr check, has range on conformance */ +/* 1524 */ NdrFcShort( 0x0 ), /* 0 */ +/* 1526 */ NdrFcShort( 0x1 ), /* 1 */ +/* 1528 */ NdrFcShort( 0x0 ), /* 0 */ + + /* Parameter msg */ + +/* 1530 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */ +/* 1532 */ NdrFcShort( 0x4 ), /* x86 Stack size/offset = 4 */ +/* 1534 */ NdrFcShort( 0x4cc ), /* Type Offset=1228 */ + + /* Parameter __result */ + +/* 1536 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */ +/* 1538 */ NdrFcShort( 0x8 ), /* x86 Stack size/offset = 8 */ +/* 1540 */ 0x8, /* FC_LONG */ + 0x0, /* 0 */ + /* Return value */ -/* 1506 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */ -/* 1508 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */ -/* 1510 */ 0x8, /* FC_LONG */ +/* 1542 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */ +/* 1544 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */ +/* 1546 */ 0x8, /* FC_LONG */ 0x0, /* 0 */ 0x0 @@ -2324,7 +2355,8 @@ static const unsigned short IWeChatRobot_FormatStringOffsetTable[] = 1302, 1338, 1380, - 1428 + 1428, + 1470 }; static const MIDL_STUBLESS_PROXY_INFO IWeChatRobot_ProxyInfo = @@ -2348,7 +2380,7 @@ static const MIDL_SERVER_INFO IWeChatRobot_ServerInfo = 0, 0, 0}; -CINTERFACE_PROXY_VTABLE(41) _IWeChatRobotProxyVtbl = +CINTERFACE_PROXY_VTABLE(42) _IWeChatRobotProxyVtbl = { &IWeChatRobot_ProxyInfo, &IID_IWeChatRobot, @@ -2392,7 +2424,8 @@ CINTERFACE_PROXY_VTABLE(41) _IWeChatRobotProxyVtbl = (void *) (INT_PTR) -1 /* IWeChatRobot::CUnHookImageMsg */ , (void *) (INT_PTR) -1 /* IWeChatRobot::CChangeWeChatVer */ , (void *) (INT_PTR) -1 /* IWeChatRobot::CSendAppMsg */ , - (void *) (INT_PTR) -1 /* IWeChatRobot::CDeleteUser */ + (void *) (INT_PTR) -1 /* IWeChatRobot::CDeleteUser */ , + (void *) (INT_PTR) -1 /* IWeChatRobot::CIsWxLogin */ }; @@ -2435,6 +2468,7 @@ static const PRPC_STUB_FUNCTION IWeChatRobot_table[] = NdrStubCall2, NdrStubCall2, NdrStubCall2, + NdrStubCall2, NdrStubCall2 }; @@ -2442,7 +2476,7 @@ CInterfaceStubVtbl _IWeChatRobotStubVtbl = { &IID_IWeChatRobot, &IWeChatRobot_ServerInfo, - 41, + 42, &IWeChatRobot_table[-3], CStdStubBuffer_DELEGATING_METHODS }; @@ -2458,7 +2492,7 @@ static const unsigned short IRobotEvent_FormatStringOffsetTable[] = (unsigned short) -1, (unsigned short) -1, (unsigned short) -1, - 1470 + 1506 }; static const MIDL_STUBLESS_PROXY_INFO IRobotEvent_ProxyInfo = diff --git a/CWeChatRobot/pch.cpp b/CWeChatRobot/pch.cpp index 4bdb86728aa98a6d99201e71e75bf10a9ed92064..ee1a0c32e4d28c01877bf5cef221fb365eb404a5 100644 --- a/CWeChatRobot/pch.cpp +++ b/CWeChatRobot/pch.cpp @@ -21,6 +21,7 @@ DWORD DeleteUserInfoCacheOffset = 0x0; DWORD GetSelfInfoOffset = 0x0; DWORD DeleteSelfInfoCacheOffset = 0x0; DWORD SearchContactByNetRemoteOffset = 0x0; +DWORD isWxLoginOffset = 0; DWORD VerifyFriendApplyOffset = 0x0; @@ -144,6 +145,8 @@ BOOL GetProcOffset(wchar_t* workPath) { DeleteSelfInfoCacheOffset = DeleteSelfInfoCacheProcAddr - WeChatBase; DWORD SearchContactByNetRemoteAddr = (DWORD)GetProcAddress(hd, SearchContactByNetRemote); SearchContactByNetRemoteOffset = SearchContactByNetRemoteAddr - WeChatBase; + DWORD isWxLoginAddr = (DWORD)GetProcAddress(hd, isWxLoginRemote); + isWxLoginOffset = isWxLoginAddr - WeChatBase; DWORD CheckFriendStatusRemoteAddr = (DWORD)GetProcAddress(hd, CheckFriendStatusRemote); CheckFriendStatusRemoteOffset = CheckFriendStatusRemoteAddr - WeChatBase; diff --git a/CWeChatRobot/robotdata.h b/CWeChatRobot/robotdata.h index 81549dff26f3ea99d9511cf82ba89d6b7f0fdc12..57bf2bc9895d7d4b968fe4cae7b6d91e54080934 100644 --- a/CWeChatRobot/robotdata.h +++ b/CWeChatRobot/robotdata.h @@ -43,6 +43,7 @@ extern DWORD VerifyFriendApplyOffset; extern DWORD GetSelfInfoOffset; extern DWORD DeleteSelfInfoCacheOffset; extern wstring SelfInfoString; +extern DWORD isWxLoginOffset; extern DWORD CheckFriendStatusRemoteOffset; @@ -89,6 +90,7 @@ extern DWORD ChangeWeChatVerRemoteOffset; #define GetSelfInfoRemote "GetSelfInfoRemote" #define DeleteSelfInfoCacheRemote "DeleteSelfInfoCacheRemote" #define SearchContactByNetRemote "SearchContactByNetRemote" +#define isWxLoginRemote "isWxLogin" #define VerifyFriendApplyRemote "VerifyFriendApplyRemote" diff --git a/DWeChatRobot/SelfInfo.cpp b/DWeChatRobot/SelfInfo.cpp index 9c0015b75f83d1df543c63ec280f88904636f8dc..7a7b15cab3688e4693c8e2783e966e2936146417 100644 --- a/DWeChatRobot/SelfInfo.cpp +++ b/DWeChatRobot/SelfInfo.cpp @@ -1,6 +1,8 @@ #include "pch.h" #include +#define CheckLoginOffset 0x2366538 + /* * ⲿʱķ * messageselfinfo.c_str() @@ -40,6 +42,7 @@ wstring GetSelfInfo() { WeChatWinBase + 0x236607C, WeChatWinBase + 0x2366548, WeChatWinBase + 0x23660F4, + WeChatWinBase + 0x23661F8, *(DWORD*)(WeChatWinBase + 0x236622C), *(DWORD*)(WeChatWinBase + 0x23A111C), *(DWORD*)(WeChatWinBase + 0x23663D4), @@ -53,6 +56,7 @@ wstring GetSelfInfo() { L"\"wxId\"", L"\"wxNumber\"", L"\"wxNickName\"", + L"\"Sex\"", L"\"wxSignature\"", L"\"wxBigAvatar\"", L"\"wxSmallAvatar\"", @@ -88,10 +92,29 @@ wstring GetSelfInfo() { temp = (char*)SelfInfoAddr[i]; } } + else if (!SelfInfoKey[i].compare(L"\"Sex\"")) { + int sex = *(int*)SelfInfoAddr[i]; + switch (sex) { + case 1: { + selfinfo = selfinfo + L"\","; + break; + } + case 2: { + selfinfo = selfinfo + L"Ů\","; + break; + } + default: { + selfinfo = selfinfo + L"δ֪\","; + break; + } + } + continue; + } else { temp = (char*)SelfInfoAddr[i]; - if (temp == NULL || strlen(temp) == 0) + if (temp == NULL || strlen(temp) == 0) { temp = (char*)"null"; + } } wchar_t* wtemp = new wchar_t[strlen(temp) + 1]; ZeroMemory(wtemp, (strlen(temp) + 1) * 2); @@ -112,6 +135,11 @@ wstring GetSelfInfo() { return selfinfo; } +BOOL isWxLogin() { + DWORD CheckLoginAddr = GetWeChatWinBase() + CheckLoginOffset; + return *(BOOL*)CheckLoginAddr; +} + /* * ɾϢ * returnvoid diff --git a/DWeChatRobot/SelfInfo.h b/DWeChatRobot/SelfInfo.h index ce166135f2d773cfaff9cdef6e84740ad5d18e15..acb4cc14cc619405a14a18fc496c7c93051b3d6b 100644 --- a/DWeChatRobot/SelfInfo.h +++ b/DWeChatRobot/SelfInfo.h @@ -6,4 +6,7 @@ wstring GetSelfInfo(); #ifndef USE_SOCKET extern "C" __declspec(dllexport) DWORD GetSelfInfoRemote(); extern "C" __declspec(dllexport) VOID DeleteSelfInfoCacheRemote(); +extern "C" __declspec(dllexport) BOOL isWxLogin(); +#else +BOOL isWxLogin(); #endif \ No newline at end of file diff --git a/Python/wxRobot.py b/Python/wxRobot.py index 81cd8fbb6bbc07fba490fc0d16704a5ef9ae86a4..8dc2a0ba3925b65ced381e6b5f2d8d74d9b1842b 100644 --- a/Python/wxRobot.py +++ b/Python/wxRobot.py @@ -134,6 +134,18 @@ class WeChatRobot(): """ status = self.robot.CStartRobotService() return status + + def IsWxLogin(self) -> int: + """ + 获取微信登录状态 + + Returns + ------- + bool + 微信登录状态. + + """ + return self.robot.CIsWxLogin() def SendText(self,receiver:str,msg:str) -> int: """ diff --git a/Release/CWeChatRobot.exe b/Release/CWeChatRobot.exe index 9530c11b80f42e8d8175c3e4a1e4a672bd3cd2eb..a0c193b56a2efa80ac2654e271071295ebf59b5e 100644 Binary files a/Release/CWeChatRobot.exe and b/Release/CWeChatRobot.exe differ diff --git a/Release/DWeChatRobot.dll b/Release/DWeChatRobot.dll index 1468140636d40f12665e7880adafa3304990f966..1776322ef305d9c1d15510caf6e07e3c607b3885 100644 Binary files a/Release/DWeChatRobot.dll and b/Release/DWeChatRobot.dll differ diff --git a/Release/socket/SWeChatRobot.dll b/Release/socket/SWeChatRobot.dll index c80d5c2a70e4f8c550e8b9c72c64527fbefa6c47..66e18b8b22968c711fe97ae1cdfe71b2affb424f 100644 Binary files a/Release/socket/SWeChatRobot.dll and b/Release/socket/SWeChatRobot.dll differ