void CrashRptAPITests::Test_crUninstall()
{   
  // Call crUninstall - should fail, because crInstall should be called first
    
  int nUninstallResult = crUninstall();
  TEST_ASSERT(nUninstallResult!=0); 

  // And another time... 
  int nUninstallResult2 = crUninstall();
  TEST_ASSERT(nUninstallResult2!=0); 

  __TEST_CLEANUP__;
}
void CrashRptAPITests::Test_crInstallToCurrentThread()
{ 
  // Call before install - must fail
  int nResult = crInstallToCurrentThread();
  TEST_ASSERT(nResult!=0);

  // Call before install - must fail
  int nResult2 = crInstallToCurrentThread2(0);
  TEST_ASSERT(nResult2!=0);

  // Install crash handler for the main thread

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);
  info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail.

  int nInstResult = crInstall(&info);
  TEST_ASSERT(nInstResult==0);
  
  // Call in the main thread - must fail
  int nResult3 = crInstallToCurrentThread2(0);
  TEST_ASSERT(nResult3!=0);

  // Run a worker thread
  HANDLE hThread = CreateThread(NULL, 0, ThreadProc2, NULL, 0, NULL);

  // Wait until thread exits
  WaitForSingleObject(hThread, INFINITE);

  __TEST_CLEANUP__;  

  // Uninstall should succeed
  crUninstall();  
}
void CrashRptAPITests::Test_crInstallToCurrentThread_concurrent()
{ 
  // Install crash handler for the main thread

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);
  info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail.

  int nInstResult = crInstall(&info);
  TEST_ASSERT(nInstResult==0);
    
  // Run a worker thread
  HANDLE hThread = CreateThread(NULL, 0, ThreadProc3, NULL, 0, NULL);

  // Run another worker thread
  HANDLE hThread2 = CreateThread(NULL, 0, ThreadProc3, NULL, 0, NULL);

  // Run the third worker thread
  HANDLE hThread3 = CreateThread(NULL, 0, ThreadProc3, NULL, 0, NULL);

  // Wait until threads exit
  WaitForSingleObject(hThread, INFINITE);
  WaitForSingleObject(hThread2, INFINITE);
  WaitForSingleObject(hThread3, INFINITE);

  __TEST_CLEANUP__;  

  // Uninstall
  crUninstall();  
}
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_crInstallA_short_path_name()
{ 
  CString sTmpDir;
  char szShortPath[1024] = "";
  strconv_t strconv;
  
  // Call crInstallA with short path name pszErrorReportSaveDir - should succeed
  
  // Create tmp file name
  sTmpDir = Utility::getTempFileName();
  GetShortPathNameA(strconv.t2a(sTmpDir), szShortPath, 1024);
  // Remove tmp file
  Utility::RecycleFile(sTmpDir, TRUE);

  CR_INSTALL_INFOA infoA;
  memset(&infoA, 0, sizeof(CR_INSTALL_INFOA));
  infoA.cb = sizeof(CR_INSTALL_INFOA);
  infoA.pszAppVersion = "1.0.0"; // Specify app version, otherwise it will fail.
  infoA.pszErrorReportSaveDir = szShortPath;

  int nInstallResult = crInstallA(&infoA);
  TEST_ASSERT(nInstallResult==0);
  
  __TEST_CLEANUP__

  crUninstall();

  Utility::RecycleFile(sTmpDir, TRUE);
}
示例#9
0
void OCPNPlatform::OnExit_2( void ){
    
#ifdef OCPN_USE_CRASHRPT
#ifndef _DEBUG
        // Uninstall Windows crash reporting
    crUninstall();
#endif
#endif
    
}
示例#10
0
// This test tries to send report in silent mode over SMAPI.
// Since SMAPI is not available in silent mode, test passes when delivery fails.
void DeliveryTests::Test_SMAPI_Delivery()
{ 
    CString sAppDataFolder;
    CString sExeFolder;
    CString sTmpFolder;

    // Create a temporary folder  
    Utility::GetSpecialFolder(CSIDL_APPDATA, sAppDataFolder);
    sTmpFolder = sAppDataFolder+_T("\\CrashRpt");
    BOOL bCreate = Utility::CreateFolder(sTmpFolder);
    TEST_ASSERT(bCreate);

    // Install crash handler for the main thread

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);
    info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail.
    info.dwFlags = CR_INST_NO_GUI;
    info.pszEmailTo = _T("*****@*****.**");
    info.pszEmailSubject = _T("Crash Report Whooaaa!!!");
    info.pszEmailText = _T("And some text in the email body...");
    info.uPriorities[CR_HTTP] = CR_NEGATIVE_PRIORITY;
    info.uPriorities[CR_SMTP] = CR_NEGATIVE_PRIORITY;
    info.uPriorities[CR_SMAPI] = 0;  
    info.pszErrorReportSaveDir = sTmpFolder;
    int nInstResult = crInstall(&info);
    TEST_ASSERT(nInstResult==0);

    // Generate and send error report
    CR_EXCEPTION_INFO exc;
    memset(&exc, 0, sizeof(CR_EXCEPTION_INFO));
    exc.cb = sizeof(CR_EXCEPTION_INFO);
    int nResult2 = crGenerateErrorReport(&exc);
    TEST_ASSERT(nResult2==0);

    // Wait until CrashSender exits and check exit code
    WaitForSingleObject(exc.hSenderProcess, INFINITE);

    DWORD dwExitCode = 1;
    GetExitCodeProcess(exc.hSenderProcess, &dwExitCode);
    // Since SMAPI is not available in silent mode, test passes when delivery fails.
    TEST_ASSERT(dwExitCode!=0); // Exit code should be non-zero

    __TEST_CLEANUP__;  

    // Uninstall
    crUninstall();  

    // Delete tmp folder
    Utility::RecycleFile(sTmpFolder, TRUE);
}
示例#11
0
void DeliveryTests::Test_HttpDelivery()
{ 
    CString sAppDataFolder;
    CString sExeFolder;
    CString sTmpFolder;

    // Create a temporary folder  
    Utility::GetSpecialFolder(CSIDL_APPDATA, sAppDataFolder);
    sTmpFolder = sAppDataFolder+_T("\\CrashRpt");
    BOOL bCreate = Utility::CreateFolder(sTmpFolder);
    TEST_ASSERT(bCreate);

    // Install crash handler for the main thread

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);
    info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail.
    info.dwFlags = CR_INST_NO_GUI;
    info.pszUrl = _T("localhost/crashrpt.php"); // Use HTTP address for delivery 
    info.uPriorities[CR_HTTP] = 0;
    info.uPriorities[CR_SMTP] = CR_NEGATIVE_PRIORITY;
    info.uPriorities[CR_SMAPI] = CR_NEGATIVE_PRIORITY;  
    info.pszErrorReportSaveDir = sTmpFolder;
    int nInstResult = crInstall(&info);
    TEST_ASSERT(nInstResult==0);

    // Generate and send error report
    CR_EXCEPTION_INFO exc;
    memset(&exc, 0, sizeof(CR_EXCEPTION_INFO));
    exc.cb = sizeof(CR_EXCEPTION_INFO);
    int nResult2 = crGenerateErrorReport(&exc);
    TEST_ASSERT(nResult2==0);

    // Wait until CrashSender exits and check exit code
    WaitForSingleObject(exc.hSenderProcess, INFINITE);

    DWORD dwExitCode = 1;
    GetExitCodeProcess(exc.hSenderProcess, &dwExitCode);
    TEST_ASSERT(dwExitCode==0); // Exit code should be zero

    __TEST_CLEANUP__;  

    // Uninstall
    crUninstall();  

    // Delete tmp folder
    Utility::RecycleFile(sTmpFolder, TRUE);
}
void CrashRptAPITests::Test_crGenerateErrorReport()
{ 
  CString sAppDataFolder;
  CString sExeFolder;
  CString sTmpFolder;

  // Create a temporary folder  
  Utility::GetSpecialFolder(CSIDL_APPDATA, sAppDataFolder);
  sTmpFolder = sAppDataFolder+_T("\\CrashRpt");
  BOOL bCreate = Utility::CreateFolder(sTmpFolder);
  TEST_ASSERT(bCreate);

  // Install crash handler for the main thread

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);
  info.pszAppVersion = _T("1.0.0"); // Specify app version, otherwise it will fail.
  info.dwFlags = CR_INST_NO_GUI|CR_INST_DONT_SEND_REPORT;
  info.pszErrorReportSaveDir = sTmpFolder;
  int nInstResult = crInstall(&info);
  TEST_ASSERT(nInstResult==0);
  
  // Call with NULL parameter - should fail
  int nResult = crGenerateErrorReport(NULL);
  TEST_ASSERT(nResult!=0);
  
  // Call with valid parameter - should succeed
  CR_EXCEPTION_INFO exc;
  memset(&exc, 0, sizeof(CR_EXCEPTION_INFO));
  exc.cb = sizeof(CR_EXCEPTION_INFO);
  int nResult2 = crGenerateErrorReport(&exc);
  TEST_ASSERT(nResult2==0);

  // Check that a folder with crash report files exists
  WIN32_FIND_DATA fd;
  HANDLE hFind = FindFirstFile(sTmpFolder+_T("\\*"), &fd);
  FindClose(hFind);
  TEST_ASSERT(hFind!=INVALID_HANDLE_VALUE && hFind!=NULL);

  __TEST_CLEANUP__;  

  // Uninstall
  crUninstall();  

  // Delete tmp folder
  Utility::RecycleFile(sTmpFolder, TRUE);
}
void CrashRptAPITests::Test_crInstallA_zero_info()
{   
  // Test crInstallA with zero info
  
  CR_INSTALL_INFOA infoA;
  memset(&infoA, 0, sizeof(CR_INSTALL_INFOA));
  infoA.cb = sizeof(CR_INSTALL_INFOA);
  infoA.pszAppVersion = "1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallA(&infoA);
  TEST_ASSERT(nInstallResult==0);

  __TEST_CLEANUP__

  crUninstall();  
}
示例#14
0
int main(int argc, char* argv[])
{
    argc; // this is to avoid C4100 unreferenced formal parameter warning
    argv; // this is to avoid C4100 unreferenced formal parameter warning

    // Install crash reporting

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);             // Size of the structure
    info.pszAppName = _T("CrashRpt Console Test"); // App name
    info.pszAppVersion = _T("1.0.0");              // App version
    info.pszEmailSubject = _T("CrashRpt Console Test 1.0.0 Error Report"); // Email subject
    info.pszEmailTo = _T("*****@*****.**");      // Email recipient address

    // Install crash handlers
    int nInstResult = crInstall(&info);            
    assert(nInstResult==0);

    // Check result
    if(nInstResult!=0)
    {
        TCHAR buff[256];
        crGetLastErrorMsg(buff, 256); // Get last error
        _tprintf(_T("%s\n"), buff); // and output it to the screen
        return FALSE;
    }

    printf("Press Enter to simulate a null pointer exception or any other key to exit...\n");
    int n = _getch();
    if(n==13)
    {
        int *p = 0;
        *p = 0; // Access violation
    }

