/* Determines the encoding mode from a string * Returns 1 if successful or -1 on error */ int unainput_determine_encoding_mode( const system_character_t *string, uint8_t *encoding_mode, libcerror_error_t **error ) { static char *function = "unainput_determine_encoding_mode"; size_t string_length = 0; int result = -1; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( encoding_mode == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid encoding mode.", function ); return( -1 ); } string_length = system_string_length( string ); if( string_length == 6 ) { if( system_string_compare( string, _SYSTEM_STRING( "decode" ), 6 ) == 0 ) { *encoding_mode = UNACOMMON_ENCODING_MODE_DECODE; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "encode" ), 6 ) == 0 ) { *encoding_mode = UNACOMMON_ENCODING_MODE_ENCODE; result = 1; } } return( result ); }
/* Sets the ascii codepage * Returns 1 if successful or -1 on error */ int export_handle_set_ascii_codepage( export_handle_t *export_handle, const system_character_t *string, libcerror_error_t **error ) { static char *function = "export_handle_set_ascii_codepage"; size_t string_length = 0; uint32_t feature_flags = 0; int result = 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 ); } feature_flags = LIBCLOCALE_CODEPAGE_FEATURE_FLAG_HAVE_KOI8 | LIBCLOCALE_CODEPAGE_FEATURE_FLAG_HAVE_WINDOWS; string_length = system_string_length( string ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libclocale_codepage_copy_from_string_wide( &( export_handle->ascii_codepage ), string, string_length, feature_flags, error ); #else result = libclocale_codepage_copy_from_string( &( export_handle->ascii_codepage ), string, string_length, feature_flags, error ); #endif if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine ASCII codepage.", function ); return( -1 ); } return( result ); }
/* Sets the format * Returns 1 if successful, 0 if unsupported value or -1 on error */ int mount_handle_set_format( mount_handle_t *mount_handle, const system_character_t *string, libcerror_error_t **error ) { static char *function = "mount_handle_set_format"; size_t string_length = 0; int result = 0; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } string_length = system_string_length( string ); if( string_length == 3 ) { if( system_string_compare( string, _SYSTEM_STRING( "raw" ), 3 ) == 0 ) { mount_handle->input_format = MOUNT_HANDLE_INPUT_FORMAT_RAW; result = 1; } } else if( string_length == 5 ) { if( system_string_compare( string, _SYSTEM_STRING( "files" ), 5 ) == 0 ) { mount_handle->input_format = MOUNT_HANDLE_INPUT_FORMAT_FILES; result = 1; } } return( result ); }
/* Retrieves a descriptive string of the error number * This function uses the POSIX strerror function or equivalent * Returns the string_length if successful or -1 on error */ int libcerror_system_copy_string_from_error_number( system_character_t *string, size_t string_size, uint32_t error_number ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) const wchar_t *static_error_string = NULL; #else const char *static_error_string = NULL; #endif size_t static_error_string_length = 0; if( string == NULL ) { return( -1 ); } if( string_size > (size_t) INT_MAX ) { return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) static_error_string = _wcserror( (int) error_number ); #else static_error_string = strerror( (int) error_number ); #endif if( static_error_string == NULL ) { return( -1 ); } static_error_string_length = system_string_length( static_error_string ); if( system_string_copy( string, static_error_string, static_error_string_length ) == NULL ) { return( -1 ); } string[ static_error_string_length ] = 0; return( (int) static_error_string_length ); }
/* Retrieves a descriptive string of the error number * This function uses the POSIX strerror_r function or equivalent * Returns the string_length if successful or -1 on error */ int libcerror_system_copy_string_from_error_number( system_character_t *string, size_t string_size, uint32_t error_number ) { size_t string_length = 0; if( string == NULL ) { return( -1 ); } if( string_size > (size_t) INT_MAX ) { return( -1 ); } #if defined( STRERROR_R_CHAR_P ) if( strerror_r( (int) error_number, string, string_size ) == NULL ) #else if( strerror_r( (int) error_number, string, string_size ) != 0 ) #endif { return( -1 ); } string[ string_size - 1 ] = (system_character_t) 0; string_length = system_string_length( string ); return( (int) string_length ); }
/* Tests the libesedb_check_file_signature_file_io_handle function * Returns 1 if successful or 0 if not */ int esedb_test_check_file_signature_file_io_handle( const system_character_t *source ) { uint8_t empty_block[ 8192 ]; libbfio_handle_t *file_io_handle = NULL; libcerror_error_t *error = NULL; void *memset_result = NULL; size_t source_length = 0; int result = 0; /* Initialize test */ memset_result = memory_set( empty_block, 0, sizeof( uint8_t ) * 8192 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "memset_result", memset_result ); if( source != NULL ) { /* Initialize test */ result = libbfio_file_initialize( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); source_length = system_string_length( source ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libbfio_file_set_name_wide( file_io_handle, source, source_length, &error ); #else result = libbfio_file_set_name( file_io_handle, source, source_length, &error ); #endif ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libbfio_handle_open( file_io_handle, LIBBFIO_OPEN_READ, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); /* Test check file signature */ result = libesedb_check_file_signature_file_io_handle( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); } /* Test error cases */ result = libesedb_check_file_signature_file_io_handle( NULL, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); /* Clean up */ if( source != NULL ) { result = libbfio_handle_close( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libbfio_handle_free( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); } /* Test check file signature with data too small */ result = esedb_test_open_file_io_handle( &file_io_handle, empty_block, sizeof( uint8_t ) * 1, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libesedb_check_file_signature_file_io_handle( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = esedb_test_close_file_io_handle( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); /* Test check file signature with empty block */ result = esedb_test_open_file_io_handle( &file_io_handle, empty_block, sizeof( uint8_t ) * 8192, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); ESEDB_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = libesedb_check_file_signature_file_io_handle( file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); result = esedb_test_close_file_io_handle( &file_io_handle, &error ); ESEDB_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); ESEDB_TEST_ASSERT_IS_NULL( "error", error ); return( 1 ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } if( file_io_handle != NULL ) { libbfio_handle_free( &file_io_handle, NULL ); } return( 0 ); }
/* Determines the database type * Returns 1 if successful or -1 on error */ int database_type_determine( int *database_type, libcdata_array_t *table_names, libcerror_error_t **error ) { int database_types[ NUMBER_OF_DATABASE_TYPES ]; database_type_descriptor_t *database_type_descriptor = NULL; const system_character_t *known_table_name = NULL; system_character_t *table_name = NULL; static char *function = "export_handle_determine_database_type"; size_t known_table_name_length = 0; size_t table_name_length = 0; int database_type_index = 0; int known_table_name_index = 0; int number_of_tables = 0; int table_index = 0; if( database_type == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid database type.", function ); return( -1 ); } for( database_type_index = 0; database_type_index < NUMBER_OF_DATABASE_TYPES; database_type_index++ ) { database_types[ database_type_index ] = 0; } if( libcdata_array_get_number_of_entries( table_names, &number_of_tables, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of tables.", function ); return( -1 ); } for( table_index = 0; table_index < number_of_tables; table_index++ ) { if( libcdata_array_get_entry_by_index( table_names, table_index, (intptr_t **) &table_name, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve the name of table: %d from array.", function, table_index ); return( -1 ); } if( table_name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing name of table: %d.", function, table_index ); return( -1 ); } table_name_length = system_string_length( table_name ); database_type_index = 0; database_type_descriptor = &( database_type_descriptors[ database_type_index++ ] ); while( database_type_descriptor->database_type != DATABASE_TYPE_UNKNOWN ) { known_table_name_index = 0; known_table_name = database_type_descriptor->known_table_names[ known_table_name_index++ ]; while( known_table_name != NULL ) { known_table_name_length = system_string_length( known_table_name ); if( ( known_table_name_length == table_name_length ) && ( system_string_compare( known_table_name, table_name, known_table_name_length ) == 0 ) ) { database_types[ database_type_descriptor->database_type ] += 1; } known_table_name = database_type_descriptor->known_table_names[ known_table_name_index++ ]; } database_type_descriptor = &( database_type_descriptors[ database_type_index++ ] ); } } *database_type = DATABASE_TYPE_UNKNOWN; for( database_type_index = 0; database_type_index < NUMBER_OF_DATABASE_TYPES; database_type_index++ ) { if( database_types[ *database_type ] < database_types[ database_type_index ] ) { *database_type = database_type_index; } } return( 1 ); }
/* Determines the event log type from the filename * Returns 1 if successful, 0 if unsupported value or -1 on error */ int evtxinput_determine_event_log_type_from_filename( const system_character_t *filename, int *event_log_type, libcerror_error_t **error ) { const system_character_t *path_separator = NULL; static char *function = "evtxinput_determine_event_log_type_from_filename"; size_t filename_length = 0; int result = 0; if( filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid filename.", function ); return( -1 ); } if( event_log_type == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid event log type.", function ); return( -1 ); } filename_length = system_string_length( filename ); path_separator = system_string_search_character_reverse( filename, (system_character_t) LIBCPATH_SEPARATOR, filename_length ); if( path_separator == NULL ) { path_separator = filename; } else { path_separator++; filename_length = system_string_length( path_separator ); } if( filename_length == 11 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "System.evtx" ), 11 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_SYSTEM; result = 1; } } else if( filename_length == 13 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "Security.evtx" ), 13 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_SECURITY; result = 1; } } else if( filename_length == 16 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "Application.evtx" ), 16 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_APPLICATION; result = 1; } } else if( filename_length == 17 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "Media Center.evtx" ), 17 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_MEDIA_CENTER; result = 1; } } else if( filename_length == 19 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "HardwareEvents.evtx" ), 19 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_HARDWARE_EVENTS; result = 1; } } else if( filename_length == 20 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "DFS Replication.evtx" ), 20 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_DFS_REPLICATION; result = 1; } } else if( filename_length == 22 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "Internet Explorer.evtx" ), 22 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_INTERNET_EXPLORER; result = 1; } } else if( filename_length == 27 ) { if( system_string_compare_no_case( path_separator, _SYSTEM_STRING( "Key Management Service.evtx" ), 27 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_KEY_MANAGEMENT_SERVICE; result = 1; } } return( result ); }
/* Retrieves the sub file entry for the specific index * Returns 1 if successful or -1 on error */ int mount_file_entry_get_sub_file_entry_by_index( mount_file_entry_t *file_entry, int sub_file_entry_index, mount_file_entry_t **sub_file_entry, libcerror_error_t **error ) { system_character_t path[ 32 ]; libvshadow_store_t *vshadow_store = NULL; static char *function = "mount_file_entry_get_sub_file_entry_by_index"; size_t path_length = 0; int number_of_sub_file_entries = 0; if( file_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file entry.", function ); return( -1 ); } if( sub_file_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid sub file entry.", function ); return( -1 ); } if( *sub_file_entry != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid sub file entry value already set.", function ); return( -1 ); } if( mount_file_entry_get_number_of_sub_file_entries( file_entry, &number_of_sub_file_entries, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve number of sub file entries.", function ); return( -1 ); } if( ( sub_file_entry_index < 0 ) || ( sub_file_entry_index >= number_of_sub_file_entries ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid sub file entry index value out of bounds.", function ); return( -1 ); } if( mount_file_system_get_path_from_store_index( file_entry->file_system, sub_file_entry_index, path, 32, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve path for file entry: %d.", function, sub_file_entry_index ); return( -1 ); } if( mount_file_system_get_store_by_index( file_entry->file_system, sub_file_entry_index, &vshadow_store, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve store: %d from file system.", function, sub_file_entry_index ); return( -1 ); } if( vshadow_store == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing store: %d.", function, sub_file_entry_index ); return( -1 ); } path_length = system_string_length( path ); if( mount_file_entry_initialize( sub_file_entry, file_entry->file_system, &( path[ 1 ] ), path_length - 1, vshadow_store, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to initialize sub file entry: %d.", function, sub_file_entry_index ); return( -1 ); } return( 1 ); }
/* Sets the keys * Returns 1 if successful or -1 on error */ int rc4crypt_set_keys( const system_character_t *string, uint8_t **key_data, size_t *key_data_size, libcerror_error_t **error ) { static char *function = "rc4crypt_set_keys"; size_t string_length = 0; uint32_t base16_variant = 0; string_length = system_string_length( string ); *key_data_size = string_length / 2; *key_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * *key_data_size ); if( *key_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create key data.", function ); goto on_error; } if( memory_set( *key_data, 0, *key_data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear key data.", function ); goto on_error; } base16_variant = LIBUNA_BASE16_VARIANT_RFC4648; #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( _BYTE_STREAM_HOST_IS_ENDIAN_BIG ) { base16_variant |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN; } else { base16_variant |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN; } #endif if( libuna_base16_stream_copy_to_byte_stream( (uint8_t *) string, string_length, *key_data, *key_data_size, base16_variant, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy key data.", function ); goto on_error; } return( 1 ); on_error: if( *key_data != NULL ) { memory_set( *key_data, 0, *key_data_size ); memory_free( *key_data ); *key_data = NULL; *key_data_size = 0; } return( -1 ); }
/* Tests the libmdmp_file_open_file_io_handle function * Returns 1 if successful or 0 if not */ int mdmp_test_file_open_file_io_handle( const system_character_t *source ) { libbfio_handle_t *file_io_handle = NULL; libcerror_error_t *error = NULL; libmdmp_file_t *file = NULL; size_t string_length = 0; int result = 0; /* Initialize test */ result = libbfio_file_initialize( &file_io_handle, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); string_length = system_string_length( source ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libbfio_file_set_name_wide( file_io_handle, source, string_length, &error ); #else result = libbfio_file_set_name( file_io_handle, source, string_length, &error ); #endif MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); result = libmdmp_file_initialize( &file, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "file", file ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); /* Test open */ result = libmdmp_file_open_file_io_handle( file, file_io_handle, LIBMDMP_OPEN_READ, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); /* Test error cases */ result = libmdmp_file_open_file_io_handle( NULL, file_io_handle, LIBMDMP_OPEN_READ, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libmdmp_file_open_file_io_handle( file, NULL, LIBMDMP_OPEN_READ, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libmdmp_file_open_file_io_handle( file, file_io_handle, -1, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); /* Test open when already opened */ result = libmdmp_file_open_file_io_handle( file, file_io_handle, LIBMDMP_OPEN_READ, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); /* Clean up */ result = libmdmp_file_free( &file, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NULL( "file", file ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); result = libbfio_handle_free( &file_io_handle, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NULL( "file_io_handle", file_io_handle ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); return( 1 ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } if( file != NULL ) { libmdmp_file_free( &file, NULL ); } if( file_io_handle != NULL ) { libbfio_handle_free( &file_io_handle, NULL ); } return( 0 ); }
if( password != NULL ) { string_length = system_string_length( password ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = ${library_name}_${type_name}_set_utf16_password( *${type_name}, (uint16_t *) password, string_length, error ); #else result = ${library_name}_${type_name}_set_utf8_password( *${type_name}, (uint8_t *) password, string_length, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set password.", function ); goto on_error; } }
/* Sets the target path * Returns 1 if successful or -1 on error */ int export_handle_set_target_path( export_handle_t *export_handle, const system_character_t *target_path, libcerror_error_t **error ) { static char *function = "export_handle_set_target_path"; size_t target_path_length = 0; #if defined( WINAPI ) system_character_t *extended_length_target_path = NULL; size_t extended_length_target_path_size = 0; int result = 0; #endif 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( target_path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid target path.", function ); return( -1 ); } if( export_handle->target_path != NULL ) { memory_free( export_handle->target_path ); export_handle->target_path = NULL; export_handle->target_path_size = 0; } target_path_length = system_string_length( target_path ); #if defined( WINAPI ) result = libcpath_path_get_full_path_wide( target_path, target_path_length, (wchar_t **) &extended_length_target_path, &extended_length_target_path_size, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create extended-length target path.", function ); return( -1 ); } else if( result != 0 ) { target_path = extended_length_target_path; target_path_length = extended_length_target_path_size - 1; } #endif if( target_path_length > 0 ) { export_handle->target_path = system_string_allocate( target_path_length + 1 ); if( export_handle->target_path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create target path.", function ); #if defined( WINAPI ) memory_free( extended_length_target_path ); #endif return( -1 ); } if( system_string_copy( export_handle->target_path, target_path, target_path_length ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy target path.", function ); #if defined( WINAPI ) memory_free( extended_length_target_path ); #endif memory_free( export_handle->target_path ); export_handle->target_path = NULL; return( -1 ); } ( export_handle->target_path )[ target_path_length ] = 0; export_handle->target_path_size = target_path_length + 1; } #if defined( WINAPI ) memory_free( extended_length_target_path ); #endif return( 1 ); }
/* Retrieves a file entry for a specific path * Returns 1 if successful, 0 if no such file entry or -1 on error */ int mount_handle_get_file_entry_by_path( mount_handle_t *mount_handle, const system_character_t *path, mount_file_entry_t **file_entry, libcerror_error_t **error ) { libregf_key_t *regf_key = NULL; libregf_value_t *regf_value = NULL; const system_character_t *filename = NULL; static char *function = "mount_handle_get_file_entry_by_path"; size_t filename_length = 0; size_t key_path_length = 0; size_t last_path_index = 0; size_t path_index = 0; size_t path_length = 0; int file_entry_type = MOUNT_FILE_ENTRY_TYPE_UNKNOWN; int result = 0; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } if( path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); return( -1 ); } path_length = system_string_length( path ); if( path_length == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid path length value out of bounds.", function ); goto on_error; } if( ( path_length >= 2 ) && ( path[ path_length - 1 ] == LIBCPATH_SEPARATOR ) ) { path_length -= 1; } path_index = path_length; while( path_index > 0 ) { if( path[ path_index ] == LIBCPATH_SEPARATOR ) { break; } path_index--; } /* Ignore the name of the root item */ if( path_length == 0 ) { filename = _SYSTEM_STRING( "" ); filename_length = 0; } else { filename = &( path[ path_index + 1 ] ); filename_length = path_length - ( path_index + 1 ); } if( filename_length == 11 ) { #if defined( WINAPI ) result = system_string_compare_no_case( filename, _SYSTEM_STRING( "(classname)" ), 11 ); #else result = system_string_compare( filename, _SYSTEM_STRING( "(classname)" ), 11 ); #endif if( result == 0 ) { file_entry_type = MOUNT_FILE_ENTRY_TYPE_CLASS_NAME; key_path_length = path_index + 1; } } else if( filename_length == 8 ) { #if defined( WINAPI ) result = system_string_compare_no_case( filename, _SYSTEM_STRING( "(values)" ), 8 ); #else result = system_string_compare( filename, _SYSTEM_STRING( "(values)" ), 8 ); #endif if( result == 0 ) { file_entry_type = MOUNT_FILE_ENTRY_TYPE_VALUES; key_path_length = path_index + 1; } } if( ( file_entry_type == MOUNT_FILE_ENTRY_TYPE_UNKNOWN ) && ( path_index > 0 ) && ( path_length > 10 ) ) { last_path_index = path_index; path_index -= 1; while( path_index > 0 ) { if( path[ path_index ] == LIBCPATH_SEPARATOR ) { break; } path_index--; } if( ( last_path_index - ( path_index + 1 ) ) == 8 ) { #if defined( WINAPI ) result = system_string_compare_no_case( &( path[ path_index + 1 ] ), _SYSTEM_STRING( "(values)" ), 8 ); #else result = system_string_compare( &( path[ path_index + 1 ] ), _SYSTEM_STRING( "(values)" ), 8 ); #endif if( result == 0 ) { file_entry_type = MOUNT_FILE_ENTRY_TYPE_VALUE; key_path_length = path_index + 1; } } } if( file_entry_type == MOUNT_FILE_ENTRY_TYPE_UNKNOWN ) { file_entry_type = MOUNT_FILE_ENTRY_TYPE_KEY; key_path_length = path_length; } result = mount_file_system_get_key_by_path( mount_handle->file_system, path, key_path_length, ®f_key, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve key.", function ); goto on_error; } else if( result != 0 ) { if( file_entry_type == MOUNT_FILE_ENTRY_TYPE_VALUE ) { result = mount_file_system_get_value_by_filename( mount_handle->file_system, regf_key, filename, filename_length, ®f_value, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve value.", function ); goto on_error; } } if( result != 0 ) { if( mount_file_entry_initialize( file_entry, mount_handle->file_system, filename, filename_length, file_entry_type, regf_key, regf_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to initialize file entry.", function ); goto on_error; } } } return( result ); on_error: if( regf_value != NULL ) { libregf_value_free( ®f_value, NULL ); } if( regf_key != NULL ) { libregf_key_free( ®f_key, NULL ); } return( -1 ); }
/* Opens the mount handle * Returns 1 if successful or -1 on error */ int mount_handle_open( mount_handle_t *mount_handle, system_character_t * const * filenames, int number_of_filenames, libcerror_error_t **error ) { libewf_handle_t *ewf_handle = NULL; system_character_t **globbed_filenames = NULL; static char *function = "mount_handle_open"; size_t filename_length = 0; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } if( filenames == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid filenames.", function ); return( -1 ); } if( number_of_filenames <= 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_ZERO_OR_LESS, "%s: invalid number of filenames.", function ); return( -1 ); } if( number_of_filenames == 1 ) { filename_length = system_string_length( filenames[ 0 ] ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libewf_glob_wide( filenames[ 0 ], filename_length, LIBEWF_FORMAT_UNKNOWN, &globbed_filenames, &number_of_filenames, error ) != 1 ) #else if( libewf_glob( filenames[ 0 ], filename_length, LIBEWF_FORMAT_UNKNOWN, &globbed_filenames, &number_of_filenames, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to resolve filename(s).", function ); goto on_error; } filenames = (system_character_t * const *) globbed_filenames; } if( libewf_handle_initialize( &ewf_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to initialize handle.", function ); goto on_error; } if( libewf_handle_set_maximum_number_of_open_handles( ewf_handle, mount_handle->maximum_number_of_open_handles, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set maximum number of open handles in handle.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libewf_handle_open_wide( ewf_handle, filenames, number_of_filenames, LIBEWF_OPEN_READ, error ) != 1 ) #else if( libewf_handle_open( ewf_handle, filenames, number_of_filenames, LIBEWF_OPEN_READ, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file(s).", function ); goto on_error; } if( mount_file_system_set_handle( mount_handle->file_system, ewf_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set handle in file system.", function ); goto on_error; } if( globbed_filenames != NULL ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libewf_glob_wide_free( globbed_filenames, number_of_filenames, error ) != 1 ) #else if( libewf_glob_free( globbed_filenames, number_of_filenames, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free globbed filenames.", function ); goto on_error; } } return( 1 ); on_error: if( ewf_handle != NULL ) { libewf_handle_free( &ewf_handle, NULL ); } if( globbed_filenames != NULL ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) libewf_glob_wide_free( globbed_filenames, number_of_filenames, NULL ); #else libewf_glob_free( globbed_filenames, number_of_filenames, NULL ); #endif } return( -1 ); }
/* Determines the codepage from a string * Returns 1 if successful, 0 if unsupported value or -1 on error */ int wtcdbinput_determine_ascii_codepage( const system_character_t *string, int *ascii_codepage, libcerror_error_t **error ) { static char *function = "wtcdbinput_determine_ascii_codepage"; size_t string_length = 0; int result = 0; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( ascii_codepage == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid ASCII codepage.", function ); return( -1 ); } string_length = system_string_length( string ); if( string_length == 5 ) { if( system_string_compare( string, _SYSTEM_STRING( "ascii" ), 5 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ASCII; result = 1; } } #if defined( HAVE_ISO_CODEPAGES ) if( ( string_length == 10 ) || ( string_length == 11 ) ) { if( system_string_compare( string, _SYSTEM_STRING( "iso" ), 3 ) == 0 ) { if( ( string[ 3 ] != '-' ) && ( string[ 3 ] != '_' ) ) { } else if( system_string_compare( &( string[ 4 ] ), _SYSTEM_STRING( "8859" ), 4 ) == 0 ) { if( ( string[ 8 ] != '-' ) && ( string[ 8 ] != '_' ) ) { } else if( string_length == 10 ) { if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "1" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_1; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "2" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_2; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "3" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_3; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "4" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_4; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "5" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_5; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "6" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_6; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "7" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_7; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "8" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_8; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "9" ), 1 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_9; result = 1; } } else if( string_length == 11 ) { if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "10" ), 2 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_10; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "11" ), 2 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_11; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "13" ), 2 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_13; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "14" ), 2 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_14; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "15" ), 2 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_15; result = 1; } else if( system_string_compare( &( string[ 9 ] ), _SYSTEM_STRING( "16" ), 2 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_ISO_8859_16; result = 1; } } } } } #endif if( ( string_length == 11 ) || ( string_length == 12 ) ) { if( system_string_compare( string, _SYSTEM_STRING( "windows" ), 7 ) == 0 ) { if( ( string[ 7 ] != '-' ) && ( string[ 7 ] != '_' ) ) { } else if( string_length == 11 ) { if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "874" ), 3 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_874; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "932" ), 3 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_932; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "936" ), 3 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_936; result = 1; } } else if( string_length == 12 ) { if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1250" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1250; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1251" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1251; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1252" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1252; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1253" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1253; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1253" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1253; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1254" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1254; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1255" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1255; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1256" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1256; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1257" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1257; result = 1; } else if( system_string_compare( &( string[ 8 ] ), _SYSTEM_STRING( "1258" ), 4 ) == 0 ) { *ascii_codepage = LIBWTCDB_CODEPAGE_WINDOWS_1258; result = 1; } } } } return( result ); }
/* Determines the event log type from a string * Returns 1 if successful, 0 if unsupported value or -1 on error */ int evtxinput_determine_event_log_type( const system_character_t *string, int *event_log_type, libcerror_error_t **error ) { static char *function = "evtxinput_determine_event_log_type"; size_t string_length = 0; int result = 0; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( event_log_type == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid event log type.", function ); return( -1 ); } string_length = system_string_length( string ); if( string_length == 6 ) { if( system_string_compare_no_case( string, _SYSTEM_STRING( "system" ), 6 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_SYSTEM; result = 1; } } else if( string_length == 8 ) { if( system_string_compare_no_case( string, _SYSTEM_STRING( "security" ), 8 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_SECURITY; result = 1; } } else if( string_length == 11 ) { if( system_string_compare_no_case( string, _SYSTEM_STRING( "application" ), 11 ) == 0 ) { *event_log_type = EVTXTOOLS_EVENT_LOG_TYPE_APPLICATION; result = 1; } } return( result ); }
/* Determines the format from a string * Returns 1 if successful or -1 on error */ int unainput_determine_format( const system_character_t *string, uint8_t *format, libcerror_error_t **error ) { static char *function = "unainput_determine_format"; size_t string_length = 0; int result = -1; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", 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 ); } string_length = system_string_length( string ); if( string_length == 4 ) { if( system_string_compare( string, _SYSTEM_STRING( "utf7" ), 4 ) == 0 ) { *format = UNACOMMON_FORMAT_UTF7; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "utf8" ), 4 ) == 0 ) { *format = UNACOMMON_FORMAT_UTF8; result = 1; } } else if( string_length == 7 ) { if( system_string_compare( string, _SYSTEM_STRING( "utf16be" ), 7 ) == 0 ) { *format = UNACOMMON_FORMAT_UTF16BE; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "utf16le" ), 7 ) == 0 ) { *format = UNACOMMON_FORMAT_UTF16LE; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "utf32be" ), 7 ) == 0 ) { *format = UNACOMMON_FORMAT_UTF32BE; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "utf32le" ), 7 ) == 0 ) { *format = UNACOMMON_FORMAT_UTF32LE; result = 1; } } else if( string_length == 11 ) { if( system_string_compare( string, _SYSTEM_STRING( "byte-stream" ), 11 ) == 0 ) { *format = UNACOMMON_FORMAT_BYTE_STREAM; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "byte_stream" ), 11 ) == 0 ) { *format = UNACOMMON_FORMAT_BYTE_STREAM; result = 1; } } return( result ); }
/* Determines the newline conversion from a string * Returns 1 if successful, 0 if unsupported value or -1 on error */ int unainput_determine_newline_conversion( const system_character_t *string, uint8_t *newline_conversion, libcerror_error_t **error ) { static char *function = "unainput_determine_newline_conversion"; size_t string_length = 0; int result = 0; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( newline_conversion == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid newline conversion.", function ); return( -1 ); } string_length = system_string_length( string ); if( string_length == 2 ) { if( system_string_compare( string, _SYSTEM_STRING( "cr" ), 2 ) == 0 ) { *newline_conversion = UNACOMMON_NEWLINE_CONVERSION_CR; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "lf" ), 2 ) == 0 ) { *newline_conversion = UNACOMMON_NEWLINE_CONVERSION_LF; result = 1; } } else if( string_length == 4 ) { if( system_string_compare( string, _SYSTEM_STRING( "none" ), 4 ) == 0 ) { *newline_conversion = UNACOMMON_NEWLINE_CONVERSION_NONE; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "crlf" ), 4 ) == 0 ) { *newline_conversion = UNACOMMON_NEWLINE_CONVERSION_CRLF; result = 1; } } return( result ); }
int main( int argc, char * const argv[] ) #endif { libbfio_handle_t *file_io_handle = NULL; libcerror_error_t *error = NULL; libmdmp_file_t *file = NULL; system_character_t *source = NULL; system_integer_t option = 0; size_t string_length = 0; int result = 0; while( ( option = mdmp_test_getopt( argc, argv, _SYSTEM_STRING( "" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM ".\n", argv[ optind - 1 ] ); return( EXIT_FAILURE ); } } if( optind < argc ) { source = argv[ optind ]; } #if defined( HAVE_DEBUG_OUTPUT ) && defined( MDMP_TEST_FILE_VERBOSE ) libmdmp_notify_set_verbose( 1 ); libmdmp_notify_set_stream( stderr, NULL ); #endif MDMP_TEST_RUN( "libmdmp_file_initialize", mdmp_test_file_initialize ); MDMP_TEST_RUN( "libmdmp_file_free", mdmp_test_file_free ); #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) if( source != NULL ) { result = libbfio_file_initialize( &file_io_handle, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); string_length = system_string_length( source ); #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libbfio_file_set_name_wide( file_io_handle, source, string_length, &error ); #else result = libbfio_file_set_name( file_io_handle, source, string_length, &error ); #endif MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); result = libmdmp_check_file_signature_file_io_handle( file_io_handle, &error ); MDMP_TEST_ASSERT_NOT_EQUAL_INT( "result", result, -1 ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); } if( result != 0 ) { MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_open", mdmp_test_file_open, source ); #if defined( HAVE_WIDE_CHARACTER_TYPE ) MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_open_wide", mdmp_test_file_open_wide, source ); #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_open_file_io_handle", mdmp_test_file_open_file_io_handle, source ); MDMP_TEST_RUN( "libmdmp_file_close", mdmp_test_file_close ); MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_open_close", mdmp_test_file_open_close, source ); /* Initialize file for tests */ result = mdmp_test_file_open_source( &file, file_io_handle, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NOT_NULL( "file", file ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_signal_abort", mdmp_test_file_signal_abort, file ); #if defined( __GNUC__ ) && !defined( LIBMDMP_DLL_IMPORT ) /* TODO: add tests for libmdmp_file_open_read */ #endif /* defined( __GNUC__ ) && !defined( LIBMDMP_DLL_IMPORT ) */ MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_get_number_of_streams", mdmp_test_file_get_number_of_streams, file ); MDMP_TEST_RUN_WITH_ARGS( "libmdmp_file_get_stream", mdmp_test_file_get_stream, file ); /* TODO: add tests for libmdmp_file_get_stream_by_type */ /* Clean up */ result = mdmp_test_file_close_source( &file, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); MDMP_TEST_ASSERT_IS_NULL( "file", file ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); } if( file_io_handle != NULL ) { result = libbfio_handle_free( &file_io_handle, &error ); MDMP_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); MDMP_TEST_ASSERT_IS_NULL( "file_io_handle", file_io_handle ); MDMP_TEST_ASSERT_IS_NULL( "error", error ); } #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */ return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } if( file != NULL ) { libmdmp_file_free( &file, NULL ); } if( file_io_handle != NULL ) { libbfio_handle_free( &file_io_handle, NULL ); } return( EXIT_FAILURE ); }
/* Determines the encoding from a string * Returns 1 if successful or -1 on error */ int unainput_determine_encoding( const system_character_t *string, uint8_t *encoding, libcerror_error_t **error ) { static char *function = "unainput_determine_encoding"; size_t string_length = 0; int result = -1; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( encoding == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid encoding.", function ); return( -1 ); } string_length = system_string_length( string ); if( string_length == 6 ) { if( system_string_compare( string, _SYSTEM_STRING( "base16" ), 6 ) == 0 ) { *encoding = UNACOMMON_ENCODING_BASE16; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "base32" ), 6 ) == 0 ) { *encoding = UNACOMMON_ENCODING_BASE32; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "base64" ), 6 ) == 0 ) { *encoding = UNACOMMON_ENCODING_BASE64; result = 1; } } else if( string_length == 9 ) { if( system_string_compare( string, _SYSTEM_STRING( "base32hex" ), 9 ) == 0 ) { *encoding = UNACOMMON_ENCODING_BASE32HEX; result = 1; } else if( system_string_compare( string, _SYSTEM_STRING( "base64url" ), 9 ) == 0 ) { *encoding = UNACOMMON_ENCODING_BASE64URL; result = 1; } } return( result ); }
/* Retrieves the handle for a specific path * Returns 1 if successful, 0 if no such handle or -1 on error */ int mount_file_system_get_handle_by_path( mount_file_system_t *file_system, const system_character_t *path, size_t path_length, libvmdk_handle_t **vmdk_handle, libcerror_error_t **error ) { static char *function = "mount_file_system_get_handle_by_path"; system_character_t character = 0; size_t path_index = 0; int handle_index = 0; int result = 0; if( file_system == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file system.", function ); return( -1 ); } if( file_system->path_prefix == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid file system - missing path prefix.", function ); return( -1 ); } if( path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); return( -1 ); } if( path_length > (size_t) ( SSIZE_MAX - 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid path length value exceeds maximum.", function ); return( -1 ); } if( vmdk_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid handle.", function ); return( -1 ); } path_length = system_string_length( path ); if( ( path_length == 1 ) && ( path[ 0 ] == file_system->path_prefix[ 0 ] ) ) { *vmdk_handle = NULL; return( 1 ); } if( ( path_length < file_system->path_prefix_size ) || ( path_length > ( file_system->path_prefix_size + 3 ) ) ) { return( 0 ); } #if defined( WINAPI ) result = system_string_compare_no_case( path, file_system->path_prefix, file_system->path_prefix_size - 1 ); #else result = system_string_compare( path, file_system->path_prefix, file_system->path_prefix_size - 1 ); #endif if( result != 0 ) { return( 0 ); } handle_index = 0; path_index = file_system->path_prefix_size - 1; while( path_index < path_length ) { character = path[ path_index++ ]; if( ( character < (system_character_t) '0' ) || ( character > (system_character_t) '9' ) ) { return( 0 ); } handle_index *= 10; handle_index += character - (system_character_t) '0'; } handle_index -= 1; if( libcdata_array_get_entry_by_index( file_system->handles_array, handle_index, (intptr_t **) vmdk_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve handle: %d.", function, handle_index ); return( -1 ); } return( 1 ); }
int main( int argc, char * const argv[] ) #endif { libcerror_error_t *error = NULL; system_character_t *option_offset = NULL; system_character_t *source = NULL; system_integer_t option = 0; size_t string_length = 0; off64_t volume_offset = 0; int result = 0; while( ( option = fsntfs_test_getopt( argc, argv, _SYSTEM_STRING( "o:" ) ) ) != (system_integer_t) -1 ) { switch( option ) { case (system_integer_t) '?': default: fprintf( stderr, "Invalid argument: %" PRIs_SYSTEM ".\n", argv[ optind - 1 ] ); return( EXIT_FAILURE ); case (system_integer_t) 'o': option_offset = optarg; break; } } if( optind < argc ) { source = argv[ optind ]; } if( option_offset != NULL ) { string_length = system_string_length( option_offset ); result = fsntfs_test_system_string_copy_from_64_bit_in_decimal( option_offset, string_length + 1, (uint64_t *) &volume_offset, &error ); FSNTFS_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); FSNTFS_TEST_ASSERT_IS_NULL( "error", error ); } FSNTFS_TEST_RUN( "libfsntfs_get_version", fsntfs_test_get_version ); FSNTFS_TEST_RUN( "libfsntfs_get_access_flags_read", fsntfs_test_get_access_flags_read ); FSNTFS_TEST_RUN( "libfsntfs_get_codepage", fsntfs_test_get_codepage ); FSNTFS_TEST_RUN( "libfsntfs_set_codepage", fsntfs_test_set_codepage ); #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) if( ( source != NULL ) && ( volume_offset == 0 ) ) { FSNTFS_TEST_RUN_WITH_ARGS( "libfsntfs_check_volume_signature", fsntfs_test_check_volume_signature, source ); #if defined( HAVE_WIDE_CHARACTER_TYPE ) FSNTFS_TEST_RUN_WITH_ARGS( "libfsntfs_check_volume_signature_wide", fsntfs_test_check_volume_signature_wide, source ); #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ FSNTFS_TEST_RUN_WITH_ARGS( "libfsntfs_check_volume_signature_file_io_handle", fsntfs_test_check_volume_signature_file_io_handle, source ); } #endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */ return( EXIT_SUCCESS ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } return( EXIT_FAILURE ); }
/* 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 */ system_integer_t cregtools_getopt( int argument_count, system_character_t * const argument_values[], const system_character_t *options_string ) { system_character_t *argument_value = NULL; system_character_t *option_value = NULL; static char *function = "cregtools_getopt"; size_t options_string_length = 0; if( next_option != NULL ) { argument_value = next_option; next_option = NULL; } else if( optind >= argument_count ) { return( (system_integer_t) -1 ); } else { argument_value = argument_values[ optind ]; /* Check if the argument value is not an empty string */ if( *argument_value == (system_character_t) '\0' ) { return( (system_integer_t) -1 ); } /* Check if the first character is a option marker '-' */ if( *argument_value != (system_character_t) '-' ) { return( (system_integer_t) -1 ); } argument_value++; /* Check if long options are provided '--' */ if( *argument_value == (system_character_t) '-' ) { optind++; return( (system_integer_t) -1 ); } } options_string_length = system_string_length( options_string ); optopt = *argument_value; option_value = system_string_search_character( options_string, optopt, options_string_length ); argument_value++; /* Check if an argument was specified or that the option was not found * in the option string */ if( ( optopt == (system_integer_t) ':' ) || ( option_value == NULL ) ) { if( *argument_value == (system_character_t) '\0' ) { optind++; } if( ( *options_string != (system_character_t) ':' ) && ( optopt != (system_integer_t) '?' ) ) { libcnotify_printf( "%s: no such option: %" PRIc_SYSTEM ".\n", function, optopt ); } return( (system_integer_t) '?' ); } option_value++; /* Check if no option argument is required */ if( *option_value != (system_character_t) ':' ) { optarg = NULL; if( *argument_value == (system_character_t) '\0' ) { optind++; } else { /* Multiple options are grouped */ next_option = argument_value; } } /* Check if the argument is right after the option flag with no space in between */ else if( *argument_value != (system_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( (system_integer_t) ':' ); } libcnotify_printf( "%s: option: %" PRIc_SYSTEM " requires an argument.\n", function, optopt ); return( (system_integer_t) '?' ); } optarg = argument_values[ optind ]; optind++; } return( optopt ); }
/* Retrieves a file entry for a specific path * Returns 1 if successful, 0 if no such file entry or -1 on error */ int mount_handle_get_file_entry_by_path( mount_handle_t *mount_handle, const system_character_t *path, mount_file_entry_t **file_entry, libcerror_error_t **error ) { libolecf_item_t *olecf_item = NULL; const system_character_t *filename = NULL; static char *function = "mount_handle_get_file_entry_by_path"; size_t filename_length = 0; size_t path_index = 0; size_t path_length = 0; int result = 0; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } if( path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); return( -1 ); } path_length = system_string_length( path ); if( path_length == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid path length value out of bounds.", function ); goto on_error; } if( ( path_length >= 2 ) && ( path[ path_length - 1 ] == LIBCPATH_SEPARATOR ) ) { path_length--; } path_index = path_length; while( path_index > 0 ) { if( path[ path_index ] == LIBCPATH_SEPARATOR ) { break; } path_index--; } /* Ignore the name of the root item */ if( path_length == 0 ) { filename = _SYSTEM_STRING( "" ); filename_length = 0; } else { filename = &( path[ path_index + 1 ] ); filename_length = path_length - ( path_index + 1 ); } result = mount_file_system_get_item_by_path( mount_handle->file_system, path, path_length, &olecf_item, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve item.", function ); goto on_error; } else if( result != 0 ) { if( mount_file_entry_initialize( file_entry, mount_handle->file_system, filename, filename_length, olecf_item, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to initialize file entry.", function ); goto on_error; } } return( result ); on_error: if( olecf_item != NULL ) { libolecf_item_free( &olecf_item, NULL ); } return( -1 ); }
/* Retrieves source as a narrow string * Returns 1 if successful or -1 on error */ int smdev_test_get_narrow_source( const system_character_t *source, char *narrow_string, size_t narrow_string_size, libcerror_error_t **error ) { static char *function = "smdev_test_get_narrow_source"; size_t narrow_source_size = 0; size_t source_length = 0; #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) int result = 0; #endif if( source == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid source.", function ); return( -1 ); } if( narrow_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid narrow string.", function ); return( -1 ); } if( narrow_string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid narrow string size value exceeds maximum.", function ); return( -1 ); } source_length = system_string_length( source ); if( source_length > (size_t) ( SSIZE_MAX - 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid source length value out of bounds.", function ); return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) source, source_length + 1, &narrow_source_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) source, source_length + 1, &narrow_source_size, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_size_from_utf32( (libuna_utf32_character_t *) source, source_length + 1, libclocale_codepage, &narrow_source_size, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_size_from_utf16( (libuna_utf16_character_t *) source, source_length + 1, libclocale_codepage, &narrow_source_size, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to determine narrow string size.", function ); return( -1 ); } #else narrow_source_size = source_length + 1; #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ if( narrow_string_size < narrow_source_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: narrow string too small.", function ); return( -1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) if( libclocale_codepage == 0 ) { #if SIZEOF_WCHAR_T == 4 result = libuna_utf8_string_copy_from_utf32( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf32_character_t *) source, source_length + 1, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_utf8_string_copy_from_utf16( (libuna_utf8_character_t *) narrow_string, narrow_string_size, (libuna_utf16_character_t *) source, source_length + 1, error ); #endif } else { #if SIZEOF_WCHAR_T == 4 result = libuna_byte_stream_copy_from_utf32( (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, (libuna_utf32_character_t *) source, source_length + 1, error ); #elif SIZEOF_WCHAR_T == 2 result = libuna_byte_stream_copy_from_utf16( (uint8_t *) narrow_string, narrow_string_size, libclocale_codepage, (libuna_utf16_character_t *) source, source_length + 1, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set narrow string.", function ); return( -1 ); } #else if( system_string_copy( narrow_string, source, source_length ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set narrow string.", function ); return( -1 ); } narrow_string[ source_length ] = 0; #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ return( 1 ); }
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 ); }