WxGlobal.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #include "StdAfx.h"
  2. #include "WxGlobal.h"
  3. #include <io.h>
  4. // 获取文件版本号函数头文件;
  5. #include <WinVer.h>
  6. #pragma comment(lib,"version.lib")
  7. using namespace std;
  8. #include <psapi.h>
  9. #pragma comment(lib,"Psapi.lib")
  10. // 进程相关头文件;
  11. #include <TlHelp32.h>
  12. #include "EncodingConversion.h"
  13. #include "..\common\CurlClient.h"
  14. HMODULE g_hCurModule = NULL;
  15. TCHAR g_szCurModulePath[MAX_PATH] = {0};
  16. TCHAR g_szFna[MAX_PATH] = {0};
  17. /************************************************************************/
  18. /* 函数:WriteTextLog[7/28/2016 IT];
  19. /* 描述:写文本日志;
  20. /* 参数:;
  21. /* [IN] :;
  22. /* 返回:void;
  23. /* 注意:;
  24. /* 示例:;
  25. /*
  26. /* 修改:;
  27. /* 日期:;
  28. /* 内容:;
  29. /************************************************************************/
  30. void WriteTextLog(const TCHAR *format, ...)
  31. {
  32. // 解析出日志路径;
  33. TCHAR szlogpath[MAX_PATH] = { 0 };
  34. _stprintf_s(szlogpath, _T("%s%s.txt"), g_szCurModulePath, g_szFna);
  35. // 打开或创建文件;
  36. FILE *fp = NULL;
  37. //if (_taccess(szlogpath, 0) != -1)
  38. #ifndef UNICODE
  39. if (_access(szlogpath, 0) != -1)
  40. #else
  41. if (_taccess(szlogpath, 0) != -1)
  42. #endif
  43. {// 存在;
  44. fp = _tfopen(szlogpath, _T("a+"));
  45. // 移动到末尾;
  46. fseek(fp, 0, SEEK_END);
  47. }
  48. else
  49. {// 不存在;
  50. fp = _tfopen(szlogpath, _T("w+"));
  51. }
  52. if ( fp == NULL )
  53. return;
  54. // 格式化前设置语言区域;
  55. TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
  56. _tsetlocale(LC_CTYPE, _T("chs"));//设定中文;
  57. // 格式化日志内容;
  58. va_list args = NULL;
  59. int len = 0;
  60. TCHAR *buffer = NULL;
  61. va_start(args, format);
  62. // _vscprintf doesn't count. terminating '\0'
  63. len = _vsctprintf(format, args) + 1;
  64. buffer = (TCHAR*)malloc(len * sizeof(TCHAR));
  65. _vstprintf_s(buffer, len, format, args);
  66. // 将日志内容输入到文件中;
  67. // 获取今年年份;
  68. __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
  69. struct tm gmtm = {0};
  70. localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
  71. _ftprintf(fp, _T("%04d-%02d-%02d %02d:%02d:%02d %s\n"), gmtm.tm_year+1990, gmtm.tm_mon+1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec, buffer);
  72. // 关闭文件,释放资源并设置回原语言区域;
  73. free(buffer);
  74. fclose(fp);
  75. _tsetlocale(LC_CTYPE, old_locale);
  76. free(old_locale);//还原区域设定;
  77. }
  78. void WriteTextLogW(const WCHAR *format, ...)
  79. {
  80. // 解析出日志路径;
  81. WCHAR szlogpath[MAX_PATH] = { 0 };
  82. swprintf_s(szlogpath, L"%s%s.txt", g_szCurModulePath, g_szFna);
  83. // 打开或创建文件;
  84. FILE *fp = NULL;
  85. if (_waccess(szlogpath, 0) != -1)
  86. {// 存在;
  87. fp = _wfopen(szlogpath, L"a+");
  88. // 移动到末尾;
  89. fseek(fp, 0, SEEK_END);
  90. }
  91. else
  92. {// 不存在;
  93. fp = _wfopen(szlogpath, L"w+");
  94. }
  95. if ( fp == NULL )
  96. return;
  97. // 格式化前设置语言区域;
  98. WCHAR* old_locale = _wcsdup(_wsetlocale(LC_CTYPE, NULL));
  99. _wsetlocale(LC_CTYPE, L"chs");//设定中文;
  100. // 格式化日志内容;
  101. va_list args = NULL;
  102. int len = 0;
  103. WCHAR *buffer = NULL;
  104. va_start(args, format);
  105. // _vscprintf doesn't count. terminating '\0'
  106. len = _vscwprintf(format, args) + 1;
  107. buffer = (WCHAR*)malloc(len * sizeof(WCHAR));
  108. vswprintf_s(buffer, len, format, args);
  109. // 将日志内容输入到文件中;
  110. // 获取今年年份;
  111. __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
  112. struct tm gmtm = {0};
  113. localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
  114. fwprintf(fp, L"%04d-%02d-%02d %02d:%02d:%02d %s\n", gmtm.tm_year+1990, gmtm.tm_mon+1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec, buffer);
  115. // 关闭文件,释放资源并设置回原语言区域;
  116. free(buffer);
  117. fclose(fp);
  118. _wsetlocale(LC_CTYPE, old_locale);
  119. free(old_locale);//还原区域设定;
  120. }
  121. BOOL GetWxInfo(WxInfo &wxInfo)
  122. {
  123. HMODULE hWeChatWin = GetModuleHandle(_T("WeChatWin.dll"));
  124. if ( hWeChatWin == NULL )
  125. {
  126. WriteTextLog(_T("找不到WeChatWin.dll"));
  127. return FALSE;
  128. }
  129. DWORD dwWeChatWinAddr = DWORD(hWeChatWin);
  130. TCHAR szTemp[MAX_PATH] = {0};
  131. #if 0
  132. // 两种方式;
  133. _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131B90);
  134. #else
  135. memcpy(szTemp, (LPVOID)(dwWeChatWinAddr+0x1131B90), MAX_PATH);
  136. #endif
  137. WriteTextLog(_T("微信账号:%s"), szTemp);
  138. wxInfo.strWxAccount = szTemp;
  139. _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131B78)));
  140. WriteTextLog(_T("微信ID:%s"), szTemp);
  141. _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131BEC)));
  142. WriteTextLog(_T("微信ID:%s"), szTemp);
  143. wxInfo.strWxID = szTemp;
  144. // 微信中文不是宽字符,而是URL编译的UTF8格式;
  145. string str;
  146. _stprintf_s(szTemp, _T("%s"), LPDWORD(dwWeChatWinAddr + 0x1131C64));
  147. EncodingConverion::DeCode_URLUTF8(szTemp,str);
  148. WriteTextLog(_T("微信昵称:%s"), str.c_str());
  149. wxInfo.strWxNick = szTemp;
  150. _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131C98);
  151. WriteTextLog(_T("微信手机:%s"), szTemp);
  152. wxInfo.strWxPhone = szTemp;
  153. _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131D50);
  154. WriteTextLog(_T("微信省:%s"), szTemp);
  155. wxInfo.strWxProvince = szTemp;
  156. _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131D68);
  157. WriteTextLog(_T("微信市:%s"), szTemp);
  158. wxInfo.strWxCity = szTemp;
  159. _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1132030);
  160. WriteTextLog(_T("微信手机设备:%s"), szTemp);
  161. wxInfo.strWxDevice = szTemp;
  162. _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131C80)));
  163. WriteTextLog(_T("微信邮箱:0x%p, 0x%p"), dwWeChatWinAddr + 0x1131C80, *(LPDWORD(dwWeChatWinAddr + 0x1131C80)) );
  164. WriteTextLog(_T("微信邮箱:%s"), szTemp);
  165. wxInfo.strWxEmail = szTemp;
  166. _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131F2C)));
  167. WriteTextLog(_T("微信大头像:%s"), szTemp);
  168. wxInfo.strWxLImgAddr = szTemp;
  169. _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131F44)));
  170. WriteTextLog(_T("微信小头像:%s"), szTemp);
  171. wxInfo.strWxSImgAddr = szTemp;
  172. return TRUE;
  173. }
  174. BOOL GetProcInfo(DWORD &dwThreadId)
  175. {
  176. DWORD dwMID = 0;
  177. THREADENTRY32 the32 = { 0 };
  178. DWORD dwProcId = ::GetCurrentProcessId();
  179. HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, dwProcId);
  180. if (hSnapshot == NULL)
  181. return FALSE;
  182. BOOL bRet = FALSE;
  183. the32.dwSize = sizeof(THREADENTRY32);
  184. // 注意:第一次找到的线程ID就是主线程ID;
  185. for ( bRet = Thread32First(hSnapshot, &the32); bRet == TRUE; bRet = Thread32Next(hSnapshot, &the32) )
  186. {
  187. if ( the32.th32OwnerProcessID == dwProcId )
  188. {
  189. dwThreadId = the32.th32ThreadID;
  190. WriteTextLog(_T("Thread32 进程ID=%ld, 进程ID=%d, 线程ID=%d, Boolean=%d"), the32.th32OwnerProcessID, dwProcId, the32.th32ThreadID, bRet);
  191. break;
  192. }
  193. }
  194. CloseHandle(hSnapshot);
  195. return bRet;
  196. }