#ifdef TEST_DEPRECATED_FUNCS
    Uninstall(lpvState); // Uninstall exception handlers
#else
    int nUninstRes = crUninstall(); // Uninstall exception handlers
    assert(nUninstRes==0);
    nUninstRes;
#endif //TEST_DEPRECATED_FUNCS

    // Exit
    return 0;
}
示例#15
0
void Test_HttpDelivery_binary_encoding()
{ 
  CString sAppDataFolder;
  CString sExeFolder;
  CString sTmpFolder;

  // Create a temporary folder  
  Utility::GetSpecialFolder(CSIDL_APPDATA, sAppDataFolder);
  sTmpFolder = sAppDataFolder+_T("\\CrashRpt");
  BOOL bCreate = Utility::CreateFolder(sTmpFolder);
  TEST_ASSERT(bCreate);

  // Install crash handler for the main thread

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.size = sizeof(CR_INSTALL_INFO);
  info.application_version = _T("1.0.0"); // Specify app version, otherwise it will fail.
  info.flags = CR_INST_NO_GUI;
  info.crash_server_url = _T("localhost/crashrpt.php"); // Use HTTP address for delivery 
  info.send_method = CR_HTTP_MutilPart;
  info.save_dir = sTmpFolder;
  int nInstResult = crInstall(&info);
  TEST_ASSERT(nInstResult==0);
    
  // Generate and send error report
  CR_EXCEPTION_INFO exc;
  memset(&exc, 0, sizeof(CR_EXCEPTION_INFO));
  exc.cb = sizeof(CR_EXCEPTION_INFO);
  int nResult2 = crGenerateErrorReport(&exc);
  TEST_ASSERT(nResult2==0);

  // Wait until CrashSender exits and check exit code
  WaitForSingleObject(exc.hSenderProcess, INFINITE);

  DWORD dwExitCode = 1;
  GetExitCodeProcess(exc.hSenderProcess, &dwExitCode);
  TEST_ASSERT(dwExitCode==0); // Exit code should be zero
  
  __TEST_CLEANUP__;  

  // Uninstall
  crUninstall();  

  // Delete tmp folder
  Utility::RecycleFile(sTmpFolder, TRUE);
}
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_crInstallA_twice()
{   
  // Call crInstallA two times - the second one should fail
  
  CR_INSTALL_INFOA infoA;
  memset(&infoA, 0, sizeof(CR_INSTALL_INFOA));
  infoA.cb = sizeof(CR_INSTALL_INFOA);
  infoA.pszAppVersion = "1.0.0"; // Specify app version, otherwise it will fail.

  int nInstallResult = crInstallA(&infoA);
  TEST_ASSERT(nInstallResult==0);

  int nInstallResult2 = crInstallA(&infoA);
  TEST_ASSERT(nInstallResult2!=0);

  __TEST_CLEANUP__

  crUninstall();
  
}
示例#18
0
int CMFCDemoApp::Run() 
{
  // Install crash reporting
 
  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);  
  info.pszAppName = _T("MFCDemo"); // Define application name.
  //info.pszAppVersion = _T("1.0.0"); // Define application version.
  // URL for sending error reports over HTTP.
  info.pszUrl = _T("http://someserver.com/crashrpt.php");                    
  // Install all available exception handlers.
  info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; 
  // Provide privacy policy URL
  info.pszPrivacyPolicyURL = _T("http://someserver.com/privacy.html");

  int nResult = crInstall(&info);
  if(nResult!=0)
  {
    TCHAR buff[256];
    crGetLastErrorMsg(buff, 256);
    MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
    return 1;
  }

  // Take screenshot of the app window at the moment of crash
  crAddScreenshot2(CR_AS_MAIN_WINDOW|CR_AS_USE_JPEG_FORMAT, 95);

  BOOL bRun = TRUE;
  BOOL bExit=FALSE;
  while(!bExit)
  {
    bRun= CWinApp::Run();
    bExit=TRUE;
  }

  // Uninstall crash reporting
  crUninstall();

  return bRun;
} 
void CrashRptAPITests::Test_crEmulateCrash()
{ 
  CString sAppDataFolder;
  CString sExeFolder;
  CString sTmpFolder;
  
  // Test it with invalid argument - should fail
  int nResult = crEmulateCrash((UINT)-1);
  TEST_ASSERT(nResult!=0);
  
  // Test it with invalid argument - should fail
  int nResult2 = crEmulateCrash(CR_THROW+1);
  TEST_ASSERT(nResult2!=0);

  __TEST_CLEANUP__;    
  
  crUninstall();

  // Delete tmp folder
  Utility::RecycleFile(sTmpFolder, TRUE);
}
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();  
}
void CrashRptAPITests::Test_crAddFileA()
{ 
  strconv_t strconv;
  CString sFileName;

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

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

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

  if(g_bRunningFromUNICODEFolder==FALSE)
  {
    // Add existing file, crAddFileA should succeed
    
    sFileName = Utility::GetModulePath(NULL)+_T("\\dummy.ini");
    LPCSTR szFileName = strconv.t2a(sFileName);
    int nResult3 = crAddFileA(szFileName, "Dummy INI File");
    TEST_ASSERT(nResult3==0);
  }

  __TEST_CLEANUP__;

  // Uninstall
  crUninstall();  
}
// Test the case when CrashRpt.dll and CrashSender.exe are located in
// a different folder (not the same where process executable is located).
// This test also checks that crInstall and crUninstall function names
// are undecorated.
void CrashRptAPITests::Test_crInstall_in_different_folder()
{ 
  CString sAppDataFolder;
  CString sExeFolder;
  CString sTmpFolder;
  HMODULE hCrashRpt = NULL;

  // Create a temporary folder  
  Utility::GetSpecialFolder(CSIDL_APPDATA, sAppDataFolder);
  sTmpFolder = sAppDataFolder+_T("\\CrashRpt");
  BOOL bCreate = Utility::CreateFolder(sTmpFolder);
  TEST_ASSERT(bCreate);

  // Copy CrashRpt.dll and CrashSender.exe into that folder
  sExeFolder = Utility::GetModulePath(NULL);

#ifdef _DEBUG
  BOOL bCopy = CopyFile(sExeFolder+_T("\\CrashRptd.dll"), sTmpFolder+_T("\\CrashRptd.dll"), TRUE);
  TEST_ASSERT(bCopy);
  BOOL bCopy2 = CopyFile(sExeFolder+_T("\\CrashSenderd.exe"), sTmpFolder+_T("\\CrashSenderd.exe"), TRUE);
  TEST_ASSERT(bCopy2);
#else
  BOOL bCopy = CopyFile(sExeFolder+_T("\\CrashRpt.dll"), sTmpFolder+_T("\\CrashRpt.dll"), TRUE);
  TEST_ASSERT(bCopy);
  BOOL bCopy2 = CopyFile(sExeFolder+_T("\\CrashSender.exe"), sTmpFolder+_T("\\CrashSender.exe"), TRUE);
  TEST_ASSERT(bCopy2);
#endif

  BOOL bCopy3 = CopyFile(sExeFolder+_T("\\crashrpt_lang.ini"), sTmpFolder+_T("\\crashrpt_lang.ini"), TRUE);
  TEST_ASSERT(bCopy3);
  
  // Load CrashRpt.dll dynamically
#ifdef _DEBUG
  hCrashRpt = LoadLibrary(sTmpFolder+_T("\\CrashRptd.dll"));
  TEST_ASSERT(hCrashRpt!=NULL);
#else
  hCrashRpt = LoadLibrary(sTmpFolder+_T("\\CrashRpt.dll"));
  TEST_ASSERT(hCrashRpt!=NULL);
#endif
  

  // Install crash handler
  CR_INSTALL_INFO 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"; // Specify app version, otherwise it will fail.  

  typedef int (WINAPI *PFNCRINSTALLW)(PCR_INSTALL_INFOW);
  PFNCRINSTALLW pfncrInstallW = (PFNCRINSTALLW)GetProcAddress(hCrashRpt, "crInstallW");
  TEST_ASSERT(pfncrInstallW!=NULL);

  typedef int (WINAPI *PFNCRUNINSTALL)();
  PFNCRUNINSTALL pfncrUninstall = (PFNCRUNINSTALL)GetProcAddress(hCrashRpt, "crUninstall");
  TEST_ASSERT(pfncrUninstall!=NULL);

  // Install should succeed
  int nInstallResult = pfncrInstallW(&infoW);
  TEST_ASSERT(nInstallResult==0);
  
  __TEST_CLEANUP__

  crUninstall();
    
  FreeLibrary(hCrashRpt);

  // Delete temporary folder
  Utility::RecycleFile(sTmpFolder, TRUE);
}
示例#23
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
}
示例#24
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

  // Install crash reporting
