diff --git a/CWeChatRobot/FriendList.cpp b/CWeChatRobot/FriendList.cpp index 35c21567826c1f1f86b5109ad833bed90d83a6c0..86ef4e9e033090d0bd48bf0991131227a929854c 100644 --- a/CWeChatRobot/FriendList.cpp +++ b/CWeChatRobot/FriendList.cpp @@ -95,6 +95,8 @@ void FreeWxFriend(int index) { } std::wstring GetFriendList() { + if (!hProcess) + return L"[]"; DWORD GetFriendListInitAddr = GetWeChatRobotBase() + GetFriendListInitOffset; DWORD GetFriendListRemoteAddr = GetWeChatRobotBase() + GetFriendListRemoteOffset; DWORD GetFriendListFinishAddr = GetWeChatRobotBase() + GetFriendListFinishOffset; @@ -108,7 +110,7 @@ std::wstring GetFriendList() { CloseHandle(hThread); } // 获取保存第一个好友的数据指针的结构体首地址 - hThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetFriendListRemoteAddr, 0, 0, &dwId); + hThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetFriendListRemoteAddr, NULL, 0, &dwId); if (hThread) { WaitForSingleObject(hThread, INFINITE); GetExitCodeThread(hThread, &dwHandle); diff --git a/CWeChatRobot/InjertDll.cpp b/CWeChatRobot/InjertDll.cpp index 9eadda805b4d69bade19ff3b02af19be8b864d09..fe969ae72310c32e331f38585b503e7651f2a972 100644 --- a/CWeChatRobot/InjertDll.cpp +++ b/CWeChatRobot/InjertDll.cpp @@ -36,7 +36,7 @@ bool Injert(DWORD dwPid,wchar_t* workPath) { swprintf_s(dllpath, MAX_PATH, L"%ws%ws%ws", workPath, L"\\", dllname); string name = _com_util::ConvertBSTRToString((BSTR)workPath); if (!isFileExists_stat(name)) { - MessageBoxA(NULL, name.c_str(), "文件不存在", MB_ICONWARNING); + MessageBox(NULL, dllpath, L"文件不存在", MB_ICONWARNING); return 1; } bool status = InjectDll(dwPid, dllpath); diff --git a/CWeChatRobot/SelfInfo.cpp b/CWeChatRobot/SelfInfo.cpp index 87c75976d004af97709fac4340bdddbde7760f1b..0e6268318cbf8a29974f93d1f8df59a91ec5d2fd 100644 --- a/CWeChatRobot/SelfInfo.cpp +++ b/CWeChatRobot/SelfInfo.cpp @@ -19,7 +19,7 @@ VOID DeleteSelfInfoCache() { std::wstring GetSelfInfo() { if (!hProcess) - return L""; + return L"{}"; if (SelfInfoString.compare(L"")) { return SelfInfoString; } diff --git a/CWeChatRobot/SendArticle.cpp b/CWeChatRobot/SendArticle.cpp index fa7140f3698b8944b7e52a5f6ca99b6307dc5352..7ff782dad6c111780188588da3014d63f66965b4 100644 --- a/CWeChatRobot/SendArticle.cpp +++ b/CWeChatRobot/SendArticle.cpp @@ -9,7 +9,7 @@ struct SendArticleStruct { BOOL SendArticle(wchar_t* wxid, wchar_t* title, wchar_t* abstract, wchar_t* url) { if (!hProcess) - return 0; + return 1; DWORD WeChatRobotBase = GetWeChatRobotBase(); DWORD dwId = 0; DWORD dwWriteSize = 0; @@ -24,7 +24,7 @@ BOOL SendArticle(wchar_t* wxid, wchar_t* title, wchar_t* abstract, wchar_t* url) if (!wxidaddr || !titleaddr || !abstractaddr || !urladdr || !paramAndFunc || !WeChatRobotBase) { - return 0; + return 1; } if (wxidaddr) @@ -52,5 +52,5 @@ BOOL SendArticle(wchar_t* wxid, wchar_t* title, wchar_t* abstract, wchar_t* url) VirtualFreeEx(hProcess, abstractaddr, 0, MEM_RELEASE); VirtualFreeEx(hProcess, urladdr, 0, MEM_RELEASE); VirtualFreeEx(hProcess, paramAndFunc, 0, MEM_RELEASE); - return 1; + return 0; } \ No newline at end of file diff --git a/CWeChatRobot/SendCard.cpp b/CWeChatRobot/SendCard.cpp index 3296af25956e15574d539b9b28b453d4f398c3d1..51db545d0f3f793150deffe9ec1847c7005d13ad 100644 --- a/CWeChatRobot/SendCard.cpp +++ b/CWeChatRobot/SendCard.cpp @@ -8,7 +8,7 @@ struct SendCardStruct { BOOL SendCard(wchar_t* receiver, wchar_t* sharedwxid, wchar_t* nickname) { if (!hProcess) - return 0; + return 1; DWORD WeChatRobotBase = GetWeChatRobotBase(); DWORD dwId = 0; DWORD dwWriteSize = 0; @@ -22,7 +22,7 @@ BOOL SendCard(wchar_t* receiver, wchar_t* sharedwxid, wchar_t* nickname) { if (!receiveraddr || !sharedwxidaddr || !nicknameaddr || !paramAndFunc || !WeChatRobotBase) { - return 0; + return 1; } if (receiveraddr) WriteProcessMemory(hProcess, receiveraddr, receiver, wcslen(receiver) * 2 + 2, &dwWriteSize); @@ -45,5 +45,5 @@ BOOL SendCard(wchar_t* receiver, wchar_t* sharedwxid, wchar_t* nickname) { VirtualFreeEx(hProcess, sharedwxidaddr, 0, MEM_RELEASE); VirtualFreeEx(hProcess, nicknameaddr, 0, MEM_RELEASE); VirtualFreeEx(hProcess, paramAndFunc, 0, MEM_RELEASE); - return 1; + return 0; } \ No newline at end of file diff --git a/CWeChatRobot/SendFile.cpp b/CWeChatRobot/SendFile.cpp index e4c13d755bff23c2eaca05282f22b1ca321bd369..b8719e1b87ccd9080b8397cbd82dff7aeac0c4de 100644 --- a/CWeChatRobot/SendFile.cpp +++ b/CWeChatRobot/SendFile.cpp @@ -6,6 +6,8 @@ struct FileParamStruct { }; int SendFile(wchar_t* wxid, wchar_t* filepath) { + if (!hProcess) + return 1; DWORD WeChatRobotBase = GetWeChatRobotBase(); DWORD dwId = 0; DWORD dwWriteSize = 0; diff --git a/CWeChatRobot/SendImage.cpp b/CWeChatRobot/SendImage.cpp index 9a94d521cee54706f69b40d16b4199072edebaf0..9a25f9b8d27b8c79c4d9c542969027fa2400f6bc 100644 --- a/CWeChatRobot/SendImage.cpp +++ b/CWeChatRobot/SendImage.cpp @@ -6,6 +6,8 @@ struct ImageParamStruct { }; int SendImage(wchar_t* wxid, wchar_t* imagepath) { + if (!hProcess) + return 1; DWORD WeChatRobotBase = GetWeChatRobotBase(); DWORD dwId = 0; DWORD dwWriteSize = 0; diff --git a/CWeChatRobot/SendText.cpp b/CWeChatRobot/SendText.cpp index a9d5b3b4804e32f8cba100774c4330e8e82a6126..921871c4c5bfd0698fb0331e4ab737210c719f91 100644 --- a/CWeChatRobot/SendText.cpp +++ b/CWeChatRobot/SendText.cpp @@ -7,6 +7,8 @@ struct SendTextStruct }; int SendText(wchar_t* wxid, wchar_t* wxmsg) { + if (!hProcess) + return 1; DWORD WeChatRobotBase = GetWeChatRobotBase(); DWORD dwId = 0; DWORD dwWriteSize = 0; diff --git a/CWeChatRobot/UserInfo.cpp b/CWeChatRobot/UserInfo.cpp index 8cad05ec76233101fb7caf51262b9e609155334a..84e9d82564cdfc34f53fccf3a00627ced088b820 100644 --- a/CWeChatRobot/UserInfo.cpp +++ b/CWeChatRobot/UserInfo.cpp @@ -19,7 +19,7 @@ VOID DeleteUserInfoCache() { std::wstring GetWxUserInfo(wchar_t* wxid) { if (!hProcess) - return L""; + return L"{}"; wstring WString = L""; DWORD GetUserInfoProcAddr = GetWeChatRobotBase() + GetWxUserInfoOffset; LPVOID wxidaddr = VirtualAllocEx(hProcess, NULL, 1, MEM_COMMIT, PAGE_READWRITE); @@ -28,7 +28,7 @@ std::wstring GetWxUserInfo(wchar_t* wxid) { DWORD dwHandle = 0; GetUserInfoStruct userinfo = { 0 }; if (!wxidaddr) - return WString; + return L"{}"; WriteProcessMemory(hProcess, wxidaddr, wxid, wcslen(wxid) * 2 + 2, &dwWriteSize); HANDLE hThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetUserInfoProcAddr, wxidaddr, 0, &dwId); if (hThread) { diff --git a/CWeChatRobot/pch.cpp b/CWeChatRobot/pch.cpp index 7833bbe7a95e628648140f2cbe8e831be882a838..da45a2d801ec516eb50d97fc5ebd13206895e4b6 100644 --- a/CWeChatRobot/pch.cpp +++ b/CWeChatRobot/pch.cpp @@ -127,9 +127,14 @@ DWORD StartRobotService(wchar_t* workPath) { MessageBoxA(NULL, "璇峰厛鍚姩鐩爣绋嬪簭", "鎻愮ず", MB_ICONWARNING); return 1; } - GetProcOffset(workPath); + hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, wxPid); bool status = Injert(wxPid, workPath); + if (status == 1) { + CloseHandle(hProcess); + return status; + } + GetProcOffset(workPath); return status; } diff --git a/DWeChatRobot/FriendList.cpp b/DWeChatRobot/FriendList.cpp index 18615adea182f7f632019acc4b9e59ce421a5e8a..8d680b7ef25e8f2c47a77bb7c54be8ae0ca228c3 100644 --- a/DWeChatRobot/FriendList.cpp +++ b/DWeChatRobot/FriendList.cpp @@ -27,14 +27,14 @@ int GetFriendListInit() { return WxFriendList.size(); } -DWORD GetFriendListRemote(int index) { - if (WxFriendList.size() <= (unsigned int)index) +DWORD GetFriendListRemote() { + if (WxFriendList.size() == 0) return 0; #ifdef _DEBUG - printf("0x%08X\n", (DWORD)&WxFriendList[index]); - printf("0x%08X\n", (DWORD)&(WxFriendList[index].wxIdAddr)); + printf("0x%08X\n", (DWORD)&WxFriendList[0]); + printf("0x%08X\n", (DWORD)&(WxFriendList[0].wxIdAddr)); #endif - return (DWORD)&WxFriendList[index].wxIdAddr; + return (DWORD)&WxFriendList[0].wxIdAddr; } void GetFriendListFinish() { diff --git a/DWeChatRobot/FriendList.h b/DWeChatRobot/FriendList.h index 49cd8f47a6d0ee486657ca8fa826dba88a67ff4a..5ab556de2bb610b131b67d0c5c409fade0a78df3 100644 --- a/DWeChatRobot/FriendList.h +++ b/DWeChatRobot/FriendList.h @@ -1,6 +1,6 @@ #pragma once void __stdcall GetFriendList(); -extern "C" __declspec(dllexport) DWORD GetFriendListRemote(int index); +extern "C" __declspec(dllexport) DWORD GetFriendListRemote(); extern "C" __declspec(dllexport) int GetFriendListInit(); extern "C" __declspec(dllexport) void GetFriendListFinish(); \ No newline at end of file diff --git a/Release/CWeChatRobot.exe b/Release/CWeChatRobot.exe index 1973e02c1185622e376c5ab1c82f94b1eb5bc558..2ac25bd42b00d0db68bdf14cab3ac36444b819ce 100644 Binary files a/Release/CWeChatRobot.exe and b/Release/CWeChatRobot.exe differ diff --git a/Release/DWeChatRobot.dll b/Release/DWeChatRobot.dll index 7cc5a3d0d9a326d5b575f473b3f8ed7600378d71..879ae5149992b6f41308884ef5933ba0f328ea33 100644 Binary files a/Release/DWeChatRobot.dll and b/Release/DWeChatRobot.dll differ diff --git a/wxRobot.py b/wxRobot.py index b1b4705eb4219fd154a92cc0cd27faeffc0dfa1a..879522253e9c31671967959e51d82e7f5d57f48b 100644 --- a/wxRobot.py +++ b/wxRobot.py @@ -49,7 +49,10 @@ class WeChatRobot(): # 鏈塨ug寰呬慨澶嶏紝闇瑕佸垽鏂煇椤逛俊鎭槸鍚︽槸鎸囬拡锛屼慨澶嶅墠涓嶈浣跨敤 def GetSelfInfo(self): myinfo = self.robot.CGetSelfInfo().replace('\n','\\n') - myinfo = ast.literal_eval(myinfo) + try: + myinfo = ast.literal_eval(myinfo) + except SyntaxError: + return {} myinfo['wxBigAvatar'] = myinfo['wxBigAvatar'].replace("/132","/0") self.myinfo = myinfo return self.myinfo @@ -122,13 +125,14 @@ class WeChatRobot(): return ast.literal_eval(userinfo) def test(): - import os,sys + import os # DWeChatRobot.dll path - dllpath = os.path.join(sys.path[0],'Release') + path = os.path.split(os.path.realpath(__file__))[0] + dllpath = os.path.join(path,'Release') # image full path - imgpath = os.path.join(sys.path[0],'test\\娴嬭瘯鍥剧墖.png') + imgpath = os.path.join(path,'test\\娴嬭瘯鍥剧墖.png') # file full path - filepath = os.path.join(sys.path[0],'test\\娴嬭瘯鏂囦欢') + filepath = os.path.join(path,'test\\娴嬭瘯鏂囦欢') wx = WeChatRobot(dllpath) wx.StartService() myinfo = wx.GetSelfInfo() @@ -145,7 +149,6 @@ def test(): session.SendCard(shared.get('wxid'),shared.get('wxNickName')) wx.StopService() - if __name__ == '__main__': test() \ No newline at end of file