int main(int argc, char *argv[]) { PCHAR lpRootPathName; PCHAR requiredVolLabel; CHAR lpVolumeNameBuffer[MAX_PATH+1]; CHAR lpFileSystemNameBuffer[MAX_PATH+1]; BOOL retVal; if(argc < 3) { printf("usage: chkvol.exe <Root Path Name> <Required Volume Label>\n"); printf("example: chkvol.exe C:\\ WINXP\n"); return 1; } lpRootPathName = argv[1]; requiredVolLabel = argv[2]; retVal = GetVolumeInformationA(lpRootPathName, lpVolumeNameBuffer, sizeof(lpVolumeNameBuffer), NULL, NULL, NULL, lpFileSystemNameBuffer, sizeof(lpFileSystemNameBuffer) ); if(retVal == 0) { printf("GetVolumeInformation failed with error %i\n", GetLastError()); return 2; } else { printf("GetVolumeInformation succeeded\n"); printf("Volume label for '%s' is '%s'\n", lpRootPathName, lpVolumeNameBuffer); } if(StrCmpIA(requiredVolLabel, lpVolumeNameBuffer) != 0 ) { printf("Volume label is NOT equial to '%s'. Return code is 3\n", requiredVolLabel); return 3; } else { printf("Volume label is equial to '%s'. Return code is 0\n", requiredVolLabel); return 0; } }
STDMETHODIMP ContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { BOOL fEx = FALSE; BOOL fUnicode = FALSE; if(lpcmi->cbSize == sizeof(CMINVOKECOMMANDINFOEX)) { fEx = TRUE; if((lpcmi->fMask & CMIC_MASK_UNICODE)) { fUnicode = TRUE; } } if( !fUnicode && HIWORD(lpcmi->lpVerb)) { if(StrCmpIA(lpcmi->lpVerb, VERB_A)) { return E_FAIL; } } else if( fUnicode && HIWORD(((CMINVOKECOMMANDINFOEX *) lpcmi)->lpVerbW)) { if(StrCmpIW(((CMINVOKECOMMANDINFOEX *)lpcmi)->lpVerbW, VERB_W)) { return E_FAIL; } } else if(LOWORD(lpcmi->lpVerb) != IDM_SHAREWITHBOX) { return E_FAIL; } else { if (m_pdtobj) { return ShareWithBoxItems(m_pdtobj, lpcmi->hwnd); } } return S_OK; }
// // FUNCTION: FileContextMenuExt::InvokeCommand // // PURPOSE: This method is called when a user clicks a menu item to tell // the handler to run the associated command. The lpcmi parameter // points to a structure that contains the needed information. // IFACEMETHODIMP FileContextMenuExt::InvokeCommand(LPCMINVOKECOMMANDINFO pici) { BOOL fUnicode = FALSE; // Determine which structure is being passed in, CMINVOKECOMMANDINFO or // CMINVOKECOMMANDINFOEX based on the cbSize member of lpcmi. Although // the lpcmi parameter is declared in Shlobj.h as a CMINVOKECOMMANDINFO // structure, in practice it often points to a CMINVOKECOMMANDINFOEX // structure. This struct is an extended version of CMINVOKECOMMANDINFO // and has additional members that allow Unicode strings to be passed. if (pici->cbSize == sizeof(CMINVOKECOMMANDINFOEX)) { if (pici->fMask & CMIC_MASK_UNICODE) { fUnicode = TRUE; } } // Determines whether the command is identified by its offset or verb. // There are two ways to identify commands: // // 1) The command's verb string // 2) The command's identifier offset // // If the high-order word of lpcmi->lpVerb (for the ANSI case) or // lpcmi->lpVerbW (for the Unicode case) is nonzero, lpVerb or lpVerbW // holds a verb string. If the high-order word is zero, the command // offset is in the low-order word of lpcmi->lpVerb. // For the ANSI case, if the high-order word is not zero, the command's // verb string is in lpcmi->lpVerb. if (!fUnicode && HIWORD(pici->lpVerb)) { // Is the verb supported by this context menu extension? if (StrCmpIA(pici->lpVerb, m_pszVerb) == 0) { OnVerbDisplayFileName(pici->hwnd); } else { // If the verb is not recognized by the context menu handler, it // must return E_FAIL to allow it to be passed on to the other // context menu handlers that might implement that verb. return E_FAIL; } } // For the Unicode case, if the high-order word is not zero, the // command's verb string is in lpcmi->lpVerbW. else if (fUnicode && HIWORD(((CMINVOKECOMMANDINFOEX*)pici)->lpVerbW)) { // Is the verb supported by this context menu extension? if (StrCmpIW(((CMINVOKECOMMANDINFOEX*)pici)->lpVerbW, m_pwszVerb) == 0) { OnVerbDisplayFileName(pici->hwnd); } else { // If the verb is not recognized by the context menu handler, it // must return E_FAIL to allow it to be passed on to the other // context menu handlers that might implement that verb. return E_FAIL; } } // If the command cannot be identified through the verb string, then // check the identifier offset. else { // Is the command identifier offset supported by this context menu // extension? if (LOWORD(pici->lpVerb) == IDM_DISPLAY) { OnVerbDisplayFileName(pici->hwnd); } else { // If the verb is not recognized by the context menu handler, it // must return E_FAIL to allow it to be passed on to the other // context menu handlers that might implement that verb. return E_FAIL; } } return S_OK; }
STDMETHODIMP CContextMenuHandler::InvokeCommand(CMINVOKECOMMANDINFO *pici) { f_log(__FUNCTION__); BOOL fEx = FALSE; BOOL fUnicode = FALSE; if (pici->cbSize = sizeof(CMINVOKECOMMANDINFOEX)) { fEx = TRUE; if ((pici->fMask & CMIC_MASK_UNICODE)) { fUnicode = TRUE; } } if (!fUnicode && HIWORD(pici->lpVerb)) { if (StrCmpIA(pici->lpVerb, szVerbRunConsoleA) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, false); } return S_OK; } else if (StrCmpIA(pici->lpVerb, szVerbPostConsoleA) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, true); } return S_OK; } return E_FAIL; } if (fUnicode && HIWORD(reinterpret_cast<CMINVOKECOMMANDINFOEX*>(pici)->lpVerbW)) { if (StrCmpIW(reinterpret_cast<CMINVOKECOMMANDINFOEX*>(pici)->lpVerbW, szVerbRunConsoleW) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, false); } return S_OK; } else if (StrCmpIW(reinterpret_cast<CMINVOKECOMMANDINFOEX*>(pici)->lpVerbW, szVerbRunConsoleW) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, true); } return S_OK; } return E_FAIL; } if (LOWORD(pici->lpVerb) == eMC_RunConsole) { // Run console with default tab if(!sPath.IsEmpty()) { RunConsole(sPath, false); } } else if (LOWORD(pici->lpVerb) == eMC_PostConsole) { // Run console with default tab if(!sPath.IsEmpty()) { RunConsole(sPath, true); } } else if (LOWORD(pici->lpVerb) >= eMC_RunConsoleWithTab && LOWORD(pici->lpVerb) < eMC_RunConsoleWithTab + 50) { // Run console with specified tab if (!sPath.IsEmpty()) { wstring sTabName; // get tab name { // synchronization syncAutoLock oLock(g_oSync); if ((LOWORD(pici->lpVerb) - eMC_RunConsoleWithTab) < (int)g_vTabs.size()) sTabName = g_vTabs[LOWORD(pici->lpVerb) - eMC_RunConsoleWithTab]->sName; } // run RunConsole(sPath, false, sTabName.c_str()); } } else if (LOWORD(pici->lpVerb) >= eMC_PostConsoleWithTab && LOWORD(pici->lpVerb) < eMC_PostConsoleWithTab + 50) { // Run console with specified tab if (!sPath.IsEmpty()) { wstring sTabName; // get tab name { // synchronization syncAutoLock oLock(g_oSync); if ((LOWORD(pici->lpVerb) - eMC_PostConsoleWithTab) < (int)g_vTabs.size()) sTabName = g_vTabs[LOWORD(pici->lpVerb) - eMC_PostConsoleWithTab]->sName; } // run RunConsole(sPath, true, sTabName.c_str()); } } return S_OK; }
BOOL CHttpRecvParser::ParseData(const char * pBuffer,int nLen) { BOOL bRes = FALSE; if (pBuffer == NULL || nLen < 50 ) { return bRes; } CStringA strData; strData = pBuffer; CStringA strHttpHeader; int HttpHeadEnd = strData.Find("\r\n\r\n"); if ( HttpHeadEnd > 0 ) { char chHeadData[9]; memcpy_s(chHeadData,8,pBuffer,8); chHeadData[8] = 0; if( StrCmpIA(chHeadData,"http/1.1") == 0 || StrCmpIA(chHeadData,"http/1.0") == 0 ) { m_bResponseHead = TRUE; m_ContentStart = HttpHeadEnd+4; bRes = TRUE; } else { return FALSE; } strHttpHeader = strData.Left(HttpHeadEnd); CStringA strHeaders[MAX_ACCEPT_HEAD_LEN]; int nCount = DivisionString("\r\n",strHttpHeader,strHeaders,MAX_ACCEPT_HEAD_LEN); if (nCount >= 1) { CStringA strTempStrs[10]; int nTempCount = DivisionString(" ",strHeaders[0],strTempStrs,10); m_strHttpVersion = strTempStrs[0]; m_strResponseCode = strTempStrs[1]; for (int i=2;i<nTempCount;i++) { m_strResponseText += strTempStrs[i]+" "; } m_strResponseText.TrimRight(); for(int i = 1;i<nCount;i++) { CStringA strHeader; CStringA strValue; int nHeadEnd = strHeaders[i].Find(":"); if ( nHeadEnd > 0 ) { strHeader = strHeaders[i].Left(nHeadEnd); strValue = strHeaders[i].Right(strHeaders[i].GetLength() - nHeadEnd - 1); strValue.Trim(); AddResponseNode(strHeader,strValue); } } } } else { } return bRes; }
void DoReport(LPCTSTR lpstrCmdLine, BOOL *pIsHandled) { WSADATA wsaData = {0}; WSAStartup(MAKEWORD(2, 2), &wsaData); //LogFinal(LOG::KBugReport) << L"Bugreport启动命令行: " << lpstrCmdLine; REPORT_CONTEXT report; std::wstring strProductName; const TCHAR * p = _tcsstr(lpstrCmdLine, _T("pid=")); if (p) { *pIsHandled = TRUE; DWORD client_process_id = _tcstoul(p + _tcslen(_T("pid=")), 0, 0); p = _tcsstr(lpstrCmdLine, _T("context=")); if (p) { void *addr = (void*)_tcstoul(p + _tcslen(_T("context=")), 0, 0); //YYBrowser Begin //by ZC. 2013-10-30 11:26. // hClientProcess客户进程,即是启动YGCrashReport的进程,不一定是崩溃的目标进程。 HANDLE client_process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, client_process_id); // 崩溃目标进程。 HANDLE target_process_handle = NULL; //YYBrowser End if (!client_process_handle) LogFinal(LOG::KBugReport) << L"打开进程句柄失败"; //解释REPORT_PARAMS CRASH_LAUNCH_PARAMS crash_launch_params = {0}; DWORD cbRead = 0; if (addr && ::ReadProcessMemory(client_process_handle, addr, &crash_launch_params, sizeof(crash_launch_params), &cbRead)) { LogFinal(LOG::KBugReport) << L"读取REPORT_PARAMS成功"; std::set<std::wstring> setSuspectModule; std::set<std::wstring> setModule; std::wstring strPathNoExt = GenerateNewFilePath(crash_launch_params.dwPID); report.strZipFilePath = strPathNoExt + _T(".zip"); report.strOSVer = GetOSVer(); AtoW(crash_launch_params.szProductName, -1, strProductName); report.dwReportId = crash_launch_params.dwReportId; report.strUserId = crash_launch_params.szUserId; report.strProductId = crash_launch_params.szProductId; report.strProductVer = crash_launch_params.szProductVer; report.strProductVerDetail = crash_launch_params.szProductVerDetail; //AtoW(crash_launch_params.szRestartExePath, -1, report.wstrRestartExePath); report.strDynaReleaseVer = crash_launch_params.szDynaReleaseVer; WriteBugInfo(report.dwReportId); report.dwCount24Hour = GetBugCount(report.dwReportId); //parse 自定义文件路径 if (crash_launch_params.nFileCount > 0) { char *pPaths = new char[MAX_PATH * crash_launch_params.nFileCount]; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCustomFilePaths, pPaths, MAX_PATH * crash_launch_params.nFileCount, &cbRead)) { for (UINT k = 0; k < cbRead / MAX_PATH; k++) { std::wstring wstrPath; AtoW(pPaths + k * MAX_PATH, -1, wstrPath); report.vecOtherFilePath.push_back(wstrPath); } } delete [] pPaths; pPaths = NULL; } //生成log std::string strLog; char szTemp[1024] = {0}; //Date time_t curTime = 0; time(&curTime); strftime(szTemp, _countof(szTemp)-1, "%Y-%m-%d %H.%M.%S\r\n", localtime(&curTime)); strLog += szTemp; strLog += "\r\n"; //异常信息 strLog += "Exception:\r\n"; const char *pModName = strrchr(crash_launch_params.szExcepModPath, '\\'); if (pModName) pModName++; else pModName = crash_launch_params.szExcepModPath; report.strExcepModuleName = pModName; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "Module=%s\r\n", pModName); strLog += szTemp; //YYBrowser Begin //打开目标进程。by ZC. 2013-10-30 11:30. target_process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, crash_launch_params.dwPID); //YYBrowser End //YYBrowser Begin //从目标进程中读出结构异常。by ZC. 2013-10-30 11:28. if (crash_launch_params.pExceptionInfo) { EXCEPTION_RECORD excep = {0}; CONTEXT ct = {0}; EXCEPTION_POINTERS ptr = {0}; if (::ReadProcessMemory(target_process_handle, crash_launch_params.pExceptionInfo, &ptr, sizeof(ptr), &cbRead) && ::ReadProcessMemory(target_process_handle, ptr.ExceptionRecord, &excep, sizeof(excep), &cbRead) && ::ReadProcessMemory(target_process_handle, ptr.ContextRecord, &ct, sizeof(ct), &cbRead)) { report.dwExcepAddr = (DWORD)excep.ExceptionAddress; report.dwExcepCode = excep.ExceptionCode; report.strExcepDiscription = GetExceptionDescription(excep.ExceptionCode); _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ExceptionCode=0x%08x, %s\r\n", excep.ExceptionCode, GetExceptionDescription(excep.ExceptionCode)); strLog += szTemp; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "eip=0x%08x, ebp=0x%08x, esp=0x%08x, eax=0x%08x, ebx=0x%08x, ecx=0x%08x, edx=0x%08x, esi=0x%08x, edi=0x%08x\r\n", ct.Eip, ct.Ebp, ct.Esp, ct.Eax, ct.Ebx, ct.Ecx, ct.Edx, ct.Esi, ct.Edi); strLog += szTemp; } strLog += "\r\n"; } //YYBrowser End strLog += "Summary:\r\n"; strLog += GetSummary(client_process_handle); strLog += "UserId(YY)=" + report.strUserId + "\r\n"; strLog += "ProductVer=" + report.strProductVer + "\r\n"; strLog += "DynaReleaseVer=" + report.strDynaReleaseVer + "\r\n"; strLog += "ProductVerDetail=" + report.strProductVerDetail + "\r\n"; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ReportId=%u\r\n", report.dwReportId); strLog += szTemp; strLog += "\r\n"; std::string strLoginHistoryLog; std::string strLoginHistory = ReadLoginHistory(strLoginHistoryLog); //用户自定义信息 strLog += "CustomProperty:\r\n"; char *pCustomProperty = new char[crash_launch_params.cchCustomProperty + 1]; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCustomProperty, pCustomProperty, crash_launch_params.cchCustomProperty, &cbRead)) { pCustomProperty[cbRead/sizeof(char)] = 0; report.strCustomProperty = pCustomProperty; } strLog += report.strCustomProperty; if(strLoginHistory.size()>0) { if(report.strCustomProperty.size()>0) { report.strCustomProperty+="&"; } report.strCustomProperty+=strLoginHistory; } if(strLoginHistoryLog.size()>0) { strLog += "\r\n"; strLog += strLoginHistoryLog; } strLog += "\r\n"; //CallStack strLog += "Call Stack:\r\n"; char *pCallStack = new char[crash_launch_params.cchCallStack + 1]; cbRead = 0; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCallStack, pCallStack, crash_launch_params.cchCallStack, &cbRead)) { pCallStack[cbRead/sizeof(char)] = 0; strLog += pCallStack; } strLog += "\r\n"; //收集进程列表&检测运行环境 std::string strProcListA; std::wstring strProcListW; report.dwRunEnvironment = CheckRunEnvironment(strProcListW); WtoA(strProcListW.c_str(), -1, strProcListA); strLog += "Process List:\r\n"; strLog += strProcListA; strLog += "\r\n"; //收集版本的语言种类,不写入日志 report.strProductLang = GetLanguageName(); //模块列表 strLog += "Module List:\r\n"; strLog += GetModuleList(target_process_handle,&setModule,&setSuspectModule); strLog += "\r\n"; //程序Log strLog += "Log:\r\n"; TCHAR szExePath[MAX_PATH] = {0}; GetModuleFileNameEx(target_process_handle, NULL, szExePath, _countof(szExePath)); TCHAR *p = _tcsrchr(szExePath, _T('.')); if (p) *p = 0; TCHAR* pExeName = _tcsrchr(szExePath, _T('\\')); if (pExeName) pExeName++; else pExeName = szExePath; const DWORD dwMaxLogSize = 1024 * 200; // char *pContent = new char [dwMaxLogSize]; // GetLastLog(pExeName, reportParams.dwPID, 0, pContent, dwMaxLogSize); // strLog += pContent; // delete [] pContent; // pContent = NULL; strLog += "\r\n\r\n"; /************************************************************************/ /*功能:在日志文件中添加安装目录下所有dll和rcc文件的md5*/ /***************************只有yy.exe崩溃时,才会计算相关文件的md5*/ if (StrCmpIA(crash_launch_params.szProductId, "YY") == 0) { strLog += "[List *.dll and *.rcc files MD5:] \r\n\r\n"; TCHAR szCurrentProcesspath[MAX_PATH] = {0}; if ( GetModuleFileName(NULL,szCurrentProcesspath,_countof(szCurrentProcesspath)) > 0) { TCHAR* p_findDir = _tcsrchr(szCurrentProcesspath,_T('\\')); std::wstring rawCurrentProcessPath = szCurrentProcesspath; std::wstring strCurrentProcesspath = rawCurrentProcessPath.substr(0, p_findDir - szCurrentProcesspath); strLog += dwCalculateMD5(strCurrentProcesspath.c_str()); } else { strLog += "Get the files'MD5 failed!"; } } else { strLog += "Hint:\r\nThe crash was caused by the other products except the YY!"; } /************************************************************************/ TCHAR szLogPath[_MAX_PATH] = {0}; _sntprintf_s(szLogPath, _countof(szLogPath), _TRUNCATE, _T("%s.txt"), strPathNoExt.c_str()); report.strLogPath = szLogPath; LogFinal(LOG::KBugReport) << L"写入log文件: " << szLogPath; HANDLE hFile = ::CreateFile(szLogPath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, NULL, NULL); DWORD dwWriten = 0; ::WriteFile(hFile, strLog.c_str(), strLog.size(), &dwWriten, NULL); ::CloseHandle(hFile); //生成dump TCHAR szDumpPath[_MAX_PATH] = {0}; _sntprintf_s(szDumpPath, _countof(szDumpPath), _TRUNCATE, _T("%s.dmp"), strPathNoExt.c_str()); LogFinal(LOG::KBugReport) << L"生成dump文件: " << szDumpPath; int nDumpType = (MiniDumpNormal|MiniDumpWithHandleData|MiniDumpWithIndirectlyReferencedMemory|MiniDumpWithUnloadedModules|MiniDumpWithProcessThreadData); if (!CreateDump(szDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, nDumpType, MyMiniDumpCallBack, &crash_launch_params)) { crash_launch_params.curCustomDataIdx = 0; CreateDump(szDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, MiniDumpNormal, MyMiniDumpCallBack, &crash_launch_params); } report.strDumpPath = szDumpPath; //生成fulldump CRegKey key; LONG lResult = key.Open(HKEY_CURRENT_USER, _T("Software\\duowan\\bugreport"), KEY_READ); if (ERROR_SUCCESS == lResult) { TCHAR szFullDump[1024] = {0}; DWORD dwSize = _countof(szFullDump); lResult = key.QueryValue(szFullDump, _T("fulldump"), &dwSize); if (ERROR_SUCCESS == lResult) { szFullDump[dwSize] = 0; if (_tcsicmp(szFullDump, _T("yes")) == 0) { nDumpType = (MiniDumpNormal | MiniDumpWithFullMemory | MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithHandleData | MiniDumpWithUnloadedModules | MiniDumpWithProcessThreadData); TCHAR szFullDumpPath[_MAX_PATH] = {0}; ::GetTempPath(_countof(szFullDumpPath), szFullDumpPath); _tcsncat_s(szFullDumpPath, _countof(szFullDumpPath), _T("duowan\\fulldump.dmp"), _TRUNCATE); LogFinal(LOG::KBugReport) << L"生成fulldump文件: " << szFullDumpPath; CreateDump(szFullDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, nDumpType, MyMiniDumpCallBack, &crash_launch_params); } } } ::SetEvent(crash_launch_params.evDumpComplete); if (crash_launch_params.bShowReportUI) { LogFinal(LOG::KBugReport) << L"开始弹出崩溃界面"; std::string strRecv; bool bShowModifyStatus = false; //if(GetBugModifyStatus(&report,strRecv)) //{ // const char* p = strstr(strRecv.c_str(),"return=true"); // if(p) // { // bShowModifyStatus = true; // } //} CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); CDlgReport dlgMain(strProductName.c_str(), &report, crash_launch_params.dwPID, &setModule, &setSuspectModule, bShowModifyStatus, strRecv.c_str()); dlgMain.Create(NULL); dlgMain.ShowWindow(SW_SHOW); theLoop.Run(); _Module.RemoveMessageLoop(); } else { SendReport(&report, &setModule, &setSuspectModule); } } else { LogFinal(LOG::KBugReport) << L"读取崩溃进程REPORT_PARAMS失败"; } ::CloseHandle(target_process_handle); ::CloseHandle(client_process_handle); } } }