WeChats.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // WeChats.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "WeChats.h"
  5. #include "WeChatsDlg.h"
  6. #include "Injection.h"
  7. #include "CDLG_Login.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11. // CWeChatsApp
  12. BEGIN_MESSAGE_MAP(CWeChatsApp, CWinAppEx)
  13. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  14. END_MESSAGE_MAP()
  15. // CWeChatsApp 构造
  16. CWeChatsApp::CWeChatsApp()
  17. {
  18. // TODO: 在此处添加构造代码,
  19. // 将所有重要的初始化放置在 InitInstance 中
  20. }
  21. // 唯一的一个 CWeChatsApp 对象
  22. CWeChatsApp theApp;
  23. // CWeChatsApp 初始化
  24. //////////////////////////////////////////////////////////////////////////
  25. // BEGIN
  26. // killWeChatMutex函数用到的未公开的声明;
  27. typedef ULONG PPS_POST_PROCESS_INIT_ROUTINE;
  28. // 以下声明,都是系统未公开的定义;
  29. //
  30. typedef enum {
  31. ProcessBasicInformation = 0,
  32. ProcessDebugPort = 7,
  33. ProcessWow64Information = 26,
  34. ProcessImageFileName = 27,
  35. ProcessBreakOnTermination = 29,
  36. ProcessProtectionInformation = 61,
  37. }PROCESSINFOCLASS;
  38. typedef struct _PEB_LDR_DATA {
  39. BYTE Reserved1[8];
  40. PVOID Reserved2[3];
  41. LIST_ENTRY InMemoryOrderModuleList;
  42. } PEB_LDR_DATA, *PPEB_LDR_DATA;
  43. typedef struct _LDR_DATA_TABLE_ENTRY {
  44. PVOID Reserved1[2];
  45. LIST_ENTRY InMemoryOrderLinks;
  46. PVOID Reserved2[2];
  47. PVOID DllBase;
  48. PVOID EntryPoint;
  49. PVOID Reserved3;
  50. UNICODE_STRING FullDllName;
  51. BYTE Reserved4[8];
  52. PVOID Reserved5[3];
  53. union {
  54. ULONG CheckSum;
  55. PVOID Reserved6;
  56. };
  57. ULONG TimeDateStamp;
  58. } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
  59. typedef struct _RTL_USER_PROCESS_PARAMETERS {
  60. BYTE Reserved1[16];
  61. PVOID Reserved2[10];
  62. UNICODE_STRING ImagePathName;
  63. UNICODE_STRING CommandLine;
  64. } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
  65. // 32位下的结构;
  66. typedef struct _PEB {
  67. BYTE Reserved1[2];
  68. BYTE BeingDebugged;
  69. BYTE Reserved2[1];
  70. PVOID Reserved3[2];
  71. PPEB_LDR_DATA Ldr;
  72. PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
  73. PVOID Reserved4[3];
  74. PVOID AtlThunkSListPtr;
  75. PVOID Reserved5;
  76. ULONG Reserved6;
  77. PVOID Reserved7;
  78. ULONG Reserved8;
  79. ULONG AtlThunkSListPtr32;
  80. PVOID Reserved9[45];
  81. BYTE Reserved10[96];
  82. PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
  83. BYTE Reserved11[128];
  84. PVOID Reserved12[1];
  85. ULONG SessionId;
  86. } PEB, *PPEB;
  87. // 64位下的结构;
  88. typedef struct _PEBX64 {
  89. BYTE Reserved1[2];
  90. BYTE BeingDebugged;
  91. BYTE Reserved2[21];
  92. PPEB_LDR_DATA LoaderData;
  93. PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
  94. BYTE Reserved3[520];
  95. PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
  96. BYTE Reserved4[136];
  97. ULONG SessionId;
  98. } PEBX64;
  99. typedef struct _PROCESS_BASIC_INFORMATION {
  100. PVOID Reserved1;
  101. PPEB PebBaseAddress;
  102. PVOID Reserved2[2];
  103. ULONG_PTR UniqueProcessId;
  104. PVOID Reserved3;
  105. } PROCESS_BASIC_INFORMATION;
  106. // 声音函数指针;
  107. typedef NTSTATUS (WINAPI *pfZwQueryInformationProcess)(
  108. _In_ HANDLE ProcessHandle,
  109. _In_ PROCESSINFOCLASS ProcessInformationClass,
  110. _Out_ PVOID ProcessInformation,
  111. _In_ ULONG ProcessInformationLength,
  112. _Out_opt_ PULONG ReturnLength
  113. );
  114. // END
  115. //////////////////////////////////////////////////////////////////////////
  116. NTSTATUS GetProcessModules(HANDLE hProcess, LPCTSTR lpTypName, LPCTSTR lpName)
  117. {
  118. NTSTATUS Status = 0;
  119. pfZwQueryInformationProcess ZwQueryInformationProcess = NULL;
  120. PROCESS_BASIC_INFORMATION ProcessInfo;
  121. PPEB pPeb;
  122. ZwQueryInformationProcess = (pfZwQueryInformationProcess)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "ZwQueryInformationProcess");
  123. if (ZwQueryInformationProcess == NULL)
  124. {
  125. WriteTextLog(_T("查找进程模块名称失败"));
  126. return Status;
  127. }
  128. Status = ZwQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcessInfo, sizeof(ProcessInfo), NULL);
  129. if (NT_SUCCESS(Status))
  130. {
  131. pPeb = (PPEB)ProcessInfo.PebBaseAddress;
  132. for (PLIST_ENTRY pListEntry = pPeb->Ldr->InMemoryOrderModuleList.Flink;pListEntry != &pPeb->Ldr->InMemoryOrderModuleList;pListEntry = pListEntry->Flink)
  133. {
  134. //PLDR_DATA_TABLE_ENTRY pEntry = CONTAINING_RECORD(pListEntry, LDR_DATA_TABLE_ENTRY, pListEntry);
  135. //wprintf(L"%s\n", pEntry->FullDllName.Buffer);
  136. WriteTextLog(_T("模块名称"));
  137. }
  138. }
  139. else
  140. WriteTextLog(_T("查找进程模块名称失败1"));
  141. CloseHandle(hProcess);
  142. return Status;
  143. }
  144. BOOL CWeChatsApp::InitInstance()
  145. {
  146. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  147. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  148. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  149. INITCOMMONCONTROLSEX InitCtrls;
  150. InitCtrls.dwSize = sizeof(InitCtrls);
  151. // 将它设置为包括所有要在应用程序中使用的
  152. // 公共控件类。
  153. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  154. InitCommonControlsEx(&InitCtrls);
  155. CWinAppEx::InitInstance();
  156. AfxEnableControlContainer();
  157. // 获取配置信息;
  158. GetIniInfo();
  159. GetDebugPriv();
  160. CDLG_Login dlg_login;
  161. if ( dlg_login.DoModal() == IDCANCEL )
  162. {
  163. return FALSE;
  164. }
  165. // HANDLE hObject = CreateMutex(NULL, FALSE, _T("CYLGLAppXiao"));
  166. // if (GetLastError() == ERROR_ALREADY_EXISTS)
  167. // {
  168. // return FALSE;
  169. // }
  170. // GetProcessModules(::GetCurrentProcess(), _T("Mutant"), _T("_WeChat_Instance_Identity_Mutex_Name"));
  171. // int nCount = 3;
  172. // getWeChatPath();
  173. // for (int i = 0; i < nCount; i++)
  174. // OpenWeChat();
  175. #if 0
  176. TCHAR szDllPath[MAX_PATH];
  177. ZeroMemory(szDllPath,MAX_PATH);
  178. DWORD ss = sizeof(szDllPath);
  179. DWORD sss = _tcslen(szDllPath)*sizeof(TCHAR);
  180. _stprintf_s(szDllPath, _T("%shook.dll"), g_szModulePath);
  181. vector<DWORD> vtPID = FindAllProcess(WECHAT);
  182. if (vtPID.size() != 0 )
  183. {
  184. vector<DWORD>::iterator it = vtPID.begin();
  185. //for (int i = 0; i < 1; i++)
  186. for (;it != vtPID.end(); it++)
  187. {
  188. CInjection inject(*it,szDllPath);
  189. inject.InjectDynamicLibrary();
  190. Sleep(3000);
  191. inject.EjectDynamicLibrary();
  192. }
  193. }
  194. #endif
  195. // 标准初始化
  196. // 如果未使用这些功能并希望减小
  197. // 最终可执行文件的大小,则应移除下列
  198. // 不需要的特定初始化例程
  199. // 更改用于存储设置的注册表项
  200. // TODO: 应适当修改该字符串,
  201. // 例如修改为公司或组织名
  202. SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
  203. CWeChatsDlg dlg;
  204. m_pMainWnd = &dlg;
  205. INT_PTR nResponse = dlg.DoModal();
  206. if (nResponse == IDOK)
  207. {
  208. // TODO: 在此放置处理何时用
  209. // “确定”来关闭对话框的代码
  210. }
  211. else if (nResponse == IDCANCEL)
  212. {
  213. // TODO: 在此放置处理何时用
  214. // “取消”来关闭对话框的代码
  215. }
  216. // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
  217. // 而不是启动应用程序的消息泵。
  218. return FALSE;
  219. }