int main( int argc, char * const argv[] ) #endif { #if defined( HAVE_GETRLIMIT ) struct rlimit limit_data; #endif system_character_t * const *source_filenames = NULL; libcerror_error_t *error = NULL; system_character_t *option_date_format = NULL; system_character_t *option_header_codepage = NULL; system_character_t *option_output_format = NULL; system_character_t *program = _SYSTEM_STRING( "ewfinfo" ); system_integer_t option = 0; uint8_t verbose = 0; int number_of_filenames = 0; int print_header = 1; int result = 0; char info_option = 'a'; #if !defined( HAVE_GLOB_H ) ewftools_glob_t *glob = NULL; #endif libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "ewftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( ewftools_output_initialize( _IONBF, &error ) != 1 ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } while( ( option = ewftools_getopt( argc, argv, _SYSTEM_STRING( "A:d:ef:himvV" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind ] ); usage_fprint( stdout ); goto on_error; case (system_integer_t) 'A': option_header_codepage = optarg; break; case (system_integer_t) 'd': option_date_format = optarg; break; case (system_integer_t) 'e': if( info_option != 'a' ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Conflicting options: %" PRIc_SYSTEM " and %c\n", option, info_option ); usage_fprint( stdout ); goto on_error; } info_option = 'e'; break; case (system_integer_t) 'f': option_output_format = optarg; break; case (system_integer_t) 'h': ewftools_output_version_fprint( stdout, program ); usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'i': if( info_option != 'a' ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Conflicting options: %" PRIc_SYSTEM " and %c\n", option, info_option ); usage_fprint( stdout ); goto on_error; } info_option = 'i'; break; case (system_integer_t) 'm': if( info_option != 'a' ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Conflicting options: %" PRIc_SYSTEM " and %c\n", option, info_option ); usage_fprint( stdout ); goto on_error; } info_option = 'm'; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': ewftools_output_version_fprint( stdout, program ); ewftools_output_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Missing EWF image file(s).\n" ); usage_fprint( stdout ); goto on_error; } libcnotify_verbose_set( verbose ); #if !defined( HAVE_LOCAL_LIBEWF ) libewf_notify_set_verbose( verbose ); libewf_notify_set_stream( stderr, NULL ); #endif if( info_handle_initialize( &ewfinfo_info_handle, &error ) != 1 ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Unable to create info handle.\n" ); goto on_error; } if( option_output_format != NULL ) { result = info_handle_set_output_format( ewfinfo_info_handle, option_output_format, &error ); if( result == -1 ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Unable to set output format.\n" ); goto on_error; } else if( result == 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; fprintf( stderr, "Unsupported output format defaulting to: text.\n" ); } } if( ewfinfo_info_handle->output_format == INFO_HANDLE_OUTPUT_FORMAT_DFXML ) { if( info_handle_dfxml_header_fprint( ewfinfo_info_handle, &error ) != 1 ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Unable to print header.\n" ); goto on_error; } } else if( ewfinfo_info_handle->output_format == INFO_HANDLE_OUTPUT_FORMAT_TEXT ) { ewftools_output_version_fprint( stdout, program ); print_header = 0; } if( ( option_output_format == NULL ) && ( option_date_format != NULL ) ) { result = info_handle_set_date_format( ewfinfo_info_handle, option_date_format, &error ); if( result == -1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to set date format.\n" ); goto on_error; } else if( result == 0 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unsupported date format defaulting to: ctime.\n" ); } } if( option_header_codepage != NULL ) { result = info_handle_set_header_codepage( ewfinfo_info_handle, option_header_codepage, &error ); if( result == -1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to set header codepage in info handle.\n" ); goto on_error; } else if( result == 0 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unsupported header codepage defaulting to: ascii.\n" ); } } #if !defined( HAVE_GLOB_H ) if( ewftools_glob_initialize( &glob, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to initialize glob.\n" ); goto on_error; } if( ewftools_glob_resolve( glob, &( argv[ optind ] ), argc - optind, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to resolve glob.\n" ); goto on_error; } if( ewftools_glob_get_results( glob, &number_of_filenames, (system_character_t ***) &source_filenames, &error ) != 1 ) { fprintf( stderr, "Unable to retrieve glob results.\n" ); goto on_error; } #else source_filenames = &( argv[ optind ] ); number_of_filenames = argc - optind; #endif #if defined( HAVE_GETRLIMIT ) if( getrlimit( RLIMIT_NOFILE, &limit_data ) != 0 ) { fprintf( stderr, "Unable to determine limit: number of open file descriptors.\n" ); } if( limit_data.rlim_max > (rlim_t) INT_MAX ) { limit_data.rlim_max = (rlim_t) INT_MAX; } if( limit_data.rlim_max > 0 ) { limit_data.rlim_max /= 2; } if( info_handle_set_maximum_number_of_open_handles( ewfinfo_info_handle, (int) limit_data.rlim_max, &error ) != 1 ) { fprintf( stderr, "Unable to set maximum number of open file handles.\n" ); goto on_error; } #endif if( ewftools_signal_attach( ewfinfo_signal_handler, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } result = info_handle_open_input( ewfinfo_info_handle, source_filenames, number_of_filenames, &error ); if( ewfinfo_abort != 0 ) { goto on_abort; } if( result != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to open EWF file(s).\n" ); goto on_error; } #if !defined( HAVE_GLOB_H ) if( ewftools_glob_free( &glob, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to free glob.\n" ); goto on_error; } #endif if( ( info_option == 'a' ) || ( info_option == 'i' ) ) { if( info_handle_header_values_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print header values.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } } if( ( info_option == 'a' ) || ( info_option == 'm' ) ) { if( info_handle_media_information_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print media information.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( info_handle_hash_values_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print hash values.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( info_handle_sessions_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print sessions.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( info_handle_tracks_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print tracks.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } } if( ( info_option == 'a' ) || ( info_option == 'e' ) ) { if( info_handle_acquiry_errors_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print acquiry errors.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } } if( info_handle_single_files_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print single files.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( ewfinfo_info_handle->output_format == INFO_HANDLE_OUTPUT_FORMAT_DFXML ) { if( info_handle_dfxml_footer_fprint( ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to print footer.\n" ); goto on_error; } } on_abort: if( info_handle_close( ewfinfo_info_handle, &error ) != 0 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to close info handle.\n" ); goto on_error; } if( ewftools_signal_detach( &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( info_handle_free( &ewfinfo_info_handle, &error ) != 1 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stderr, "Unable to free info handle.\n" ); goto on_error; } if( ewfinfo_abort != 0 ) { if( print_header != 0 ) { ewftools_output_version_fprint( stderr, program ); print_header = 0; } fprintf( stdout, "%" PRIs_SYSTEM ": ABORTED\n", program ); return( EXIT_FAILURE ); } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( ewfinfo_info_handle != NULL ) { info_handle_free( &ewfinfo_info_handle, NULL ); } #if !defined( HAVE_GLOB_H ) if( glob != NULL ) { ewftools_glob_free( &glob, NULL ); } #endif return( EXIT_FAILURE ); }
/* Retrieves the table of contents from the optical disk using the SCSI READ TOC command * Returns 1 if successful, 0 if not or -1 on error */ int libsmdev_optical_disc_get_table_of_contents_scsi( libcfile_file_t *device_file, libsmdev_internal_handle_t *internal_handle, libcerror_error_t **error ) { uint8_t track_info_data[ 64 ]; uint8_t *toc_data = NULL; uint8_t *toc_entries = NULL; static char *function = "libsmdev_optical_disc_get_table_of_contents_scsi"; void *reallocation = NULL; size_t toc_data_offset = 0; size_t toc_data_size = 0; ssize_t read_count = 0; uint32_t lead_out_size = 0; uint32_t lead_out_offset = 0; uint32_t last_track_offset = 0; uint32_t track_offset = 0; uint32_t session_size = 0; uint32_t session_offset = 0; uint32_t next_session_offset = 0; uint16_t entry_index = 0; uint8_t first_track_number = 0; uint8_t last_track_number = 0; uint8_t lead_out_index = 0; uint8_t number_of_sessions = 0; uint8_t session_index = 0; uint8_t track_index = 0; uint8_t track_number = 0; uint8_t track_type = 0; int result = 0; toc_data_size = 1024; toc_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * toc_data_size ); if( toc_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create TOC data.", function ); goto on_error; } if( memory_set( toc_data, 0, sizeof( uint8_t ) * toc_data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear TOC data.", function ); goto on_error; } read_count = libsmdev_scsi_read_toc( device_file, LIBSMDEV_SCSI_TOC_CDB_FORMAT_RAW_TOC, toc_data, toc_data_size, error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve TOC.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); byte_stream_copy_to_uint16_big_endian( toc_data, toc_data_size ); if( toc_data_size > 1024 ) { reallocation = memory_reallocate( toc_data, sizeof( uint8_t ) * toc_data_size ); if( reallocation == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to resize TOC data.", function ); goto on_error; } toc_data = (uint8_t *) reallocation; read_count = libsmdev_scsi_read_toc( device_file, LIBSMDEV_SCSI_TOC_CDB_FORMAT_RAW_TOC, toc_data, toc_data_size, error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve TOC.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } } } toc_data_size = (size_t) read_count; if( toc_data_size > 4 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: header:\n", function ); libcnotify_print_data( toc_data, 4, 0 ); } #endif number_of_sessions = (uint16_t) toc_data[ 3 ]; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: number of sessions\t\t\t: %" PRIu8 "\n", function, number_of_sessions ); libcnotify_printf( "\n" ); } #endif toc_entries = &( toc_data[ 4 ] ); toc_data_offset = 4; while( toc_data_offset < (size_t) toc_data_size ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: entry: %02" PRIu16 ":\n", function, entry_index ); libcnotify_print_data( toc_entries, 11, 0 ); } #endif if( toc_entries[ 3 ] <= 0x63 ) { libsmdev_optical_disc_copy_msf_to_lba( toc_entries[ 8 ], toc_entries[ 9 ], toc_entries[ 10 ], track_offset ); } else if( toc_entries[ 3 ] == 0xa0 ) { first_track_number = toc_entries[ 8 ]; } else if( toc_entries[ 3 ] == 0xa1 ) { last_track_number = toc_entries[ 8 ]; } else if( toc_entries[ 3 ] == 0xa2 ) { libsmdev_optical_disc_copy_msf_to_lba( toc_entries[ 8 ], toc_entries[ 9 ], toc_entries[ 10 ], lead_out_offset ); } else if( toc_entries[ 3 ] == 0xb0 ) { libsmdev_optical_disc_copy_absolute_msf_to_lba( toc_entries[ 4 ], toc_entries[ 5 ], toc_entries[ 6 ], next_session_offset ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( toc_entries[ 3 ] <= 0x63 ) { libcnotify_printf( "%s: session: %02" PRIu16 " track: %02" PRIu8 "\t\t\t: %02" PRIu8 ":%02" PRIu8 ".%02" PRIu8 " (offset: %" PRIu32 ")\n", function, toc_entries[ 0 ], toc_entries[ 3 ], toc_entries[ 4 ], toc_entries[ 5 ], toc_entries[ 6 ], track_offset ); } else if( toc_entries[ 3 ] == 0xa0 ) { libcnotify_printf( "%s: session: %02" PRIu8 " first track number\t: %" PRIu8 "\n", function, toc_entries[ 0 ], first_track_number ); } else if( toc_entries[ 3 ] == 0xa1 ) { libcnotify_printf( "%s: session: %02" PRIu8 " last track number\t\t: %" PRIu8 "\n", function, toc_entries[ 0 ], last_track_number ); } else if( toc_entries[ 3 ] == 0xa2 ) { libcnotify_printf( "%s: session: %02" PRIu8 " lead out\t\t\t: %02" PRIu8 ":%02" PRIu8 ".%02" PRIu8 " (offset: %" PRIu32 ")\n", function, toc_entries[ 0 ], toc_entries[ 8 ], toc_entries[ 9 ], toc_entries[ 10 ], lead_out_offset ); } else if( toc_entries[ 3 ] == 0xb0 ) { libcnotify_printf( "%s: session: %02" PRIu16 " end\t\t\t: %02" PRIu8 ":%02" PRIu8 ".%02" PRIu8 " (offset: %" PRIu32 ")\n", function, toc_entries[ 0 ], toc_entries[ 4 ], toc_entries[ 5 ], toc_entries[ 6 ], next_session_offset ); } libcnotify_printf( "\n" ); } #endif if( ( toc_entries[ 3 ] <= 0x63 ) || ( toc_entries[ 3 ] == 0xb0 ) ) { if( track_number >= first_track_number ) { if( toc_entries[ 3 ] == 0xb0 ) { track_offset = lead_out_offset; } if( track_offset < last_track_offset ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track offset value out of bounds.", function ); goto on_error; } if( ( track_index + 1 ) != track_number ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track number value out of bounds.", function ); goto on_error; } if( toc_entries[ 3 ] == 0xa2 ) { if( track_number != last_track_number ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track number value out of bounds.", function ); goto on_error; } } if( memory_set( track_info_data, 0, 64 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear track info data.", function ); goto on_error; } read_count = libsmdev_scsi_read_track_information( device_file, last_track_offset, track_info_data, 64, error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve track info data: %d.", function, track_index ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); break; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: track information data: %d:\n", function, track_index ); libcnotify_print_data( track_info_data, (size_t) read_count, 0 ); } #endif if( track_info_data[ 2 ] != toc_entries[ 0 ] ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track information data - session number value out of bounds.", function ); goto on_error; } if( track_info_data[ 3 ] != track_number ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track information data - track number value out of bounds.", function ); goto on_error; } track_type = LIBSMDEV_TRACK_TYPE_UNKNOWN; if( ( track_info_data[ 5 ] & 0x04 ) != 0 ) { if( ( track_info_data[ 5 ] & 0x08 ) == 0 ) { if( ( track_info_data[ 6 ] & 0x0f ) == 1 ) { track_type = LIBSMDEV_TRACK_TYPE_MODE1_2048; } else if( ( track_info_data[ 6 ] & 0x0f ) == 2 ) { track_type = LIBSMDEV_TRACK_TYPE_MODE2_2048; } } } else { track_type = LIBSMDEV_TRACK_TYPE_AUDIO; } if( libsmdev_handle_append_track( internal_handle, last_track_offset, track_offset - last_track_offset, track_type, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append track: %d.", function, track_index ); goto on_error; } track_index++; } last_track_offset = track_offset; if( toc_entries[ 3 ] != 0xb0 ) { track_number = toc_entries[ 3 ]; } } if( toc_entries[ 3 ] == 0xb0 ) { if( session_offset >= next_session_offset ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid session offset value out of bounds.", function ); goto on_error; } if( ( session_index + 1 ) != toc_entries[ 0 ] ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid session number value out of bounds.", function ); goto on_error; } lead_out_size = 0; if( ( lead_out_offset >= session_offset ) && ( lead_out_offset < next_session_offset ) ) { lead_out_size = next_session_offset - lead_out_offset; if( libsmdev_handle_append_lead_out( internal_handle, lead_out_offset, lead_out_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append lead_out: %d.", function, lead_out_index ); goto on_error; } lead_out_index++; } session_size = next_session_offset - session_offset; if( ( session_index + 1 ) == number_of_sessions ) { session_size -= lead_out_size; } if( libsmdev_handle_append_session( internal_handle, session_offset, session_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append session: %d.", function, session_index ); goto on_error; } session_offset = next_session_offset; session_index++; } toc_entries += 11; toc_data_offset += 11; entry_index++; } if( ( track_index + 1 ) == track_number ) { if( track_offset < last_track_offset ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track offset value out of bounds.", function ); goto on_error; } if( memory_set( track_info_data, 0, 64 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear track info data.", function ); goto on_error; } read_count = libsmdev_scsi_read_track_information( device_file, last_track_offset, track_info_data, 64, error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve track info data: %d.", function, track_index ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } else { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: track information data: %d:\n", function, track_index ); libcnotify_print_data( track_info_data, (size_t) read_count, 0 ); } #endif if( track_info_data[ 2 ] != toc_entries[ 0 ] ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track information data - session number value out of bounds.", function ); goto on_error; } if( track_info_data[ 3 ] != toc_entries[ 3 ] ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid track information data - track number value out of bounds.", function ); goto on_error; } track_type = LIBSMDEV_TRACK_TYPE_UNKNOWN; if( ( track_info_data[ 5 ] & 0x04 ) != 0 ) { if( ( track_info_data[ 5 ] & 0x08 ) == 0 ) { if( ( track_info_data[ 6 ] & 0x0f ) == 1 ) { track_type = LIBSMDEV_TRACK_TYPE_MODE1_2048; } else if( ( track_info_data[ 6 ] & 0x0f ) == 2 ) { track_type = LIBSMDEV_TRACK_TYPE_MODE2_2048; } } } else { track_type = LIBSMDEV_TRACK_TYPE_AUDIO; } if( libsmdev_handle_append_track( internal_handle, last_track_offset, track_offset - last_track_offset, track_type, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append last track: %d.", function, track_index ); goto on_error; } } if( session_index != number_of_sessions ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid session index value out of bounds.", function ); goto on_error; } result = 1; } } if( result == 0 ) { if( libcdata_array_empty( internal_handle->tracks_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_track_value_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to empty tracks array.", function ); goto on_error; } if( libcdata_array_empty( internal_handle->lead_outs_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_sector_range_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to empty lead outs array.", function ); goto on_error; } if( libcdata_array_empty( internal_handle->sessions_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_sector_range_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to empty sessions array.", function ); goto on_error; } } memory_free( toc_data ); toc_data = NULL; return( result ); on_error: if( toc_data != NULL ) { memory_free( toc_data ); } libcdata_array_empty( internal_handle->tracks_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_track_value_free, NULL ); libcdata_array_empty( internal_handle->lead_outs_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_sector_range_free, NULL ); libcdata_array_empty( internal_handle->sessions_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_sector_range_free, NULL ); return( -1 ); }
/* Opens a file for reading * Returns 1 if successful or -1 on error */ int libevt_file_open_read( libevt_internal_file_t *internal_file, libcerror_error_t **error ) { static char *function = "libevt_file_open_read"; off64_t last_record_offset = 0; uint32_t end_of_file_record_offset = 0; uint32_t first_record_offset = 0; int result_record_read = 0; int result_record_recovery = 0; if( internal_file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid internal file.", function ); return( -1 ); } if( internal_file->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid internal file - missing IO handle.", function ); return( -1 ); } if( internal_file->io_handle->abort != 0 ) { internal_file->io_handle->abort = 0; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading file header:\n" ); } #endif if( libevt_io_handle_read_file_header( internal_file->io_handle, internal_file->file_io_handle, &first_record_offset, &end_of_file_record_offset, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read file header.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading records:\n" ); } #endif result_record_read = libevt_io_handle_read_records( internal_file->io_handle, internal_file->file_io_handle, first_record_offset, end_of_file_record_offset, internal_file->records_list, &last_record_offset, error ); if( result_record_read != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read records.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif } if( internal_file->io_handle->abort == 0 ) { result_record_recovery = libevt_io_handle_recover_records( internal_file->io_handle, internal_file->file_io_handle, first_record_offset, end_of_file_record_offset, last_record_offset, internal_file->records_list, internal_file->recovered_records_list, error ); if( result_record_recovery != 1 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( result_record_read != 1 ) { libcerror_error_free( error ); } #endif libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to recover records.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif } } if( ( result_record_read != 1 ) && ( result_record_recovery != 1 ) ) { return( -1 ); } if( ( error != NULL ) && ( *error != NULL ) ) { libcerror_error_free( error ); } if( internal_file->io_handle->abort != 0 ) { internal_file->io_handle->abort = 0; } return( 1 ); }
/* Parses the header, header2 and/or xheader section for header values * Returns 1 if successful or -1 on error */ int libewf_header_sections_parse( libewf_header_sections_t *header_sections, libewf_io_handle_t *io_handle, libfvalue_table_t *header_values, uint8_t *format, libcerror_error_t **error ) { static char *function = "libewf_header_sections_parse"; int result_header = 1; int result_header2 = 1; int result_xheader = 1; if( header_sections == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid header sections.", function ); return( -1 ); } if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } if( format == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid format.", function ); return( -1 ); } /* For EWF version 1 format read all the header sections * and overwrite values by the most specific data * This also applied to the format */ if( header_sections->header != NULL ) { if( libewf_header_values_parse_header( header_values, header_sections->header, header_sections->header_size, io_handle->header_codepage, format, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to parse header.", function ); result_header = -1; } } if( header_sections->header2 != NULL ) { if( libewf_header_values_parse_header2( header_values, header_sections->header2, header_sections->header2_size, format, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to parse header2.", function ); result_header2 = -1; } } if( header_sections->xheader != NULL ) { if( libewf_header_values_parse_xheader( header_values, header_sections->xheader, header_sections->xheader_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to parse xheader.", function ); result_xheader = -1; } *format = LIBEWF_FORMAT_EWFX; } if( ( result_header != 1 ) && ( result_header2 != 1 ) && ( result_xheader != 1 ) ) { return( -1 ); } if( ( result_header != 1 ) || ( result_header2 != 1 ) || ( result_xheader != 1 ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } return( 1 ); }
int main( int argc, char * const argv[] ) #endif { export_handle_t *olecfexport_export_handle = NULL; libcerror_error_t *error = NULL; log_handle_t *log_handle = NULL; libcstring_system_character_t *log_filename = NULL; libcstring_system_character_t *option_ascii_codepage = NULL; libcstring_system_character_t *option_target_path = NULL; libcstring_system_character_t *path_separator = NULL; libcstring_system_character_t *source = NULL; char *program = "olecfexport"; size_t source_length = 0; libcstring_system_integer_t option = 0; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "olecftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } olecfoutput_version_fprint( stdout, program ); while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "c:hl:t:vV" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (libcstring_system_integer_t) 'c': option_ascii_codepage = optarg; break; case (libcstring_system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'l': log_filename = optarg; break; case (libcstring_system_integer_t) 't': option_target_path = optarg; break; case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': olecfoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; if( option_target_path == NULL ) { source_length = libcstring_system_string_length( source ); path_separator = libcstring_system_string_search_character_reverse( source, (libcstring_system_character_t) LIBCPATH_SEPARATOR, source_length ); if( path_separator == NULL ) { path_separator = source; } else { path_separator++; } option_target_path = path_separator; } libcnotify_verbose_set( verbose ); libolecf_notify_set_stream( stderr, NULL ); libolecf_notify_set_verbose( verbose ); if( export_handle_initialize( &olecfexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize export handle.\n" ); goto on_error; } if( export_handle_set_target_path( olecfexport_export_handle, option_target_path, &error ) != 1 ) { fprintf( stderr, "Unable to set target path.\n" ); goto on_error; } result = export_handle_create_items_export_path( olecfexport_export_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to create items export path.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "%" PRIs_LIBCSTRING_SYSTEM " already exists.\n", olecfexport_export_handle->items_export_path ); goto on_error; } if( log_handle_initialize( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize log handle.\n" ); goto on_error; } if( log_handle_open( log_handle, log_filename, &error ) != 1 ) { fprintf( stderr, "Unable to open log file: %" PRIs_LIBCSTRING_SYSTEM ".\n", log_filename ); goto on_error; } if( option_ascii_codepage != NULL ) { result = export_handle_set_ascii_codepage( olecfexport_export_handle, option_ascii_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set ASCII codepage in export handle.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported ASCII codepage defaulting to: windows-1252.\n" ); } } fprintf( stdout, "Opening file.\n" ); if( export_handle_open_input( olecfexport_export_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_LIBCSTRING_SYSTEM ".\n", source ); goto on_error; } if( export_handle_export_file( olecfexport_export_handle, log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to export file stream and storage items.\n" ); goto on_error; } if( export_handle_close( olecfexport_export_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close export handle.\n" ); goto on_error; } if( export_handle_free( &olecfexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free export handle.\n" ); goto on_error; } if( log_handle_close( log_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close log file: %" PRIs_LIBCSTRING_SYSTEM ".\n", log_filename ); goto on_error; } if( log_handle_free( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free log handle.\n" ); goto on_error; } fprintf( stdout, "Export completed.\n" ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_handle != NULL ) { log_handle_close( log_handle, NULL ); log_handle_free( &log_handle, NULL ); } if( olecfexport_export_handle != NULL ) { export_handle_close( olecfexport_export_handle, NULL ); export_handle_free( &olecfexport_export_handle, NULL ); } return( EXIT_FAILURE ); }
/* Tries to recover records * Returns 1 if successful or -1 on error */ int libevt_io_handle_recover_records( libevt_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, uint32_t first_record_offset, uint32_t end_of_file_record_offset, off64_t last_record_offset, libfdata_list_t *records_list, libfdata_list_t *recovered_records_list, libcerror_error_t **error ) { static char *function = "libevt_io_handle_recover_records"; int result = 0; if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } if( last_record_offset == (off64_t) first_record_offset ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: no records found at specified offsets scanning for end-of-file record.\n", function ); } #endif io_handle->flags |= LIBEVT_IO_HANDLE_FLAG_IS_CORRUPTED; result = libevt_io_handle_end_of_file_record_scan( io_handle, file_io_handle, &first_record_offset, &end_of_file_record_offset, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to scan for end of file record.", function ); return( -1 ); } else if( result != 0 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: end-of-file record found at offset: 0x%08" PRIx64 ".\n", function, end_of_file_record_offset ); } #endif result = libevt_io_handle_read_records( io_handle, file_io_handle, first_record_offset, end_of_file_record_offset, records_list, &last_record_offset, error ); if( result != 1 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcerror_error_free( error ); } } #endif libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read records.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } } else { first_record_offset = (uint32_t) sizeof( evt_file_header_t ); last_record_offset = (off64_t) sizeof( evt_file_header_t ); } } if( io_handle->has_wrapped == 0 ) { if( first_record_offset > (uint32_t) sizeof( evt_file_header_t ) ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: scanning unused space before records at offset: 0x%08" PRIzd " - 0x%08" PRIx32 "\n", function, sizeof( evt_file_header_t ), first_record_offset ); } #endif if( libevt_io_handle_event_record_scan( io_handle, file_io_handle, (off64_t) sizeof( evt_file_header_t ), (size64_t) ( first_record_offset - sizeof( evt_file_header_t ) ), recovered_records_list, error ) != 1 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcerror_error_free( error ); } } #endif libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to scan for event records.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } } if( last_record_offset < (off64_t) io_handle->file_size ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( last_record_offset > (off64_t) sizeof( evt_file_header_t ) ) { libcnotify_printf( "%s: scanning unused space after records at offset: 0x%08" PRIx64 " - 0x%08" PRIx64 "\n", function, last_record_offset, io_handle->file_size ); } else { libcnotify_printf( "%s: scanning unused space after header at offset: 0x%08" PRIx64 " - 0x%08" PRIx64 "\n", function, last_record_offset, io_handle->file_size ); } } #endif if( libevt_io_handle_event_record_scan( io_handle, file_io_handle, last_record_offset, io_handle->file_size - last_record_offset, recovered_records_list, error ) != 1 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcerror_error_free( error ); } } #endif libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to scan for event records.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } } } else { if( last_record_offset < (off64_t) first_record_offset ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: scanning unused space between records at offset: 0x%08" PRIx64 " - 0x%08" PRIx32 "\n", function, last_record_offset, first_record_offset ); } #endif if( libevt_io_handle_event_record_scan( io_handle, file_io_handle, last_record_offset, (size64_t) first_record_offset - last_record_offset, recovered_records_list, error ) != 1 ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcerror_error_free( error ); } } #endif libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to scan for event records.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } } } return( 1 ); }
/* Exports the sub items * Returns 1 if successful or -1 on error */ int export_handle_export_sub_items( export_handle_t *export_handle, libolecf_item_t *item, const system_character_t *export_path, size_t export_path_length, log_handle_t *log_handle, libcerror_error_t **error ) { libolecf_item_t *sub_item = NULL; static char *function = "export_handle_export_sub_items"; int number_of_sub_items = 0; int sub_item_iterator = 0; if( export_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid export handle.", function ); return( -1 ); } if( item == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid item.", function ); return( -1 ); } if( export_path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid export path.", function ); return( -1 ); } if( libolecf_item_get_number_of_sub_items( item, &number_of_sub_items, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of sub items.", function ); return( -1 ); } for( sub_item_iterator = 0; sub_item_iterator < number_of_sub_items; sub_item_iterator++ ) { if( libolecf_item_get_sub_item( item, sub_item_iterator, &sub_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve sub item: %d.", function, sub_item_iterator + 1 ); return( -1 ); } if( export_handle_export_item( export_handle, sub_item, sub_item_iterator, number_of_sub_items, export_path, export_path_length, log_handle, error ) != 1 ) { fprintf( stdout, "Unable to export item %d out of %d.\n", sub_item_iterator + 1, number_of_sub_items ); if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unable to export sub item: %d.\n", function, sub_item_iterator + 1 ); } if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } libcerror_error_free( error ); log_handle_printf( log_handle, "Unable to export sub item: %d.\n", sub_item_iterator + 1 ); } if( libolecf_item_free( &sub_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free sub item: %d.", function, sub_item_iterator + 1 ); return( -1 ); } } return( 1 ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; system_character_t *option_ascii_codepage = NULL; system_character_t *source = NULL; char *program = "olecfinfo"; system_integer_t option = 0; uint8_t show_allocation_information = 0; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "olecftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( olecftools_output_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } olecftools_output_version_fprint( stdout, program ); while( ( option = olecftools_getopt( argc, argv, _SYSTEM_STRING( "ac:hvV" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (system_integer_t) 'a': show_allocation_information = 1; break; case (system_integer_t) 'c': option_ascii_codepage = optarg; break; case (system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': olecftools_output_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_verbose_set( verbose ); libolecf_notify_set_stream( stderr, NULL ); libolecf_notify_set_verbose( verbose ); if( info_handle_initialize( &olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize info handle.\n" ); goto on_error; } if( option_ascii_codepage != NULL ) { result = info_handle_set_ascii_codepage( olecfinfo_info_handle, option_ascii_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set ASCII codepage in info handle.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported ASCII codepage defaulting to: windows-1252.\n" ); } } if( info_handle_open_input( olecfinfo_info_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_SYSTEM ".\n", source ); goto on_error; } if( info_handle_file_fprint( olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file information.\n" ); goto on_error; } if( info_handle_items_fprint( olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file stream and storage items.\n" ); goto on_error; } if( show_allocation_information != 0 ) { if( info_handle_unallocated_blocks_fprint( olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file unallocated blocks.\n" ); goto on_error; } } if( info_handle_summary_information_fprint( olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print summary information.\n" ); goto on_error; } if( info_handle_document_summary_information_fprint( olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print document summary information.\n" ); goto on_error; } if( info_handle_close( olecfinfo_info_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close info handle.\n" ); goto on_error; } if( info_handle_free( &olecfinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free info handle.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( olecfinfo_info_handle != NULL ) { info_handle_close( olecfinfo_info_handle, NULL ); info_handle_free( &olecfinfo_info_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; system_character_t *destination_filename = NULL; system_character_t *option_encoding = NULL; system_character_t *option_encoding_mode = NULL; system_character_t *source_filename = NULL; char *program = "unabase"; system_integer_t option = 0; uint8_t print_status_information = 1; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "unatools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( unatools_output_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } unatools_output_version_fprint( stdout, program ); while( ( option = unatools_getopt( argc, argv, _SYSTEM_STRING( "e:hm:qvV" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); goto on_error; case (system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'e': option_encoding = optarg; break; case (system_integer_t) 'm': option_encoding_mode = optarg; break; case (system_integer_t) 'q': print_status_information = 0; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': unatools_output_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source_filename = argv[ optind++ ]; if( optind == argc ) { fprintf( stderr, "Missing destination.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } destination_filename = argv[ optind++ ]; libcnotify_verbose_set( verbose ); if( export_handle_initialize( &unabase_export_handle, EXPORT_HANDLE_MODE_BASE_ENCODING, &error ) != 1 ) { fprintf( stderr, "Unable to create export handle.\n" ); goto on_error; } if( unatools_signal_attach( unabase_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( export_handle_set_string( unabase_export_handle, source_filename, &( unabase_export_handle->source_filename ), &( unabase_export_handle->source_filename_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set source filename.\n" ); goto on_error; } if( export_handle_set_string( unabase_export_handle, destination_filename, &( unabase_export_handle->destination_filename ), &( unabase_export_handle->destination_filename_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set destination filename.\n" ); goto on_error; } if( option_encoding != NULL ) { result = export_handle_set_encoding( unabase_export_handle, option_encoding, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set encoding.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported encoding defaulting to: base64.\n" ); } } if( option_encoding_mode != NULL ) { result = export_handle_set_encoding_mode( unabase_export_handle, option_encoding_mode, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set encoding mode.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported encoding mode defaulting to: encode.\n" ); } } if( export_handle_print_parameters( unabase_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print export parameters.\n" ); goto on_error; } if( export_handle_open_input( unabase_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to open source file.\n" ); goto on_error; } if( export_handle_open_output( unabase_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to open destination file.\n" ); goto on_error; } result = export_handle_export_input( unabase_export_handle, print_status_information, &error ); if( result != 1 ) { fprintf( stderr, "Unable to export input.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( export_handle_close( unabase_export_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close export handle.\n" ); goto on_error; } if( unatools_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( export_handle_free( &unabase_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free export handle.\n" ); goto on_error; } if( unabase_abort != 0 ) { fprintf( stdout, "%" PRIs_SYSTEM ": ABORTED\n", program ); return( EXIT_FAILURE ); } if( result != 1 ) { fprintf( stdout, "%" PRIs_SYSTEM ": FAILURE\n", program ); return( EXIT_FAILURE ); } fprintf( stdout, "%" PRIs_SYSTEM ": SUCCESS\n", program ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( unabase_export_handle != NULL ) { export_handle_close( unabase_export_handle, NULL ); export_handle_free( &unabase_export_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; system_character_t *option_file_entry = NULL; system_character_t *option_mft_entry_index = NULL; system_character_t *option_volume_offset = NULL; system_character_t *source = NULL; char *program = "fsntfsinfo"; system_integer_t option = 0; size_t string_length = 0; uint64_t mft_entry_index = 0; int option_mode = FSNTFSINFO_MODE_VOLUME; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "fsntfstools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( fsntfstools_output_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } fsntfstools_output_version_fprint( stdout, program ); while( ( option = fsntfstools_getopt( argc, argv, _SYSTEM_STRING( "E:F:hHo:UvV" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (system_integer_t) 'E': option_mode = FSNTFSINFO_MODE_MFT_ENTRY; option_mft_entry_index = optarg; break; case (system_integer_t) 'F': option_mode = FSNTFSINFO_MODE_FILE_ENTRY; option_file_entry = optarg; break; case (system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'H': option_mode = FSNTFSINFO_MODE_FILE_SYSTEM_HIERARCHY; break; case (system_integer_t) 'o': option_volume_offset = optarg; break; case (system_integer_t) 'U': option_mode = FSNTFSINFO_MODE_USN_CHANGE_JOURNAL; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': fsntfstools_output_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file or device.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_verbose_set( verbose ); libfsntfs_notify_set_stream( stderr, NULL ); libfsntfs_notify_set_verbose( verbose ); if( info_handle_initialize( &fsntfsinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize info handle.\n" ); goto on_error; } if( option_volume_offset != NULL ) { if( info_handle_set_volume_offset( fsntfsinfo_info_handle, option_volume_offset, &error ) != 1 ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); fprintf( stderr, "Unsupported volume offset defaulting to: %" PRIi64 ".\n", fsntfsinfo_info_handle->volume_offset ); } } if( info_handle_open_input( fsntfsinfo_info_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_SYSTEM ".\n", source ); goto on_error; } switch( option_mode ) { case FSNTFSINFO_MODE_FILE_ENTRY: if( fsntfsinfo_info_handle->input_volume == NULL ) { fprintf( stderr, "Unable to print file entry information.\n" ); goto on_error; } if( info_handle_file_entry_fprint( fsntfsinfo_info_handle, option_file_entry, &error ) != 1 ) { fprintf( stderr, "Unable to print file entry information.\n" ); goto on_error; } break; case FSNTFSINFO_MODE_FILE_SYSTEM_HIERARCHY: if( info_handle_file_system_hierarchy_fprint( fsntfsinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file system hierarchy.\n" ); goto on_error; } break; case FSNTFSINFO_MODE_MFT_ENTRY: if( option_mft_entry_index == NULL ) { fprintf( stderr, "Mising MFT entry index string.\n" ); goto on_error; } string_length = system_string_length( option_mft_entry_index ); if( ( string_length == 3 ) && ( system_string_compare( option_mft_entry_index, _SYSTEM_STRING( "all" ), 3 ) == 0 ) ) { if( info_handle_mft_entries_fprint( fsntfsinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print MFT entries.\n" ); goto on_error; } } else if( fsntfstools_system_string_copy_from_64_bit_in_decimal( option_mft_entry_index, string_length + 1, &mft_entry_index, &error ) == 1 ) { if( mft_entry_index > (uint64_t) INT64_MAX ) { fprintf( stderr, "Invalid MFT entry index value out of bounds." ); goto on_error; } if( info_handle_mft_entry_fprint( fsntfsinfo_info_handle, mft_entry_index, &error ) != 1 ) { fprintf( stderr, "Unable to print MFT entry: %" PRIu64 ".\n", mft_entry_index ); goto on_error; } } else { fprintf( stderr, "Unable to copy MFT entry index string to 64-bit decimal.\n" ); goto on_error; } break; case FSNTFSINFO_MODE_USN_CHANGE_JOURNAL: if( fsntfsinfo_info_handle->input_volume == NULL ) { fprintf( stderr, "Unable to print USN change journal ($UsnJrnl) information.\n" ); goto on_error; } if( info_handle_usn_change_journal_fprint( fsntfsinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print USN change journal ($UsnJrnl) information.\n" ); goto on_error; } break; case FSNTFSINFO_MODE_VOLUME: default: if( info_handle_volume_fprint( fsntfsinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print volume information.\n" ); goto on_error; } break; } if( info_handle_close_input( fsntfsinfo_info_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close info handle.\n" ); goto on_error; } if( info_handle_free( &fsntfsinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free info handle.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( fsntfsinfo_info_handle != NULL ) { info_handle_free( &fsntfsinfo_info_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; libcstring_system_character_t *log_filename = NULL; libcstring_system_character_t *option_additional_digest_types = NULL; libcstring_system_character_t *option_bytes_per_sector = NULL; libcstring_system_character_t *option_case_number = NULL; libcstring_system_character_t *option_compression_values = NULL; libcstring_system_character_t *option_description = NULL; libcstring_system_character_t *option_examiner_name = NULL; libcstring_system_character_t *option_evidence_number = NULL; libcstring_system_character_t *option_format = NULL; libcstring_system_character_t *option_header_codepage = NULL; libcstring_system_character_t *option_maximum_segment_size = NULL; libcstring_system_character_t *option_media_flags = NULL; libcstring_system_character_t *option_media_type = NULL; libcstring_system_character_t *option_notes = NULL; libcstring_system_character_t *option_offset = NULL; libcstring_system_character_t *option_process_buffer_size = NULL; libcstring_system_character_t *option_secondary_target_filename = NULL; libcstring_system_character_t *option_sectors_per_chunk = NULL; libcstring_system_character_t *option_size = NULL; libcstring_system_character_t *option_target_filename = NULL; libcstring_system_character_t *program = _LIBCSTRING_SYSTEM_STRING( "ewfacquirestream" ); log_handle_t *log_handle = NULL; libcstring_system_integer_t option = 0; size_t string_length = 0; uint8_t calculate_md5 = 1; uint8_t print_status_information = 1; uint8_t read_error_retries = 2; uint8_t resume_acquiry = 0; uint8_t swap_byte_pairs = 0; uint8_t use_chunk_data_functions = 0; uint8_t verbose = 0; int result = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "ewftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { ewfoutput_version_fprint( stdout, program ); fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } #if defined( WINAPI ) && !defined( __CYGWIN__ ) #if defined( _MSC_VER ) if( _setmode( _fileno( stdin ), _O_BINARY ) == -1 ) #else if( setmode( _fileno( stdin ), _O_BINARY ) == -1 ) #endif { ewfoutput_version_fprint( stdout, program ); fprintf( stderr, "Unable to set stdin to binary mode.\n" ); usage_fprint( stdout ); goto on_error; } #endif while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "A:b:B:c:C:d:D:e:E:f:hl:m:M:N:o:p:P:qsS:t:vVx2:" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: ewfoutput_version_fprint( stdout, program ); fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); goto on_error; case (libcstring_system_integer_t) 'A': option_header_codepage = optarg; break; case (libcstring_system_integer_t) 'b': option_sectors_per_chunk = optarg; break; case (libcstring_system_integer_t) 'B': option_size = optarg; break; case (libcstring_system_integer_t) 'c': option_compression_values = optarg; break; case (libcstring_system_integer_t) 'C': option_case_number = optarg; break; case (libcstring_system_integer_t) 'd': option_additional_digest_types = optarg; break; case (libcstring_system_integer_t) 'D': option_description = optarg; break; case (libcstring_system_integer_t) 'e': option_examiner_name = optarg; break; case (libcstring_system_integer_t) 'E': option_evidence_number = optarg; break; case (libcstring_system_integer_t) 'f': option_format = optarg; break; case (libcstring_system_integer_t) 'h': ewfoutput_version_fprint( stdout, program ); usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'l': log_filename = optarg; break; case (libcstring_system_integer_t) 'm': option_media_type = optarg; break; case (libcstring_system_integer_t) 'M': option_media_flags = optarg; break; case (libcstring_system_integer_t) 'N': option_notes = optarg; break; case (libcstring_system_integer_t) 'o': option_offset = optarg; break; case (libcstring_system_integer_t) 'p': option_process_buffer_size = optarg; break; case (libcstring_system_integer_t) 'P': option_bytes_per_sector = optarg; break; case (libcstring_system_integer_t) 'q': print_status_information = 0; break; case (libcstring_system_integer_t) 's': swap_byte_pairs = 1; break; case (libcstring_system_integer_t) 'S': option_maximum_segment_size = optarg; break; case (libcstring_system_integer_t) 't': option_target_filename = optarg; break; case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': ewfoutput_version_fprint( stdout, program ); ewfoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'x': use_chunk_data_functions = 1; break; case (libcstring_system_integer_t) '2': option_secondary_target_filename = optarg; break; } } ewfoutput_version_fprint( stdout, program ); libcnotify_verbose_set( verbose ); #if !defined( HAVE_LOCAL_LIBEWF ) libewf_notify_set_verbose( verbose ); libewf_notify_set_stream( stderr, NULL ); #endif if( ( option_target_filename != NULL ) && ( option_secondary_target_filename != NULL ) ) { string_length = libcstring_system_string_length( option_secondary_target_filename ); if( libcstring_system_string_length( option_target_filename ) == string_length ) { if( libcstring_system_string_compare( option_target_filename, option_secondary_target_filename, string_length ) == 0 ) { fprintf( stderr, "Primary and secondary target cannot be the same.\n" ); goto on_error; } } } if( imaging_handle_initialize( &ewfacquirestream_imaging_handle, calculate_md5, use_chunk_data_functions, &error ) != 1 ) { fprintf( stderr, "Unable to create imaging handle.\n" ); goto on_error; } if( option_header_codepage != NULL ) { result = imaging_handle_set_header_codepage( ewfacquirestream_imaging_handle, option_header_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set header codepage.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported header codepage defaulting to: ascii.\n" ); } } if( option_target_filename != NULL ) { if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_target_filename, &( ewfacquirestream_imaging_handle->target_filename ), &( ewfacquirestream_imaging_handle->target_filename_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set target filename.\n" ); goto on_error; } } else { /* Make sure the target filename is set */ if( imaging_handle_set_string( ewfacquirestream_imaging_handle, _LIBCSTRING_SYSTEM_STRING( "image" ), &( ewfacquirestream_imaging_handle->target_filename ), &( ewfacquirestream_imaging_handle->target_filename_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set target filename.\n" ); goto on_error; } } if( option_secondary_target_filename != NULL ) { if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_secondary_target_filename, &( ewfacquirestream_imaging_handle->secondary_target_filename ), &( ewfacquirestream_imaging_handle->secondary_target_filename_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set secondary target filename.\n" ); goto on_error; } } if( option_case_number == NULL ) { option_case_number = _LIBCSTRING_SYSTEM_STRING( "case_number" ); } if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_case_number, &( ewfacquirestream_imaging_handle->case_number ), &( ewfacquirestream_imaging_handle->case_number_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set case number.\n" ); goto on_error; } if( option_description == NULL ) { option_description = _LIBCSTRING_SYSTEM_STRING( "description" ); } if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_description, &( ewfacquirestream_imaging_handle->description ), &( ewfacquirestream_imaging_handle->description_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set description.\n" ); goto on_error; } if( option_evidence_number == NULL ) { option_evidence_number = _LIBCSTRING_SYSTEM_STRING( "evidence_number" ); } if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_evidence_number, &( ewfacquirestream_imaging_handle->evidence_number ), &( ewfacquirestream_imaging_handle->evidence_number_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set evidence number.\n" ); goto on_error; } if( option_examiner_name == NULL ) { option_examiner_name = _LIBCSTRING_SYSTEM_STRING( "examiner_name" ); } if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_examiner_name, &( ewfacquirestream_imaging_handle->examiner_name ), &( ewfacquirestream_imaging_handle->examiner_name_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set examiner name.\n" ); goto on_error; } if( option_notes == NULL ) { option_notes = _LIBCSTRING_SYSTEM_STRING( "notes" ); } if( imaging_handle_set_string( ewfacquirestream_imaging_handle, option_notes, &( ewfacquirestream_imaging_handle->notes ), &( ewfacquirestream_imaging_handle->notes_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set notes.\n" ); goto on_error; } if( option_format != NULL ) { result = imaging_handle_set_format( ewfacquirestream_imaging_handle, option_format, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set format.\n" ); goto on_error; } else if( ( result == 0 ) || ( ewfacquirestream_imaging_handle->ewf_format == LIBEWF_FORMAT_EWF ) || ( ewfacquirestream_imaging_handle->ewf_format == LIBEWF_FORMAT_ENCASE1 ) || ( ewfacquirestream_imaging_handle->ewf_format == LIBEWF_FORMAT_SMART ) ) { ewfacquirestream_imaging_handle->ewf_format = LIBEWF_FORMAT_ENCASE6; fprintf( stderr, "Unsupported EWF format defaulting to: encase6.\n" ); } } if( option_compression_values != NULL ) { result = imaging_handle_set_compression_values( ewfacquirestream_imaging_handle, option_compression_values, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set compression values.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported compression values defaulting to method: deflate with level: none.\n" ); } } if( option_media_type != NULL ) { result = imaging_handle_set_media_type( ewfacquirestream_imaging_handle, option_media_type, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set media type.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported media type defaulting to: fixed.\n" ); } } if( option_media_flags != NULL ) { result = imaging_handle_set_media_flags( ewfacquirestream_imaging_handle, option_media_flags, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set media flags.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported media flags defaulting to: physical.\n" ); } } if( option_bytes_per_sector != NULL ) { result = imaging_handle_set_bytes_per_sector( ewfacquirestream_imaging_handle, option_bytes_per_sector, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set bytes per sector.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported bytes per sector defaulting to: %" PRIu32 ".\n", ewfacquirestream_imaging_handle->bytes_per_sector ); } } if( option_sectors_per_chunk != NULL ) { result = imaging_handle_set_sectors_per_chunk( ewfacquirestream_imaging_handle, option_sectors_per_chunk, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set sectors per chunk.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported sectors per chunk defaulting to: %" PRIu32 ".\n", ewfacquirestream_imaging_handle->sectors_per_chunk ); } } if( option_maximum_segment_size != NULL ) { result = imaging_handle_set_maximum_segment_size( ewfacquirestream_imaging_handle, option_maximum_segment_size, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set maximum segment size.\n" ); goto on_error; } else if( result == 0 ) { ewfacquirestream_imaging_handle->maximum_segment_size = EWFCOMMON_DEFAULT_SEGMENT_FILE_SIZE; fprintf( stderr, "Unsupported maximum segment size defaulting to: %" PRIu64 ".\n", ewfacquirestream_imaging_handle->maximum_segment_size ); } } if( option_offset != NULL ) { result = imaging_handle_set_acquiry_offset( ewfacquirestream_imaging_handle, option_offset, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set acquiry offset.\n" ); goto on_error; } else if( result == 0 ) { ewfacquirestream_imaging_handle->acquiry_offset = 0; fprintf( stderr, "Unsupported acquiry offset defaulting to: 0.\n" ); } } if( option_size != NULL ) { result = imaging_handle_set_acquiry_size( ewfacquirestream_imaging_handle, option_size, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set acquiry size.\n" ); goto on_error; } else if( result == 0 ) { ewfacquirestream_imaging_handle->acquiry_size = 0; fprintf( stderr, "Unsupported acquiry size defaulting to: all bytes.\n" ); } } if( option_process_buffer_size != NULL ) { result = imaging_handle_set_process_buffer_size( ewfacquirestream_imaging_handle, option_process_buffer_size, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set process buffer size.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported process buffer size defaulting to: chunk size.\n" ); } } if( option_additional_digest_types != NULL ) { result = imaging_handle_set_additional_digest_types( ewfacquirestream_imaging_handle, option_additional_digest_types, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set additional digest types.\n" ); goto on_error; } } fprintf( stdout, "Using the following acquiry parameters:\n" ); if( imaging_handle_print_parameters( ewfacquirestream_imaging_handle, 0, read_error_retries, 0, 0, &error ) != 1 ) { fprintf( stderr, "Unable to print acquiry parameters.\n" ); goto on_error; } if( imaging_handle_open_output( ewfacquirestream_imaging_handle, ewfacquirestream_imaging_handle->target_filename, resume_acquiry, &error ) != 1 ) { fprintf( stderr, "Unable to open output.\n" ); goto on_error; } if( ewfacquirestream_imaging_handle->secondary_target_filename != NULL ) { if( imaging_handle_open_secondary_output( ewfacquirestream_imaging_handle, ewfacquirestream_imaging_handle->secondary_target_filename, resume_acquiry, &error ) != 1 ) { fprintf( stderr, "Unable to open secondary output.\n" ); goto on_error; } } if( imaging_handle_set_output_values( ewfacquirestream_imaging_handle, program, _LIBCSTRING_SYSTEM_STRING( LIBEWF_VERSION_STRING ), NULL, NULL, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } if( libcsystem_signal_attach( ewfacquirestream_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_filename != NULL ) { if( log_handle_initialize( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to create log handle.\n" ); goto on_error; } if( log_handle_open( log_handle, log_filename, &error ) != 1 ) { fprintf( stderr, "Unable to open log file: %" PRIs_LIBCSTRING_SYSTEM ".\n", log_filename ); goto on_error; } } result = ewfacquirestream_read_input( ewfacquirestream_imaging_handle, 0, swap_byte_pairs, read_error_retries, print_status_information, use_chunk_data_functions, log_handle, &error ); if( result != 1 ) { fprintf( stderr, "Unable to read input.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_handle != NULL ) { if( log_handle_close( log_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close log handle.\n" ); goto on_error; } if( log_handle_free( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free log handle.\n" ); goto on_error; } } if( libcsystem_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( imaging_handle_close( ewfacquirestream_imaging_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close output.\n" ); goto on_error; } if( imaging_handle_free( &ewfacquirestream_imaging_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free imaging handle.\n" ); goto on_error; } if( ewfacquirestream_abort != 0 ) { fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": ABORTED\n", program ); return( EXIT_FAILURE ); } if( result != 1 ) { fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": FAILURE\n", program ); return( EXIT_FAILURE ); } fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": SUCCESS\n", program ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_handle != NULL ) { log_handle_close( log_handle, NULL ); log_handle_free( &log_handle, NULL ); } if( ewfacquirestream_imaging_handle != NULL ) { imaging_handle_close( ewfacquirestream_imaging_handle, NULL ); imaging_handle_free( &ewfacquirestream_imaging_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; libcfile_file_t *destination_file = NULL; libcfile_file_t *source_file = NULL; system_character_t *option_target_path = NULL; system_character_t *options_string = NULL; system_character_t *source = NULL; uint8_t *buffer = NULL; uint8_t *uncompressed_data = NULL; char *program = "lznt1decompress"; system_integer_t option = 0; size64_t source_size = 0; size_t buffer_size = 0; size_t uncompressed_data_size = 0; ssize_t read_count = 0; ssize_t write_count = 0; off_t source_offset = 0; int decompression_method = 1; int result = 0; int verbose = 0; #if defined( WINAPI ) unsigned short winapi_compression_method = 0; #endif assorted_output_version_fprint( stdout, program ); #if defined( WINAPI ) options_string = _SYSTEM_STRING( "d:ho:s:t:vV12" ); #else options_string = _SYSTEM_STRING( "d:ho:s:t:vV1" ); #endif while( ( option = assorted_getopt( argc, argv, options_string ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (system_integer_t) '1': decompression_method = 1; break; #if defined( WINAPI ) case (system_integer_t) '2': decompression_method = 2; break; #endif case (system_integer_t) 'd': uncompressed_data_size = atol( optarg ); break; case (system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'o': source_offset = atol( optarg ); break; case (system_integer_t) 's': source_size = atol( optarg ); break; case (system_integer_t) 't': option_target_path = optarg; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': assorted_output_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( verbose ); /* Open the source file */ if( libcfile_file_initialize( &source_file, &error ) != 1 ) { fprintf( stderr, "Unable to create source file.\n" ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libcfile_file_open_wide( source_file, source, LIBCFILE_OPEN_READ, &error ); #else result = libcfile_file_open( source_file, source, LIBCFILE_OPEN_READ, &error ); #endif if( result != 1 ) { fprintf( stderr, "Unable to open source file.\n" ); goto on_error; } if( source_size == 0 ) { if( libcfile_file_get_size( source_file, &source_size, &error ) == -1 ) { fprintf( stderr, "Unable to determine size of source file.\n" ); goto on_error; } if( source_size <= (size64_t) source_offset ) { fprintf( stderr, "Invalid source size value is less equal than source offset.\n" ); goto on_error; } source_size -= source_offset; } if( source_size == 0 ) { fprintf( stderr, "Invalid source size value is zero.\n" ); goto on_error; } if( source_size > (size_t) SSIZE_MAX ) { fprintf( stderr, "Invalid source size value exceeds maximum.\n" ); goto on_error; } /* Create the input buffer */ buffer_size = source_size; buffer = (uint8_t *) memory_allocate( sizeof( uint8_t ) * buffer_size ); if( buffer == NULL ) { fprintf( stderr, "Unable to create buffer.\n" ); goto on_error; } if( uncompressed_data_size == 0 ) { uncompressed_data_size = 65536; } uncompressed_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * uncompressed_data_size ); if( uncompressed_data == NULL ) { fprintf( stderr, "Unable to create uncompressed data buffer.\n" ); goto on_error; } if( memory_set( uncompressed_data, 0, uncompressed_data_size ) == NULL ) { fprintf( stderr, "Unable to clear uncompressed data buffer.\n" ); goto on_error; } /* Position the source file at the right offset */ if( libcfile_file_seek_offset( source_file, source_offset, SEEK_SET, &error ) == -1 ) { fprintf( stderr, "Unable to seek offset in source file.\n" ); goto on_error; } fprintf( stdout, "Starting LZNT1 decompression of: %" PRIs_SYSTEM " at offset: %" PRIjd " (0x%08" PRIjx ").\n", source, source_offset, source_offset ); read_count = libcfile_file_read_buffer( source_file, buffer, source_size, &error ); if( read_count != (ssize_t) source_size ) { fprintf( stderr, "Unable to read from source file.\n" ); goto on_error; } /* Decompress the data */ if( option_target_path == NULL ) { fprintf( stderr, "Compressed data:\n" ); libcnotify_print_data( buffer, source_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } if( decompression_method == 1 ) { result = libfwnt_lznt1_decompress( buffer, (size_t) source_size, uncompressed_data, &uncompressed_data_size, &error ); } #if defined( WINAPI ) else if( decompression_method == 2 ) { result = lznt1compress_RtlDecompressBuffer( COMPRESSION_FORMAT_LZNT1, (unsigned char *) uncompressed_data, (unsigned long) uncompressed_data_size, (unsigned char *) buffer, (unsigned long) source_size, (unsigned long *) &uncompressed_data_size ); if( result != 0 ) { result = -1; } else { result = 1; } } #endif if( result == -1 ) { fprintf( stderr, "Unable to decompress data.\n" ); libcnotify_print_data( uncompressed_data, uncompressed_data_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); goto on_error; } if( option_target_path == NULL ) { fprintf( stderr, "Uncompressed data:\n" ); libcnotify_print_data( uncompressed_data, uncompressed_data_size, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } else { if( libcfile_file_initialize( &destination_file, &error ) != 1 ) { fprintf( stderr, "Unable to create destination file.\n" ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libcfile_file_open_wide( destination_file, option_target_path, LIBCFILE_OPEN_WRITE, &error ); #else result = libcfile_file_open( destination_file, option_target_path, LIBCFILE_OPEN_WRITE, &error ); #endif if( result != 1 ) { fprintf( stderr, "Unable to open destination file.\n" ); goto on_error; } write_count = libcfile_file_write_buffer( destination_file, uncompressed_data, uncompressed_data_size, &error ); if( write_count != (ssize_t) uncompressed_data_size ) { fprintf( stderr, "Unable to write to destination file.\n" ); goto on_error; } if( libcfile_file_close( destination_file, &error ) != 0 ) { fprintf( stderr, "Unable to close destination file.\n" ); goto on_error; } if( libcfile_file_free( &destination_file, &error ) != 1 ) { fprintf( stderr, "Unable to free destination file.\n" ); goto on_error; } } /* Clean up */ if( libcfile_file_close( source_file, &error ) != 0 ) { fprintf( stderr, "Unable to close source file.\n" ); goto on_error; } if( libcfile_file_free( &source_file, &error ) != 1 ) { fprintf( stderr, "Unable to free source file.\n" ); goto on_error; } memory_free( uncompressed_data ); uncompressed_data = NULL; memory_free( buffer ); buffer = NULL; fprintf( stdout, "LZNT1 decompression:\tSUCCESS\n" ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( destination_file != NULL ) { libcfile_file_free( &destination_file, NULL ); } if( uncompressed_data != NULL ) { memory_free( uncompressed_data ); } if( buffer != NULL ) { memory_free( buffer ); } if( source_file != NULL ) { libcfile_file_free( &source_file, NULL ); } fprintf( stdout, "LZNT1 decompression:\tFAILURE\n" ); return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; log_handle_t *log_handle = NULL; libcstring_system_character_t *log_filename = NULL; libcstring_system_character_t *option_ascii_codepage = NULL; libcstring_system_character_t *option_export_mode = NULL; libcstring_system_character_t *option_preferred_export_format = NULL; libcstring_system_character_t *option_target_path = NULL; libcstring_system_character_t *path_separator = NULL; libcstring_system_character_t *source = NULL; char *program = "pffexport"; size_t source_length = 0; libcstring_system_integer_t option = 0; uint8_t dump_item_values = 0; uint8_t print_status_information = 1; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "pfftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } pffoutput_version_fprint( stdout, program ); while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "c:df:hl:m:qt:vV" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (libcstring_system_integer_t) 'c': option_ascii_codepage = optarg; break; case (libcstring_system_integer_t) 'd': dump_item_values = 1; break; case (libcstring_system_integer_t) 'f': option_preferred_export_format = optarg; break; case (libcstring_system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'l': log_filename = optarg; break; case (libcstring_system_integer_t) 'm': option_export_mode = optarg; break; case (libcstring_system_integer_t) 'q': print_status_information = 0; break; case (libcstring_system_integer_t) 't': option_target_path = optarg; break; case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': pffoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; if( option_target_path == NULL ) { source_length = libcstring_system_string_length( source ); path_separator = libcstring_system_string_search_character_reverse( source, (libcstring_system_character_t) LIBCPATH_SEPARATOR, source_length ); if( path_separator == NULL ) { path_separator = source; } else { path_separator++; } option_target_path = path_separator; } libcnotify_verbose_set( verbose ); libpff_notify_set_stream( stderr, NULL ); libpff_notify_set_verbose( verbose ); if( export_handle_initialize( &pffexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to create export handle.\n" ); goto on_error; } pffexport_export_handle->print_status_information = print_status_information; if( option_export_mode != NULL ) { result = export_handle_set_export_mode( pffexport_export_handle, option_export_mode, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set export mode.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported export mode defaulting to: items.\n" ); } } pffexport_export_handle->dump_item_values = dump_item_values; if( option_preferred_export_format != NULL ) { result = export_handle_set_preferred_export_format( pffexport_export_handle, option_preferred_export_format, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set preferred export format.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported preferred export format defaulting to: text.\n" ); } } if( option_ascii_codepage != NULL ) { result = export_handle_set_ascii_codepage( pffexport_export_handle, option_ascii_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set ASCII codepage in export handle.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported ASCII codepage defaulting to: windows-1252.\n" ); } } if( export_handle_set_target_path( pffexport_export_handle, option_target_path, &error ) != 1 ) { fprintf( stderr, "Unable to set target path.\n" ); goto on_error; } result = export_handle_create_items_export_path( pffexport_export_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to create items export path.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "%" PRIs_LIBCSTRING_SYSTEM " already exists.\n", pffexport_export_handle->items_export_path ); goto on_error; } result = export_handle_create_orphans_export_path( pffexport_export_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to create orphans export path.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "%" PRIs_LIBCSTRING_SYSTEM " already exists.\n", pffexport_export_handle->orphans_export_path ); goto on_error; } result = export_handle_create_recovered_export_path( pffexport_export_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to create recovered export path.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "%" PRIs_LIBCSTRING_SYSTEM " already exists.\n", pffexport_export_handle->recovered_export_path ); goto on_error; } if( log_handle_initialize( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to create log handle.\n" ); goto on_error; } if( log_handle_open( log_handle, log_filename, &error ) != 1 ) { fprintf( stderr, "Unable to open log file: %" PRIs_LIBCSTRING_SYSTEM ".\n", log_filename ); goto on_error; } if( libpff_file_initialize( &pffexport_file, &error ) != 1 ) { fprintf( stderr, "Unable to create file.\n" ); goto on_error; } if( libpff_file_set_ascii_codepage( pffexport_file, pffexport_export_handle->ascii_codepage, &error ) != 1 ) { fprintf( stderr, "Unable to set ASCII codepage.\n" ); goto on_error; } if( libcsystem_signal_attach( pffexport_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); goto on_error; } fprintf( stdout, "Opening file.\n" ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libpff_file_open_wide( pffexport_file, source, LIBPFF_OPEN_READ, &error ) != 1 ) #else if( libpff_file_open( pffexport_file, source, LIBPFF_OPEN_READ, &error ) != 1 ) #endif { fprintf( stderr, "Error opening file: %" PRIs_LIBCSTRING_SYSTEM ".\n", source ); goto on_error; } if( export_handle_export_file( pffexport_export_handle, pffexport_file, log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to export file.\n" ); goto on_error; } if( libpff_file_close( pffexport_file, &error ) != 0 ) { fprintf( stderr, "Unable to close file.\n" ); goto on_error; } if( libcsystem_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); goto on_error; } if( libpff_file_free( &pffexport_file, &error ) != 1 ) { fprintf( stderr, "Unable to free file.\n" ); goto on_error; } if( log_handle_close( log_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close log file.\n" ); goto on_error; } if( log_handle_free( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free log handle.\n" ); goto on_error; } if( export_handle_free( &pffexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free export handle.\n" ); goto on_error; } if( pffexport_abort != 0 ) { fprintf( stdout, "Export aborted.\n" ); return( EXIT_FAILURE ); } fprintf( stdout, "Export completed.\n" ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( pffexport_file != NULL ) { libpff_file_close( pffexport_file, NULL ); libpff_file_free( &pffexport_file, NULL ); } if( log_handle != NULL ) { log_handle_close( log_handle, NULL ); log_handle_free( &log_handle, NULL ); } if( pffexport_export_handle != NULL ) { export_handle_free( &pffexport_export_handle, NULL ); } return( EXIT_FAILURE ); }
/* Retrieves the table of contents from the optical disk using IOCTL * Returns 1 if successful, 0 if not or -1 on error */ int libsmdev_optical_disc_get_table_of_contents_ioctl( libcfile_file_t *device_file, libsmdev_internal_handle_t *internal_handle, libcerror_error_t **error ) { struct cdrom_tochdr toc_header; struct cdrom_tocentry toc_entry; static char *function = "libsmdev_optical_disc_get_table_of_contents_ioctl"; ssize_t read_count = 0; uint32_t last_session_size = 0; uint32_t last_session_offset = 0; uint32_t last_track_size = 0; uint32_t last_track_offset = 0; uint32_t offset = 0; uint16_t entry_index = 0; uint8_t first_entry = 0; uint8_t last_entry = 0; uint8_t last_track_type = 0; uint8_t session_index = 0; uint8_t track_index = 0; uint8_t track_type = 0; int result = 0; read_count = libcfile_file_io_control_read( device_file, CDROMREADTOCHDR, NULL, 0, (uint8_t *) &toc_header, sizeof( struct cdrom_tochdr ), error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_IOCTL_FAILED, "%s: unable to query device for: CDROMREADTOCHDR.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); return( 0 ); } first_entry = toc_header.cdth_trk0; last_entry = toc_header.cdth_trk1; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: number of entries\t: %" PRIu8 "\n", function, last_entry ); } #endif for( entry_index = (uint16_t) first_entry; entry_index <= (uint16_t) last_entry; entry_index++ ) { if( memory_set( &toc_entry, 0, sizeof( struct cdrom_tocentry ) ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear TOC entry.", function ); goto on_error; } toc_entry.cdte_track = (uint8_t) entry_index; toc_entry.cdte_format = CDROM_LBA; read_count = libcfile_file_io_control_read( device_file, CDROMREADTOCENTRY, NULL, 0, (uint8_t *) &toc_entry, sizeof( struct cdrom_tocentry ), error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_IOCTL_FAILED, "%s: unable to query device for: CDROMREADTOCENTRY.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); break; } if( toc_entry.cdte_format == CDROM_LBA ) { offset = (uint32_t) toc_entry.cdte_addr.lba; } else if( toc_entry.cdte_format == CDROM_MSF ) { libsmdev_optical_disc_copy_msf_to_lba( toc_entry.cdte_addr.msf.minute, toc_entry.cdte_addr.msf.second, toc_entry.cdte_addr.msf.frame, offset ); } else { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported CDTE format.", function ); goto on_error; } if( ( toc_entry.cdte_ctrl & CDROM_DATA_TRACK ) == 0 ) { track_type = LIBSMDEV_TRACK_TYPE_AUDIO; } else { track_type = LIBSMDEV_TRACK_TYPE_MODE1_2048; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: entry: %" PRIu16 "", function, entry_index ); if( ( toc_entry.cdte_ctrl & CDROM_DATA_TRACK ) == 0 ) { libcnotify_printf( " (audio)" ); } else { libcnotify_printf( " (data)" ); } if( toc_entry.cdte_format == CDROM_LBA ) { libcnotify_printf( " start\t: %" PRIu32 "", toc_entry.cdte_addr.lba ); } else if( toc_entry.cdte_format == CDROM_MSF ) { libcnotify_printf( " start\t: %02" PRIu8 ":%02" PRIu8 ".%02" PRIu8 "", toc_entry.cdte_addr.msf.minute, toc_entry.cdte_addr.msf.second, toc_entry.cdte_addr.msf.frame ); } libcnotify_printf( " (offset: %" PRIu32 ")\n", offset ); } #endif if( entry_index > first_entry ) { if( ( offset < last_track_offset ) || ( offset < last_session_offset ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid offset value out of bounds.", function ); goto on_error; } last_track_size = offset - last_track_offset; if( ( last_track_type == LIBSMDEV_TRACK_TYPE_MODE1_2048 ) || ( last_track_type != track_type ) ) { if( session_index == 0 ) { if( last_track_size < 11400 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid last track size value out of bounds.", function ); goto on_error; } last_track_size -= 11400; } else { if( last_track_size < 6900 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid last track size value out of bounds.", function ); goto on_error; } last_track_size -= 6900; } } if( libsmdev_handle_append_track( internal_handle, last_track_offset, last_track_size, last_track_type, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append track: %" PRIu8 ".", function, track_index ); goto on_error; } track_index++; if( ( last_track_type == LIBSMDEV_TRACK_TYPE_MODE1_2048 ) || ( last_track_type != track_type ) ) { last_session_size = offset - last_session_offset; if( libsmdev_handle_append_session( internal_handle, last_session_offset, last_session_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append session: %" PRIu8 ".", function, session_index ); goto on_error; } session_index++; last_session_offset = offset; } } last_track_offset = offset; last_track_type = track_type; } if( read_count != -1 ) { if( memory_set( &toc_entry, 0, sizeof( struct cdrom_tocentry ) ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear TOC entry.", function ); goto on_error; } toc_entry.cdte_track = CDROM_LEADOUT; toc_entry.cdte_format = CDROM_LBA; read_count = libcfile_file_io_control_read( device_file, CDROMREADTOCENTRY, NULL, 0, (uint8_t *) &toc_entry, sizeof( struct cdrom_tocentry ), error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_IOCTL_FAILED, "%s: unable to query device for: CDROMREADTOCENTRY.", function ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); } else { if( toc_entry.cdte_format == CDROM_LBA ) { offset = (uint32_t) toc_entry.cdte_addr.lba; } else if( toc_entry.cdte_format == CDROM_MSF ) { libsmdev_optical_disc_copy_msf_to_lba( toc_entry.cdte_addr.msf.minute, toc_entry.cdte_addr.msf.second, toc_entry.cdte_addr.msf.frame, offset ); } else { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported CDTE format.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\tLead out" ); if( ( toc_entry.cdte_ctrl & CDROM_DATA_TRACK ) == 0 ) { libcnotify_printf( " (audio)" ); } else { libcnotify_printf( " (data)" ); } if( toc_entry.cdte_format == CDROM_LBA ) { libcnotify_printf( " start:\t%" PRIu32 "", toc_entry.cdte_addr.lba ); } else if( toc_entry.cdte_format == CDROM_MSF ) { libcnotify_printf( " start:\t%02" PRIu8 ":%02" PRIu8 ".02%" PRIu8 "", toc_entry.cdte_addr.msf.minute, toc_entry.cdte_addr.msf.second, toc_entry.cdte_addr.msf.frame ); } libcnotify_printf( " (offset: %" PRIu32 ")\n\n", offset ); } #endif if( ( offset < last_track_offset ) || ( offset < last_session_offset ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid offset value out of bounds.", function ); goto on_error; } last_track_size = offset - last_track_offset; if( libsmdev_handle_append_track( internal_handle, last_track_offset, last_track_size, last_track_type, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append last track: %" PRIu8 ".", function, track_index ); goto on_error; } last_session_size = offset - last_session_offset; if( libsmdev_handle_append_session( internal_handle, last_session_offset, last_session_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append session: %" PRIu8 ".", function, session_index ); goto on_error; } result = 1; } } if( result == 0 ) { if( libcdata_array_empty( internal_handle->tracks_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_track_value_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to empty tracks array.", function ); goto on_error; } if( libcdata_array_empty( internal_handle->sessions_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_sector_range_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to empty sessions array.", function ); goto on_error; } } return( result ); on_error: libcdata_array_empty( internal_handle->tracks_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_track_value_free, NULL ); libcdata_array_empty( internal_handle->sessions_array, (int (*)(intptr_t **, libcerror_error_t **)) &libsmdev_sector_range_free, NULL ); return( -1 ); }
int main( int argc, char * const argv[] ) #endif { libqcow_error_t *error = NULL; libcstring_system_character_t *source = NULL; char *program = "qcowinfo"; libcstring_system_integer_t option = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "qcowtools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } qcowoutput_version_fprint( stdout, program ); while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "hvV" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (libcstring_system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': qcowoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_verbose_set( verbose ); libqcow_notify_set_stream( stderr, NULL ); libqcow_notify_set_verbose( verbose ); if( info_handle_initialize( &qcowinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize info handle.\n" ); goto on_error; } if( info_handle_open_input( qcowinfo_info_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open source file.\n" ); goto on_error; } if( info_handle_file_fprint( qcowinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file information.\n" ); goto on_error; } if( info_handle_close( qcowinfo_info_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close info handle.\n" ); goto on_error; } if( info_handle_free( &qcowinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free info handle.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( qcowinfo_info_handle != NULL ) { info_handle_free( &qcowinfo_info_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { #if defined( HAVE_GETRLIMIT ) struct rlimit limit_data; #endif libcerror_error_t *error = NULL; libcstring_system_character_t * const *source_filenames = NULL; #if !defined( HAVE_GLOB_H ) libcsystem_glob_t *glob = NULL; #endif libcstring_system_character_t *log_filename = NULL; libcstring_system_character_t *program = _LIBCSTRING_SYSTEM_STRING( "ewfverify" ); libcstring_system_character_t *option_additional_digest_types = NULL; libcstring_system_character_t *option_format = NULL; libcstring_system_character_t *option_header_codepage = NULL; libcstring_system_character_t *option_number_of_jobs = NULL; libcstring_system_character_t *option_process_buffer_size = NULL; log_handle_t *log_handle = NULL; libcstring_system_integer_t option = 0; uint8_t calculate_md5 = 1; uint8_t print_status_information = 1; uint8_t use_chunk_data_functions = 0; uint8_t verbose = 0; uint8_t zero_chunk_on_error = 0; int number_of_filenames = 0; int result = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "ewftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } ewfoutput_version_fprint( stdout, program ); while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "A:d:f:j:hl:p:qvVwx" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind ] ); usage_fprint( stdout ); goto on_error; case (libcstring_system_integer_t) 'A': option_header_codepage = optarg; break; case (libcstring_system_integer_t) 'd': option_additional_digest_types = optarg; break; case (libcstring_system_integer_t) 'f': option_format = optarg; break; case (libcstring_system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'j': option_number_of_jobs = optarg; break; case (libcstring_system_integer_t) 'l': log_filename = optarg; break; case (libcstring_system_integer_t) 'p': option_process_buffer_size = optarg; break; case (libcstring_system_integer_t) 'q': print_status_information = 0; break; case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': ewfoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'w': zero_chunk_on_error = 1; break; case (libcstring_system_integer_t) 'x': use_chunk_data_functions = 1; break; } } if( optind == argc ) { fprintf( stderr, "Missing EWF image file(s).\n" ); usage_fprint( stdout ); goto on_error; } libcnotify_verbose_set( verbose ); #if !defined( HAVE_LOCAL_LIBEWF ) libewf_notify_set_verbose( verbose ); libewf_notify_set_stream( stderr, NULL ); #endif if( verification_handle_initialize( &ewfverify_verification_handle, calculate_md5, use_chunk_data_functions, &error ) != 1 ) { fprintf( stderr, "Unable to create verification handle.\n" ); goto on_error; } if( option_header_codepage != NULL ) { result = verification_handle_set_header_codepage( ewfverify_verification_handle, option_header_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set header codepage.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported header codepage defaulting to: ascii.\n" ); } } if( option_format != NULL ) { result = verification_handle_set_format( ewfverify_verification_handle, option_format, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set format.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported input format defaulting to: raw.\n" ); } } if( option_process_buffer_size != NULL ) { result = verification_handle_set_process_buffer_size( ewfverify_verification_handle, option_process_buffer_size, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set process buffer size.\n" ); goto on_error; } else if( ( result == 0 ) || ( ewfverify_verification_handle->process_buffer_size > (size_t) SSIZE_MAX ) ) { ewfverify_verification_handle->process_buffer_size = 0; fprintf( stderr, "Unsupported process buffer size defaulting to: chunk size.\n" ); } } if( option_number_of_jobs != NULL ) { result = verification_handle_set_number_of_threads( ewfverify_verification_handle, option_number_of_jobs, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set number of jobs (threads).\n" ); goto on_error; } else if( ( result == 0 ) || ( ewfverify_verification_handle->number_of_threads > (int) 32 ) ) { #if defined( HAVE_MULTI_THREAD_SUPPORT ) ewfverify_verification_handle->number_of_threads = 4; #else ewfverify_verification_handle->number_of_threads = 0; #endif fprintf( stderr, "Unsupported number of jobs (threads) defaulting to: %d.\n", ewfverify_verification_handle->number_of_threads ); } } if( option_additional_digest_types != NULL ) { result = verification_handle_set_additional_digest_types( ewfverify_verification_handle, option_additional_digest_types, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set additional digest types.\n" ); goto on_error; } } #if !defined( HAVE_GLOB_H ) if( libcsystem_glob_initialize( &glob, &error ) != 1 ) { fprintf( stderr, "Unable to initialize glob.\n" ); goto on_error; } if( libcsystem_glob_resolve( glob, &( argv[ optind ] ), argc - optind, &error ) != 1 ) { fprintf( stderr, "Unable to resolve glob.\n" ); goto on_error; } if( libcsystem_glob_get_results( glob, &number_of_filenames, (libcstring_system_character_t ***) &source_filenames, &error ) != 1 ) { fprintf( stderr, "Unable to retrieve glob results.\n" ); goto on_error; } #else source_filenames = &( argv[ optind ] ); number_of_filenames = argc - optind; #endif #if defined( HAVE_GETRLIMIT ) if( getrlimit( RLIMIT_NOFILE, &limit_data ) != 0 ) { fprintf( stderr, "Unable to determine limit: number of open file descriptors.\n" ); } if( limit_data.rlim_max > (rlim_t) INT_MAX ) { limit_data.rlim_max = (rlim_t) INT_MAX; } if( limit_data.rlim_max > 0 ) { limit_data.rlim_max /= 2; } if( verification_handle_set_maximum_number_of_open_handles( ewfverify_verification_handle, (int) limit_data.rlim_max, &error ) != 1 ) { fprintf( stderr, "Unable to set maximum number of open file handles.\n" ); goto on_error; } #endif if( libcsystem_signal_attach( ewfverify_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } result = verification_handle_open_input( ewfverify_verification_handle, source_filenames, number_of_filenames, &error ); if( ewfverify_abort != 0 ) { goto on_abort; } if( result != 1 ) { fprintf( stderr, "Unable to open EWF image file(s).\n" ); goto on_error; } #if !defined( HAVE_GLOB_H ) if( libcsystem_glob_free( &glob, &error ) != 1 ) { fprintf( stderr, "Unable to free glob.\n" ); goto on_error; } #endif if( verification_handle_set_zero_chunk_on_error( ewfverify_verification_handle, zero_chunk_on_error, &error ) != 1 ) { fprintf( stderr, "Unable to set zero on chunk error.\n" ); goto on_error; } if( log_filename != NULL ) { if( log_handle_initialize( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to create log handle.\n" ); goto on_error; } if( log_handle_open( log_handle, log_filename, &error ) != 1 ) { fprintf( stderr, "Unable to open log file: %" PRIs_LIBCSTRING_SYSTEM ".\n", log_filename ); goto on_error; } } if( ewfverify_verification_handle->input_format == VERIFICATION_HANDLE_INPUT_FORMAT_FILES ) { result = verification_handle_verify_single_files( ewfverify_verification_handle, print_status_information, log_handle, &error ); if( result != 1 ) { fprintf( stderr, "Unable to verify single files.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } } else { result = verification_handle_verify_input( ewfverify_verification_handle, print_status_information, log_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to verify input.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } } if( log_handle != NULL ) { if( log_handle_close( log_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close log handle.\n" ); goto on_error; } if( log_handle_free( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free log handle.\n" ); goto on_error; } } on_abort: if( libcsystem_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( verification_handle_close( ewfverify_verification_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close verification handle.\n" ); goto on_error; } if( verification_handle_free( &ewfverify_verification_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free verification handle.\n" ); goto on_error; } if( ewfverify_abort != 0 ) { fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": ABORTED\n", program ); return( EXIT_FAILURE ); } if( result != 1 ) { fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": FAILURE\n", program ); return( EXIT_FAILURE ); } fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": SUCCESS\n", program ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_handle != NULL ) { log_handle_close( log_handle, NULL ); log_handle_free( &log_handle, NULL ); } if( ewfverify_verification_handle != NULL ) { verification_handle_close( ewfverify_verification_handle, NULL ); verification_handle_free( &ewfverify_verification_handle, NULL ); } #if !defined( HAVE_GLOB_H ) if( glob != NULL ) { libcsystem_glob_free( &glob, NULL ); } #endif return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; libcstring_system_character_t *option_ascii_codepage = NULL; libcstring_system_character_t *source = NULL; char *program = "evtinfo"; libcstring_system_integer_t option = 0; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "evttools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } evtoutput_version_fprint( stdout, program ); while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "c:hvV" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (libcstring_system_integer_t) 'c': option_ascii_codepage = optarg; break; case (libcstring_system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': evtoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_verbose_set( verbose ); libevt_notify_set_stream( stderr, NULL ); libevt_notify_set_verbose( verbose ); if( info_handle_initialize( &evtinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize info handle.\n" ); goto on_error; } if( option_ascii_codepage != NULL ) { result = info_handle_set_ascii_codepage( evtinfo_info_handle, option_ascii_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set ASCII codepage in info handle.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported ASCII codepage defaulting to: windows-1252.\n" ); } } result = info_handle_set_event_log_type_from_filename( evtinfo_info_handle, source, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set event log type from filename in info handle.\n" ); goto on_error; } if( info_handle_open_input( evtinfo_info_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_LIBCSTRING_SYSTEM ".\n", source ); goto on_error; } if( info_handle_file_fprint( evtinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file information.\n" ); goto on_error; } if( info_handle_close_input( evtinfo_info_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close info handle.\n" ); goto on_error; } if( info_handle_free( &evtinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free info handle.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( evtinfo_info_handle != NULL ) { info_handle_free( &evtinfo_info_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { char destination[ 128 ]; libcerror_error_t *error = NULL; libcfile_file_t *destination_file = NULL; libcfile_file_t *source_file = NULL; system_character_t *source = NULL; uint8_t *buffer = NULL; uint8_t *uncompressed_data = NULL; char *program = "lzvndecompress"; system_integer_t option = 0; size64_t source_size = 0; size_t uncompressed_data_size = 0; ssize_t read_count = 0; ssize_t write_count = 0; off_t source_offset = 0; int print_count = 0; int result = 0; int verbose = 0; assorted_output_version_fprint( stdout, program ); while( ( option = assorted_getopt( argc, argv, _SYSTEM_STRING( "ho:s:vV" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case 'o': source_offset = atol( optarg ); break; case 's': source_size = atol( optarg ); break; case 'v': verbose = 1; break; case 'V': assorted_output_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( verbose ); /* Open the source file */ if( libcfile_file_initialize( &source_file, &error ) != 1 ) { fprintf( stderr, "Unable to create source file.\n" ); goto on_error; } if( libcfile_file_open( source_file, source, LIBCFILE_OPEN_READ, &error ) != 1 ) { fprintf( stderr, "Unable to open source file.\n" ); goto on_error; } if( source_size == 0 ) { if( libcfile_file_get_size( source_file, &source_size, &error ) == -1 ) { fprintf( stderr, "Unable to determine size of source file.\n" ); goto on_error; } } if( source_size == 0 ) { fprintf( stderr, "Invalid source size value is zero.\n" ); goto on_error; } if( source_size > (size64_t) ( SSIZE_MAX / 16 ) ) { fprintf( stderr, "Invalid source size value exceeds maximum.\n" ); goto on_error; } buffer = (uint8_t *) memory_allocate( sizeof( uint8_t ) * source_size ); if( buffer == NULL ) { fprintf( stderr, "Unable to create buffer.\n" ); goto on_error; } uncompressed_data_size = source_size * 16; uncompressed_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * uncompressed_data_size ); if( uncompressed_data == NULL ) { fprintf( stderr, "Unable to create uncompressed data buffer.\n" ); goto on_error; } /* Position the source file at the right offset */ if( libcfile_file_seek_offset( source_file, source_offset, SEEK_SET, &error ) == -1 ) { fprintf( stderr, "Unable to seek offset in source file.\n" ); goto on_error; } print_count = narrow_string_snprintf( destination, 128, "%s.lzvndecompressed", source ); if( ( print_count < 0 ) || ( print_count > 128 ) ) { fprintf( stderr, "Unable to set destination filename.\n" ); goto on_error; } /* Read and decompress the data */ read_count = libcfile_file_read_buffer( source_file, buffer, source_size, &error ); if( read_count != (ssize_t) source_size ) { fprintf( stderr, "Unable to read from source file.\n" ); goto on_error; } if( lzvn_decompress( buffer, source_size, uncompressed_data, &uncompressed_data_size, &error ) != 1 ) { fprintf( stderr, "Unable to decompress data.\n" ); goto on_error; } /* Open the destination file */ if( libcfile_file_initialize( &destination_file, &error ) != 1 ) { fprintf( stderr, "Unable to create destination file.\n" ); goto on_error; } if( libcfile_file_open( destination_file, destination, LIBCFILE_OPEN_WRITE, &error ) != 1 ) { fprintf( stderr, "Unable to open destination file.\n" ); goto on_error; } write_count = libcfile_file_write_buffer( destination_file, uncompressed_data, uncompressed_data_size, &error ); if( write_count != (ssize_t) uncompressed_data_size ) { fprintf( stderr, "Unable to write to destination file.\n" ); goto on_error; } /* Clean up */ if( libcfile_file_close( destination_file, &error ) != 0 ) { fprintf( stderr, "Unable to close destination file.\n" ); goto on_error; } if( libcfile_file_free( &destination_file, &error ) != 1 ) { fprintf( stderr, "Unable to free destination file.\n" ); goto on_error; } if( libcfile_file_close( source_file, &error ) != 0 ) { fprintf( stderr, "Unable to close source file.\n" ); goto on_error; } if( libcfile_file_free( &source_file, &error ) != 1 ) { fprintf( stderr, "Unable to free source file.\n" ); goto on_error; } memory_free( uncompressed_data ); memory_free( buffer ); if( result == -1 ) { fprintf( stdout, "LZVN decompression:\tFAILURE\n" ); return( EXIT_FAILURE ); } fprintf( stdout, "LZVN decompression:\tSUCCESS\n" ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( destination_file != NULL ) { libcfile_file_free( &destination_file, NULL ); } if( uncompressed_data != NULL ) { memory_free( uncompressed_data ); } if( buffer != NULL ) { memory_free( buffer ); } if( source_file != NULL ) { libcfile_file_free( &source_file, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libfvde_error_t *error = NULL; libcstring_system_character_t *encrypted_root_plist_filename = NULL; libcstring_system_character_t *volume_key_data = NULL; char *program = "fvdewipekey"; libcstring_system_integer_t option = 0; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "fvdetools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } fvdeoutput_version_fprint( stdout, program ); while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "hvV" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (libcstring_system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': fvdeoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing name of the EncryptedRoot.plist.wipekey file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } encrypted_root_plist_filename = argv[ optind++ ]; if( optind == argc ) { fprintf( stderr, "Missing volume key data.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } volume_key_data = argv[ optind ]; libcnotify_verbose_set( verbose ); libfvde_notify_set_stream( stderr, NULL ); libfvde_notify_set_verbose( verbose ); if( wipekey_handle_initialize( &fvdewipekey_wipekey_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize wipekey handle.\n" ); goto on_error; } if( wipekey_handle_set_volume_key_data( fvdewipekey_wipekey_handle, volume_key_data, &error ) != 1 ) { fprintf( stderr, "Unable to set volume key data.\n" ); goto on_error; } result = wipekey_handle_open_input( fvdewipekey_wipekey_handle, encrypted_root_plist_filename, &error ); if( result == -1 ) { fprintf( stderr, "Unable to open: %" PRIs_LIBCSTRING_SYSTEM ".\n", encrypted_root_plist_filename ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unable to unlock EncryptedRoot.plist.wipekey.\n" ); goto on_error; } if( wipekey_handle_wipekey_fprint( fvdewipekey_wipekey_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print decrypted EncryptedRoot.plist.wipekey.\n" ); goto on_error; } if( wipekey_handle_close_input( fvdewipekey_wipekey_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close wipekey handle.\n" ); goto on_error; } if( wipekey_handle_free( &fvdewipekey_wipekey_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free wipekey handle.\n" ); goto on_error; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( fvdewipekey_wipekey_handle != NULL ) { wipekey_handle_free( &fvdewipekey_wipekey_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; log_handle_t *log_handle = NULL; system_character_t *option_ascii_codepage = NULL; system_character_t *option_event_log_type = NULL; system_character_t *option_export_format = NULL; system_character_t *option_export_mode = NULL; system_character_t *option_log_filename = NULL; system_character_t *option_resource_files_path = NULL; system_character_t *option_preferred_language = NULL; system_character_t *option_registry_directory_name = NULL; system_character_t *option_software_registry_filename = NULL; system_character_t *option_system_registry_filename = NULL; system_character_t *source = NULL; char *program = "evtxexport"; system_integer_t option = 0; int result = 0; int use_template_definition = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "evtxtools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( evtxtools_output_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } evtxoutput_version_fprint( stdout, program ); while( ( option = evtxtools_getopt( argc, argv, _SYSTEM_STRING( "c:f:hl:m:p:r:s:S:t:TvV" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM "\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (system_integer_t) 'c': option_ascii_codepage = optarg; break; case (system_integer_t) 'f': option_export_format = optarg; break; case (system_integer_t) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'l': option_log_filename = optarg; break; case (system_integer_t) 'm': option_export_mode = optarg; break; case (system_integer_t) 'p': option_resource_files_path = optarg; break; case (system_integer_t) 'r': option_registry_directory_name = optarg; break; case (system_integer_t) 's': option_system_registry_filename = optarg; break; case (system_integer_t) 'S': option_software_registry_filename = optarg; break; case (system_integer_t) 't': option_event_log_type = optarg; break; case (system_integer_t) 'T': use_template_definition = 1; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': evtxoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { fprintf( stderr, "Missing source file.\n" ); usage_fprint( stdout ); return( EXIT_FAILURE ); } source = argv[ optind ]; libcnotify_verbose_set( verbose ); libevtx_notify_set_stream( stderr, NULL ); libevtx_notify_set_verbose( verbose ); if( log_handle_initialize( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize log handle.\n" ); goto on_error; } if( export_handle_initialize( &evtxexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize export handle.\n" ); goto on_error; } if( option_ascii_codepage != NULL ) { result = export_handle_set_ascii_codepage( evtxexport_export_handle, option_ascii_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set ASCII codepage in export handle.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported ASCII codepage defaulting to: windows-1252.\n" ); } } if( option_event_log_type != NULL ) { result = export_handle_set_event_log_type( evtxexport_export_handle, option_event_log_type, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set event log type in export handle.\n" ); goto on_error; } } if( option_export_format != NULL ) { result = export_handle_set_export_format( evtxexport_export_handle, option_export_format, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set export format.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported export format defaulting to: text.\n" ); } } if( option_export_mode != NULL ) { result = export_handle_set_export_mode( evtxexport_export_handle, option_export_mode, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set export mode.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported export mode defaulting to: items.\n" ); } } if( ( option_event_log_type == NULL ) || ( result == 0 ) ) { result = export_handle_set_event_log_type_from_filename( evtxexport_export_handle, source, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set event log type from filename in export handle.\n" ); goto on_error; } } if( option_resource_files_path != NULL ) { if( export_handle_set_resource_files_path( evtxexport_export_handle, option_resource_files_path, &error ) != 1 ) { fprintf( stderr, "Unable to set resource files path in export handle.\n" ); goto on_error; } } if( option_software_registry_filename != NULL ) { if( export_handle_set_software_registry_filename( evtxexport_export_handle, option_software_registry_filename, &error ) != 1 ) { fprintf( stderr, "Unable to set software registry filename in export handle.\n" ); goto on_error; } } if( option_system_registry_filename != NULL ) { if( export_handle_set_system_registry_filename( evtxexport_export_handle, option_system_registry_filename, &error ) != 1 ) { fprintf( stderr, "Unable to set system registry filename in export handle.\n" ); goto on_error; } } if( option_registry_directory_name != NULL ) { if( export_handle_set_registry_directory_name( evtxexport_export_handle, option_registry_directory_name, &error ) != 1 ) { fprintf( stderr, "Unable to set registry directory name in export handle.\n" ); goto on_error; } } if( option_preferred_language != NULL ) { /* TODO set preferred language identifier from input */ if( export_handle_set_preferred_language_identifier( evtxexport_export_handle, 0x0409, &error ) != 1 ) { fprintf( stderr, "Unable to set preferred language identifier in export handle.\n" ); goto on_error; } } evtxexport_export_handle->use_template_definition = use_template_definition; evtxexport_export_handle->verbose = verbose; if( log_handle_open( log_handle, option_log_filename, &error ) != 1 ) { fprintf( stderr, "Unable to open log file: %" PRIs_SYSTEM ".\n", option_log_filename ); goto on_error; } if( export_handle_open_input( evtxexport_export_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_SYSTEM ".\n", source ); goto on_error; } result = export_handle_export_file( evtxexport_export_handle, log_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to export file.\n" ); goto on_error; } if( export_handle_close_input( evtxexport_export_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close export handle.\n" ); goto on_error; } if( export_handle_free( &evtxexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free export handle.\n" ); goto on_error; } if( log_handle_close( log_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close log handle.\n" ); goto on_error; } if( log_handle_free( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free log handle.\n" ); goto on_error; } if( result == 0 ) { fprintf( stdout, "No records to export.\n" ); } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( evtxexport_export_handle != NULL ) { export_handle_free( &evtxexport_export_handle, NULL ); } if( log_handle != NULL ) { log_handle_free( &log_handle, NULL ); } return( EXIT_FAILURE ); }
int main( int argc, char * const argv[] ) #endif { #if defined( HAVE_GETRLIMIT ) struct rlimit limit_data; #endif system_character_t acquiry_operating_system[ 32 ]; system_character_t * const *source_filenames = NULL; libcerror_error_t *error = NULL; log_handle_t *log_handle = NULL; system_character_t *acquiry_software_version = NULL; system_character_t *log_filename = NULL; system_character_t *option_header_codepage = NULL; system_character_t *option_process_buffer_size = NULL; system_character_t *option_target_path = NULL; system_character_t *program = _SYSTEM_STRING( "ewfrecover" ); system_integer_t option = 0; uint8_t calculate_md5 = 1; uint8_t print_status_information = 1; uint8_t use_chunk_data_functions = 0; uint8_t verbose = 0; int number_of_filenames = 0; int result = 1; #if !defined( HAVE_GLOB_H ) ewftools_glob_t *glob = NULL; #endif libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "ewftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( ewftools_output_initialize( _IONBF, &error ) != 1 ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } #if defined( WINAPI ) && !defined( __CYGWIN__ ) #if defined( _MSC_VER ) if( _setmode( _fileno( stdout ), _O_BINARY ) == -1 ) #else if( setmode( _fileno( stdout ), _O_BINARY ) == -1 ) #endif { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Unable to set stdout to binary mode.\n" ); usage_fprint( stdout ); goto on_error; } #endif while( ( option = ewftools_getopt( argc, argv, _SYSTEM_STRING( "A:f:hl:p:qt:vVx" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM ".\n", argv[ optind ] ); usage_fprint( stderr ); goto on_error; case (system_integer_t) 'A': option_header_codepage = optarg; break; case (system_integer_t) 'h': ewftools_output_version_fprint( stderr, program ); usage_fprint( stderr ); return( EXIT_SUCCESS ); case (system_integer_t) 'l': log_filename = optarg; break; case (system_integer_t) 'p': option_process_buffer_size = optarg; break; case (system_integer_t) 'q': print_status_information = 0; break; case (system_integer_t) 't': option_target_path = optarg; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': ewftools_output_version_fprint( stderr, program ); ewftools_output_copyright_fprint( stderr ); return( EXIT_SUCCESS ); case (system_integer_t) 'x': use_chunk_data_functions = 1; break; } } if( optind == argc ) { ewftools_output_version_fprint( stderr, program ); fprintf( stderr, "Missing EWF image file(s).\n" ); usage_fprint( stderr ); goto on_error; } ewftools_output_version_fprint( stderr, program ); libcnotify_verbose_set( verbose ); #if !defined( HAVE_LOCAL_LIBEWF ) libewf_notify_set_verbose( verbose ); libewf_notify_set_stream( stderr, NULL ); #endif #if !defined( HAVE_GLOB_H ) if( ewftools_glob_initialize( &glob, &error ) != 1 ) { fprintf( stderr, "Unable to initialize glob.\n" ); goto on_error; } if( ewftools_glob_resolve( glob, &( argv[ optind ] ), argc - optind, &error ) != 1 ) { fprintf( stderr, "Unable to resolve glob.\n" ); goto on_error; } if( ewftools_glob_get_results( glob, &number_of_filenames, (system_character_t ***) &source_filenames, &error ) != 1 ) { fprintf( stderr, "Unable to retrieve glob results.\n" ); goto on_error; } #else source_filenames = &( argv[ optind ] ); number_of_filenames = argc - optind; #endif if( export_handle_initialize( &ewfrecover_export_handle, calculate_md5, use_chunk_data_functions, &error ) != 1 ) { fprintf( stderr, "Unable to create export handle.\n" ); goto on_error; } #if defined( HAVE_GETRLIMIT ) if( getrlimit( RLIMIT_NOFILE, &limit_data ) != 0 ) { fprintf( stderr, "Unable to determine limit: number of open file descriptors.\n" ); } if( limit_data.rlim_max > (rlim_t) INT_MAX ) { limit_data.rlim_max = (rlim_t) INT_MAX; } if( limit_data.rlim_max > 0 ) { limit_data.rlim_max /= 2; } if( export_handle_set_maximum_number_of_open_handles( ewfrecover_export_handle, (int) limit_data.rlim_max, &error ) != 1 ) { fprintf( stderr, "Unable to set maximum number of open file handles.\n" ); goto on_error; } #endif if( ewftools_signal_attach( ewfrecover_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } result = export_handle_open_input( ewfrecover_export_handle, source_filenames, number_of_filenames, &error ); if( ewfrecover_abort != 0 ) { goto on_abort; } if( result != 1 ) { fprintf( stderr, "Unable to open EWF file(s).\n" ); goto on_error; } #if !defined( HAVE_GLOB_H ) if( ewftools_glob_free( &glob, &error ) != 1 ) { fprintf( stderr, "Unable to free glob.\n" ); goto on_error; } #endif result = export_handle_input_is_corrupted( ewfrecover_export_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to determine if EWF file(s) are corrupted.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "EWF file(s) are not corrupted.\n" ); goto on_error; } ewfrecover_export_handle->output_format = EXPORT_HANDLE_OUTPUT_FORMAT_EWF; ewfrecover_export_handle->export_size = ewfrecover_export_handle->input_media_size; if( option_header_codepage != NULL ) { result = export_handle_set_header_codepage( ewfrecover_export_handle, option_header_codepage, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set header codepage.\n" ); goto on_error; } else if( result == 0 ) { fprintf( stderr, "Unsupported header codepage defaulting to: ascii.\n" ); } } if( option_target_path != NULL ) { if( export_handle_set_string( ewfrecover_export_handle, option_target_path, &( ewfrecover_export_handle->target_path ), &( ewfrecover_export_handle->target_path_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set target path.\n" ); goto on_error; } } else { /* Make sure the target filename is set */ if( export_handle_set_string( ewfrecover_export_handle, _SYSTEM_STRING( "recover" ), &( ewfrecover_export_handle->target_path ), &( ewfrecover_export_handle->target_path_size ), &error ) != 1 ) { fprintf( stderr, "Unable to set target filename.\n" ); goto on_error; } } /* Make sure we can write the target file */ if( export_handle_check_write_access( ewfrecover_export_handle, ewfrecover_export_handle->target_path, &error ) != 1 ) { #if defined( HAVE_VERBOSE_OUTPUT ) libcnotify_print_error_backtrace( error ); #endif libcerror_error_free( &error ); fprintf( stdout, "Unable to write target file.\n" ); goto on_error; } if( option_process_buffer_size != NULL ) { result = export_handle_set_process_buffer_size( ewfrecover_export_handle, option_process_buffer_size, &error ); if( result == -1 ) { fprintf( stderr, "Unable to set process buffer size.\n" ); goto on_error; } else if( ( result == 0 ) || ( ewfrecover_export_handle->process_buffer_size > (size_t) SSIZE_MAX ) ) { ewfrecover_export_handle->process_buffer_size = 0; fprintf( stderr, "Unsupported process buffer size defaulting to: chunk size.\n" ); } } /* Initialize values */ if( log_filename != NULL ) { if( log_handle_initialize( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to create log handle.\n" ); goto on_error; } if( log_handle_open( log_handle, log_filename, &error ) != 1 ) { fprintf( stderr, "Unable to open log file: %" PRIs_SYSTEM ".\n", log_filename ); goto on_error; } } if( export_handle_open_output( ewfrecover_export_handle, ewfrecover_export_handle->target_path, &error ) != 1 ) { fprintf( stderr, "Unable to open output.\n" ); goto on_error; } if( platform_get_operating_system( acquiry_operating_system, 32, &error ) != 1 ) { fprintf( stderr, "Unable to determine operating system.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); acquiry_operating_system[ 0 ] = 0; } acquiry_software_version = _SYSTEM_STRING( LIBEWF_VERSION_STRING ); if( export_handle_set_output_values( ewfrecover_export_handle, acquiry_operating_system, program, acquiry_software_version, 0, 1, &error ) != 1 ) { fprintf( stderr, "Unable to set output values.\n" ); goto on_error; } result = export_handle_export_input( ewfrecover_export_handle, 0, print_status_information, log_handle, &error ); if( result != 1 ) { fprintf( stderr, "Unable to recover input.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_handle != NULL ) { if( log_handle_close( log_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close log file: %" PRIs_SYSTEM ".\n", log_filename ); goto on_error; } if( log_handle_free( &log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free log handle.\n" ); goto on_error; } } on_abort: if( export_handle_close( ewfrecover_export_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close export handle.\n" ); goto on_error; } if( ewftools_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( export_handle_free( &ewfrecover_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free export handle.\n" ); goto on_error; } if( ewfrecover_abort != 0 ) { fprintf( stdout, "%" PRIs_SYSTEM ": ABORTED\n", program ); return( EXIT_FAILURE ); } if( result != 1 ) { fprintf( stdout, "%" PRIs_SYSTEM ": FAILURE\n", program ); return( EXIT_FAILURE ); } fprintf( stdout, "%" PRIs_SYSTEM ": SUCCESS\n", program ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( log_handle != NULL ) { log_handle_close( log_handle, NULL ); log_handle_free( &log_handle, NULL ); } if( ewfrecover_export_handle != NULL ) { export_handle_close( ewfrecover_export_handle, NULL ); export_handle_free( &ewfrecover_export_handle, NULL ); } #if !defined( HAVE_GLOB_H ) if( glob != NULL ) { ewftools_glob_free( &glob, NULL ); } #endif return( EXIT_FAILURE ); }
/* Scans for the event record and adds them to the recovered records array * Returns 1 if successful, 0 if not or -1 on error */ int libevt_io_handle_event_record_scan( libevt_io_handle_t *io_handle, libbfio_handle_t *file_io_handle, off64_t file_offset, size64_t size, libfdata_list_t *recovered_records_list, libcerror_error_t **error ) { libevt_record_values_t *record_values = NULL; uint8_t *scan_block = NULL; static char *function = "libevt_io_handle_event_record_scan"; off64_t record_offset = 0; size_t read_size = 0; size_t scan_block_offset = 0; size_t scan_block_size = 8192; ssize_t read_count = 0; int element_index = 0; if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } if( file_offset < 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, "%s: invalid file offset value less than zero.", function ); return( -1 ); } if( size > (off64_t) INT64_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid size value exceeds maximum.", function ); return( -1 ); } scan_block = (uint8_t *) memory_allocate( sizeof( uint8_t ) * scan_block_size ); if( scan_block == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create scan block.", function ); goto on_error; } while( size > 0 ) { if( libbfio_handle_seek_offset( file_io_handle, file_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek scan block offset: %" PRIi64 ".", function, file_offset ); goto on_error; } if( scan_block_size > size ) { read_size = (size_t) size; } else { read_size = scan_block_size; } read_count = libbfio_handle_read_buffer( file_io_handle, scan_block, read_size, error ); if( read_count != (ssize_t) read_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read scan block at offset: %" PRIi64 ".", function, file_offset ); goto on_error; } scan_block_offset = 0; while( scan_block_offset < read_size ) { if( memory_compare( &( scan_block[ scan_block_offset ] ), evt_file_signature, 4 ) != 0 ) { scan_block_offset += 4; continue; } record_offset = file_offset + scan_block_offset - 4; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reading recovered record at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, record_offset, record_offset ); } #endif if( libbfio_handle_seek_offset( file_io_handle, record_offset, SEEK_SET, error ) == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek record offset: %" PRIi64 ".", function, record_offset ); goto on_error; } if( record_values == NULL ) { if( libevt_record_values_initialize( &record_values, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create record values.", function ); goto on_error; } } read_count = libevt_record_values_read( record_values, file_io_handle, io_handle, &record_offset, 0, error ); if( read_count == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read record at offset: %" PRIi64 ".", function, record_offset ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( error != NULL ) && ( *error != NULL ) ) { libcnotify_print_error_backtrace( *error ); } } #endif libcerror_error_free( error ); scan_block_offset += 4; continue; } if( record_values->type == LIBEVT_RECORD_TYPE_EVENT ) { if( libfdata_list_append_element( recovered_records_list, &element_index, 0, file_offset + scan_block_offset - 4, (size64_t) read_count, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, "%s: unable to append recovered record to records list.", function ); goto on_error; } } if( libevt_record_values_free( &record_values, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free record values.", function ); goto on_error; } scan_block_offset += read_count - 4; if( ( scan_block_offset + read_count - 4 ) > read_size ) { break; } } file_offset += scan_block_offset; size -= scan_block_offset; } if( record_values != NULL ) { if( libevt_record_values_free( &record_values, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free record values.", function ); goto on_error; } } memory_free( scan_block ); scan_block = NULL; return( 1 ); on_error: if( record_values != NULL ) { libevt_record_values_free( &record_values, NULL ); } if( scan_block != NULL ) { memory_free( scan_block ); } return( -1 ); }
int main( int argc, char * const argv[] ) #endif { #if !defined( HAVE_GLOB_H ) libcsystem_glob_t *glob = NULL; #endif libcerror_error_t *error = NULL; libcstring_system_character_t * const *source_filenames = NULL; libcstring_system_character_t **ewf_filenames = NULL; libcstring_system_character_t *option_header_codepage = NULL; libcstring_system_character_t *program = _LIBCSTRING_SYSTEM_STRING( "ewfdebug" ); libcstring_system_integer_t option = 0; size_t first_filename_length = 0; uint8_t verbose = 0; int number_of_filenames = 0; int header_codepage = LIBEWF_CODEPAGE_ASCII; int result = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "ewftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( libcsystem_initialize( _IONBF, &error ) != 1 ) { ewfoutput_version_fprint( stdout, program ); fprintf( stderr, "Unable to initialize system values.\n" ); goto on_error; } while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "A:hqvV" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: ewfoutput_version_fprint( stdout, program ); fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM ".\n", argv[ optind - 1 ] ); usage_fprint( stdout ); return( EXIT_FAILURE ); case (libcstring_system_integer_t) 'A': option_header_codepage = optarg; break; case (libcstring_system_integer_t) 'h': ewfoutput_version_fprint( stdout, program ); usage_fprint( stdout ); return( EXIT_SUCCESS ); case (libcstring_system_integer_t) 'q': break; case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': ewfoutput_version_fprint( stdout, program ); ewfoutput_copyright_fprint( stdout ); return( EXIT_SUCCESS ); } } if( optind == argc ) { ewfoutput_version_fprint( stdout, program ); fprintf( stderr, "Missing EWF image file(s).\n" ); usage_fprint( stdout ); goto on_error; } ewfoutput_version_fprint( stdout, program ); libcnotify_verbose_set( verbose ); #if !defined( HAVE_LOCAL_LIBEWF ) libewf_notify_set_verbose( verbose ); libewf_notify_set_stream( stderr, NULL ); #endif if( option_header_codepage != NULL ) { if( ewfinput_determine_header_codepage( option_header_codepage, &header_codepage, &error ) != 1 ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); fprintf( stderr, "Unsupported header codepage defaulting to: ascii.\n" ); header_codepage = LIBEWF_CODEPAGE_ASCII; } } if( libcsystem_signal_attach( ewfdebug_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } #if !defined( HAVE_GLOB_H ) if( libcsystem_glob_initialize( &glob, &error ) != 1 ) { fprintf( stderr, "Unable to initialize glob.\n" ); goto on_error; } if( libcsystem_glob_resolve( glob, &( argv[ optind ] ), argc - optind, &error ) != 1 ) { fprintf( stderr, "Unable to resolve glob.\n" ); goto on_error; } source_filenames = glob->result; number_of_filenames = glob->number_of_results; #else source_filenames = &( argv[ optind ] ); number_of_filenames = argc - optind; #endif if( number_of_filenames == 1 ) { first_filename_length = libcstring_system_string_length( source_filenames[ 0 ] ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libewf_glob_wide( source_filenames[ 0 ], first_filename_length, LIBEWF_FORMAT_UNKNOWN, &ewf_filenames, &number_of_filenames, &error ) != 1 ) #else if( libewf_glob( source_filenames[ 0 ], first_filename_length, LIBEWF_FORMAT_UNKNOWN, &ewf_filenames, &number_of_filenames, &error ) != 1 ) #endif { fprintf( stderr, "Unable to resolve ewf file(s).\n" ); goto on_error; } source_filenames = (libcstring_system_character_t * const *) ewf_filenames; } if( libewf_handle_initialize( &ewfdebug_input_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize input handle.\n" ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libewf_handle_open_wide( ewfdebug_input_handle, source_filenames, number_of_filenames, LIBEWF_OPEN_READ, &error ); #else result = libewf_handle_open( ewfdebug_input_handle, source_filenames, number_of_filenames, LIBEWF_OPEN_READ, &error ); #endif #if !defined( HAVE_GLOB_H ) if( libcsystem_glob_free( &glob, &error ) != 1 ) { fprintf( stderr, "Unable to free glob.\n" ); goto on_error; } #endif if( ewf_filenames != NULL ) { for( ; number_of_filenames > 0; number_of_filenames-- ) { memory_free( ewf_filenames[ number_of_filenames - 1 ] ); } memory_free( ewf_filenames ); } if( ( ewfdebug_abort == 0 ) && ( result != 1 ) ) { fprintf( stderr, "Unable to open EWF file(s).\n" ); libewf_handle_close( ewfdebug_input_handle, NULL ); libewf_handle_free( &ewfdebug_input_handle, NULL ); return( EXIT_FAILURE ); } /* TODO */ if( libewf_handle_close( ewfdebug_input_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close EWF file(s).\n" ); libewf_handle_free( &ewfdebug_input_handle, NULL ); return( EXIT_FAILURE ); } if( libewf_handle_free( &ewfdebug_input_handle, &error ) != 1 ) { fprintf( stderr, "Unable to free input handle.\n" ); return( EXIT_FAILURE ); } if( libcsystem_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( ewfdebug_abort != 0 ) { fprintf( stdout, "%" PRIs_LIBCSTRING_SYSTEM ": ABORTED\n", program ); return( EXIT_FAILURE ); } fprintf( stdout, "Debug completed.\n" ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } #if !defined( HAVE_GLOB_H ) if( glob != NULL ) { libcsystem_glob_free( &glob, NULL ); } #endif return( EXIT_FAILURE ); }