#ifdef TEST_DEPRECATED_FUNCS

  g_pCrashRptState = Install(
    CrashCallback, 
    _T("*****@*****.**"), 
    _T("Crash"));

#else

  CString szSubject;
  szSubject.Format(_T("%s %s Error Report"), APP_NAME, APP_VERSION);

  CR_INSTALL_INFO info;
  memset(&info, 0, sizeof(CR_INSTALL_INFO));
  info.cb = sizeof(CR_INSTALL_INFO);  
  info.pszAppName = APP_NAME;
  info.pszAppVersion = APP_VERSION;
  info.pszEmailSubject = szSubject;
  info.pszEmailTo = _T("*****@*****.**");    
  info.pfnCrashCallback = CrashCallback;    
  info.uPriorities[CR_SMTP] = 1;
  info.uPriorities[CR_SMAPI] = 0;  
    
  int nInstResult = crInstall(&info);
  ATLASSERT(nInstResult==0);
  nInstResult;

#endif //TEST_DEPRECATED_FUNCS

  /* Create another thread */
  g_CrashThreadInfo.m_pCrashRptState = g_pCrashRptState;
  g_CrashThreadInfo.m_bStop = false;
  g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent"));
  ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL);

  DWORD dwThreadId = 0;
  g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId);
  ATLASSERT(g_hWorkingThread!=NULL);

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();

  // Close another thread
  g_CrashThreadInfo.m_bStop = true;
  SetEvent(g_CrashThreadInfo.m_hWakeUpEvent);
  // Wait until thread terminates
  WaitForSingleObject(g_hWorkingThread, INFINITE);

  // Uninstall crash reporting
  
