Exemple #1
0
void	ffl_dump_log::log( ffl_text_file * file, ffl_dump_param_t * param )
{
    if( file != NULL && param != NULL )
    {
        static const ffl_tchar_t	unknown[] = FFL_T( "Unknown" );

        PEXCEPTION_RECORD	exception = param->exception_ptr->ExceptionRecord;
        PCONTEXT			context = param->exception_ptr->ContextRecord;

        ffl_tchar_t	module_name[MAX_PATH] = { 0, };
        if( ::GetModuleFileName( NULL, module_name, FFL_COUNTOF(module_name) ) <= 0 )
        {
            ffl_strncpy( module_name, FFL_COUNTOF(module_name), unknown, FFL_COUNTOF(unknown) );
        }

        ffl_tchar_t	crash_module_path[MAX_PATH] = { 0, };
        MEMORY_BASIC_INFORMATION	memory_info;
        ::memset( &memory_info, 0, sizeof(memory_info) );
        if( ::VirtualQuery( reinterpret_cast< void * >( context->Eip ), &memory_info, sizeof(memory_info) ) != 0 )
        {
            if( ::GetModuleFileName( reinterpret_cast< HINSTANCE >( memory_info.AllocationBase ), crash_module_path, FFL_COUNTOF(crash_module_path) ) <= 0 )
            {
                ffl_strncpy( crash_module_path, FFL_COUNTOF(crash_module_path), unknown, FFL_COUNTOF(unknown) );
            }
        }

        ffl_dump_print( file,
                        FFL_T( "%s caused %s (0x%08x) \r\nin module %s at %04x:%08x.\r\n\r\n" ),
                        module_name,
                        ffl_get_exception_string( exception->ExceptionCode ),
                        exception->ExceptionCode,
                        crash_module_path,
                        context->SegCs,
                        context->Eip );

        system_information_log( file );

        if( exception->ExceptionCode == STATUS_ACCESS_VIOLATION && exception->NumberParameters >= 2 )
        {
            const ffl_tchar_t *	read_from = FFL_T( "Read from" );
            if( exception->ExceptionInformation[0] )
            {
                read_from = FFL_T( "Write to" );
            }

            ffl_dump_print( file, FFL_T( "%s location %08x caused an access violation.\r\n" ),
                            read_from, exception->ExceptionInformation[1] );
        }

        register_log( file, context );

        ffl_dump_print( file, FFL_T( "\r\nBytes at CS:EIP:\r\n" ) );

        BYTE *	code = reinterpret_cast< BYTE * >( context->Eip );

        const int	NUM_CODE_BYTES = 16;
        for( int nCodebyte = 0; nCodebyte < NUM_CODE_BYTES; ++nCodebyte )
        {
            __try
            {
                ffl_dump_print( file, FFL_T( "%02x " ), code[nCodebyte] );
            }
            __except( EXCEPTION_EXECUTE_HANDLER )
            {
                ffl_dump_print( file, FFL_T( "?? " ) );
            }
        }

        DWORD *	stack = reinterpret_cast< DWORD * >( context->Esp );
        stack_log( file, stack );

        module_list_log( file );

        ffl_dump_print( file, FFL_T( "\r\n===== [ end of file ] =====\r\n" ) );
    }

    return;
}
 registry(): mutex_(), logs_(), true_( true ), false_( false )
 {
     register_log( "default", &true_ );
 }