├── .gitignore ├── LICENSE ├── README.md ├── getMsgDllDemo ├── dllmain.cpp ├── framework.h ├── getMsgDllDemo.sln ├── getMsgDllDemo.vcxproj ├── getMsgDllDemo.vcxproj.filters ├── getMsgDllDemo.vcxproj.user ├── pch.cpp └── pch.h └── recvMsgConsole └── ConsoleApplication1 ├── ConsoleApplication1.cpp ├── ConsoleApplication1.sln ├── ConsoleApplication1.vcxproj ├── ConsoleApplication1.vcxproj.filters ├── ConsoleApplication1.vcxproj.user └── pch.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Roperl 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 注意 2 | 3 | ### PC微信hook源码,仅供学习,请不要用于商业、违法途径,本人不对此源码造成的违法负责! 4 | 5 | 当前项目适配的微信版本为3.9.2.23 6 | 7 | 8 | 本项目为Demo版本,仅供学习参考。 9 | 10 | ## 更新说明 11 | 12 | ### 提供3.9.2.23微信消息钩子 13 | 任何微信消息皆可接收 14 | 下载地址:https://github.com/Roperl/wxMsgHook_HTTP/releases/tag/3.9.2 15 | 16 | ## 使用教程 17 | 18 | 创建端口为8888的HTTP服务器,例如Apache、Nginx等,或者用代码自己写一个HTTP服务器。 19 | 20 | 将release下载下来后,确保ConsoleApplication1.exe和getMsgDllDemo.dll在同一目录,双击运行ConsoleApplication1.exe即刻。 21 | 22 | 当微信有消息(朋友消息、群消息、朋友圈消息、公众号消息...)或发送微信消息时钩子程序会发送请求到http://127.0.0.1:8888/recvmsg 23 | 24 | 接口详情为 25 | GET http://127.0.0.1:8888/recvmsg 26 | 27 | |QueryParams key|解释| 28 | |-|-| 29 | |msgId|消息唯一id| 30 | |msgForm|消息来源| 31 | |msg|消息内容| 32 | |wxqunSender|微信群是谁发送的消息| 33 | 34 | 35 | ## 商务合作,请捐献且备注联系信息 36 | ![微信二维码](https://mp-36d1c2f3-2ce9-4f84-9090-887a579e6782.cdn.bspapp.com/微信图片_20240307114331.jpg) 37 | -------------------------------------------------------------------------------- /getMsgDllDemo/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "pch.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #pragma comment(lib,"ws2_32.lib") 14 | 15 | using namespace std; 16 | #define HOOK_LEN 5 17 | #define HOOK_ADD 0xCED0D7 18 | #define RET_ADD 0xCED0DC 19 | #define SOURCE_CALL_ADD 0xCF20E0 20 | #define WXMSGID_OFFSET 0x188//消息唯一id 21 | #define WXID_OFFSET 0x48 //收到消息的群或发送人的id 22 | #define WXQ_SENDER_OFFSET 0x174//群中发送人id,如果是自己就没有,如果是别人就有消息 23 | #define MSG_OFFSET 0x70//消息内容 24 | #define TXT_PATH "F:\\桌面\\try.txt " 25 | 26 | BYTE backCode[HOOK_LEN] = { 0 }; 27 | //获取基址 28 | DWORD getWechatWin() { 29 | return (DWORD)LoadLibrary(L"WeChatWin.dll"); 30 | } 31 | 32 | int httpGet(const char* bufSend) 33 | { 34 | 35 | //开始进行socket初始化 36 | WSADATA wData; 37 | ::WSAStartup(MAKEWORD(2, 2), &wData); 38 | 39 | SOCKET clientSocket = socket(AF_INET, 1, 0); 40 | struct sockaddr_in ServerAddr = { 0 }; 41 | int Ret = 0; 42 | int AddrLen = 0; 43 | HANDLE hThread = 0; 44 | ServerAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1"); 45 | ServerAddr.sin_port = htons(8888);; 46 | ServerAddr.sin_family = AF_INET; 47 | char bufRecv[3069] = { 0 }; 48 | int errNo = 0; 49 | errNo = connect(clientSocket, (sockaddr*)&ServerAddr, sizeof(ServerAddr)); 50 | if (errNo == 0) 51 | { 52 | send(clientSocket, bufSend, strlen(bufSend), 0); 53 | ::WSACleanup(); 54 | 55 | } 56 | else 57 | { 58 | ::WSACleanup(); 59 | } 60 | //socket环境清理 61 | 62 | return 0; 63 | } 64 | 65 | 66 | //这个函数是将宽字符的微信内容存到txt文件中去的转化函数 67 | void saveWideFile(ostream& out, wchar_t const* str, int size) 68 | { 69 | 70 | char const* pos = (char const*)str; 71 | if (str[0] != 0xFEFF) // 写入unicode文件头 72 | { 73 | char const* const utf16head = "\xFF\xFE "; 74 | out.write(utf16head, 2); 75 | } 76 | 77 | out.write(pos, size); 78 | 79 | } 80 | VOID saveMsg(DWORD msgcode) { 81 | 82 | DWORD wxidadd = msgcode + WXID_OFFSET; 83 | DWORD msgadd = msgcode + MSG_OFFSET; 84 | DWORD msgMsgId = msgcode + WXMSGID_OFFSET; 85 | DWORD msgWxqSender = msgcode + WXQ_SENDER_OFFSET; 86 | 87 | 88 | //wchar_t Wxid[0xFF] = { 0 }; 89 | //wchar_t Msg[0xFFF] = { 0 }; 90 | //wchar_t WXMsgId[0xFF] = { 0 }; 91 | //wchar_t WXWxqSender[0xFF] = { 0 }; 92 | wchar_t url[0xFFFF] = { 0 }; 93 | swprintf_s(url, L"GET /recvmsg?msgId=%s&msgForm=%s&msg=%s&wxqunSender=%s HTTP/1.1 \r\n" 94 | "Accept : */*" 95 | , (wchar_t*)*((LPVOID*)msgMsgId), (wchar_t*)*((LPVOID*)wxidadd), (wchar_t*)*((LPVOID*)msgadd), (wchar_t*)*((LPVOID*)msgWxqSender)); 96 | /*swprintf_s(Wxid, L"&msgForm=%s", (wchar_t*)*((LPVOID*)wxidadd)); 97 | swprintf_s(Msg, L"&msg=%s", (wchar_t*)*((LPVOID*)msgadd)); 98 | swprintf_s(WXMsgId, L"msgId=%s", (wchar_t*)*((LPVOID*)msgMsgId)); 99 | swprintf_s(WXWxqSender, L"&wxqunSender=%s", (wchar_t*)*((LPVOID*)msgWxqSender));*/ 100 | //MessageBox(NULL, url, L"测试", MB_OK); 101 | std::wstring_convert> converter; 102 | std::string str = converter.to_bytes(url); 103 | httpGet(str.c_str()); 104 | memset(url, 0, sizeof(url)); 105 | 106 | 107 | /*int MsgLen = wcslen(Msg) * 2 ; 108 | int WxidLen = wcslen(Wxid) * 2 ; 109 | int WXMsgIdLen = wcslen(WXMsgId) * 2 ; 110 | int WXWxqSenderLen = wcslen(WXWxqSender) * 2 ; 111 | 112 | ofstream out(TXT_PATH, ios::binary | ios::out | ios::app); 113 | saveWideFile(out, WXMsgId, WXMsgIdLen); 114 | saveWideFile(out, Wxid, WxidLen); 115 | saveWideFile(out, Msg, MsgLen); 116 | saveWideFile(out, WXWxqSender, WXWxqSenderLen); 117 | out.close();*/ 118 | 119 | } 120 | 121 | 122 | 123 | 124 | DWORD pEax = 0; 125 | DWORD pEcx = 0; 126 | DWORD pEdx = 0; 127 | DWORD pEbx = 0; 128 | DWORD pEsp = 0; 129 | DWORD pEbp = 0; 130 | DWORD pEsi = 0; 131 | DWORD pEdi = 0; 132 | DWORD pEip = 0; 133 | 134 | DWORD WinAdd = getWechatWin(); 135 | DWORD retAdd = WinAdd + RET_ADD; 136 | DWORD SourceAdd = WinAdd + SOURCE_CALL_ADD; 137 | //自己函数用来写入微信的 138 | //声明一个裸函数(就是告诉编译器不做任何多余的事情操作) 139 | VOID __declspec(naked) showMsg() { 140 | 141 | //备份寄存器 142 | __asm { 143 | mov pEax, eax 144 | mov pEcx, ecx 145 | mov pEdx, edx 146 | mov pEbx, ebx 147 | mov pEsp, esp 148 | mov pEbp, ebp 149 | mov pEsi, esi 150 | mov pEdi, edi 151 | 152 | } 153 | //我们的二维码数据在ecx里,所以要写一个函数来保存二维码数据 154 | saveMsg(pEdi); 155 | 156 | //把寄存器恢复 157 | __asm { 158 | mov eax, pEax 159 | mov ecx, pEcx 160 | mov edx, pEdx 161 | mov ebx, pEbx 162 | mov esp, pEsp 163 | mov ebp, pEbp 164 | mov esi, pEsi 165 | mov edi, pEdi 166 | call SourceAdd 167 | jmp retAdd 168 | } 169 | 170 | } 171 | 172 | 173 | 174 | 175 | 176 | //开始hook 177 | VOID startHook(LPVOID funAdd) { 178 | DWORD WinAdd = getWechatWin(); 179 | //HOOK的地址 180 | DWORD hookAdd = WinAdd + HOOK_ADD; 181 | //组装数据byte 182 | BYTE jmpCode[HOOK_LEN] = { 0 }; 183 | jmpCode[0] = 0xE9; 184 | //要跳转的地址-现在要hook的地址-5 185 | *(DWORD*)&jmpCode[1] = (DWORD)funAdd - hookAdd - 5; 186 | 187 | 188 | //获取自己的进程句柄 189 | HANDLE hWHND = OpenProcess(PROCESS_ALL_ACCESS, NULL, GetCurrentProcessId()); 190 | //先记下它原本的内容,到时取消hook的时候就写回去 191 | if (ReadProcessMemory(hWHND, (LPCVOID)hookAdd, backCode, HOOK_LEN, NULL) == 0) { 192 | MessageBox(NULL, L"读取内存数据失败", L"错误", 0); 193 | return; 194 | } 195 | //写入我们组好的数据 196 | WriteProcessMemory(hWHND, (LPVOID)hookAdd, jmpCode, HOOK_LEN, NULL); 197 | 198 | 199 | } 200 | 201 | BOOL APIENTRY DllMain( HMODULE hModule, 202 | DWORD ul_reason_for_call, 203 | LPVOID lpReserved 204 | ) 205 | { 206 | switch (ul_reason_for_call) 207 | { 208 | case DLL_PROCESS_ATTACH: 209 | startHook(showMsg); 210 | case DLL_THREAD_ATTACH: 211 | case DLL_THREAD_DETACH: 212 | case DLL_PROCESS_DETACH: 213 | break; 214 | } 215 | return TRUE; 216 | } 217 | 218 | -------------------------------------------------------------------------------- /getMsgDllDemo/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 4 | // Windows 头文件 5 | #include 6 | -------------------------------------------------------------------------------- /getMsgDllDemo/getMsgDllDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.34301.259 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "getMsgDllDemo", "getMsgDllDemo.vcxproj", "{5079C20A-9497-4937-AFC0-9CD7E597EE9E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Debug|x64.ActiveCfg = Debug|x64 17 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Debug|x64.Build.0 = Debug|x64 18 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Debug|x86.Build.0 = Debug|Win32 20 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Release|x64.ActiveCfg = Release|x64 21 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Release|x64.Build.0 = Release|x64 22 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Release|x86.ActiveCfg = Release|Win32 23 | {5079C20A-9497-4937-AFC0-9CD7E597EE9E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {D80B6019-F3F8-45EA-A6D4-424A773696A7} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /getMsgDllDemo/getMsgDllDemo.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {5079c20a-9497-4937-afc0-9cd7e597ee9e} 25 | getMsgDllDemo 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;GETMSGDLLDEMO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 90 | true 91 | Use 92 | pch.h 93 | 94 | 95 | Windows 96 | true 97 | false 98 | 99 | 100 | 101 | 102 | Level3 103 | true 104 | true 105 | true 106 | WIN32;NDEBUG;GETMSGDLLDEMO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 107 | true 108 | Use 109 | pch.h 110 | 111 | 112 | Windows 113 | true 114 | true 115 | true 116 | false 117 | 118 | 119 | 120 | 121 | Level3 122 | true 123 | _DEBUG;GETMSGDLLDEMO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 124 | true 125 | Use 126 | pch.h 127 | 128 | 129 | Windows 130 | true 131 | false 132 | 133 | 134 | 135 | 136 | Level3 137 | true 138 | true 139 | true 140 | NDEBUG;GETMSGDLLDEMO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 141 | true 142 | Use 143 | pch.h 144 | 145 | 146 | Windows 147 | true 148 | true 149 | true 150 | false 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | Create 161 | Create 162 | Create 163 | Create 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /getMsgDllDemo/getMsgDllDemo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /getMsgDllDemo/getMsgDllDemo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /getMsgDllDemo/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /getMsgDllDemo/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | #define _WINSOCK_DEPRECATED_NO_WARNINGS 1; 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /recvMsgConsole/ConsoleApplication1/ConsoleApplication1.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include // 需要包含这个头文件以使用PathCombine 9 | using namespace std; 10 | 11 | 12 | /// 13 | /// 根据进程名称获取进程信息 14 | /// 15 | /// 16 | /// 17 | /// 18 | BOOL getProcess32Info(PROCESSENTRY32* info, const TCHAR processName[]) 19 | { 20 | HANDLE handle; //定义CreateToolhelp32Snapshot系统快照句柄 21 | handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//获得系统快照句柄 22 | //PROCESSENTRY32 结构的 dwSize 成员设置成 sizeof(PROCESSENTRY32) 23 | info->dwSize = sizeof(PROCESSENTRY32); 24 | //调用一次 Process32First 函数,从快照中获取进程列表 25 | Process32First(handle, info); 26 | //重复调用 Process32Next,直到函数返回 FALSE 为止 27 | 28 | while (Process32Next(handle, info) != FALSE) 29 | { 30 | if (wcscmp(processName, info->szExeFile) == 0) 31 | { 32 | return TRUE; 33 | } 34 | } 35 | return FALSE; 36 | } 37 | 38 | /// 39 | /// 注入DLL文件 40 | /// 41 | /// DLL文件的全路径 42 | /// 要注入的程序的PID 43 | /// 44 | int InjectDLL(const wchar_t* DllFullPath, const DWORD pid) 45 | { 46 | 47 | HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, pid);//权限 不继承此句柄 要打开的目标-----返回指定进程的打开句柄 48 | if (hProc == 0) return -1; 49 | 50 | // 计算路径的字节数 51 | int pathSize = (wcslen(DllFullPath) + 1) * sizeof(wchar_t); 52 | WCHAR str[10]; 53 | _itow_s(pathSize, str, 10, 10); 54 | 55 | //指定进程的虚拟地址空间中保留或开辟一段区域(初始化内存) 56 | //无类型指针 LPVOID 57 | //申请内存所在的进程句柄 58 | // NULL自动分配 59 | //欲分配的内存大小 60 | LPVOID buffer = VirtualAllocEx(hProc, 0, pathSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 61 | if (buffer == 0) return -2; 62 | 63 | //把自定义的dll文件注入目标进程,并判断是否写入成功 64 | if (!WriteProcessMemory(hProc, buffer, DllFullPath, pathSize, NULL)) return -3; 65 | 66 | //调用Kernel32.dll中的LoadLibraryW方法用以加载DLL文件 67 | LPVOID pFunc = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryW"); 68 | 69 | //创建一个在另一个进程的虚拟地址空间中运行的线程 70 | CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)pFunc, buffer, 0, 0); 71 | //MessageBox(NULL, str, L"pathSize注入成功", MB_OK); 72 | } 73 | 74 | 75 | wstring GetProgramDir() 76 | { 77 | TCHAR exeFullPath[MAX_PATH]; // Full path 78 | GetModuleFileName(NULL, exeFullPath, MAX_PATH); 79 | wstring strPath = __TEXT(""); 80 | strPath = (wstring)exeFullPath; // Get full path of the file 81 | int pos = strPath.find_last_of(L'\\', strPath.length()); 82 | return strPath.substr(0, pos); // Return the directory without the file name 83 | } 84 | 85 | int main(int argc, char* argv[]) 86 | { 87 | 88 | PROCESSENTRY32 info;//TIHelp32.h 89 | if (getProcess32Info(&info, L"WeChat.exe")) 90 | { 91 | wstring fullPath = GetProgramDir(); 92 | fullPath.append(L"\\getMsgDllDemo.dll"); 93 | //TCHAR str[0x20]; 94 | //memset(str, 0, 0x20); 95 | /* wsprintf(str, TEXT("%d"), info.th32ProcessID); 96 | MessageBox(NULL, fullPath.c_str(), L"测试", MB_OK); 97 | MessageBox(NULL, str, L"测试1", MB_OK);*/ 98 | InjectDLL(fullPath.c_str(), info.th32ProcessID); 99 | } 100 | else { 101 | MessageBox(NULL, L"查找失败", L"测试2", MB_OK); 102 | } 103 | return 0; 104 | } 105 | -------------------------------------------------------------------------------- /recvMsgConsole/ConsoleApplication1/ConsoleApplication1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.34301.259 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1.vcxproj", "{3BE6927D-0CD4-4A35-BCB0-10D682675268}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Debug|x64.ActiveCfg = Debug|x64 17 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Debug|x64.Build.0 = Debug|x64 18 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Debug|x86.ActiveCfg = Debug|Win32 19 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Debug|x86.Build.0 = Debug|Win32 20 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Release|x64.ActiveCfg = Release|x64 21 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Release|x64.Build.0 = Release|x64 22 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Release|x86.ActiveCfg = Release|Win32 23 | {3BE6927D-0CD4-4A35-BCB0-10D682675268}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {9F8B1629-0878-4B60-8C32-1463C97B75C4} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /recvMsgConsole/ConsoleApplication1/ConsoleApplication1.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {3be6927d-0cd4-4a35-bcb0-10d682675268} 25 | ConsoleApplication1 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | 106 | 107 | Console 108 | true 109 | true 110 | true 111 | 112 | 113 | 114 | 115 | Level3 116 | true 117 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /recvMsgConsole/ConsoleApplication1/ConsoleApplication1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | 24 | 头文件 25 | 26 | 27 | -------------------------------------------------------------------------------- /recvMsgConsole/ConsoleApplication1/ConsoleApplication1.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /recvMsgConsole/ConsoleApplication1/pch.h: -------------------------------------------------------------------------------- 1 | 2 | #define _CRT_SECURE_NO_WARNINGS 1; --------------------------------------------------------------------------------