#ifdef TEST_DEPRECATED_FUNCS

  Uninstall(g_pCrashRptState);

#else
  
  int nUninstResult = crUninstall();
  ATLASSERT(nUninstResult==0);
  nUninstResult;

#endif //TEST_DEPRECATED_FUNCS

	::CoUninitialize();

	return nRet;
}
示例#25
0
int _tmain(int argc, _TCHAR* argv[])
{
	CR_INSTALL_INFO info;
	memset(&info, 0, sizeof(CR_INSTALL_INFO));
	info.cb = sizeof(CR_INSTALL_INFO);  
	info.pszAppName = _T("WTLDemo"); // Define application name.
	info.pszAppVersion = _T("1.3.1");     // Define application version.
	info.pszEmailSubject = _T("WTLDemo Error Report"); // Define subject for email.
	info.pszEmailTo = _T("*****@*****.**");   // Define E-mail recipient address.  
	//info.pszSmtpProxy = _T("127.0.0.1");  // Use SMTP proxy.
	//info.pszSmtpLogin = _T("test");      // SMTP Login
	//info.pszSmtpPassword = _T("test");       // SMTP Password
	info.pszUrl = _T("http://192.168.0.26:9000/Operation/CrashLog"); // URL for sending reports over HTTP.				
	//info.pfnCrashCallback = CrashCallback; // Define crash callback function.   
	// Define delivery methods priorities. 
	info.uPriorities[CR_HTTP] = 3;         // Use HTTP the first.
	info.uPriorities[CR_SMTP] = 2;         // Use SMTP the second.
	info.uPriorities[CR_SMAPI] = 1;        // Use Simple MAPI the last.  
	info.dwFlags = 0;                    
	info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers.    
	//info.dwFlags |= CR_INST_APP_RESTART;            // Restart the application on crash.  
	//info.dwFlags |= CR_INST_NO_MINIDUMP;          // Do not include minidump.
	//info.dwFlags |= CR_INST_NO_GUI;               // Don't display GUI.
	//info.dwFlags |= CR_INST_DONT_SEND_REPORT;     // Don't send report immediately, just queue for later delivery.
	//info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES;   // Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT)
	//info.dwFlags |= CR_INST_SEND_MANDATORY;         // Remove "Close" and "Other actions..." buttons from Error Report dialog.
	//info.dwFlags |= CR_INST_SHOW_ADDITIONAL_INFO_FIELDS; //!< Make "Your E-mail" and "Describe what you were doing when the problem occurred" fields of Error Report dialog always visible.
	info.dwFlags |= CR_INST_ALLOW_ATTACH_MORE_FILES; //!< Adds an ability for user to attach more files to crash report by clicking "Attach More File(s)" item from context menu of Error Report Details dialog.
	//info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;    // Send reports that were failed to send recently.	
	//info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; 
	info.pszDebugHelpDLL = NULL;                    // Search for dbghelp.dll using default search sequence.
	info.uMiniDumpType = MiniDumpNormal;            // Define minidump size.
	// Define privacy policy URL.
	//info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
	info.pszErrorReportSaveDir = NULL;       // Save error reports to the default location.
	info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart.
	//info.pszLangFilePath = _T("D:\\");       // Specify custom dir or filename for language file.
	//info.pszCustomSenderIcon = _T("C:\\WINDOWS\\System32\\user32.dll, 1"); // Specify custom icon for CrashRpt dialogs.

	// Install crash handlers.
	CrAutoInstallHelper cr_install_helper(&info);
	if(cr_install_helper.m_nInstallStatus!=0)
	{
		TCHAR buff[256];
		crGetLastErrorMsg(buff, 256);
		MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
		return FALSE;
	}
	assert(cr_install_helper.m_nInstallStatus==0); 

	std::wstring sLogFile =L".\\*.log";
	std::wstring sIniFile = L".\\dummy.ini";

	int nResult = crAddFile2(sLogFile.c_str(), NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY|CR_AF_ALLOW_DELETE);
	assert(nResult==0);

	nResult = crAddFile2(sIniFile.c_str(), NULL, _T("Dummy INI File"), 0);
	assert(nResult==0);

	nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT|CR_AS_ALLOW_DELETE, 10);
	//nResult = crAddScreenshot(CR_AS_MAIN_WINDOW);
	assert(nResult==0);

	nResult = crAddProperty(_T("AnExampleProperty"),_T("Property value"));
	assert(nResult==0);

	nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
	assert(nResult==0);

	nResult = crAddProperty(_T("HDDSerialNumber"),_T("1234512345098765"));
	assert(nResult==0);

	nResult = crAddProperty(_T("MACAddress"),_T("11.11.11.11"));
	assert(nResult==0);

	nResult = crAddProperty(_T("UserName"),_T("TheUserName"));
	assert(nResult==0);

	nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), CR_AR_ALLOW_DELETE);
	assert(nResult==0);

	nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), CR_AR_ALLOW_DELETE);
	assert(nResult==0);

	printf("Press Enter to simulate a null pointer exception or any other key to exit...\n");
	int n = _getch();
	if(n==13)
	{
		int *p = 0;
		*p = 0; // Access violation
	}

	int nUninstRes = crUninstall(); // Uninstall exception handlers
	assert(nUninstRes==0);
	return 0;
}
示例#26
0
CAdminControlApp::~CAdminControlApp()
{
	int nUninstRes = crUninstall(); // Uninstall exception handlers
}
示例#27
0
// WinMain parses the command line and either calls the main App
// routine or, under NT, the main service routine.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{

	if (VNCOS.OS_NOTSUPPORTED==true)
	{
		 MessageBoxSecure(NULL, "Error OS not supported","Unsupported OS", MB_ICONERROR);
		return true;
	}
	// make vnc last service to stop
	SetProcessShutdownParameters(0x100,false);
	// handle dpi on aero
	/*HMODULE hUser32 = LoadLibrary(_T("user32.dll"));
	typedef BOOL (*SetProcessDPIAwareFunc)();
	SetProcessDPIAwareFunc setDPIAware=NULL;
	if (hUser32) setDPIAware = (SetProcessDPIAwareFunc)GetProcAddress(hUser32, "SetProcessDPIAware");
	if (setDPIAware) setDPIAware();
	if (hUser32) FreeLibrary(hUser32);*/

