| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #include "StdAfx.h"
- #include "WxGlobal.h"
- #include <io.h>
- // 获取文件版本号函数头文件;
- #include <WinVer.h>
- #pragma comment(lib,"version.lib")
- using namespace std;
- #include <psapi.h>
- #pragma comment(lib,"Psapi.lib")
- // 进程相关头文件;
- #include <TlHelp32.h>
- #include "EncodingConversion.h"
- #include "..\common\CurlClient.h"
- HMODULE g_hCurModule = NULL;
- TCHAR g_szCurModulePath[MAX_PATH] = {0};
- TCHAR g_szFna[MAX_PATH] = {0};
- /************************************************************************/
- /* 函数:WriteTextLog[7/28/2016 IT];
- /* 描述:写文本日志;
- /* 参数:;
- /* [IN] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void WriteTextLog(const TCHAR *format, ...)
- {
- // 解析出日志路径;
- TCHAR szlogpath[MAX_PATH] = { 0 };
- _stprintf_s(szlogpath, _T("%s%s.txt"), g_szCurModulePath, g_szFna);
- // 打开或创建文件;
- FILE *fp = NULL;
- //if (_taccess(szlogpath, 0) != -1)
- #ifndef UNICODE
- if (_access(szlogpath, 0) != -1)
- #else
- if (_taccess(szlogpath, 0) != -1)
- #endif
- {// 存在;
- fp = _tfopen(szlogpath, _T("a+"));
- // 移动到末尾;
- fseek(fp, 0, SEEK_END);
- }
- else
- {// 不存在;
- fp = _tfopen(szlogpath, _T("w+"));
- }
- if ( fp == NULL )
- return;
- // 格式化前设置语言区域;
- TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
- _tsetlocale(LC_CTYPE, _T("chs"));//设定中文;
- // 格式化日志内容;
- va_list args = NULL;
- int len = 0;
- TCHAR *buffer = NULL;
- va_start(args, format);
- // _vscprintf doesn't count. terminating '\0'
- len = _vsctprintf(format, args) + 1;
- buffer = (TCHAR*)malloc(len * sizeof(TCHAR));
- _vstprintf_s(buffer, len, format, args);
- // 将日志内容输入到文件中;
- // 获取今年年份;
- __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
- struct tm gmtm = {0};
- localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
- _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);
- // 关闭文件,释放资源并设置回原语言区域;
- free(buffer);
- fclose(fp);
- _tsetlocale(LC_CTYPE, old_locale);
- free(old_locale);//还原区域设定;
- }
- void WriteTextLogW(const WCHAR *format, ...)
- {
- // 解析出日志路径;
- WCHAR szlogpath[MAX_PATH] = { 0 };
- swprintf_s(szlogpath, L"%s%s.txt", g_szCurModulePath, g_szFna);
- // 打开或创建文件;
- FILE *fp = NULL;
- if (_waccess(szlogpath, 0) != -1)
- {// 存在;
- fp = _wfopen(szlogpath, L"a+");
- // 移动到末尾;
- fseek(fp, 0, SEEK_END);
- }
- else
- {// 不存在;
- fp = _wfopen(szlogpath, L"w+");
- }
- if ( fp == NULL )
- return;
- // 格式化前设置语言区域;
- WCHAR* old_locale = _wcsdup(_wsetlocale(LC_CTYPE, NULL));
- _wsetlocale(LC_CTYPE, L"chs");//设定中文;
- // 格式化日志内容;
- va_list args = NULL;
- int len = 0;
- WCHAR *buffer = NULL;
- va_start(args, format);
- // _vscprintf doesn't count. terminating '\0'
- len = _vscwprintf(format, args) + 1;
- buffer = (WCHAR*)malloc(len * sizeof(WCHAR));
- vswprintf_s(buffer, len, format, args);
- // 将日志内容输入到文件中;
- // 获取今年年份;
- __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
- struct tm gmtm = {0};
- localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
- 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);
- // 关闭文件,释放资源并设置回原语言区域;
- free(buffer);
- fclose(fp);
- _wsetlocale(LC_CTYPE, old_locale);
- free(old_locale);//还原区域设定;
- }
- BOOL GetWxInfo(WxInfo &wxInfo)
- {
- HMODULE hWeChatWin = GetModuleHandle(_T("WeChatWin.dll"));
- if ( hWeChatWin == NULL )
- {
- WriteTextLog(_T("找不到WeChatWin.dll"));
- return FALSE;
- }
- DWORD dwWeChatWinAddr = DWORD(hWeChatWin);
- TCHAR szTemp[MAX_PATH] = {0};
- #if 0
- // 两种方式;
- _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131B90);
- #else
- memcpy(szTemp, (LPVOID)(dwWeChatWinAddr+0x1131B90), MAX_PATH);
- #endif
- WriteTextLog(_T("微信账号:%s"), szTemp);
- wxInfo.strWxAccount = szTemp;
- _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131B78)));
- WriteTextLog(_T("微信ID:%s"), szTemp);
- _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131BEC)));
- WriteTextLog(_T("微信ID:%s"), szTemp);
- wxInfo.strWxID = szTemp;
-
- // 微信中文不是宽字符,而是URL编译的UTF8格式;
- string str;
- _stprintf_s(szTemp, _T("%s"), LPDWORD(dwWeChatWinAddr + 0x1131C64));
- EncodingConverion::DeCode_URLUTF8(szTemp,str);
- WriteTextLog(_T("微信昵称:%s"), str.c_str());
- wxInfo.strWxNick = szTemp;
- _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131C98);
- WriteTextLog(_T("微信手机:%s"), szTemp);
- wxInfo.strWxPhone = szTemp;
- _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131D50);
- WriteTextLog(_T("微信省:%s"), szTemp);
- wxInfo.strWxProvince = szTemp;
- _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1131D68);
- WriteTextLog(_T("微信市:%s"), szTemp);
- wxInfo.strWxCity = szTemp;
- _stprintf_s(szTemp, _T("%s"), dwWeChatWinAddr + 0x1132030);
- WriteTextLog(_T("微信手机设备:%s"), szTemp);
- wxInfo.strWxDevice = szTemp;
- _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131C80)));
- WriteTextLog(_T("微信邮箱:0x%p, 0x%p"), dwWeChatWinAddr + 0x1131C80, *(LPDWORD(dwWeChatWinAddr + 0x1131C80)) );
- WriteTextLog(_T("微信邮箱:%s"), szTemp);
- wxInfo.strWxEmail = szTemp;
- _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131F2C)));
- WriteTextLog(_T("微信大头像:%s"), szTemp);
- wxInfo.strWxLImgAddr = szTemp;
- _stprintf_s(szTemp, _T("%s"), *(LPDWORD(dwWeChatWinAddr + 0x1131F44)));
- WriteTextLog(_T("微信小头像:%s"), szTemp);
- wxInfo.strWxSImgAddr = szTemp;
- return TRUE;
- }
- BOOL GetProcInfo(DWORD &dwThreadId)
- {
- DWORD dwMID = 0;
- THREADENTRY32 the32 = { 0 };
- DWORD dwProcId = ::GetCurrentProcessId();
- HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, dwProcId);
- if (hSnapshot == NULL)
- return FALSE;
- BOOL bRet = FALSE;
- the32.dwSize = sizeof(THREADENTRY32);
- // 注意:第一次找到的线程ID就是主线程ID;
- for ( bRet = Thread32First(hSnapshot, &the32); bRet == TRUE; bRet = Thread32Next(hSnapshot, &the32) )
- {
- if ( the32.th32OwnerProcessID == dwProcId )
- {
- dwThreadId = the32.th32ThreadID;
- WriteTextLog(_T("Thread32 进程ID=%ld, 进程ID=%d, 线程ID=%d, Boolean=%d"), the32.th32OwnerProcessID, dwProcId, the32.th32ThreadID, bRet);
- break;
- }
- }
-
- CloseHandle(hSnapshot);
- return bRet;
- }
|