/* Prints the version information to a stream */ void ewfoutput_version_fprint( FILE *stream, const libcstring_system_character_t *program ) { static char *function = "ewfoutput_version_fprint"; if( stream == NULL ) { libsystem_notify_printf( "%s: invalid stream.\n", function ); return; } if( program == NULL ) { libsystem_notify_printf( "%s: invalid program name.\n", function ); return; } fprintf( stream, "%" PRIs_LIBCSTRING_SYSTEM " %s\n\n", program, LIBEWF_VERSION_STRING ); }
/* Signal handler for esedbinfo */ void esedbinfo_signal_handler( libsystem_signal_t signal ) { liberror_error_t *error = NULL; static char *function = "esedbinfo_signal_handler"; esedbinfo_abort = 1; if( esedbinfo_info_handle != NULL ) { if( info_handle_signal_abort( esedbinfo_info_handle, &error ) != 1 ) { libsystem_notify_printf( "%s: unable to signal info handle to abort.\n", function ); libsystem_notify_print_error_backtrace( error ); liberror_error_free( &error ); } } /* Force stdin to close otherwise any function reading it will remain blocked */ if( libsystem_file_io_close( 0 ) != 0 ) { libsystem_notify_printf( "%s: unable to close stdin.\n", function ); } }
/* Signal handler for ewfinfo */ void ewfinfo_signal_handler( libsystem_signal_t signal LIBSYSTEM_ATTRIBUTE_UNUSED ) { liberror_error_t *error = NULL; static char *function = "ewfinfo_signal_handler"; LIBSYSTEM_UNREFERENCED_PARAMETER( signal ) ewfinfo_abort = 1; if( ( ewfinfo_info_handle != NULL ) && ( info_handle_signal_abort( ewfinfo_info_handle, &error ) != 1 ) ) { libsystem_notify_printf( "%s: unable to signal info handle to abort.\n", function ); libsystem_notify_print_error_backtrace( error ); liberror_error_free( &error ); } /* Force stdin to close otherwise any function reading it will remain blocked */ if( libsystem_file_io_close( 0 ) != 0 ) { libsystem_notify_printf( "%s: unable to close stdin.\n", function ); } }
/* Prints the executable version information */ void ewfoutput_copyright_fprint( FILE *stream ) { static char *function = "ewfoutput_copyright_fprint"; if( stream == NULL ) { libsystem_notify_printf( "%s: invalid stream.\n", function ); return; } fprintf( stream, "Copyright (c) 2006-2012, Joachim Metz <%s>.\n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", PACKAGE_BUGREPORT ); }
/* Prints the detailed version information to a stream */ void ewfoutput_version_detailed_fprint( FILE *stream, const libcstring_system_character_t *program ) { static char *function = "ewfoutput_version_detailed_fprint"; if( stream == NULL ) { libsystem_notify_printf( "%s: invalid stream.\n", function ); return; } if( program == NULL ) { libsystem_notify_printf( "%s: invalid program name.\n", function ); return; } fprintf( stream, "%" PRIs_LIBCSTRING_SYSTEM " %s (libewf %s", program, LIBEWF_VERSION_STRING, LIBEWF_VERSION_STRING ); #if defined( HAVE_LIBUNA ) || defined( HAVE_LOCAL_LIBUNA ) fprintf( stream, ", libuna %s", LIBUNA_VERSION_STRING ); #endif #if defined( HAVE_LIBBFIO ) || defined( HAVE_LOCAL_LIBBFIO ) fprintf( stream, ", libbfio %s", LIBBFIO_VERSION_STRING ); #endif #if defined( HAVE_LIBFVALUE ) || defined( HAVE_LOCAL_LIBFVALUE ) fprintf( stream, ", libfvalue %s", LIBFVALUE_VERSION_STRING ); #endif #if defined( HAVE_LIBZ ) fprintf( stream, ", zlib %s", ZLIB_VERSION ); #endif fprintf( stream, ", libsystem %s", LIBSYSTEM_VERSION_STRING ); #if defined( HAVE_LIBHMAC ) || defined( HAVE_LOCAL_LIBHMAC ) fprintf( stream, ", libhmac %s", LIBHMAC_VERSION_STRING ); #if defined( HAVE_LIBCRYPTO ) fprintf( stream, " (libcrypto %s)", SHLIB_VERSION_NUMBER ); #endif #endif #if defined( HAVE_LIBODRAW ) || defined( HAVE_LOCAL_LIBODRAW ) fprintf( stream, ", libodraw %s", LIBODRAW_VERSION_STRING ); #endif #if defined( HAVE_LIBSMDEV ) || defined( HAVE_LOCAL_LIBSMDEV ) fprintf( stream, ", libsmdev %s", LIBSMDEV_VERSION_STRING ); #endif #if defined( HAVE_LIBSMRAW ) || defined( HAVE_LOCAL_LIBSMRAW ) fprintf( stream, ", libsmraw %s", LIBSMRAW_VERSION_STRING ); #endif #if defined( HAVE_LIBUUID ) fprintf( stream, ", libuuid" ); #endif fprintf( stream, ")\n\n" ); }
/* Prints the data on the notify stream * Returns the number of printed characters if successful or -1 on error */ int libsystem_notify_print_data( const uint8_t *data, size_t data_size ) { size_t byte_iterator = 0; size_t data_iterator = 0; int print_count = 0; int total_print_count = 0; if( libsystem_notify_stream == NULL ) { return( 0 ); } if( data == NULL ) { return( -1 ); } while( data_iterator < data_size ) { while( byte_iterator < data_size ) { if( byte_iterator % 16 == 0 ) { print_count = libsystem_notify_printf( "%.8" PRIzx ": ", byte_iterator ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; } print_count = libsystem_notify_printf( "%.2" PRIx8 " ", data[ byte_iterator++ ] ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; if( byte_iterator % 16 == 0 ) { break; } else if( byte_iterator % 8 == 0 ) { print_count = libsystem_notify_printf( " " ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; } } while( byte_iterator % 16 != 0 ) { byte_iterator++; print_count = libsystem_notify_printf( " " ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; if( ( byte_iterator % 8 == 0 ) && ( byte_iterator % 16 != 0 ) ) { print_count = libsystem_notify_printf( " " ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; } } print_count = libsystem_notify_printf( " " ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; byte_iterator = data_iterator; while( byte_iterator < data_size ) { if( ( data[ byte_iterator ] >= 0x20 ) && ( data[ byte_iterator ] <= 0x7e ) ) { print_count = libsystem_notify_printf( "%c", (char) data[ byte_iterator ] ); } else { print_count = libsystem_notify_printf( "." ); } if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; byte_iterator++; if( byte_iterator % 16 == 0 ) { break; } else if( byte_iterator % 8 == 0 ) { print_count = libsystem_notify_printf( " " ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; } } print_count = libsystem_notify_printf( "\n" ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; data_iterator = byte_iterator; } print_count = libsystem_notify_printf( "\n" ); if( print_count <= -1 ) { return( -1 ); } total_print_count += print_count; return( total_print_count ); }
/* Print the version information to a stream */ void ewfoutput_version_fprint( FILE *stream, const libsystem_character_t *program ) { static char *function = "ewfoutput_version_fprint"; if( stream == NULL ) { libsystem_notify_printf( "%s: invalid stream.\n", function ); return; } if( program == NULL ) { libsystem_notify_printf( "%s: invalid program name.\n", function ); return; } fprintf( stream, "%" PRIs_LIBSYSTEM " %s (libewf %s", program, LIBEWF_VERSION_STRING, LIBEWF_VERSION_STRING ); fprintf( stream, ", libuna %s", LIBUNA_VERSION_STRING ); fprintf( stream, ", libbfio %s", LIBBFIO_VERSION_STRING ); #if defined( HAVE_LIBZ ) fprintf( stream, ", zlib %s", ZLIB_VERSION ); #endif #if defined( HAVE_LIBCRYPTO ) fprintf( stream, ", libcrypto %s", SHLIB_VERSION_NUMBER ); #endif #if defined( HAVE_LIBUUID ) fprintf( stream, ", libuuid" ); #endif fprintf( stream, ")\n\n" ); }
/* Get the program options * Function for platforms that do not have the getopt function * Returns the option character processed, or -1 on error, * ? if the option was not in the options string, : if the option argument was missing */ libsystem_integer_t libsystem_getopt( int argument_count, libsystem_character_t * const argument_values[], const libsystem_character_t *options_string ) { libsystem_character_t *option_value = NULL; libsystem_character_t *argument_value = NULL; static char *function = "libsystem_getopt"; if( optind >= argument_count ) { return( (libsystem_integer_t) -1 ); } argument_value = argument_values[ optind ]; /* Check if the argument value is not an empty string */ if( *argument_value == (libsystem_character_t) '\0' ) { return( (libsystem_integer_t) -1 ); } /* Check if the first character is a option marker '-' */ if( *argument_value != (libsystem_character_t) '-' ) { return( (libsystem_integer_t) -1 ); } argument_value++; /* Check if long options are provided '--' */ if( *argument_value == (libsystem_character_t) '-' ) { optind++; return( (libsystem_integer_t) -1 ); } optopt = *argument_value; option_value = libsystem_string_search( options_string, optopt, libsystem_string_length( options_string ) ); argument_value++; /* Check if an argument was specified or that the option was not found * in the option string */ if( ( optopt == (libsystem_integer_t) ':' ) || ( option_value == NULL ) ) { if( *argument_value == (libsystem_character_t) '\0' ) { optind++; } if( ( *options_string != (libsystem_character_t) ':' ) && ( optopt != (libsystem_integer_t) '?' ) ) { libsystem_notify_printf( "%s: no such option: %" PRIc_LIBSYSTEM ".\n", function, optopt ); } return( (libsystem_integer_t) '?' ); } option_value++; /* Check if no option argument is required */ if( *option_value != (libsystem_character_t) ':' ) { optarg = NULL; if( *argument_value == (libsystem_character_t) '\0' ) { optind++; } } /* Check if the argument is right after the option flag with no space in between */ else if( *argument_value != (libsystem_character_t) '\0' ) { optarg = argument_value; optind++; } else { optind++; /* Check if the argument was provided as the next argument value */ if( argument_count <= optind ) { if( *option_value == ':' ) { return( (libsystem_integer_t) ':' ); } libsystem_notify_printf( "%s: option: %" PRIc_LIBSYSTEM " requires an argument.\n", function, optopt ); return( (libsystem_integer_t) '?' ); } optarg = argument_values[ optind ]; optind++; } return( optopt ); }