#ifdef IPP
	InitIpp();
#endif
#ifdef CRASHRPT
	CR_INSTALL_INFO info;
	memset(&info, 0, sizeof(CR_INSTALL_INFO));
	info.cb = sizeof(CR_INSTALL_INFO);
	info.pszAppName = _T("UVNC");
	info.pszAppVersion = _T("1.2.0.9");
	info.pszEmailSubject = _T("UVNC server 1.2.0.9 Error Report");
	info.pszEmailTo = _T("*****@*****.**");
	info.uPriorities[CR_SMAPI] = 1; // Third try send report over Simple MAPI    
	// Install all available exception handlers
	info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS;
	// Restart the app on crash 
	info.dwFlags |= CR_INST_APP_RESTART;
	info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;
	info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS;
	info.pszRestartCmdLine = _T("/restart");
	// Define the Privacy Policy URL 

	// Install crash reporting
	int nResult = crInstall(&info);
	if (nResult != 0)
	{
		// Something goes wrong. Get error message.
		TCHAR szErrorMsg[512] = _T("");
		crGetLastErrorMsg(szErrorMsg, 512);
		_tprintf_s(_T("%s\n"), szErrorMsg);
		return 1;
	}
#endif
	bool Injected_autoreconnect=false;
	SPECIAL_SC_EXIT=false;
	SPECIAL_SC_PROMPT=false;
	setbuf(stderr, 0);

	// [v1.0.2-jp1 fix] Load resouce from dll
	hInstResDLL = NULL;

	 //limit the vnclang.dll searchpath to avoid
	char szCurrentDir[MAX_PATH];
	char szCurrentDir_vnclangdll[MAX_PATH];
	if (GetModuleFileName(NULL, szCurrentDir, MAX_PATH))
	{
		char* p = strrchr(szCurrentDir, '\\');
		*p = '\0';
	}
	strcpy (szCurrentDir_vnclangdll,szCurrentDir);
	strcat (szCurrentDir_vnclangdll,"\\");
	strcat (szCurrentDir_vnclangdll,"vnclang_server.dll");

	hInstResDLL = LoadLibrary(szCurrentDir_vnclangdll);

	if (hInstResDLL == NULL)
	{
		hInstResDLL = hInstance;
	}
//	RegisterLinkLabel(hInstResDLL);

    //Load all messages from ressource file
    Load_Localization(hInstResDLL) ;

	char WORKDIR[MAX_PATH];
	if (GetModuleFileName(NULL, WORKDIR, MAX_PATH))
		{
		char* p = strrchr(WORKDIR, '\\');
		if (p == NULL) return 0;
		*p = '\0';
		}
    char progname[MAX_PATH];
    strncpy(progname, WORKDIR, sizeof progname);
    progname[MAX_PATH - 1] = 0;
	//strcat(WORKDIR,"\\");
	//strcat(WORKDIR,"WinVNC.log");

	vnclog.SetFile();
	//vnclog.SetMode(4);
	//vnclog.SetLevel(10);

#ifdef _DEBUG
	{
		// Get current flag
		int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );

		// Turn on leak-checking bit
		tmpFlag |= _CRTDBG_LEAK_CHECK_DF;

		// Set flag to the new value
		_CrtSetDbgFlag( tmpFlag );
	}
