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 *log_filename = NULL; system_character_t *source = NULL; char *program = "regfexport"; size_t source_length = 0; system_integer_t option = 0; int result = 0; int verbose = 0; libcnotify_stream_set( stderr, NULL ); libcnotify_verbose_set( 1 ); if( libclocale_initialize( "regftools", &error ) != 1 ) { fprintf( stderr, "Unable to initialize locale values.\n" ); goto on_error; } if( regftools_output_initialize( _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize output settings.\n" ); goto on_error; } regftools_output_version_fprint( stdout, program ); while( ( option = regftools_getopt( argc, argv, _SYSTEM_STRING( "c:hl:vV" ) ) ) != (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) 'h': usage_fprint( stdout ); return( EXIT_SUCCESS ); case (system_integer_t) 'l': log_filename = optarg; break; case (system_integer_t) 'v': verbose = 1; break; case (system_integer_t) 'V': regftools_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 ); libregf_notify_set_stream( stderr, NULL ); libregf_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( ®fexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize export 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( option_ascii_codepage != NULL ) { result = export_handle_set_ascii_codepage( regfexport_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_open_input( regfexport_export_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_SYSTEM ".\n", source ); goto on_error; } if( export_handle_export_file( regfexport_export_handle, log_handle, &error ) != 1 ) { fprintf( stderr, "Unable to export file.\n" ); goto on_error; } if( export_handle_close_input( regfexport_export_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close export handle.\n" ); goto on_error; } if( export_handle_free( ®fexport_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; } return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } if( regfexport_export_handle != NULL ) { export_handle_free( ®fexport_export_handle, NULL ); } if( log_handle != NULL ) { log_handle_free( &log_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 { 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_table_name = NULL; libcstring_system_character_t *option_target_path = NULL; libcstring_system_character_t *path_separator = NULL; libcstring_system_character_t *source = NULL; liberror_error_t *error = NULL; log_handle_t *log_handle = NULL; char *program = "esedbexport"; size_t source_length = 0; size_t option_table_name_length = 0; libcstring_system_integer_t option = 0; int result = 0; int verbose = 0; libsystem_notify_set_stream( stderr, NULL ); libsystem_notify_set_verbose( 1 ); if( libsystem_initialize( "esedbtools", _IONBF, &error ) != 1 ) { fprintf( stderr, "Unable to initialize system values.\n" ); libsystem_notify_print_error_backtrace( error ); liberror_error_free( &error ); return( EXIT_FAILURE ); } esedboutput_version_fprint( stdout, program ); while( ( option = libsystem_getopt( argc, argv, _LIBCSTRING_SYSTEM_STRING( "c:hl:m:t: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) 'm': option_export_mode = optarg; break; case (libcstring_system_integer_t) 't': option_target_path = optarg; break; case (libcstring_system_integer_t) 'T': option_table_name = optarg; break; case (libcstring_system_integer_t) 'v': verbose = 1; break; case (libcstring_system_integer_t) 'V': esedboutput_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) LIBSYSTEM_PATH_SEPARATOR, source_length ); if( path_separator == NULL ) { path_separator = source; } else { path_separator++; } option_target_path = path_separator; } if( option_table_name != NULL ) { option_table_name_length = libcstring_system_string_length( option_table_name ); } libsystem_notify_set_verbose( verbose ); libesedb_notify_set_stream( stderr, NULL ); libesedb_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( &esedbexport_export_handle, &error ) != 1 ) { fprintf( stderr, "Unable to initialize export handle.\n" ); goto on_error; } /* TODO esedbexport_export_handle->print_status_information = print_status_information; */ if( option_export_mode != NULL ) { result = export_handle_set_export_mode( esedbexport_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: tables.\n" ); } } if( option_ascii_codepage != NULL ) { result = export_handle_set_ascii_codepage( esedbexport_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( esedbexport_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( esedbexport_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", esedbexport_export_handle->items_export_path ); 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; } fprintf( stdout, "Opening file.\n" ); #ifdef TODO_SIGNAL_ABORT if( libsystem_signal_attach( esedbexport_signal_handler, &error ) != 1 ) { fprintf( stderr, "Unable to attach signal handler.\n" ); libsystem_notify_print_error_backtrace( error ); liberror_error_free( &error ); } #endif if( export_handle_open( esedbexport_export_handle, source, &error ) != 1 ) { fprintf( stderr, "Unable to open: %" PRIs_LIBCSTRING_SYSTEM ".\n", source ); goto on_error; } /* TODO fprintf( stdout, "Exporting aliases.\n" ); */ result = export_handle_export_file( esedbexport_export_handle, option_table_name, option_table_name_length, log_handle, &error ); if( result == -1 ) { fprintf( stderr, "Unable to export file.\n" ); goto on_error; } #ifdef TODO_SIGNAL_ABORT if( libsystem_signal_detach( &error ) != 1 ) { fprintf( stderr, "Unable to detach signal handler.\n" ); libsystem_notify_print_error_backtrace( error ); liberror_error_free( &error ); } #endif if( export_handle_close( esedbexport_export_handle, &error ) != 0 ) { fprintf( stderr, "Unable to close export handle.\n" ); goto on_error; } if( export_handle_free( &esedbexport_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( esedbexport_abort != 0 ) { fprintf( stdout, "Export aborted.\n" ); return( EXIT_FAILURE ); } /* TODO export FAILED ? */ fprintf( stdout, "Export completed.\n" ); return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libsystem_notify_print_error_backtrace( error ); liberror_error_free( &error ); } if( esedbexport_export_handle != NULL ) { export_handle_free( &esedbexport_export_handle, NULL ); } if( log_handle != NULL ) { log_handle_free( &log_handle, NULL ); } return( EXIT_FAILURE ); }
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 ); }
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 ); }