Beispiel #1
0
CRASHRPTAPI(int) crInstallA(CR_INSTALL_INFOA* pInfo)
{
  if(pInfo==NULL)
    return crInstallW((CR_INSTALL_INFOW*)NULL);

  // Convert pInfo members to wide char

  strconv_t strconv;
  
  CR_INSTALL_INFOW ii;
  memset(&ii, 0, sizeof(CR_INSTALL_INFOW));
  ii.cb = sizeof(CR_INSTALL_INFOW);
  ii.pfnCrashCallback = pInfo->pfnCrashCallback;
  ii.pszAppName = strconv.a2w(pInfo->pszAppName);
  ii.pszAppVersion = strconv.a2w(pInfo->pszAppVersion);
  ii.pszCrashSenderPath = strconv.a2w(pInfo->pszCrashSenderPath);
  ii.pszEmailSubject = strconv.a2w(pInfo->pszEmailSubject);
  ii.pszEmailTo = strconv.a2w(pInfo->pszEmailTo);
  ii.pszUrl = strconv.a2w(pInfo->pszUrl);
  memcpy(&ii.uPriorities, pInfo->uPriorities, 3*sizeof(UINT));
  ii.dwFlags = pInfo->dwFlags;
  ii.pszPrivacyPolicyURL = strconv.a2w(pInfo->pszPrivacyPolicyURL);
  ii.pszDebugHelpDLL = strconv.a2w(pInfo->pszDebugHelpDLL);
  ii.uMiniDumpType = pInfo->uMiniDumpType;
  ii.pszErrorReportSaveDir = strconv.a2w(pInfo->pszErrorReportSaveDir);
  ii.pszRestartCmdLine = strconv.a2w(pInfo->pszRestartCmdLine);
  ii.pszLangFilePath = strconv.a2w(pInfo->pszLangFilePath);
  ii.pszEmailText = strconv.a2w(pInfo->pszEmailText);
  ii.pszSmtpProxy = strconv.a2w(pInfo->pszSmtpProxy);

  return crInstallW(&ii);
}
void CrashRptAPITests::Test_crAddScreenshot()
{   
  // Should fail, because crInstall() should be called first
  int nResult = crAddScreenshot(CR_AS_VIRTUAL_SCREEN);
  TEST_ASSERT(nResult!=0);

  // Install crash handler
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  // Should succeed
  int nResult2 = crAddScreenshot(CR_AS_VIRTUAL_SCREEN);
  TEST_ASSERT(nResult2==0);

  // Call twice - should succeed
  int nResult3 = crAddScreenshot(CR_AS_MAIN_WINDOW);
  TEST_ASSERT(nResult3==0);

  __TEST_CLEANUP__;

  // Uninstall
  crUninstall();  
}
void CrashRptAPITests::Test_crAddPropertyW()
{   
  // Should fail, because crInstall() should be called first
  int nResult = crAddPropertyW(L"VideoAdapter", L"nVidia GeForce GTS 250");
  TEST_ASSERT(nResult!=0);

  // Install crash handler
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  // Should fail, because property name is empty
  int nResult2 = crAddPropertyW(L"", L"nVidia GeForce GTS 250");
  TEST_ASSERT(nResult2!=0);
  
  // Should succeed
  int nResult3 = crAddPropertyW(L"VideoAdapter", L"nVidia GeForce GTS 250");
  TEST_ASSERT(nResult3==0);

  __TEST_CLEANUP__;

  // Uninstall
  crUninstall();
  
}
void CrashRptAPITests::Test_crAddFileW()
{ 
  strconv_t strconv;
  CString sFileName;

  // Should fail, because crInstall() should be called first
  int nResult = crAddFileW(L"a.txt", L"invalid file");
  TEST_ASSERT(nResult!=0);

  // Install crash handler
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  // Add not existing file, crAddFileA should fail
  int nResult2 = crAddFileW(L"a.txt", L"invalid file");
  TEST_ASSERT(nResult2!=0);

  // Add existing file, crAddFileA should succeed
  
  sFileName = Utility::GetModulePath(NULL)+_T("\\dummy.ini");
  LPCWSTR szFileName = strconv.t2w(sFileName);
  int nResult3 = crAddFileW(szFileName, L"Dummy INI File");
  TEST_ASSERT(nResult3==0);

  __TEST_CLEANUP__;

  // Uninstall
  crUninstall();  
}
void CrashRptAPITests::Test_crInstallW_short_path_name()
{ 
  CString sTmpDir;
  CString sTmpDir2;
  WCHAR szShortPath[1024] = L"";
  strconv_t strconv;
  
  // Call crInstallW with short path name pszErrorReportSaveDir - should succeed
  
  // Create tmp file name with UNICODE characters
  sTmpDir = Utility::getTempFileName();  
  Utility::RecycleFile(sTmpDir, TRUE);
  sTmpDir2 = sTmpDir + L"\\应用程序名称";  
  Utility::CreateFolder(sTmpDir2);
  GetShortPathNameW(strconv.t2w(sTmpDir2), szShortPath, 1024);
  // Remove tmp folder
  Utility::RecycleFile(sTmpDir, TRUE);
  
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.
  infoW.pszErrorReportSaveDir = szShortPath;

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  __TEST_CLEANUP__

  crUninstall();

  Utility::RecycleFile(sTmpDir, TRUE);
}
void CrashRptAPITests::Test_crInstall_null()
{   
  // Test crInstall with NULL info - should fail
  
  int nInstallResult = crInstallW(NULL);
  TEST_ASSERT(nInstallResult!=0);

  int nInstallResult2 = crInstallA(NULL);
  TEST_ASSERT(nInstallResult2!=0); 

  __TEST_CLEANUP__;
}
Beispiel #7
0
CRASHRPTAPI(LPVOID) InstallW(LPGETLOGFILE pfnCallback, LPCWSTR pszEmailTo, LPCWSTR pszEmailSubject)
{
  CR_INSTALL_INFOW info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);
  info.pfnCrashCallback = pfnCallback;
  info.pszEmailTo = pszEmailTo;
  info.pszEmailSubject = pszEmailSubject;

  crInstallW(&info);

  return NULL;
}
void CrashRptAPITests::Test_crInstallW_zero_info()
{   
  // Test crInstallW with zero info
  
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);

  __TEST_CLEANUP__

  crUninstall();  
}
void CrashRptAPITests::Test_crGetLastErrorMsgW()
{ 
  // Get error message before Install
  WCHAR szErrMsg[256] = L"";
  int nResult = crGetLastErrorMsgW(szErrMsg, 256);
  TEST_ASSERT(nResult>0);

  // Install crash handler
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  // Get error message
  WCHAR szErrMsg2[256] = L"";
  int nResult2 = crGetLastErrorMsgW(szErrMsg2, 256);
  TEST_ASSERT(nResult2>0);

  // Get error message to NULL buffer - must fail  
  int nResult3 = crGetLastErrorMsgW(NULL, 256);
  TEST_ASSERT(nResult3<0);

  // Get error message to a buffer, but zero length - must fail  
  WCHAR szErrMsg3[256] = L"";
  int nResult4 = crGetLastErrorMsgW(szErrMsg3, 0);
  TEST_ASSERT(nResult4<0);

  // Get error message to a single-char buffer, must trunkate message and succeed
  WCHAR szErrMsg5[1] = L"";
  int nResult5 = crGetLastErrorMsgW(szErrMsg5, 1);
  TEST_ASSERT(nResult5==0);

  // Get error message to a small buffer, must trunkate message and succeed
  WCHAR szErrMsg6[2] = L"";
  int nResult6 = crGetLastErrorMsgW(szErrMsg6, 2);
  TEST_ASSERT(nResult6>0);

  __TEST_CLEANUP__;

  // Uninstall
  crUninstall();
  
}
void CrashRptAPITests::Test_crAddRegKeyW()
{   
  // Should fail, because crInstall() should be called first
  int nResult = crAddRegKeyW(L"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows", L"regkey.xml", 0);
  TEST_ASSERT(nResult!=0);

  // Install crash handler
  CR_INSTALL_INFOW infoW;
  memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
  infoW.cb = sizeof(CR_INSTALL_INFOW);
  infoW.pszAppVersion = L"1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  // Should fail, because registry key name is NULL
  int nResult2 = crAddRegKeyW(NULL, L"regkey.xml", 0);
  TEST_ASSERT(nResult2!=0);
  
  // Should fail, because registry key name is empty
  int nResult3 = crAddRegKeyW(L"", L"regkey.xml", 0);
  TEST_ASSERT(nResult3!=0);

  // Should succeed
  int nResult4 = crAddRegKeyW(L"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows", L"regkey.xml", 0);
  TEST_ASSERT(nResult4==0);

  // Should fail, because registry key doesn't exist
  int nResult5 = crAddRegKeyW(L"HKEY_LOCAL_MACHINE\\Softweeere\\", L"regkey.xml", 0);
  TEST_ASSERT(nResult5!=0);

  // Should fail, because registry key is a parent key
  int nResult6 = crAddRegKeyW(L"HKEY_LOCAL_MACHINE\\", L"regkey.xml", 0);
  TEST_ASSERT(nResult6!=0);

  __TEST_CLEANUP__;

  // Uninstall
  crUninstall();  
}
Beispiel #11
0
// A helper function that creates a error report for testing
BOOL TestUtils::CreateErrorReport(CString sTmpFolder, CString& sErrorReportName, CString& sMD5Hash)
{
    BOOL bStatus = FALSE;
    CString sReportFolder;
    DWORD dwExitCode = 1;
    WIN32_FIND_DATA ffd;
    HANDLE hFind = INVALID_HANDLE_VALUE;
    CString sSearchPattern = sTmpFolder + "\\*.zip";
    CString sMD5FileName;
    FILE* f = NULL;
    TCHAR szHashBuff[256] = _T("");
    HKEY hKey = NULL;
    LONG lResult = -1;
    CString sKeyName = _T("Software\\CrashRpt&&#4216wer\\应用程序名称");
    CString sKeyName2 = _T("HKEY_CURRENT_USER\\") + sKeyName;

    lResult = RegCreateKey(HKEY_CURRENT_USER, sKeyName, &hKey); 
    if(lResult!=ERROR_SUCCESS)
        goto cleanup;

    DWORD dwVal = 12345;
    lResult = RegSetValueEx(hKey, _T("Value$%^!@#&123fer"), 0, REG_DWORD, (LPBYTE)&dwVal, sizeof(DWORD));
    if(lResult!=ERROR_SUCCESS)
        goto cleanup;

    CR_INSTALL_INFOW infoW;
    memset(&infoW, 0, sizeof(CR_INSTALL_INFOW));
    infoW.cb = sizeof(CR_INSTALL_INFOW);  
    infoW.pszAppName = L"My& app Name &"; 
    // Use appname with restricted XML characters
    infoW.pszAppVersion = L"1.0.0 &<'a应> \"<"; 
    infoW.pszErrorReportSaveDir = sTmpFolder;
    infoW.dwFlags = CR_INST_NO_GUI|CR_INST_DONT_SEND_REPORT|CR_INST_STORE_ZIP_ARCHIVES;  

    int nInstallResult = crInstallW(&infoW);
    if(nInstallResult!=0)
        goto cleanup;

    crAddScreenshot(CR_AS_MAIN_WINDOW);
    crAddPropertyW(L"CustomProp", L"Property Value");
    crAddRegKey(sKeyName2, L"regkey.xml", 0);

    CR_EXCEPTION_INFO ei;
    memset(&ei, 0, sizeof(CR_EXCEPTION_INFO));
    ei.cb = sizeof(ei);
    ei.exctype = CR_SEH_EXCEPTION;
    ei.code = 0x123;

    // Generate error report
    int nGenResult = crGenerateErrorReport(&ei);
    if(nGenResult!=0)
        goto cleanup;

    // Wait until CrashSender process exits
    WaitForSingleObject(ei.hSenderProcess, INFINITE);

    // Check exit code  
    GetExitCodeProcess(ei.hSenderProcess, &dwExitCode);
    if(dwExitCode!=0)
        goto cleanup;

    // Get ZIP name  
    hFind = FindFirstFile(sSearchPattern, &ffd);
    if(hFind==INVALID_HANDLE_VALUE)
        goto cleanup;

    sErrorReportName = sTmpFolder + _T("\\") + CString(ffd.cFileName);

    FindClose(hFind);
    hFind = NULL;

    // Get MD5 name
    sSearchPattern = sTmpFolder + "\\*.md5";
    hFind = FindFirstFile(sSearchPattern, &ffd);
    if(hFind==INVALID_HANDLE_VALUE)
        goto cleanup;

    sMD5FileName = sTmpFolder + _T("\\") + CString(ffd.cFileName);

#if _MSC_VER < 1400
    f = _tfopen(sMD5FileName, _T("rt"));
#else
    _tfopen_s(&f, sMD5FileName, _T("rt"));
#endif
    if(f==NULL)
        goto cleanup;

    TCHAR* szHash = _fgetts(szHashBuff, 256, f);
    if(szHash==NULL)
        goto cleanup;

    sMD5Hash = szHash;

    if(sMD5Hash.GetLength()!=32)
        goto cleanup; // Hash must be 32 characters in length

    bStatus = TRUE;

cleanup:

    crUninstall();

    if(f!=NULL)
        fclose(f);

    if(hFind!=INVALID_HANDLE_VALUE)
        FindClose(hFind);

    if(hKey)    
        RegCloseKey(hKey);

    RegDeleteKey(HKEY_CURRENT_USER, sKeyName);

    return bStatus;
}
Beispiel #12
0
void r3dThreadEntryHelper(threadEntry_fn fn, DWORD in)
{
	/*if(!CheckCrashRptVersion())
	{
		// An invalid CrashRpt.dll loaded!
		MessageBox(NULL, "The version of CrashRpt.dll is invalid.", "CRASH RPT ERROR", MB_OK);
		return;
	}*/

	if(!IsDebuggerPresent())
	{
#ifdef DISABLE_CRASHRPT
		SetUnhandledExceptionFilter(CreateMiniDump);
#else
		// detect language file
		wchar_t curDir[MAX_PATH];
		wchar_t langFile[MAX_PATH];
		GetCurrentDirectoryW(sizeof(curDir), curDir);
		swprintf(langFile, MAX_PATH, L"%s\\%s", curDir, crashRpgGetLangFile());

		// use wide versino of structure, as pszLangFilePath *require* full path by some reasons
		CR_INSTALL_INFOW info;
		memset(&info, 0, sizeof(CR_INSTALL_INFOW));  
		info.cb = sizeof(CR_INSTALL_INFOW);
#ifdef FINAL_BUILD
		info.pszAppName = L"Undead Brasil";
#else
		info.pszAppName = L"Undead Brasil";
#endif
		info.pszAppVersion = L"1.0";
		info.pszEmailTo = NULL;
		
#ifndef HS_ENABLED
		info.pszUrl = L"http:///127.0.0.1/conexao/api/php/api_CrashRptDebug.php";
#else
		info.pszUrl = L"http:///127.0.0.1/conexao/api/api_CrashRpt.php";
#endif
		
		info.pszCrashSenderPath = NULL;
		info.pfnCrashCallback = &r3dCrashRptCallback;
		info.uPriorities[CR_HTTP] = 1;
		info.uPriorities[CR_SMTP] = CR_NEGATIVE_PRIORITY; // skip it
		info.uPriorities[CR_SMAPI] = CR_NEGATIVE_PRIORITY; // skip it
		info.dwFlags |= CR_INST_ALL_EXCEPTION_HANDLERS;
		info.dwFlags |= CR_INST_HTTP_BINARY_ENCODING;
		info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;
		//we should not restart app, as GNA using command line to pass login info
		//info.dwFlags |= CR_INST_APP_RESTART;
		//info.pszRestartCmdLine   = __r3dCmdLine; 
		info.pszPrivacyPolicyURL = L"https://127.0.0.1/conexao/PrivacyPolicy_WarZ.htm";
		info.pszLangFilePath     = langFile;

		int res = crInstallW(&info);
		if(res !=0)
		{
			// Something goes wrong. Get error message.
			TCHAR szErrorMsg[512] = _T("");        
			crGetLastErrorMsg(szErrorMsg, 512);    
			r3dOutToLog(("%s\n"), szErrorMsg);    
			//return 1;
		}

		// add files to crash report
		char filePath[1024];
		res = crAddFile2(_T("crashdmp.dmp"), NULL, _T("Crash dump file"), CR_AF_MAKE_FILE_COPY|CR_AF_MISSING_FILE_OK);

		res = crAddFile2(_T("r3dlog.txt"), NULL, _T("Log file"), CR_AF_MAKE_FILE_COPY|CR_AF_MISSING_FILE_OK);
		//CreateConfigPath(filePath);
		//remove( "r3dlog.txt");
		DeleteFile("r3dlog.txt");
		strcat(filePath, "gameSettings.ini");
		res = crAddFile2(filePath, NULL, _T("Game Settings file"), CR_AF_MAKE_FILE_COPY|CR_AF_MISSING_FILE_OK);
		CreateConfigPath(filePath);
		strcat(filePath, "GPU.txt");
		res = crAddFile2(filePath, NULL, _T("GPU information file"), CR_AF_MAKE_FILE_COPY|CR_AF_MISSING_FILE_OK);
#endif
	}

	//crEmulateCrash(CR_CPP_NEW_OPERATOR_ERROR);
	
	fn(in);

#ifndef DISABLE_CRASHRPT
	if(!IsDebuggerPresent())
	{
		crUninstall();
	}
#endif
}