#endif

	// Save the application instance and main thread id
	hAppInstance = hInstance;
	mainthreadId = GetCurrentThreadId();

	// Initialise the VSocket system
	VSocketSystem socksys;
	if (!socksys.Initialised())
	{
		MessageBoxSecure(NULL, sz_ID_FAILED_INIT, szAppName, MB_OK);
#ifdef CRASHRPT
		crUninstall();
#endif
		return 0;
	}
    // look up the current service name in the registry.
    GetServiceName(progname, service_name);

	// Make the command-line lowercase and parse it
	size_t i;
	for (i = 0; i < strlen(szCmdLine); i++)
	{
		szCmdLine[i] = tolower(szCmdLine[i]);
	}
	BOOL argfound = FALSE;
	for (i = 0; i < strlen(szCmdLine); i++)
	{
		if (szCmdLine[i] <= ' ')
			continue;
		argfound = TRUE;

		if (strncmp(&szCmdLine[i], winvncSettingshelper, strlen(winvncSettingshelper)) == 0)
		{
			Sleep(3000);
			char mycommand[MAX_PATH];
			i+=strlen(winvncSettingshelper);
			strcpy( mycommand, &(szCmdLine[i+1]));
			Set_settings_as_admin(mycommand);
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncStopserviceHelper, strlen(winvncStopserviceHelper)) == 0)
		{
			Sleep(3000);
			Set_stop_service_as_admin();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncKill, strlen(winvncKill)) == 0)
		{
			static HANDLE		hShutdownEventTmp;
			hShutdownEventTmp = OpenEvent(EVENT_ALL_ACCESS, FALSE, "Global\\SessionEventUltra");
			SetEvent(hShutdownEventTmp);
			CloseHandle(hShutdownEventTmp);

			//adzm 2010-02-10 - Finds the appropriate VNC window for any process. Sends this message to all of them!
			// do removed, loops forever with cpu 100
			HWND hservwnd = NULL;
			hservwnd = FindWinVNCWindow(false);
				if (hservwnd!=NULL)
				{
					PostMessage(hservwnd, WM_COMMAND, 40002, 0);
					PostMessage(hservwnd, WM_CLOSE, 0, 0);
				}
#ifdef CRASHRPT
				crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncopenhomepage, strlen(winvncopenhomepage)) == 0)
		{
			Open_homepage();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncopenforum, strlen(winvncopenforum)) == 0)
		{
			Open_forum();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncStartserviceHelper, strlen(winvncStartserviceHelper)) == 0)
		{
			Sleep(3000);
			Set_start_service_as_admin();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncInstallServiceHelper, strlen(winvncInstallServiceHelper)) == 0)
			{
				//Sleeps are realy needed, else runas fails...
				Sleep(3000);
				Set_install_service_as_admin();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}
		if (strncmp(&szCmdLine[i], winvncUnInstallServiceHelper, strlen(winvncUnInstallServiceHelper)) == 0)
			{
				Sleep(3000);
				Set_uninstall_service_as_admin();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}
		if (strncmp(&szCmdLine[i], winvncSoftwarecadHelper, strlen(winvncSoftwarecadHelper)) == 0)
			{
				Sleep(3000);
				Enable_softwareCAD_elevated();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}		 
		if (strncmp(&szCmdLine[i], winvncdelSoftwarecadHelper, strlen(winvncdelSoftwarecadHelper)) == 0)
			{
				Sleep(3000);
				delete_softwareCAD_elevated();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}
		if (strncmp(&szCmdLine[i], winvncRebootSafeHelper, strlen(winvncRebootSafeHelper)) == 0)
			{
				Sleep(3000);
				Reboot_in_safemode_elevated();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}

		if (strncmp(&szCmdLine[i], winvncRebootForceHelper, strlen(winvncRebootForceHelper)) == 0)
			{
				Sleep(3000);
				Reboot_with_force_reboot_elevated();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}

		if (strncmp(&szCmdLine[i], winvncSecurityEditorHelper, strlen(winvncSecurityEditorHelper)) == 0)
			{
				Sleep(3000);
				winvncSecurityEditorHelper_as_admin();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}
		if (strncmp(&szCmdLine[i], winvncSecurityEditor, strlen(winvncSecurityEditor)) == 0)
			{
			    typedef void (*vncEditSecurityFn) (HWND hwnd, HINSTANCE hInstance);
				vncEditSecurityFn vncEditSecurity = 0;
				char szCurrentDirl[MAX_PATH];
					if (GetModuleFileName(NULL, szCurrentDirl, MAX_PATH)) {
						char* p = strrchr(szCurrentDirl, '\\');
						*p = '\0';
						strcat (szCurrentDirl,"\\authSSP.dll");
					}
					HMODULE hModule = LoadLibrary(szCurrentDirl);
					if (hModule) {
						vncEditSecurity = (vncEditSecurityFn) GetProcAddress(hModule, "vncEditSecurity");
						HRESULT hr = CoInitialize(NULL);
						vncEditSecurity(NULL, hAppInstance);
						CoUninitialize();
						FreeLibrary(hModule);
					}
#ifdef CRASHRPT
					crUninstall();
#endif
				return 0;
			}

		if (strncmp(&szCmdLine[i], winvncSettings, strlen(winvncSettings)) == 0)
		{
			char mycommand[MAX_PATH];
			i+=strlen(winvncSettings);
			strcpy( mycommand, &(szCmdLine[i+1]));
			Real_settings(mycommand);
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}
		
		if (strncmp(&szCmdLine[i], dsmpluginhelper, strlen(dsmpluginhelper)) == 0)
		{
			char mycommand[MAX_PATH];
			i += strlen(dsmpluginhelper);
			strcpy(mycommand, &(szCmdLine[i + 1]));
			Secure_Plugin_elevated(mycommand);
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], dsmplugininstance, strlen(dsmplugininstance)) == 0)
		{
			char mycommand[MAX_PATH];
			i += strlen(dsmplugininstance);
			strcpy(mycommand, &(szCmdLine[i + 1]));
			Secure_Plugin(mycommand);
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}


		if (strncmp(&szCmdLine[i], winvncSoftwarecad, strlen(winvncSoftwarecad)) == 0)
		{
			Enable_softwareCAD();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncdelSoftwarecad, strlen(winvncdelSoftwarecad)) == 0)
		{
			delete_softwareCAD();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncRebootSafe, strlen(winvncRebootSafe)) == 0)
		{
			Reboot_in_safemode();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncRebootForce, strlen(winvncRebootForce)) == 0)
		{
			Reboot_with_force_reboot();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncStopservice, strlen(winvncStopservice)) == 0)
		{
			Real_stop_service();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncStartservice, strlen(winvncStartservice)) == 0)
		{
			Real_start_service();
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}

		if (strncmp(&szCmdLine[i], winvncInstallService, strlen(winvncInstallService)) == 0)
			{
                // rest of command line service name, if provided.
                char *pServiceName = &szCmdLine[i];
                // skip over command switch, find next whitepace
                while (*pServiceName && !isspace(*(unsigned char*)pServiceName))
                    ++pServiceName;

                // skip past whitespace to service name
                while (*pServiceName && isspace(*(unsigned char*)pServiceName))
                    ++pServiceName;

                // strip off any quotes
                if (*pServiceName && *pServiceName == '\"')
                    ++pServiceName;

                if (*pServiceName)
                {
                    // look for trailing quote, if found, terminate the string there.
                    char *pQuote = pServiceName;
                    pQuote = strrchr(pServiceName, '\"');
                    if (pQuote)
                        *pQuote = 0;
                }
                // if a service name is supplied, and it differs except in case from
                // the default, use the supplied service name instead
                if (*pServiceName && (_strcmpi(pServiceName, service_name) != 0))
                {
                    strncpy(service_name, pServiceName, 256);
                    service_name[255] = 0;
                }
				install_service();
				Sleep(2000);
				char command[MAX_PATH + 32]; // 29 January 2008 jdp
                _snprintf(command, sizeof command, "net start \"%s\"", service_name);
				WinExec(command,SW_HIDE);
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}
		if (strncmp(&szCmdLine[i], winvncUnInstallService, strlen(winvncUnInstallService)) == 0)
			{
				char command[MAX_PATH + 32]; // 29 January 2008 jdp
                // rest of command line service name, if provided.
                char *pServiceName = &szCmdLine[i];
                // skip over command switch, find next whitepace
                while (*pServiceName && !isspace(*(unsigned char*)pServiceName))
                    ++pServiceName;

                // skip past whitespace to service name
                while (*pServiceName && isspace(*(unsigned char*)pServiceName))
                    ++pServiceName;

                // strip off any quotes
                if (*pServiceName && *pServiceName == '\"')
                    ++pServiceName;

                if (*pServiceName)
                {
                    // look for trailing quote, if found, terminate the string there.
                    char *pQuote = pServiceName;
                    pQuote = strrchr(pServiceName, '\"');
                    if (pQuote)
                        *pQuote = 0;
                }

                if (*pServiceName && (_strcmpi(pServiceName, service_name) != 0))
                {
                    strncpy(service_name, pServiceName, 256);
                    service_name[255] = 0;
                }
                _snprintf(command, sizeof command, "net stop \"%s\"", service_name);
				WinExec(command,SW_HIDE);
				uninstall_service();
#ifdef CRASHRPT
				crUninstall();
#endif
				return 0;
			}

		if (strncmp(&szCmdLine[i], winvncRunService, strlen(winvncRunService)) == 0)
		{
			//Run as service
			if (!Myinit(hInstance)) return 0;
			fRunningFromExternalService = true;
			vncService::RunningFromExternalService(true);
			int returnvalue = WinVNCAppMain();
#ifdef CRASHRPT
			crUninstall();
#endif
			return returnvalue;
		}

		if (strncmp(&szCmdLine[i], winvncStartService, strlen(winvncStartService)) == 0)
		{
		start_service(szCmdLine);
#ifdef CRASHRPT
		crUninstall();
#endif
		return 0;
		}

		if (strncmp(&szCmdLine[i], winvncRunAsUserApp, strlen(winvncRunAsUserApp)) == 0)
		{
			// WinVNC is being run as a user-level program
			if (!Myinit(hInstance)) return 0;
			int returnvalue = WinVNCAppMain();
#ifdef CRASHRPT
			crUninstall();
#endif
			return returnvalue;
		}

		if (strncmp(&szCmdLine[i], winvncSCexit, strlen(winvncSCexit)) == 0)
		{
			SPECIAL_SC_EXIT=true;
			i+=strlen(winvncSCexit);
			continue;
		}

		if (strncmp(&szCmdLine[i], winvncSCprompt, strlen(winvncSCprompt)) == 0)
		{
			SPECIAL_SC_PROMPT=true;
			i+=strlen(winvncSCprompt);
			continue;
		}

		if (strncmp(&szCmdLine[i], winvncmulti, strlen(winvncmulti)) == 0)
		{
			multi=true;
			i+=strlen(winvncmulti);
			continue;
		}

		if (strncmp(&szCmdLine[i], winvnchttp, strlen(winvnchttp)) == 0)
		{
			G_HTTP=true;
			i+=strlen(winvnchttp);
			continue;
		}

		if (strncmp(&szCmdLine[i], winvncStopReconnect, strlen(winvncStopReconnect)) == 0)
		{
			i+=strlen(winvncStopReconnect);
			vncService::PostAddStopConnectClientAll();
			continue;
		}

		if (strncmp(&szCmdLine[i], winvncAutoReconnect, strlen(winvncAutoReconnect)) == 0)
		{
			// Note that this "autoreconnect" param MUST be BEFORE the "connect" one
			// on the command line !
			// wa@2005 -- added support for the AutoReconnectId
			i+=strlen(winvncAutoReconnect);
			Injected_autoreconnect=true;
			int start, end;
			char* pszId = NULL;
			start = i;
			// skip any spaces and grab the parameter
			while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++;

			if ( strncmp( &szCmdLine[start], winvncAutoReconnectId, strlen(winvncAutoReconnectId) ) == 0 )
			{
				end = start;
				while (szCmdLine[end] > ' ') end++;

				if (end - start > 0)
				{

					pszId = new char[end - start + 1];

					strncpy(pszId, &(szCmdLine[start]), end - start);
					pszId[end - start] = 0;
					pszId = _strupr(pszId);
				}
//multiple spaces between autoreconnect and id
				i = end;
			}// end of condition we found the ID: parameter

			// NOTE:  id must be NULL or the ID:???? (pointer will get deleted when message is processed)
			// We can not contact a runnning service, permissions, so we must store the settings
			// and process until the vncmenu has been started

			if (!vncService::PostAddAutoConnectClient( pszId ))
			{
				PostAddAutoConnectClient_bool=true;
				if (pszId==NULL)
				{
					PostAddAutoConnectClient_bool_null=true;
					PostAddAutoConnectClient_bool=false;
				}
				else
				{
					strcpy(pszId_char,pszId);
					//memory leak fix
					delete[] pszId; pszId = NULL;
				}
			}
			if (pszId != NULL) delete[] pszId; pszId = NULL;
			continue;
		}

		if ( strncmp( &szCmdLine[i], winvncReconnectId, strlen(winvncReconnectId) ) == 0 )
			{
				i+=strlen("-");
				int start, end;
				char* pszId = NULL;
				start = i;
				end = start;
				while (szCmdLine[end] > ' ') end++;
				if (end - start > 0)
				{
					pszId = new char[end - start + 1];
					if (pszId != 0)
					{
						strncpy(pszId, &(szCmdLine[start]), end - start);
						pszId[end - start] = 0;
						pszId = _strupr(pszId);
					}
				}
				i = end;
			if (!vncService::PostAddConnectClient( pszId ))
			{
				PostAddConnectClient_bool=true;
				if (pszId==NULL)
				{
					PostAddConnectClient_bool_null=true;
					PostAddConnectClient_bool=false;
				}
				else
				{
					strcpy(pszId_char,pszId);
					//memory leak fix
					delete[] pszId; pszId = NULL;
				}
				}
			if (pszId != NULL) delete[] pszId; pszId = NULL;
			continue;
		}

		if (strncmp(&szCmdLine[i], winvncConnect, strlen(winvncConnect)) == 0)
		{
			if (!Injected_autoreconnect)
			{
				vncService::PostAddStopConnectClient();
			}
			// Add a new client to an existing copy of winvnc
			i+=strlen(winvncConnect);

			// First, we have to parse the command line to get the filename to use
			int start, end;
			start=i;
			while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++;
			end = start;
			while (szCmdLine[end] > ' ') end++;

			// Was there a hostname (and optionally a port number) given?
			if (end-start > 0)
			{
				char *name = new char[end-start+1];
				if (name != 0) {
					strncpy(name, &(szCmdLine[start]), end-start);
					name[end-start] = 0;

					int port = INCOMING_PORT_OFFSET;
					char *portp = strchr(name, ':');
					if (portp) {
						*portp++ = '\0';
						if (*portp == ':') {
							port = atoi(++portp);	// Port number after "::"
						} else {
							port = atoi(portp);	// Display number after ":"
						}
					}
					vnclog.Print(LL_STATE, VNCLOG("test... %s %d\n"),name,port);
					strcpy_s(dnsname,name);
					VCard32 address = VSocket::Resolve(name);
					delete [] name;
					if (address != 0) {
						// Post the IP address to the server
						// We can not contact a runnning service, permissions, so we must store the settings
						// and process until the vncmenu has been started
						vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient III \n"));
						if (!vncService::PostAddNewClientInit(address, port))
						{
						PostAddNewClient_bool=true;
						port_int=port;
						address_vcard=address;
						}
					}
					else
					{
						//ask for host,port
						PostAddNewClient_bool=true;
						port_int=0;
						address_vcard=0;
						Sleep(2000);
						//Beep(200,1000);
						return 0;
					}
				}
				i=end;
				continue;
			}
			else
			{
				// Tell the server to show the Add New Client dialog
				// We can not contact a runnning service, permissions, so we must store the settings
				// and process until the vncmenu has been started
				vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIII\n"));
				if (!vncService::PostAddNewClient(0, 0))
				{
				PostAddNewClient_bool=true;
				port_int=0;
				address_vcard=0;
				}
			}
			continue;
		}

		//adzm 2009-06-20
		if (strncmp(&szCmdLine[i], winvncRepeater, strlen(winvncRepeater)) == 0)
		{
			// set the default repeater host
			i+=strlen(winvncRepeater);

			// First, we have to parse the command line to get the host to use
			int start, end;
			start=i;
			while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++;
			end = start;
			while (szCmdLine[end] > ' ') end++;

			// Was there a hostname (and optionally a port number) given?
			if (end-start > 0)
			{
				if (g_szRepeaterHost) {
					delete[] g_szRepeaterHost;
					g_szRepeaterHost = NULL;
				}
				g_szRepeaterHost = new char[end-start+1];
				if (g_szRepeaterHost != 0) {
					strncpy(g_szRepeaterHost, &(szCmdLine[start]), end-start);
					g_szRepeaterHost[end-start] = 0;

					// We can not contact a runnning service, permissions, so we must store the settings
					// and process until the vncmenu has been started
					vnclog.Print(LL_INTERR, VNCLOG("PostAddNewRepeaterClient I\n"));
					if (!vncService::PostAddNewRepeaterClient())
					{
						PostAddNewRepeaterClient_bool=true;
						port_int=0;
						address_vcard=0;
					}
				}
				i=end;
				continue;
			}
			else
			{
				/*
				// Tell the server to show the Add New Client dialog
				// We can not contact a runnning service, permissions, so we must store the settings
				// and process until the vncmenu has been started
				vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIII\n"));
				if (!vncService::PostAddNewClient(0, 0))
				{
				PostAddNewClient_bool=true;
				port_int=0;
				address_vcard=0;
				}
				*/
			}
			continue;
		}

		// Either the user gave the -help option or there is something odd on the cmd-line!

		// Show the usage dialog
		MessageBoxSecure(NULL, winvncUsageText, sz_ID_WINVNC_USAGE, MB_OK | MB_ICONINFORMATION);
		break;
	};

	// If no arguments were given then just run
	if (!argfound)
	{
		if (!Myinit(hInstance))
		{
#ifdef CRASHRPT
			crUninstall();
#endif
			return 0;
		}
		int returnvalue= WinVNCAppMain();
#ifdef CRASHRPT
		crUninstall();
#endif
		return returnvalue;
	}
#ifdef CRASHRPT
	crUninstall();
#endif
	return 0;
}
示例#28
0
文件: CrashRpt.cpp 项目: doo/CrashRpt
CRASHRPTAPI(void) Uninstall(LPVOID lpState)
{
  lpState;
  crUninstall();  
}
示例#29
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;
}
示例#30
0
void CrashRptTile()
{
	crUninstall();
}