Пример #1
0
DWORD GetRawReportSize()
{
	DWORD result = 0;

	result = lstrlen( g_sysInfoString ) + 1;
	result += lstrlen( g_memInfoString ) + 1;
	result += lstrlen( g_versionInfoString ) + 1;

	for ( int i=0;i<g_stackTraceCount;i++){		
		result += lstrlen( g_stackTrace[i] ) + 1;	
	}


	for (DWORD j=0; j<g_systemProcessListCount;j++ ) {				
		char tmp[1024];
		wsprintf( tmp, "%s, PID: %d", 
			g_systemProcessNameList[j],
			g_systemProcessList[j] );					
		result += lstrlen( tmp ) + 1;	
	}

	for (int j=0;j<g_systemTotalModuleCount;j++){
		result += lstrlen( g_processModuleInfoList[j].name ) + 1;
	}

	const char* faultReason = GetFaultReason( g_BlackBoxUIExPtrs );
	const char* registerString = GetRegisterString( g_BlackBoxUIExPtrs );

	result += lstrlen( faultReason ) + 1;
	result += lstrlen( registerString ) + 1;

	return result;
}
Пример #2
0
// CCrashDlg message handlers
BOOL CCrashDlg :: OnInitDialog ( )
{
    CDialog::OnInitDialog ( ) ;
    
    ASSERT ( NULL != m_pExptPtrs ) ;
    
    LPCTSTR szStr = GetFaultReason ( m_pExptPtrs ) ;
    
    m_cFaultReason.SetWindowText ( szStr ) ;
    
    szStr = GetRegisterString ( m_pExptPtrs ) ;
    
    m_cRegisters.SetWindowText ( szStr ) ;
    
    szStr = GetFirstStackTraceString ( GSTSO_MODULE     |
                                        GSTSO_SYMBOL    |
                                        GSTSO_SRCLINE    ,
                                       m_pExptPtrs        ) ;
    while ( NULL != szStr )
    {
        m_cCallStackList.AddString ( szStr ) ;
        szStr = GetNextStackTraceString ( GSTSO_MODULE     |
                                            GSTSO_SYMBOL   |
                                            GSTSO_SRCLINE   ,
                                          m_pExptPtrs        ) ;
    }
    
    if ( FALSE == IsMiniDumpFunctionAvailable ( ) )
    {
        m_cMiniDumpBtn.EnableWindow ( FALSE ) ;
    }
    return ( FALSE ) ;
}
Пример #3
0
HGLOBAL GenerateRawReport()
{
	HGLOBAL result = NULL;

	const char* faultReason = GetFaultReason( g_BlackBoxUIExPtrs );
	const char* registerString = GetRegisterString( g_BlackBoxUIExPtrs );	
	
	int reportSize = GetRawReportSize();
	char rptSizeStr[25];
	wsprintf( rptSizeStr, "%d", reportSize );

	char* reportBuf = NULL;

	result = GlobalAlloc( GHND, reportSize + lstrlen(rptSizeStr)+1 );
	if ( NULL != result ) {
		reportBuf = (char*) GlobalLock( result );
	}
	else {		
		return result;
	}


	
	char* tmp = reportBuf;
	if ( NULL == result ) {
		lstrcpy( tmp, rptSizeStr );
		tmp[lstrlen(rptSizeStr)] = '\n';
		tmp += lstrlen(rptSizeStr)+1;
	}

	int index = 0;
	lstrcpy( tmp, g_sysInfoString );
	index = lstrlen( g_sysInfoString );
	tmp[index] = '\n';
	tmp += index+1;	

	lstrcpy( tmp, g_versionInfoString );
	index = lstrlen( g_versionInfoString );
	tmp[index] = '\n';
	tmp += index+1;	
	

	lstrcpy( tmp, g_memInfoString );
	index = lstrlen( g_memInfoString );
	tmp[index] = '\n';
	tmp += index+1;	

	lstrcpy( tmp, registerString );
	index = lstrlen( registerString );
	tmp[index] = '\n';
	tmp += index+1;	

	lstrcpy( tmp, faultReason );
	index = lstrlen( faultReason );
	tmp[index] = '\n';
	tmp += index+1;	
	
	


	for ( int i=0;i<g_stackTraceCount;i++){		
		lstrcpy( tmp, g_stackTrace[i] );
		index = lstrlen( g_stackTrace[i] );
		tmp[index] = '\n';
		tmp += index+1;
	}

	for ( DWORD j=0; j<g_systemProcessListCount;j++ ) {				
		char processID[1024];
		wsprintf( processID, "%s, PID: %d", 
			g_systemProcessNameList[j],
			g_systemProcessList[j] );					
		
		lstrcpy( tmp, processID );
		index = lstrlen( processID );
		
		tmp[index] = '\n';
		tmp += index+1;
		
		bool first = true;
		for (DWORD k=0;k<g_systemTotalModuleCount;k++){
			if ( g_processModuleInfoList[k].index == j ) {
				lstrcpy( tmp, g_processModuleInfoList[k].name );
				index = lstrlen( g_processModuleInfoList[k].name );
				tmp[index] = '\n';
				tmp += index+1;

				first = false;
			}
			else if (!first) {
				break;
			}
		}
	}
	
	if ( NULL != result ) {
		GlobalUnlock( result );
	}

	return result;
}
Пример #4
0
LRESULT CALLBACK BlackBoxUI_DlgProc(HWND hBlackBoxUIDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	LRESULT result = FALSE;

	switch (message)
	{
		
		case WM_CTLCOLORSTATIC: {
			//HWND label = ::GetDlgItem( hBlackBoxUIDlg, IDC_INTRO );

			//HDC hdcStatic = (HDC) wParam;   // handle to display context 
			HWND hwndStatic = (HWND) lParam;
			
			if ( (GetDlgCtrlID(hwndStatic) == IDC_INTRO) || 
					(GetDlgCtrlID(hwndStatic) == IDC_INTRO2) || 
					(GetDlgCtrlID(hwndStatic) == IDC_BUG_LBL) ) {
				HBRUSH br = CreateSolidBrush( RGB(255,255,255) );
				result = (LRESULT)br;
			}			
		}
		break;

		case WM_INITDIALOG: {
			if ( g_BlackBoxUIExPtrs == NULL ) {
				result = FALSE;
			}
			else {
				HICON icon = (HICON)LoadImage( g_BlackBoxUIHInstance, 
											MAKEINTRESOURCE(IDI_BUG),
											IMAGE_ICON,
											0, 0, 
											LR_DEFAULTSIZE );

				HWND label = ::GetDlgItem( hBlackBoxUIDlg, IDC_INTRO );
				SetWindowText( label, g_errorLable );

				SendMessage( hBlackBoxUIDlg, WM_SETICON, ICON_BIG, (LPARAM)icon );

				HWND stackTraceHWnd = ::GetDlgItem( hBlackBoxUIDlg, IDC_STACKTRACE );
				HWND exceptionLabelHWnd = ::GetDlgItem( hBlackBoxUIDlg, IDC_EXCEPTION );

				SetWindowText( exceptionLabelHWnd, GetFaultReason( g_BlackBoxUIExPtrs ) );

				HWND registersLabelHWnd = ::GetDlgItem( hBlackBoxUIDlg, IDC_REGISTER );

				SetWindowText( registersLabelHWnd, GetRegisterString( g_BlackBoxUIExPtrs ) );
				

				int incr = 85;

				for ( int i=0;i<g_stackTraceCount;i++){
					SendMessage( stackTraceHWnd,  LB_ADDSTRING, 0, (LPARAM)g_stackTrace[i] );

					UpdateInitDlgProgress( incr  );
					incr += 2;
				}			
				
				
				DestroyWindow( g_initDlg );
			}
			result = TRUE;
		}
		break;

		case WM_COMMAND: {
			switch ( LOWORD(wParam) ) {
				case IDOK : case IDCANCEL : {
					EndDialog( hBlackBoxUIDlg, LOWORD(wParam) );
					return TRUE;
				}
				break;

				case IDC_ABOUT : {
					DialogBox( g_BlackBoxUIHInstance, 
								(LPCTSTR)IDD_ABOUT_BLACKBOX, 
								hBlackBoxUIDlg, 
								(DLGPROC)AboutBlackBox_DlgProc);
				}
				break;

				case IDC_MACHINE_INFO : {
					DialogBox( g_BlackBoxUIHInstance, 
								(LPCTSTR)IDD_MACHINE_INFO_DLG, 
								hBlackBoxUIDlg, 
								(DLGPROC)MachineInfo_DlgProc);
				}
				break;

				case IDC_MACHINE_STATE : {
					DialogBox( g_BlackBoxUIHInstance, 
								(LPCTSTR)IDD_MACHINESTATE_DLG, 
								hBlackBoxUIDlg, 
								(DLGPROC)MachineState_DlgProc);
				}
				break;

				case IDC_SEND : {
					SetCursor( LoadCursor(NULL, IDC_WAIT) );
					if ( OnSendData( hBlackBoxUIDlg ) ) {
						MessageBox( hBlackBoxUIDlg, "Successfully sent Crash Information", "Bug Trapper", MB_OK | MB_ICONINFORMATION );
					}
					else {
						MessageBox( hBlackBoxUIDlg, "Failed to send Crash Information.\nPlease save the information to a file\nand then send this to [email protected]", "Bug Trapper", MB_OK | MB_ICONERROR );
						HWND saveToFileBtn = ::GetDlgItem( hBlackBoxUIDlg, IDC_SAVE_TO_FILE );

						::SetActiveWindow( saveToFileBtn );
						SetFocus( saveToFileBtn );						
					}
					SetCursor( LoadCursor(NULL, IDC_ARROW) );
				}
				break;
				
				case IDC_MAILTO : {
					SetCursor( LoadCursor(NULL, IDC_WAIT) );
					
					::ShellExecute( NULL, NULL, g_mailToAddress, NULL, NULL, SW_NORMAL );

					SetCursor( LoadCursor(NULL, IDC_ARROW) );
				}
				break;

				case IDC_SUBMIT_NEW_VCF_BUG : {
					SetCursor( LoadCursor(NULL, IDC_WAIT) );

					::ShellExecute( NULL, NULL, g_submitBugURL, NULL, NULL, SW_NORMAL );

					SetCursor( LoadCursor(NULL, IDC_ARROW) );
				}
				break;
				
				case IDC_COPY_TO_CLIPBOARD : {
					SetCursor( LoadCursor(NULL, IDC_WAIT) );

					OnCopyToClipboardData( hBlackBoxUIDlg );

					SetCursor( LoadCursor(NULL, IDC_ARROW) );
				}
				break;

				case IDC_SAVE_TO_FILE : {
					SetCursor( LoadCursor(NULL, IDC_WAIT) );

					OnSaveDataToFile( hBlackBoxUIDlg );

					SetCursor( LoadCursor(NULL, IDC_ARROW) );
				}
				break;
			}			
		}
		break;
	}

    return result;
}
Пример #5
0
LONG MiniDumper::TopLevelFilter( struct _EXCEPTION_POINTERS *pExceptionInfo )
{
	LONG retval = EXCEPTION_CONTINUE_SEARCH;
	// firstly see if dbghelp.dll is around and has the function we need
	// look next to the EXE first, as the one in System32 might be old 
	// (e.g. Windows 2000)
	HMODULE hDll = nullptr;
	TCHAR szDbgHelpPath[_MAX_PATH];

	if (GetModuleFileName( NULL, szDbgHelpPath, _MAX_PATH ))
	{
		tstring folder = GetFolderNameFromFullFileName(szDbgHelpPath);
		folder += TEXT("dbghelp.dll");
		hDll = ::LoadLibrary( folder.c_str() );
	}

	if (hDll == nullptr)
	{
		// load any version we can
		hDll = ::LoadLibrary( TEXT("DBGHELP.DLL") );
	}

	LPCTSTR szResult = nullptr;

	if (hDll)
	{
		MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
		if (pDump)
		{
			TCHAR szDumpPath[_MAX_PATH];
			TCHAR szScratch [_MAX_PATH];

			SPrintf( szDumpPath, _MAX_PATH, TEXT("%s"), pThis->m_szDumpFilename);

			// ask the user if they want to save a dump file
			//if (::MessageBox( NULL, "Something bad happened in your program, would you like to save a diagnostic file?", m_szAppName, MB_YESNO )==IDYES)
			{
				// create the file
				HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
					FILE_ATTRIBUTE_NORMAL, NULL );

				if (hFile!=INVALID_HANDLE_VALUE)
				{
					_MINIDUMP_EXCEPTION_INFORMATION ExInfo;

					ExInfo.ThreadId = ::GetCurrentThreadId();
					ExInfo.ExceptionPointers = pExceptionInfo;
					ExInfo.ClientPointers = NULL;

					// write the dump
					BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
					::CloseHandle(hFile);
					if (bOK)
					{
						TCHAR szErrorReason[256];
						SPrintf(szErrorReason, 256, TEXT("ZViewer Error : %s"), GetFaultReason(pExceptionInfo).c_str());
						MessageBox(HWND_DESKTOP, szErrorReason, TEXT("ZViewer"), MB_OK);

						MessageBox(HWND_DESKTOP, pThis->m_szDumpMsg, TEXT("ZViewer"), MB_OK);

						SPrintf( szScratch, _MAX_PATH, TEXT("Saved dump file to '%s'"), szDumpPath );
						szResult = szScratch;
						retval = EXCEPTION_EXECUTE_HANDLER;
					}
					else
					{
						SPrintf( szScratch, _MAX_PATH, TEXT("Failed to save dump file to '%s' (error %u)"), szDumpPath, GetLastError() );
						szResult = szScratch;
					}
				}
				else
				{
					SPrintf( szScratch, _MAX_PATH, TEXT("Failed to create dump file '%s' (error %u)"), szDumpPath, GetLastError() );
					szResult = szScratch;
				}
			}
		}
		else
		{
			szResult = TEXT("DBGHELP.DLL too old");
		}
	}
	else
	{
		szResult = TEXT("DBGHELP.DLL not found");
	}
	return retval;
}