int main( int argc, char * const argv[] ) #endif { libcstring_system_character_t *source = NULL; libcstring_system_integer_t option = 0; while( ( option = libcsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "" ) ) ) != (libcstring_system_integer_t) -1 ) { switch( option ) { case (libcstring_system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_LIBCSTRING_SYSTEM ".\n", argv[ optind - 1 ] ); return( EXIT_FAILURE ); } } if( optind == argc ) { fprintf( stderr, "Missing source file or device.\n" ); return( EXIT_FAILURE ); } source = argv[ optind ]; #if defined( HAVE_DEBUG_OUTPUT ) && defined( PFF_TEST_OPEN_CLOSE_VERBOSE ) libpff_notify_set_verbose( 1 ); libpff_notify_set_stream( stderr, NULL ); #endif /* Case 0: single open and close of a file using filename */ fprintf( stdout, "Testing single open close of: %s with access: read\t", source ); if( pff_test_single_open_close_file( source, LIBPFF_OPEN_READ, 1 ) != 1 ) { fprintf( stderr, "Unable to test single open close.\n" ); return( EXIT_FAILURE ); } fprintf( stdout, "Testing single open close of: NULL with access: read\t" ); if( pff_test_single_open_close_file( NULL, LIBPFF_OPEN_READ, -1 ) != 1 ) { fprintf( stderr, "Unable to test single open close.\n" ); return( EXIT_FAILURE ); } fprintf( stdout, "Testing single open close of: %s with access: write\t", source ); if( pff_test_single_open_close_file( source, LIBPFF_OPEN_WRITE, -1 ) != 1 ) { fprintf( stderr, "Unable to test single open close.\n" ); return( EXIT_FAILURE ); } /* Case 1: multiple open and close of a file using filename */ fprintf( stdout, "Testing multi open close of: %s with access: read\t", source ); if( pff_test_multi_open_close_file( source, LIBPFF_OPEN_READ, 1 ) != 1 ) { fprintf( stderr, "Unable to test multi open close.\n" ); return( EXIT_FAILURE ); } return( EXIT_SUCCESS ); }
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 = "pffinfo"; 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( "pfftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( pfftools_output_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } pfftools_output_version_fprint( stdout, program ); while( ( option = pfftools_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': pfftools_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 ); libpff_notify_set_stream( stderr, NULL ); libpff_notify_set_verbose( verbose ); if( info_handle_initialize( &pffinfo_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( pffinfo_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" ); } } /* TODO if( pfftools_signal_attach( pffinfo_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } */ if( info_handle_open_input( pffinfo_info_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_SYSTEM ".\n", source ); goto on_error; } if( info_handle_file_fprint( pffinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file information.\n" ); goto on_error; } if( info_handle_message_store_fprint( pffinfo_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( pffinfo_info_handle, &error ) != 1 ) { fprintf( stderr, "Unable to print file unallocated blocks.\n" ); goto on_error; } } /* TODO if( pfftools_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } */ if( info_handle_close( pffinfo_info_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close info handle.\n" ); goto on_error; } if( info_handle_free( &pffinfo_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( pffinfo_info_handle != NULL ) { info_handle_close( pffinfo_info_handle, NULL ); info_handle_free( &pffinfo_info_handle, NULL ); } 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 ); }