diff --git a/.gitignore b/.gitignore index 4984fb127..431647b84 100644 --- a/.gitignore +++ b/.gitignore @@ -140,6 +140,7 @@ stamp-h[1-9] /tests/ewf_test_analytical_data /tests/ewf_test_attribute /tests/ewf_test_bit_stream +/tests/ewf_test_buffer_data_handle /tests/ewf_test_case_data /tests/ewf_test_case_data_section /tests/ewf_test_checksum @@ -172,6 +173,7 @@ stamp-h[1-9] /tests/ewf_test_lef_permission /tests/ewf_test_lef_source /tests/ewf_test_lef_subject +/tests/ewf_test_line_reader /tests/ewf_test_ltree_section /tests/ewf_test_md5_hash_section /tests/ewf_test_media_values @@ -179,6 +181,7 @@ stamp-h[1-9] /tests/ewf_test_permission_group /tests/ewf_test_read_io_handle /tests/ewf_test_restart_data +/tests/ewf_test_section_data_handle /tests/ewf_test_section_descriptor /tests/ewf_test_sector_range /tests/ewf_test_sector_range_list diff --git a/ChangeLog b/ChangeLog index 80bdd60d6..7e60108dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ TODO +* change ltree path segment separator +* calculate the MD5 while incremental ltree read, use line reader instead? + +* escape unpaired surrogates in bodyfile + * info_handle: move dfxml functions to seperate file * clean up libewf_chunk_group_correct_v1 diff --git a/acinclude.m4 b/acinclude.m4 index 374c0393d..70564fd21 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,6 +1,6 @@ dnl Checks for required headers and functions dnl -dnl Version: 20230212 +dnl Version: 20230704 dnl Function to determine the host operating system AC_DEFUN([AX_LIBEWF_CHECK_HOST_OPERATING_SYSTEM], @@ -44,8 +44,7 @@ AC_DEFUN([AX_LIBEWF_CHECK_LOCAL], AC_CHECK_HEADERS([sys/time.h]) dnl Check for functions - dnl Date and time functions used in libewf/libewf_date_time.h - AC_CHECK_FUNCS([localtime localtime_r mktime]) + AC_CHECK_FUNCS([localtime localtime_r memmove mktime]) AS_IF( [test "x$ac_cv_func_localtime" != xyes && test "x$ac_cv_func_localtime_r" != xyes], @@ -54,6 +53,13 @@ AC_DEFUN([AX_LIBEWF_CHECK_LOCAL], [1]) ]) + AS_IF( + [test "x$ac_cv_func_memmove" != xyes], + [AC_MSG_FAILURE( + [Missing function: memmove], + [1]) + ]) + AS_IF( [test "x$ac_cv_func_mktime" != xyes], [AC_MSG_FAILURE( diff --git a/appveyor.yml b/appveyor.yml index 2a1c5b505..3753de859 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -233,7 +233,7 @@ install: .\builddokan.ps1 -Configuration ${Configuration} -Platform "Win32"; .\builddokan.ps1 -Configuration ${Configuration} -Platform "x64"; } } -- sh: if test ${BUILD_ENVIRONMENT} = "python-tox" || test ${BUILD_ENVIRONMENT} = "xcode"; then brew update -q; fi +- sh: if test ${BUILD_ENVIRONMENT} = "python-tox" || test ${BUILD_ENVIRONMENT} = "xcode"; then brew update-reset && brew update -q; fi - sh: if test ${BUILD_ENVIRONMENT} = "python-tox" || test ${BUILD_ENVIRONMENT} = "xcode"; then brew install -q gettext gnu-sed || true; fi - sh: if test ${BUILD_ENVIRONMENT} = "python-tox"; then brew install -q python@${PYTHON_VERSION} tox twine-pypi || true; fi - cmd: if [%BUILD_ENVIRONMENT%]==[python] ( diff --git a/configure.ac b/configure.ac index 841e8f8fa..234152b2a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ([2.71]) AC_INIT( [libewf], - [20230702], + [20230705], [joachim.metz@gmail.com]) AC_CONFIG_SRCDIR( diff --git a/documentation/Expert Witness Compression Format (EWF).asciidoc b/documentation/Expert Witness Compression Format (EWF).asciidoc index 11e18b7da..4e95b31d3 100644 --- a/documentation/Expert Witness Compression Format (EWF).asciidoc +++ b/documentation/Expert Witness Compression Format (EWF).asciidoc @@ -1794,7 +1794,7 @@ The ltree section consists of: ==== Ltree header -The ltree header is 6 bytes of size and consists of: +The ltree header is 48 bytes of size and consists of: [cols="1,1,1,5",options="header"] |=== @@ -1828,7 +1828,7 @@ See section: <> | ... | srce | Information about acquisition sources + See section: <> | ... | | (an empty line) -|...22 | sub | Information about [yellow-background]*unknown* + +| ... | sub | Information about [yellow-background]*unknown* + See section: <> | ... | | (an empty line) | ... | entry | Information about file entries + diff --git a/ewftools/info_handle.c b/ewftools/info_handle.c index a5f121572..56df03081 100644 --- a/ewftools/info_handle.c +++ b/ewftools/info_handle.c @@ -1076,6 +1076,206 @@ int info_handle_posix_time_value_fprint( return( -1 ); } +/* Prints a file entry or data stream name to a bodyfile + * Returns 1 if successful or -1 on error + */ +int info_handle_bodyfile_name_value_fprint( + info_handle_t *info_handle, + const system_character_t *value_string, + size_t value_string_length, + libcerror_error_t **error ) +{ + system_character_t *escaped_value_string = NULL; + static char *function = "info_handle_bodyfile_name_value_fprint"; + libuna_unicode_character_t unicode_character = 0; + size_t escaped_value_string_index = 0; + size_t escaped_value_string_size = 0; + size_t value_string_index = 0; + int print_count = 0; + int result = 0; + + if( info_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid info handle.", + function ); + + return( -1 ); + } + if( value_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid value string.", + function ); + + return( -1 ); + } + /* To ensure normalization in the escaped string is handled correctly + * it stored in a temporary variable. Note that there is a worst-case of + * a 1 to 4 ratio for each escaped character. + */ + if( value_string_length > (size_t) ( ( SSIZE_MAX - 1 ) / ( sizeof( system_character_t ) * 4 ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid value string length value exceeds maximum.", + function ); + + return( -1 ); + } + escaped_value_string_size = ( value_string_length * 4 ) + 1; + + escaped_value_string = (system_character_t *) memory_allocate( + sizeof( system_character_t ) * escaped_value_string_size ); + + if( escaped_value_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create escaped value string.", + function ); + + goto on_error; + } + /* Using UCS-2 or RFC 2279 UTF-8 to support unpaired UTF-16 surrogates + */ + while( value_string_index < value_string_length ) + { +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) + result = libuna_unicode_character_copy_from_ucs2( + &unicode_character, + (libuna_utf16_character_t *) value_string, + value_string_length, + &value_string_index, + error ); +#else + result = libuna_unicode_character_copy_from_utf8_rfc2279( + &unicode_character, + (libuna_utf8_character_t *) value_string, + value_string_length, + &value_string_index, + error ); +#endif + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_CONVERSION, + LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, + "%s: unable to copy Unicode character from value string.", + function ); + + goto on_error; + } + /* Replace: + * Control characters ([U+0-U+1f, U+7f-U+9f]) by \x## + */ + if( ( unicode_character <= 0x1f ) + || ( ( unicode_character >= 0x7f ) + && ( unicode_character <= 0x9f ) ) ) + { + print_count = system_string_sprintf( + &( escaped_value_string[ escaped_value_string_index ] ), + escaped_value_string_size - escaped_value_string_index, + "\\x%02" PRIx32 "", + unicode_character ); + + if( print_count < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_CONVERSION, + LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, + "%s: unable to copy escaped Unicode character to escaped value string.", + function ); + + goto on_error; + } + escaped_value_string_index += print_count; + } + else if( ( unicode_character == '\\' ) + || ( unicode_character == '|' ) ) + { + print_count = system_string_sprintf( + &( escaped_value_string[ escaped_value_string_index ] ), + escaped_value_string_size - escaped_value_string_index, + "\\%c", + unicode_character ); + + if( print_count < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_CONVERSION, + LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, + "%s: unable to copy escaped Unicode character to escaped value string.", + function ); + + goto on_error; + } + escaped_value_string_index += print_count; + } + else + { +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) + result = libuna_unicode_character_copy_to_ucs2( + unicode_character, + (libuna_utf16_character_t *) escaped_value_string, + escaped_value_string_size, + &escaped_value_string_index, + error ); +#else + result = libuna_unicode_character_copy_to_utf8_rfc2279( + unicode_character, + (libuna_utf8_character_t *) escaped_value_string, + escaped_value_string_size, + &escaped_value_string_index, + error ); +#endif + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_CONVERSION, + LIBCERROR_CONVERSION_ERROR_INPUT_FAILED, + "%s: unable to copy Unicode character to escaped value string.", + function ); + + goto on_error; + } + } + } + escaped_value_string[ escaped_value_string_index ] = 0; + + fprintf( + info_handle->bodyfile_stream, + "%" PRIs_SYSTEM "", + escaped_value_string ); + + memory_free( + escaped_value_string ); + + return( 1 ); + +on_error: + if( escaped_value_string != NULL ) + { + memory_free( + escaped_value_string ); + } + return( -1 ); +} + /* Prints a section header * Returns 1 if successful or -1 on error */ @@ -6181,17 +6381,39 @@ int info_handle_file_entry_value_fprint( if( path != NULL ) { - fprintf( - info_handle->bodyfile_stream, - "%" PRIs_SYSTEM "", - path ); + if( info_handle_bodyfile_name_value_fprint( + info_handle, + path, + path_length, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, + "%s: unable to print path string.", + function ); + + goto on_error; + } } if( file_entry_name != NULL ) { - fprintf( - info_handle->bodyfile_stream, - "%" PRIs_SYSTEM "", - file_entry_name ); + if( info_handle_bodyfile_name_value_fprint( + info_handle, + file_entry_name, + file_entry_name_size - 1, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, + "%s: unable to print file entry name string.", + function ); + + goto on_error; + } } /* TODO print data stream name */ /* TODO determine mode as string */ diff --git a/ewftools/info_handle.h b/ewftools/info_handle.h index 46d71b815..6db63bc00 100644 --- a/ewftools/info_handle.h +++ b/ewftools/info_handle.h @@ -127,6 +127,12 @@ int info_handle_posix_time_value_fprint( int64_t value_64bit, libcerror_error_t **error ); +int info_handle_bodyfile_name_value_fprint( + info_handle_t *info_handle, + const system_character_t *value_string, + size_t value_string_length, + libcerror_error_t **error ); + int info_handle_section_header_fprint( info_handle_t *info_handle, const char *identifier, diff --git a/libewf/Makefile.am b/libewf/Makefile.am index 4a760f2d5..632374503 100644 --- a/libewf/Makefile.am +++ b/libewf/Makefile.am @@ -42,6 +42,7 @@ libewf_la_SOURCES = \ libewf_analytical_data.c libewf_analytical_data.h \ libewf_attribute.c libewf_attribute.h \ libewf_bit_stream.c libewf_bit_stream.h \ + libewf_buffer_data_handle.c libewf_buffer_data_handle.h \ libewf_case_data.c libewf_case_data.h \ libewf_case_data_section.c libewf_case_data_section.h \ libewf_checksum.c libewf_checksum.h \ @@ -52,6 +53,7 @@ libewf_la_SOURCES = \ libewf_codepage.h \ libewf_compression.c libewf_compression.h \ libewf_data_chunk.c libewf_data_chunk.h \ + libewf_data_stream.c libewf_data_stream.h \ libewf_date_time.c libewf_date_time.h \ libewf_date_time_values.c libewf_date_time_values.h \ libewf_debug.c libewf_debug.h \ @@ -90,6 +92,7 @@ libewf_la_SOURCES = \ libewf_lef_permission.c libewf_lef_permission.h \ libewf_lef_source.c libewf_lef_source.h \ libewf_lef_subject.c libewf_lef_subject.h \ + libewf_line_reader.c libewf_line_reader.h \ libewf_ltree_section.c libewf_ltree_section.h \ libewf_md5_hash_section.c libewf_md5_hash_section.h \ libewf_media_values.c libewf_media_values.h \ @@ -98,6 +101,7 @@ libewf_la_SOURCES = \ libewf_read_io_handle.c libewf_read_io_handle.h \ libewf_restart_data.c libewf_restart_data.h \ libewf_section.c libewf_section.h \ + libewf_section_data_handle.c libewf_section_data_handle.h \ libewf_section_descriptor.c libewf_section_descriptor.h \ libewf_sector_range.c libewf_sector_range.h \ libewf_sector_range_list.c libewf_sector_range_list.h \ diff --git a/libewf/libewf_buffer_data_handle.c b/libewf/libewf_buffer_data_handle.c new file mode 100644 index 000000000..4c2302f04 --- /dev/null +++ b/libewf/libewf_buffer_data_handle.c @@ -0,0 +1,324 @@ +/* + * The buffer data handle functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "libewf_buffer_data_handle.h" +#include "libewf_libcerror.h" +#include "libewf_unused.h" + +/* Creates a buffer data handle + * Make sure the value data_handle is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libewf_buffer_data_handle_initialize( + libewf_buffer_data_handle_t **data_handle, + const uint8_t *data, + size_t data_size, + libcerror_error_t **error ) +{ + static char *function = "libewf_buffer_data_handle_initialize"; + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( *data_handle != NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, + "%s: invalid data handle value already set.", + function ); + + return( -1 ); + } + if( data_size > 0 ) + { + if( data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data.", + function ); + + return( -1 ); + } + } + if( data_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid data size value exceeds maximum.", + function ); + + return( -1 ); + } + *data_handle = memory_allocate_structure( + libewf_buffer_data_handle_t ); + + if( *data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create data handle.", + function ); + + goto on_error; + } + if( memory_set( + *data_handle, + 0, + sizeof( libewf_buffer_data_handle_t ) ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to clear data handle.", + function ); + + goto on_error; + } + ( *data_handle )->data = data; + ( *data_handle )->data_size = data_size; + + return( 1 ); + +on_error: + if( *data_handle != NULL ) + { + memory_free( + *data_handle ); + + *data_handle = NULL; + } + return( -1 ); +} + +/* Frees a buffer data handle + * Returns 1 if successful or -1 on error + */ +int libewf_buffer_data_handle_free( + libewf_buffer_data_handle_t **data_handle, + libcerror_error_t **error ) +{ + static char *function = "libewf_buffer_data_handle_free"; + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( *data_handle != NULL ) + { + memory_free( + *data_handle ); + + *data_handle = NULL; + } + return( 1 ); +} + +/* Reads data from the current offset into a buffer + * Callback for the data stream + * Returns the number of bytes read or -1 on error + */ +ssize_t libewf_buffer_data_handle_read_segment_data( + libewf_buffer_data_handle_t *data_handle, + intptr_t *file_io_handle LIBEWF_ATTRIBUTE_UNUSED, + int segment_index, + int segment_file_index LIBEWF_ATTRIBUTE_UNUSED, + uint8_t *segment_data, + size_t segment_data_size, + uint32_t segment_flags LIBEWF_ATTRIBUTE_UNUSED, + uint8_t read_flags LIBEWF_ATTRIBUTE_UNUSED, + libcerror_error_t **error ) +{ + static char *function = "libewf_buffer_data_handle_read_segment_data"; + size_t read_size = 0; + + LIBEWF_UNREFERENCED_PARAMETER( file_io_handle ) + LIBEWF_UNREFERENCED_PARAMETER( segment_file_index ) + LIBEWF_UNREFERENCED_PARAMETER( segment_flags ) + LIBEWF_UNREFERENCED_PARAMETER( read_flags ) + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( data_handle->current_offset < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data handle - current offset value out of bounds.", + function ); + + return( -1 ); + } + if( segment_index != 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid segment index value out of bounds.", + function ); + + return( -1 ); + } + if( segment_data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid segment data.", + function ); + + return( -1 ); + } + if( segment_data_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid segment data size value exceeds maximum.", + function ); + + return( -1 ); + } + if( data_handle->current_offset >= (off64_t) data_handle->data_size ) + { + return( 0 ); + } + read_size = data_handle->data_size - (size_t) data_handle->current_offset; + + if( read_size > segment_data_size ) + { + read_size = segment_data_size; + } + if( memory_copy( + segment_data, + &( data_handle->data[ data_handle->current_offset ] ), + read_size ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_COPY_FAILED, + "%s: unable to copy data.", + function ); + + return( -1 ); + } + data_handle->current_offset += read_size; + + return( (ssize_t) read_size ); +} + +/* Seeks a certain offset of the data + * Callback for the data stream + * Returns the offset if seek is successful or -1 on error + */ +off64_t libewf_buffer_data_handle_seek_segment_offset( + libewf_buffer_data_handle_t *data_handle, + intptr_t *file_io_handle LIBEWF_ATTRIBUTE_UNUSED, + int segment_index, + int segment_file_index LIBEWF_ATTRIBUTE_UNUSED, + off64_t segment_offset, + libcerror_error_t **error ) +{ + static char *function = "libewf_buffer_data_handle_seek_segment_offset"; + + LIBEWF_UNREFERENCED_PARAMETER( file_io_handle ) + LIBEWF_UNREFERENCED_PARAMETER( segment_file_index ) + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( segment_index != 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid segment index value out of bounds.", + function ); + + return( -1 ); + } + if( segment_offset < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid segment offset value out of bounds.", + function ); + + return( -1 ); + } + data_handle->current_offset = segment_offset; + + return( segment_offset ); +} + diff --git a/libewf/libewf_buffer_data_handle.h b/libewf/libewf_buffer_data_handle.h new file mode 100644 index 000000000..68b25324a --- /dev/null +++ b/libewf/libewf_buffer_data_handle.h @@ -0,0 +1,85 @@ +/* + * The buffer data handle functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBEWF_BUFFER_DATA_HANDLE_H ) +#define _LIBEWF_BUFFER_DATA_HANDLE_H + +#include +#include + +#include "libewf_libcerror.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +typedef struct libewf_buffer_data_handle libewf_buffer_data_handle_t; + +struct libewf_buffer_data_handle +{ + /* The current offset + */ + off64_t current_offset; + + /* The data + */ + const uint8_t *data; + + /* The data size + */ + size_t data_size; +}; + +int libewf_buffer_data_handle_initialize( + libewf_buffer_data_handle_t **data_handle, + const uint8_t *data, + size_t data_size, + libcerror_error_t **error ); + +int libewf_buffer_data_handle_free( + libewf_buffer_data_handle_t **data_handle, + libcerror_error_t **error ); + +ssize_t libewf_buffer_data_handle_read_segment_data( + libewf_buffer_data_handle_t *data_handle, + intptr_t *file_io_handle, + int segment_index, + int segment_file_index, + uint8_t *segment_data, + size_t segment_data_size, + uint32_t segment_flags, + uint8_t read_flags, + libcerror_error_t **error ); + +off64_t libewf_buffer_data_handle_seek_segment_offset( + libewf_buffer_data_handle_t *data_handle, + intptr_t *file_io_handle, + int segment_index, + int segment_file_index, + off64_t segment_offset, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBEWF_BUFFER_DATA_HANDLE_H ) */ + diff --git a/libewf/libewf_data_stream.c b/libewf/libewf_data_stream.c new file mode 100644 index 000000000..e23352132 --- /dev/null +++ b/libewf/libewf_data_stream.c @@ -0,0 +1,235 @@ +/* + * Data stream functions + * + * Copyright (C) 2010-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "libewf_buffer_data_handle.h" +#include "libewf_data_stream.h" +#include "libewf_libcerror.h" +#include "libewf_libfdata.h" +#include "libewf_section_data_handle.h" + +/* Creates data stream from a buffer of data + * Make sure the value data_stream is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libewf_data_stream_initialize_from_buffer( + libfdata_stream_t **data_stream, + const uint8_t *buffer, + size_t buffer_size, + libcerror_error_t **error ) +{ + libewf_buffer_data_handle_t *data_handle = NULL; + libfdata_stream_t *safe_data_stream = NULL; + static char *function = "libewf_data_stream_initialize_from_buffer"; + int segment_index = 0; + + if( data_stream == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data stream.", + function ); + + return( -1 ); + } + if( libewf_buffer_data_handle_initialize( + &data_handle, + buffer, + buffer_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create buffer data handle.", + function ); + + goto on_error; + } + if( libfdata_stream_initialize( + &safe_data_stream, + (intptr_t *) data_handle, + (int (*)(intptr_t **, libcerror_error_t **)) &libewf_buffer_data_handle_free, + NULL, + NULL, + (ssize_t (*)(intptr_t *, intptr_t *, int, int, uint8_t *, size_t, uint32_t, uint8_t, libcerror_error_t **)) &libewf_buffer_data_handle_read_segment_data, + NULL, + (off64_t (*)(intptr_t *, intptr_t *, int, int, off64_t, libcerror_error_t **)) &libewf_buffer_data_handle_seek_segment_offset, + LIBFDATA_DATA_HANDLE_FLAG_MANAGED, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create data stream.", + function ); + + goto on_error; + } + data_handle = NULL; + + if( libfdata_stream_append_segment( + safe_data_stream, + &segment_index, + 0, + 0, + (size64_t) buffer_size, + 0, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, + "%s: unable to append data stream segment.", + function ); + + goto on_error; + } + *data_stream = safe_data_stream; + + return( 1 ); + +on_error: + if( safe_data_stream != NULL ) + { + libfdata_stream_free( + &safe_data_stream, + NULL ); + } + if( data_handle != NULL ) + { + libewf_buffer_data_handle_free( + &data_handle, + NULL ); + } + return( -1 ); +} + +/* Creates data stream from a section + * Make sure the value data_stream is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libewf_data_stream_initialize_from_section( + libfdata_stream_t **data_stream, + int file_io_pool_entry, + off64_t data_offset, + size64_t data_size, + libcerror_error_t **error ) +{ + libewf_section_data_handle_t *data_handle = NULL; + libfdata_stream_t *safe_data_stream = NULL; + static char *function = "libewf_data_stream_initialize_from_section"; + int segment_index = 0; + + if( data_stream == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data stream.", + function ); + + return( -1 ); + } + if( libewf_section_data_handle_initialize( + &data_handle, + data_offset, + data_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create section data handle.", + function ); + + goto on_error; + } + if( libfdata_stream_initialize( + &safe_data_stream, + (intptr_t *) data_handle, + (int (*)(intptr_t **, libcerror_error_t **)) &libewf_section_data_handle_free, + NULL, + NULL, + (ssize_t (*)(intptr_t *, intptr_t *, int, int, uint8_t *, size_t, uint32_t, uint8_t, libcerror_error_t **)) &libewf_section_data_handle_read_segment_data, + NULL, + (off64_t (*)(intptr_t *, intptr_t *, int, int, off64_t, libcerror_error_t **)) &libewf_section_data_handle_seek_segment_offset, + LIBFDATA_DATA_HANDLE_FLAG_MANAGED, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create data stream.", + function ); + + goto on_error; + } + data_handle = NULL; + + if( libfdata_stream_append_segment( + safe_data_stream, + &segment_index, + file_io_pool_entry, + 0, + data_size, + 0, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, + "%s: unable to append data stream segment.", + function ); + + goto on_error; + } + *data_stream = safe_data_stream; + + return( 1 ); + +on_error: + if( safe_data_stream != NULL ) + { + libfdata_stream_free( + &safe_data_stream, + NULL ); + } + if( data_handle != NULL ) + { + libewf_section_data_handle_free( + &data_handle, + NULL ); + } + return( -1 ); +} + diff --git a/libewf/libewf_data_stream.h b/libewf/libewf_data_stream.h new file mode 100644 index 000000000..0a8eabee1 --- /dev/null +++ b/libewf/libewf_data_stream.h @@ -0,0 +1,53 @@ +/* + * Data stream functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBEWF_DATA_STREAM_H ) +#define _LIBEWF_DATA_STREAM_H + +#include +#include + +#include "libewf_libcerror.h" +#include "libewf_libfdata.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +int libewf_data_stream_initialize_from_buffer( + libfdata_stream_t **data_stream, + const uint8_t *buffer, + size_t buffer_size, + libcerror_error_t **error ); + +int libewf_data_stream_initialize_from_section( + libfdata_stream_t **data_stream, + int file_io_pool_entry, + off64_t data_offset, + size64_t data_size, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBEWF_DATA_STREAM_H ) */ + diff --git a/libewf/libewf_handle.c b/libewf/libewf_handle.c index 52e3721e5..2ddf47471 100644 --- a/libewf/libewf_handle.c +++ b/libewf/libewf_handle.c @@ -33,6 +33,7 @@ #include "libewf_codepage.h" #include "libewf_compression.h" #include "libewf_data_chunk.h" +#include "libewf_data_stream.h" #include "libewf_debug.h" #include "libewf_definitions.h" #include "libewf_device_information.h" @@ -1612,28 +1613,25 @@ int libewf_internal_handle_open_read_segment_file_section_data( int file_io_pool_entry, libcerror_error_t **error ) { - libewf_header_sections_t *header_sections = NULL; - libewf_section_descriptor_t *section = NULL; - libfcache_cache_t *sections_cache = NULL; - uint8_t *single_files_data = NULL; - uint8_t *single_files_section_data = NULL; - uint8_t *string_data = NULL; - static char *function = "libewf_internal_handle_open_read_segment_file_section_data"; - size_t single_files_data_size = 0; - size_t single_files_section_data_size = 0; - size_t string_data_size = 0; - ssize_t read_count = 0; - off64_t section_data_offset = 0; - uint8_t header_section_found = 0; - uint8_t initialize_chunk_values = 0; - int number_of_sections = 0; - int read_table_sections = 0; - int result = 0; - int section_index = 0; - int set_identifier_change = 0; + libewf_header_sections_t *header_sections = NULL; + libewf_section_descriptor_t *section_descriptor = NULL; + libfcache_cache_t *sections_cache = NULL; + libfdata_stream_t *single_files_data_stream = NULL; + uint8_t *string_data = NULL; + static char *function = "libewf_internal_handle_open_read_segment_file_section_data"; + size_t string_data_size = 0; + ssize_t read_count = 0; + off64_t section_data_offset = 0; + uint8_t header_section_found = 0; + uint8_t initialize_chunk_values = 0; + int number_of_sections = 0; + int read_table_sections = 0; + int result = 0; + int section_index = 0; + int set_identifier_change = 0; #if defined( HAVE_VERBOSE_OUTPUT ) - int known_section = 0; + int known_section = 0; #endif if( internal_handle == NULL ) @@ -1752,7 +1750,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( (intptr_t *) file_io_pool, (libfdata_cache_t *) sections_cache, section_index, - (intptr_t **) §ion, + (intptr_t **) §ion_descriptor, 0, error ) != 1 ) { @@ -1760,14 +1758,14 @@ int libewf_internal_handle_open_read_segment_file_section_data( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve section: %d from sections list.", + "%s: unable to retrieve section: %d descriptor from list.", function, section_index ); goto on_error; } - result = libewf_section_get_data_offset( - section, + result = libewf_section_descriptor_get_data_offset( + section_descriptor, segment_file->major_version, §ion_data_offset, error ); @@ -1812,7 +1810,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( libcnotify_printf( "%s: reading %s section data from file IO pool entry: %d at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, - (char *) section->type_string, + (char *) section_descriptor->type_string, file_io_pool_entry, segment_file->current_offset, segment_file->current_offset ); @@ -1822,7 +1820,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( libcnotify_printf( "%s: reading 0x%08" PRIx32 " section data from file IO pool entry: %d at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", function, - section->type, + section_descriptor->type, file_io_pool_entry, segment_file->current_offset, segment_file->current_offset ); @@ -1830,13 +1828,13 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif /* defined( HAVE_DEBUG_OUTPUT ) */ } - if( section->type != 0 ) + if( section_descriptor->type != 0 ) { - switch( section->type ) + switch( section_descriptor->type ) { case LIBEWF_SECTION_TYPE_DEVICE_INFORMATION: read_count = libewf_device_information_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -1855,7 +1853,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( initialize_chunk_values = 1; } read_count = libewf_case_data_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -1900,7 +1898,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( { read_count = libewf_segment_file_read_table_section( segment_file, - section, + section_descriptor, file_io_pool, file_io_pool_entry, internal_handle->media_values->chunk_size, @@ -1924,7 +1922,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif read_count = libewf_error2_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -1950,7 +1948,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif read_count = libewf_session_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -1973,7 +1971,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( case LIBEWF_SECTION_TYPE_MD5_HASH: read_count = libewf_md5_hash_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -1988,7 +1986,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( case LIBEWF_SECTION_TYPE_SHA1_HASH: read_count = libewf_sha1_hash_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2002,7 +2000,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( case LIBEWF_SECTION_TYPE_RESTART_DATA: read_count = libewf_section_compressed_string_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2082,7 +2080,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( case LIBEWF_SECTION_TYPE_ANALYTICAL_DATA: read_count = libewf_section_compressed_string_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2142,15 +2140,12 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif read_count = libewf_ltree_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, segment_file->major_version, - &single_files_section_data, - &single_files_section_data_size, - &single_files_data, - &single_files_data_size, + &single_files_data_stream, error ); #if defined( HAVE_VERBOSE_OUTPUT ) @@ -2159,10 +2154,10 @@ int libewf_internal_handle_open_read_segment_file_section_data( break; } } - else if( section->type_string_length == 4 ) + else if( section_descriptor->type_string_length == 4 ) { if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "data", 4 ) == 0 ) { @@ -2178,7 +2173,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif read_count = libewf_section_data_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2203,13 +2198,13 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } else if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "disk", 4 ) == 0 ) { read_count = libewf_segment_file_read_volume_section( segment_file, - section, + section_descriptor, file_io_pool, file_io_pool_entry, internal_handle->media_values, @@ -2222,10 +2217,10 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } } - else if( section->type_string_length == 5 ) + else if( section_descriptor->type_string_length == 5 ) { if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "xhash", 5 ) == 0 ) { @@ -2241,7 +2236,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif read_count = libewf_section_compressed_string_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2297,10 +2292,10 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } } - else if( section->type_string_length == 6 ) + else if( section_descriptor->type_string_length == 6 ) { if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "digest", 6 ) == 0 ) { @@ -2316,7 +2311,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( } #endif read_count = libewf_digest_section_read_file_io_pool( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2328,12 +2323,12 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } else if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "header", 6 ) == 0 ) { read_count = libewf_section_compressed_string_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2394,7 +2389,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } else if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "table2", 6 ) == 0 ) { @@ -2402,7 +2397,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( { read_count = libewf_segment_file_read_table2_section( segment_file, - section, + section_descriptor, file_io_pool, file_io_pool_entry, error ); @@ -2412,13 +2407,13 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } else if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "volume", 6 ) == 0 ) { read_count = libewf_segment_file_read_volume_section( segment_file, - section, + section_descriptor, file_io_pool, file_io_pool_entry, internal_handle->media_values, @@ -2431,15 +2426,15 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } } - else if( section->type_string_length == 7 ) + else if( section_descriptor->type_string_length == 7 ) { if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "header2", 7 ) == 0 ) { read_count = libewf_section_compressed_string_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2501,12 +2496,12 @@ int libewf_internal_handle_open_read_segment_file_section_data( #endif } else if( memory_compare( - (void *) section->type_string, + (void *) section_descriptor->type_string, (void *) "xheader", 7 ) == 0 ) { read_count = libewf_section_compressed_string_read( - section, + section_descriptor, internal_handle->io_handle, file_io_pool, file_io_pool_entry, @@ -2577,21 +2572,21 @@ int libewf_internal_handle_open_read_segment_file_section_data( libcnotify_printf( "%s: unsupported section type: %s.\n", function, - (char *) section->type_string ); + (char *) section_descriptor->type_string ); } else if( segment_file->major_version == 2 ) { libcnotify_printf( "%s: unsupported section type: 0x%08" PRIx32 ".\n", function, - section->type ); + section_descriptor->type ); } } } #endif if( read_count == -1 ) { - if( section->type_string_length > 0 ) + if( section_descriptor->type_string_length > 0 ) { libcerror_error_set( error, @@ -2599,7 +2594,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read section: %s.", function, - (char *) section->type_string ); + (char *) section_descriptor->type_string ); } else { @@ -2609,7 +2604,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read section: 0x%08" PRIx32 ".", function, - section->type ); + section_descriptor->type ); } goto on_error; } @@ -2671,7 +2666,7 @@ int libewf_internal_handle_open_read_segment_file_section_data( goto on_error; } } - if( single_files_data != NULL ) + if( single_files_data_stream != NULL ) { if( libewf_single_files_initialize( &( internal_handle->single_files ), @@ -2686,10 +2681,10 @@ int libewf_internal_handle_open_read_segment_file_section_data( goto on_error; } - if( libewf_single_files_read_data( + if( libewf_single_files_read_data_stream( internal_handle->single_files, - single_files_data, - single_files_data_size, + single_files_data_stream, + file_io_pool, &( internal_handle->media_values->media_size ), &( internal_handle->io_handle->format ), error ) != 1 ) @@ -2703,11 +2698,6 @@ int libewf_internal_handle_open_read_segment_file_section_data( goto on_error; } - memory_free( - single_files_section_data ); - - single_files_section_data = NULL; - if( internal_handle->io_handle->segment_file_type != LIBEWF_SEGMENT_FILE_TYPE_EWF2_LOGICAL ) { if( internal_handle->io_handle->format == LIBEWF_FORMAT_LOGICAL_ENCASE7 ) @@ -2722,6 +2712,19 @@ int libewf_internal_handle_open_read_segment_file_section_data( { internal_handle->media_values->number_of_sectors += 1; } + if( libfdata_stream_free( + &single_files_data_stream, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free single files data stream.", + function ); + + goto on_error; + } } if( libewf_header_sections_free( &header_sections, @@ -2758,10 +2761,11 @@ int libewf_internal_handle_open_read_segment_file_section_data( &( internal_handle->single_files ), NULL ); } - if( single_files_section_data != NULL ) + if( single_files_data_stream != NULL ) { - memory_free( - single_files_section_data ); + libfdata_stream_free( + &single_files_data_stream, + NULL ); } if( string_data != NULL ) { @@ -3770,7 +3774,8 @@ int libewf_internal_handle_open_file_io_pool( if( ( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) && ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) { - if( internal_handle->write_io_handle->values_initialized == 0 ) + if( ( internal_handle->write_io_handle != NULL ) + && ( internal_handle->write_io_handle->values_initialized == 0 ) ) { if( libewf_write_io_handle_initialize_values( internal_handle->write_io_handle, @@ -3849,13 +3854,13 @@ int libewf_internal_handle_open_file_io_pool( { libewf_write_io_handle_free( &( internal_handle->write_io_handle ), - error ); + NULL ); } if( internal_handle->read_io_handle != NULL ) { libewf_read_io_handle_free( &( internal_handle->read_io_handle ), - error ); + NULL ); } return( -1 ); } @@ -4809,7 +4814,7 @@ ssize_t libewf_internal_handle_write_buffer_to_file_io_pool( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid handle - missing subhandle write.", + "%s: invalid handle - missing write IO handle.", function ); return( -1 ); @@ -5760,7 +5765,7 @@ ssize_t libewf_internal_handle_write_data_chunk_to_file_io_pool( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid handle - missing subhandle write.", + "%s: invalid handle - missing write IO handle.", function ); return( -1 ); diff --git a/libewf/libewf_line_reader.c b/libewf/libewf_line_reader.c new file mode 100644 index 000000000..6e8bfc564 --- /dev/null +++ b/libewf/libewf_line_reader.c @@ -0,0 +1,626 @@ +/* + * The line reader functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#if defined( HAVE_STRING_H ) || defined( WINAPI ) +#include +#endif + +#include "libewf_libbfio.h" +#include "libewf_libcerror.h" +#include "libewf_libcnotify.h" +#include "libewf_libfdata.h" +#include "libewf_libhmac.h" +#include "libewf_libuna.h" +#include "libewf_line_reader.h" + +/* Creates a line reader + * Make sure the value line_reader is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libewf_line_reader_initialize( + libewf_line_reader_t **line_reader, + libfdata_stream_t *data_stream, + libbfio_pool_t *file_io_pool, + libcerror_error_t **error ) +{ + static char *function = "libewf_line_reader_initialize"; + + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", + function ); + + return( -1 ); + } + if( *line_reader != NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, + "%s: invalid line reader value already set.", + function ); + + return( -1 ); + } + if( data_stream == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data stream.", + function ); + + return( -1 ); + } + *line_reader = memory_allocate_structure( + libewf_line_reader_t ); + + if( *line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create line reader.", + function ); + + goto on_error; + } + if( memory_set( + *line_reader, + 0, + sizeof( libewf_line_reader_t ) ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to clear line reader.", + function ); + + memory_free( + *line_reader ); + + *line_reader = NULL; + + return( -1 ); + } + if( libfdata_stream_get_size( + data_stream, + &( ( *line_reader )->stream_size ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data stream size.", + function ); + + goto on_error; + } + ( *line_reader )->buffer_size = 16 * 1024 * 1024; + + ( *line_reader )->buffer = (uint8_t *) memory_allocate( + ( *line_reader )->buffer_size ); + + if( ( *line_reader )->buffer == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create buffer.", + function ); + + goto on_error; + } + ( *line_reader )->utf8_string_size = 1 * 1024 * 1024; + + ( *line_reader )->utf8_string = (uint8_t *) memory_allocate( + ( *line_reader )->utf8_string_size ); + + if( ( *line_reader )->utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create UTF-8 string.", + function ); + + goto on_error; + } + if( libhmac_md5_initialize( + &( ( *line_reader )->md5_context ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to initialize MD5 context.", + function ); + + goto on_error; + } + ( *line_reader )->data_stream = data_stream; + ( *line_reader )->file_io_pool = file_io_pool; + + return( 1 ); + +on_error: + if( *line_reader != NULL ) + { + if( ( *line_reader )->utf8_string != NULL ) + { + memory_free( + ( *line_reader )->utf8_string ); + } + if( ( *line_reader )->buffer != NULL ) + { + memory_free( + ( *line_reader )->buffer ); + } + memory_free( + *line_reader ); + + *line_reader = NULL; + } + return( -1 ); +} + +/* Frees a line reader + * Returns 1 if successful or -1 on error + */ +int libewf_line_reader_free( + libewf_line_reader_t **line_reader, + libcerror_error_t **error ) +{ + static char *function = "libewf_line_reader_free"; + int result = 1; + + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", + function ); + + return( -1 ); + } + if( *line_reader != NULL ) + { + /* The data_stream reference is freed elsewhere + */ + if( libhmac_md5_free( + &( ( *line_reader )->md5_context ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free MD5 context.", + function ); + + result = -1; + } + memory_free( + ( *line_reader )->utf8_string ); + + memory_free( + ( *line_reader )->buffer ); + + memory_free( + *line_reader ); + + *line_reader = NULL; + } + return( result ); +} + +/* Reads a line + * Returns 1 if successful or -1 on error + */ +int libewf_line_reader_read_line( + libewf_line_reader_t *line_reader, + uint8_t **line_string, + size_t *line_string_size, + libcerror_error_t **error ) +{ + static char *function = "libewf_line_reader_read_line"; + size_t end_of_line_offset = 0; + size_t line_data_size = 0; + size_t read_size = 0; + size_t utf16_stream_size = 0; + size_t utf8_string_size = 0; + ssize_t read_count = 0; + + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", + function ); + + return( -1 ); + } + if( line_reader->buffer_offset >= line_reader->buffer_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid line reader - buffer offset value out of bounds.", + function ); + + return( -1 ); + } + if( line_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line string.", + function ); + + return( -1 ); + } + if( line_string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line string size.", + function ); + + return( -1 ); + } + read_size = line_reader->buffer_size - line_reader->buffer_offset; + + if( (size64_t) line_reader->stream_offset < line_reader->stream_size ) + { + if( ( line_reader->stream_offset == 0 ) + || ( read_size < line_reader->utf8_string_size ) ) + { +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) + { + libcnotify_printf( + "%s: additional line data needed at offset: %" PRIi64 " (0x%08" PRIx64 ").\n", + function, + line_reader->line_offset, + line_reader->line_offset ); + } +#endif + if( line_reader->buffer_offset > 0 ) + { + if( memmove( + line_reader->buffer, + &( line_reader->buffer[ line_reader->buffer_offset ] ), + read_size ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to move buffer content to start.", + function ); + + return( -1 ); + } + line_reader->buffer_offset = read_size; + + read_size = line_reader->buffer_size - read_size; + } + if( read_size > ( line_reader->stream_size - line_reader->stream_offset ) ) + { + read_size = (size_t) ( line_reader->stream_size - line_reader->stream_offset ); + } +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) + { + libcnotify_printf( + "%s: reading %" PRIzd " bytes of section data at offset: %" PRIi64 " (0x%08" PRIx64 ").\n", + function, + read_size, + line_reader->stream_offset, + line_reader->stream_offset ); + } +#endif + read_count = libfdata_stream_read_buffer_at_offset( + line_reader->data_stream, + (intptr_t *) line_reader->file_io_pool, + &( line_reader->buffer[ line_reader->buffer_offset ] ), + read_size, + line_reader->stream_offset, + 0, + error ); + + if( read_count != (ssize_t) read_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read section data at offset: %" PRIi64 " (0x%08" PRIx64 ").", + function, + line_reader->stream_offset, + line_reader->stream_offset ); + + return( -1 ); + } + line_reader->stream_offset += read_count; + + if( libhmac_md5_update( + line_reader->md5_context, + &( line_reader->buffer[ line_reader->buffer_offset ] ), + read_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_SET_FAILED, + "%s: unable to update MD5 digest hash.", + function ); + + return( -1 ); + } + line_reader->buffer_offset = 0; + } + } + for( end_of_line_offset = line_reader->buffer_offset; + end_of_line_offset < line_reader->buffer_size; + end_of_line_offset += 2 ) + { + if( ( line_reader->buffer[ end_of_line_offset ] == (uint8_t) '\n' ) + && ( line_reader->buffer[ end_of_line_offset + 1 ] == 0 ) ) + { + line_data_size = ( end_of_line_offset + 2 ) - line_reader->buffer_offset; + + break; + } + } + /* Remove trailing carriage return + */ + if( end_of_line_offset >= 2 ) + { + if( ( line_reader->buffer[ end_of_line_offset - 2 ] == (uint8_t) '\r' ) + && ( line_reader->buffer[ end_of_line_offset - 1 ] == 0 ) ) + { + end_of_line_offset -= 2; + } + } + utf16_stream_size = end_of_line_offset - line_reader->buffer_offset; + + if( utf16_stream_size == 0 ) + { + line_reader->utf8_string[ 0 ] = 0; + utf8_string_size = 1; + } + else + { + if( libuna_utf8_string_size_from_utf16_stream( + &( line_reader->buffer[ line_reader->buffer_offset ] ), + utf16_stream_size, + LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, + &utf8_string_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_CONVERSION, + LIBCERROR_CONVERSION_ERROR_GENERIC, + "%s: unable to set UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > line_reader->utf8_string_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid UTF-8 string size value out of bounds.", + function ); + + return( -1 ); + } +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) + { + libcnotify_printf( + "%s: line: %d string data at offset: %" PRIi64 " (0x%08" PRIx64 "):\n", + function, + line_reader->line_index, + line_reader->line_offset, + line_reader->line_offset ); + libcnotify_print_data( + &( line_reader->buffer[ line_reader->buffer_offset ] ), + utf16_stream_size, + 0 ); + } +#endif + if( libuna_utf8_string_copy_from_utf16_stream( + line_reader->utf8_string, + utf8_string_size, + &( line_reader->buffer[ line_reader->buffer_offset ] ), + utf16_stream_size, + LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_CONVERSION, + LIBCERROR_CONVERSION_ERROR_GENERIC, + "%s: unable to set UTF-8 string.", + function ); + + return( -1 ); + } + } + line_reader->buffer_offset += line_data_size; + line_reader->line_offset += line_data_size; + line_reader->line_index += 1; + + *line_string = line_reader->utf8_string; + *line_string_size = utf8_string_size; + + return( 1 ); +} + +/* Finalizes the line reader + * Returns 1 if successful or -1 on error + */ +int libewf_line_reader_finalize( + libewf_line_reader_t *line_reader, + libcerror_error_t **error ) +{ + uint8_t calculated_md5_hash[ LIBHMAC_MD5_HASH_SIZE ]; + + static char *function = "libewf_line_reader_finalize"; + size_t read_size = 0; + ssize_t read_count = 0; + + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", + function ); + + return( -1 ); + } + while( (size64_t) line_reader->stream_offset < line_reader->stream_size ) + { + read_size = line_reader->buffer_size; + + if( read_size > ( line_reader->stream_size - line_reader->stream_offset ) ) + { + read_size = (size_t) ( line_reader->stream_size - line_reader->stream_offset ); + } + read_count = libfdata_stream_read_buffer_at_offset( + line_reader->data_stream, + (intptr_t *) line_reader->file_io_pool, + line_reader->buffer, + read_size, + 0, + line_reader->stream_offset, + error ); + + if( read_count != (ssize_t) read_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read section data at offset: %" PRIi64 " (0x%08" PRIx64 ").", + function, + line_reader->stream_offset, + line_reader->stream_offset ); + + return( -1 ); + } + line_reader->stream_offset += read_count; + + if( libhmac_md5_update( + line_reader->md5_context, + line_reader->buffer, + read_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_SET_FAILED, + "%s: unable to update MD5 digest hash.", + function ); + + return( -1 ); + } + } + if( libhmac_md5_finalize( + line_reader->md5_context, + calculated_md5_hash, + LIBHMAC_MD5_HASH_SIZE, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to finalize MD5 hash.", + function ); + + return( -1 ); + } +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) + { + libcnotify_printf( + "%s: calculated MD5 hash:\n", + function ); + libcnotify_print_data( + calculated_md5_hash, + 16, + 0 ); + } +#endif +/* TODO + if( memory_compare( + stored_md5_hash, + calculated_md5_hash, + 16 ) != 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_INPUT, + LIBCERROR_INPUT_ERROR_VALUE_MISMATCH, + "%s: mismatch in integrity hash.", + function ); + + return( -1 ); + } +*/ + return( 1 ); +} + diff --git a/libewf/libewf_line_reader.h b/libewf/libewf_line_reader.h new file mode 100644 index 000000000..4f05ccb1d --- /dev/null +++ b/libewf/libewf_line_reader.h @@ -0,0 +1,115 @@ +/* + * The line reader functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBEWF_LINE_READER_H ) +#define _LIBEWF_LINE_READER_H + +#include +#include + +#include "libewf_libbfio.h" +#include "libewf_libcerror.h" +#include "libewf_libfdata.h" +#include "libewf_libhmac.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +typedef struct libewf_line_reader libewf_line_reader_t; + +struct libewf_line_reader +{ + /* The data stream + */ + libfdata_stream_t *data_stream; + + /* The file IO pool + */ + libbfio_pool_t *file_io_pool; + + /* The stream offset + */ + off64_t stream_offset; + + /* The stream size + */ + size64_t stream_size; + + /* The buffer + */ + uint8_t *buffer; + + /* The buffer size + */ + size_t buffer_size; + + /* The buffer offset + */ + size_t buffer_offset; + + /* The UTF-8 string + */ + uint8_t *utf8_string; + + /* The UTF-8 string size + */ + size_t utf8_string_size; + + /* The line offset + */ + off64_t line_offset; + + /* The line index + */ + int line_index; + + /* The MD5 context + */ + libhmac_md5_context_t *md5_context; +}; + +int libewf_line_reader_initialize( + libewf_line_reader_t **line_reader, + libfdata_stream_t *data_stream, + libbfio_pool_t *file_io_pool, + libcerror_error_t **error ); + +int libewf_line_reader_free( + libewf_line_reader_t **line_reader, + libcerror_error_t **error ); + +int libewf_line_reader_read_line( + libewf_line_reader_t *line_reader, + uint8_t **line_string, + size_t *line_string_size, + libcerror_error_t **error ); + +int libewf_line_reader_finalize( + libewf_line_reader_t *line_reader, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBEWF_LINE_READER_H ) */ + diff --git a/libewf/libewf_ltree_section.c b/libewf/libewf_ltree_section.c index 3194d4855..fe1d144fd 100644 --- a/libewf/libewf_ltree_section.c +++ b/libewf/libewf_ltree_section.c @@ -27,6 +27,7 @@ #include "libewf_checksum.h" #include "libewf_debug.h" +#include "libewf_data_stream.h" #include "libewf_definitions.h" #include "libewf_hash_sections.h" #include "libewf_io_handle.h" @@ -41,99 +42,226 @@ #include "ewf_ltree.h" -/* Reads a version 1 ltree section or version 2 singles files data section - * single_files_data will be set to a pointer within the section data +/* Reads a version 1 ltree header * Returns 1 if successful or -1 on error */ -int libewf_ltree_section_read_data( +int libewf_ltree_section_read_header_data( const uint8_t *data, size_t data_size, - uint8_t format_version, - uint8_t **single_files_data, - size_t *single_files_data_size, + uint64_t *single_files_data_size, libcerror_error_t **error ) { - uint8_t calculated_md5_hash[ 16 ]; - - uint8_t ltree_header_data[ sizeof( ewf_ltree_header_t ) ]; - - static char *function = "libewf_ltree_section_read_data"; - size_t data_offset = 0; - uint64_t stored_data_size = 0; - uint32_t calculated_checksum = 0; - uint32_t stored_checksum = 0; - -#if defined( HAVE_DEBUG_OUTPUT ) - size_t trailing_data_size = 0; -#endif + static char *function = "libewf_ltree_section_read_header_data"; + uint64_t safe_single_files_data_size = 0; + uint32_t calculated_checksum = 0; + uint32_t stored_checksum = 0; if( data == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing data.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data.", function ); return( -1 ); } - if( data_size > (size_t) SSIZE_MAX ) + if( ( data_size < sizeof( ewf_ltree_header_t ) ) + || ( data_size > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid data size value exceeds maximum.", + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data size value out of bounds.", function ); return( -1 ); } - if( ( format_version != 1 ) - && ( format_version != 2 ) ) + if( single_files_data_size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, - "%s: unsupported format version.", + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid single files data size.", function ); return( -1 ); } - if( single_files_data == NULL ) +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) + { + libcnotify_printf( + "%s: ltree header data:\n", + function ); + libcnotify_print_data( + data, + sizeof( ewf_ltree_header_t ), + 0 ); + } +#endif + byte_stream_copy_to_uint64_little_endian( + ( (ewf_ltree_header_t *) data )->data_size, + safe_single_files_data_size ); + + byte_stream_copy_to_uint32_little_endian( + ( (ewf_ltree_header_t *) data )->checksum, + stored_checksum ); + +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) + { + libcnotify_printf( + "%s: integrity hash:\n", + function ); + libcnotify_print_data( + ( (ewf_ltree_header_t *) data )->integrity_hash, + 16, + 0 ); + + libcnotify_printf( + "%s: data size\t\t\t: %" PRIu64 "\n", + function, + safe_single_files_data_size ); + + libcnotify_printf( + "%s: checksum\t\t\t\t: 0x%08" PRIx32 "\n", + function, + stored_checksum ); + + libcnotify_printf( + "%s: unknown1:\n", + function ); + libcnotify_print_data( + ( (ewf_ltree_header_t *) data )->unknown1, + 20, + 0 ); + } +#endif /* defined( HAVE_DEBUG_OUTPUT ) */ + + byte_stream_copy_from_uint32_little_endian( + ( (ewf_ltree_header_t *) data )->checksum, + 0 ); + + if( libewf_checksum_calculate_adler32( + &calculated_checksum, + data, + sizeof( ewf_ltree_header_t ), + 1, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_SET_FAILED, + "%s: unable to calculate header checksum.", + function ); + + return( -1 ); + } + if( stored_checksum != calculated_checksum ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_INPUT, + LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH, + "%s: header checksum does not match (stored: 0x%08" PRIx32 ", calculated: 0x%08" PRIx32 ").", + function, + stored_checksum, + calculated_checksum ); + + return( -1 ); + } + *single_files_data_size = safe_single_files_data_size; + + return( 1 ); +} + +/* Reads a version 1 ltree section or version 2 singles files data section + * Returns the number of bytes read or -1 on error + */ +ssize_t libewf_ltree_section_read_file_io_pool( + libewf_section_descriptor_t *section_descriptor, + libewf_io_handle_t *io_handle, + libbfio_pool_t *file_io_pool, + int file_io_pool_entry, + uint8_t format_version, + libfdata_stream_t **data_stream, + libcerror_error_t **error ) +{ + uint8_t header_data[ sizeof( ewf_ltree_header_t ) ]; + + libfdata_stream_t *safe_data_stream = NULL; + static char *function = "libewf_ltree_section_read_file_io_pool"; + size64_t data_size = 0; + ssize_t read_count = 0; + off64_t data_offset = 0; + uint64_t single_files_data_size = 0; + + if( section_descriptor == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid single files data.", + "%s: invalid section descriptor.", function ); return( -1 ); } - if( *single_files_data != NULL ) + if( ( section_descriptor->data_flags & LIBEWF_SECTION_DATA_FLAGS_IS_ENCRYPTED ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid single files data value already set.", + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid section descriptor - encrypted section currently not supported.", function ); return( -1 ); } - if( single_files_data_size == NULL ) + if( ( format_version != 1 ) + && ( format_version != 2 ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported format version.", + function ); + + return( -1 ); + } + if( data_stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid single files data size.", + "%s: invalid data stream.", function ); return( -1 ); } + if( libewf_section_descriptor_get_data_offset( + section_descriptor, + format_version, + &data_offset, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve section data offset.", + function ); + + goto on_error; + } + data_size = section_descriptor->data_size; + if( format_version == 1 ) { if( data_size < sizeof( ewf_ltree_header_t ) ) @@ -145,201 +273,86 @@ int libewf_ltree_section_read_data( "%s: invalid section size value out of bounds - insufficient space for header.", function ); - return( -1 ); - } -#if defined( HAVE_DEBUG_OUTPUT ) - if( libcnotify_verbose != 0 ) - { - libcnotify_printf( - "%s: ltree header data:\n", - function ); - libcnotify_print_data( - data, - sizeof( ewf_ltree_header_t ), - 0 ); - } -#endif - byte_stream_copy_to_uint64_little_endian( - ( (ewf_ltree_header_t *) data )->data_size, - stored_data_size ); - - byte_stream_copy_to_uint32_little_endian( - ( (ewf_ltree_header_t *) data )->checksum, - stored_checksum ); - -#if defined( HAVE_DEBUG_OUTPUT ) - if( libcnotify_verbose != 0 ) - { - libcnotify_printf( - "%s: integrity hash:\n", - function ); - libcnotify_print_data( - ( (ewf_ltree_header_t *) data )->integrity_hash, - 16, - 0 ); - - libcnotify_printf( - "%s: data size\t\t\t\t\t: %" PRIu64 "\n", - function, - stored_data_size ); - - libcnotify_printf( - "%s: checksum\t\t\t\t\t: 0x%08" PRIx32 "\n", - function, - stored_checksum ); - - libcnotify_printf( - "%s: unknown1:\n", - function ); - libcnotify_print_data( - ( (ewf_ltree_header_t *) data )->unknown1, - 20, - 0 ); + goto on_error; } -#endif /* defined( HAVE_DEBUG_OUTPUT ) */ - - if( memory_copy( - ltree_header_data, - data, - sizeof( ewf_ltree_header_t ) ) == NULL ) + read_count = libbfio_pool_read_buffer_at_offset( + file_io_pool, + file_io_pool_entry, + header_data, + sizeof( ewf_ltree_header_t ), + data_offset, + error ); + + if( read_count != (ssize_t) sizeof( ewf_ltree_header_t ) ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy ltree header data.", - function ); + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read header data at offset: %" PRIi64 " (0x%08" PRIx64 ").", + function, + data_offset, + data_offset ); - return( -1 ); + goto on_error; } - byte_stream_copy_from_uint32_little_endian( - ( (ewf_ltree_header_t *) ltree_header_data )->checksum, - 0 ); - - if( libewf_checksum_calculate_adler32( - &calculated_checksum, - ltree_header_data, + if( libewf_ltree_section_read_header_data( + header_data, sizeof( ewf_ltree_header_t ), - 1, + &single_files_data_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to calculate header checksum.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read header.", function ); - return( -1 ); - } - if( stored_checksum != calculated_checksum ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_INPUT, - LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH, - "%s: header checksum does not match (stored: 0x%08" PRIx32 ", calculated: 0x%08" PRIx32 ").", - function, - stored_checksum, - calculated_checksum ); - - return( -1 ); + goto on_error; } data_offset += sizeof( ewf_ltree_header_t ); data_size -= sizeof( ewf_ltree_header_t ); - if( stored_data_size > (uint64_t) data_size ) + if( single_files_data_size > data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid section size value out of bounds - insufficient space for entries data.", + "%s: invalid single files data size value out of bounds.", function ); - return( -1 ); + goto on_error; } - *single_files_data = (uint8_t *) &( data[ data_offset ] ); - *single_files_data_size = (size_t) stored_data_size; + data_size = single_files_data_size; } - else if( format_version == 2 ) - { - *single_files_data = (uint8_t *) data; - *single_files_data_size = data_size; - } -#if defined( HAVE_DEBUG_OUTPUT ) - if( libcnotify_verbose != 0 ) + if( libewf_data_stream_initialize_from_section( + &safe_data_stream, + file_io_pool_entry, + data_offset, + data_size, + error ) != 1 ) { - if( libewf_debug_utf16_stream_print( - "single files data", - *single_files_data, - *single_files_data_size, - LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, - "%s: unable to print single files data.", - function ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create section data stream.", + function ); - return( -1 ); - } + goto on_error; } -#endif - if( format_version == 1 ) - { - if( libhmac_md5_calculate( - *single_files_data, - *single_files_data_size, - calculated_md5_hash, - 16, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to calculate integrity hash.", - function ); - - return( -1 ); - } -#if defined( HAVE_DEBUG_OUTPUT ) - if( libcnotify_verbose != 0 ) - { - libcnotify_printf( - "%s: calculated MD5 hash:\n", - function ); - libcnotify_print_data( - calculated_md5_hash, - 16, - 0 ); - } -#endif - if( memory_compare( - data, - calculated_md5_hash, - 16 ) != 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_INPUT, - LIBCERROR_INPUT_ERROR_VALUE_MISMATCH, - "%s: mismatch in integrity hash.", - function ); - - return( -1 ); - } #if defined( HAVE_DEBUG_OUTPUT ) || defined( HAVE_VERBOSE_OUTPUT ) - if( libcnotify_verbose != 0 ) + if( libcnotify_verbose != 0 ) + { + if( format_version == 1 ) { - if( stored_data_size < (uint64_t) data_size ) + if( single_files_data_size < ( data_size - sizeof( ewf_ltree_header_t ) ) ) { #if defined( HAVE_DEBUG_OUTPUT ) - data_offset += stored_data_size; - trailing_data_size = data_size - stored_data_size; +/* TODO read trailing data + size_t trailing_data_size = 0; libcnotify_printf( "%s: trailing data:\n", @@ -348,6 +361,10 @@ int libewf_ltree_section_read_data( &( data[ data_offset ] ), trailing_data_size, 0 ); +*/ + libcnotify_printf( + "%s: section has trailing data.\n", + function ); #elif defined( HAVE_VERBOSE_OUTPUT ) libcnotify_printf( @@ -356,105 +373,20 @@ int libewf_ltree_section_read_data( #endif } } -#endif /* defined( HAVE_DEBUG_OUTPUT ) || defined( HAVE_VERBOSE_OUTPUT ) */ } - return( 1 ); -} - -/* Reads a version 1 ltree section or version 2 singles files data section - * section_data will be set to a buffer containing the full section data - * single_files_data will be set to a pointer within the section data - * Returns the number of bytes read or -1 on error - */ -ssize_t libewf_ltree_section_read_file_io_pool( - libewf_section_descriptor_t *section_descriptor, - libewf_io_handle_t *io_handle, - libbfio_pool_t *file_io_pool, - int file_io_pool_entry, - uint8_t format_version, - uint8_t **section_data, - size_t *section_data_size, - uint8_t **single_files_data, - size_t *single_files_data_size, - libcerror_error_t **error ) -{ - static char *function = "libewf_ltree_section_read_file_io_pool"; - ssize_t read_count = 0; - - if( section_descriptor == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid section descriptor.", - function ); - - return( -1 ); - } - read_count = libewf_section_read_data( - section_descriptor, - io_handle, - file_io_pool, - file_io_pool_entry, - section_data, - section_data_size, - error ); - - if( read_count == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_IO, - LIBCERROR_IO_ERROR_READ_FAILED, - "%s: unable to read section data.", - function ); - - goto on_error; - } - else if( read_count > 0 ) - { - if( section_data == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing section data.", - function ); +#endif /* defined( HAVE_DEBUG_OUTPUT ) || defined( HAVE_VERBOSE_OUTPUT ) */ - goto on_error; - } - if( libewf_ltree_section_read_data( - *section_data, - *section_data_size, - format_version, - single_files_data, - single_files_data_size, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_IO, - LIBCERROR_IO_ERROR_READ_FAILED, - "%s: unable to read ltree section.", - function ); + *data_stream = safe_data_stream; - goto on_error; - } - } return( read_count ); on_error: - if( *section_data != NULL ) + if( safe_data_stream != NULL ) { - memory_free( - *section_data ); - - *section_data = NULL; + libfdata_stream_free( + &safe_data_stream, + NULL ); } - *section_data_size = 0; - return( -1 ); } diff --git a/libewf/libewf_ltree_section.h b/libewf/libewf_ltree_section.h index 28f1aba4a..13d463c0b 100644 --- a/libewf/libewf_ltree_section.h +++ b/libewf/libewf_ltree_section.h @@ -28,30 +28,26 @@ #include "libewf_io_handle.h" #include "libewf_libbfio.h" #include "libewf_libcerror.h" +#include "libewf_libfdata.h" #include "libewf_section_descriptor.h" #if defined( __cplusplus ) extern "C" { #endif -int libewf_ltree_section_read_data( +int libewf_ltree_section_read_header_data( const uint8_t *data, size_t data_size, - uint8_t format_version, - uint8_t **single_files_data, - size_t *single_files_data_size, + uint64_t *single_files_data_size, libcerror_error_t **error ); ssize_t libewf_ltree_section_read_file_io_pool( libewf_section_descriptor_t *section_descriptor, - libewf_io_handle_t *io_handle, + libewf_io_handle_t *io_handle, libbfio_pool_t *file_io_pool, int file_io_pool_entry, uint8_t format_version, - uint8_t **section_data, - size_t *section_data_size, - uint8_t **single_files_data, - size_t *single_files_data_size, + libfdata_stream_t **data_stream, libcerror_error_t **error ); ssize_t libewf_ltree_section_write_file_io_pool( diff --git a/libewf/libewf_section.c b/libewf/libewf_section.c index 565148bd6..3f2e1c402 100644 --- a/libewf/libewf_section.c +++ b/libewf/libewf_section.c @@ -46,6 +46,7 @@ #include "libewf_unused.h" #include "ewf_data.h" +#include "ewf_section.h" /* Tests if a buffer entirely consists of zero values * Returns 1 if zero, 0 if not, or -1 on error @@ -92,54 +93,6 @@ int libewf_section_test_zero( return( 1 ); } -/* Retrieves the section data offset - * Returns 1 if successful, 0 if the section contains no data or -1 on error - */ -int libewf_section_get_data_offset( - libewf_section_descriptor_t *section_descriptor, - uint8_t format_version, - off64_t *data_offset, - libcerror_error_t **error ) -{ - static char *function = "libewf_section_get_data_offset"; - - if( section_descriptor == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid section descriptor.", - function ); - - return( -1 ); - } - if( data_offset == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid data offset.", - function ); - - return( -1 ); - } - if( section_descriptor->data_size == 0 ) - { - return( 0 ); - } - if( format_version == 1 ) - { - *data_offset = section_descriptor->start_offset + sizeof( ewf_section_descriptor_v1_t ); - } - else - { - *data_offset = section_descriptor->start_offset; - } - return( 1 ); -} - /* Reads the data of a section * The data is decrypted if necessary * Returns the number of bytes read or -1 on error @@ -321,7 +274,14 @@ ssize_t libewf_section_read_data( memory_free( safe_section_data ); - return( 0 ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid section descriptor - encrypted section currently not supported.", + function ); + + return( -1 ); } *section_data = safe_section_data; *section_data_size = (size_t) section_descriptor->data_size; diff --git a/libewf/libewf_section.h b/libewf/libewf_section.h index 2d4bacefa..0a0fa5cfa 100644 --- a/libewf/libewf_section.h +++ b/libewf/libewf_section.h @@ -48,12 +48,6 @@ int libewf_section_test_zero( size_t buffer_size, libcerror_error_t **error ); -int libewf_section_get_data_offset( - libewf_section_descriptor_t *section_descriptor, - uint8_t format_version, - off64_t *data_offset, - libcerror_error_t **error ); - ssize_t libewf_section_read_data( libewf_section_descriptor_t *section_descriptor, libewf_io_handle_t *io_handle, diff --git a/libewf/libewf_section_data_handle.c b/libewf/libewf_section_data_handle.c new file mode 100644 index 000000000..33ad5063f --- /dev/null +++ b/libewf/libewf_section_data_handle.c @@ -0,0 +1,310 @@ +/* + * The section data handle functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "libewf_definitions.h" +#include "libewf_libbfio.h" +#include "libewf_libcerror.h" +#include "libewf_section_data_handle.h" +#include "libewf_unused.h" + +/* Creates a section data handle + * Make sure the value data_handle is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libewf_section_data_handle_initialize( + libewf_section_data_handle_t **data_handle, + off64_t data_offset, + size64_t data_size, + libcerror_error_t **error ) +{ + static char *function = "libewf_section_data_handle_initialize"; + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( *data_handle != NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, + "%s: invalid data handle value already set.", + function ); + + return( -1 ); + } + *data_handle = memory_allocate_structure( + libewf_section_data_handle_t ); + + if( *data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create data handle.", + function ); + + goto on_error; + } + if( memory_set( + *data_handle, + 0, + sizeof( libewf_section_data_handle_t ) ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to clear data handle.", + function ); + + goto on_error; + } + ( *data_handle )->data_offset = data_offset; + ( *data_handle )->data_size = data_size; + + return( 1 ); + +on_error: + if( *data_handle != NULL ) + { + memory_free( + *data_handle ); + + *data_handle = NULL; + } + return( -1 ); +} + +/* Frees a section data handle + * Returns 1 if successful or -1 on error + */ +int libewf_section_data_handle_free( + libewf_section_data_handle_t **data_handle, + libcerror_error_t **error ) +{ + static char *function = "libewf_section_data_handle_free"; + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( *data_handle != NULL ) + { + memory_free( + *data_handle ); + + *data_handle = NULL; + } + return( 1 ); +} + +/* Reads data from the current offset into a buffer + * Callback for the data stream + * Returns the number of bytes read or -1 on error + */ +ssize_t libewf_section_data_handle_read_segment_data( + libewf_section_data_handle_t *data_handle, + libbfio_pool_t *file_io_pool, + int segment_index, + int file_io_pool_entry, + uint8_t *segment_data, + size_t segment_data_size, + uint32_t segment_flags LIBEWF_ATTRIBUTE_UNUSED, + uint8_t read_flags LIBEWF_ATTRIBUTE_UNUSED, + libcerror_error_t **error ) +{ + static char *function = "libewf_section_data_handle_read_segment_data"; + size_t read_size = 0; + ssize_t read_count = 0; + off64_t file_offset = 0; + + LIBEWF_UNREFERENCED_PARAMETER( segment_flags ) + LIBEWF_UNREFERENCED_PARAMETER( read_flags ) + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( data_handle->current_offset < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data handle - current offset value out of bounds.", + function ); + + return( -1 ); + } + if( segment_index != 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid segment index value out of bounds.", + function ); + + return( -1 ); + } + if( segment_data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid segment data.", + function ); + + return( -1 ); + } + if( segment_data_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid segment data size value exceeds maximum.", + function ); + + return( -1 ); + } + if( data_handle->current_offset >= (off64_t) data_handle->data_size ) + { + return( 0 ); + } + read_size = data_handle->data_size - (size_t) data_handle->current_offset; + + if( read_size > segment_data_size ) + { + read_size = segment_data_size; + } + file_offset = data_handle->data_offset + data_handle->current_offset; + + read_count = libbfio_pool_read_buffer_at_offset( + file_io_pool, + file_io_pool_entry, + segment_data, + segment_data_size, + file_offset, + error ); + + if( read_count != (ssize_t) read_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read section data at offset: %" PRIi64 " (0x%08" PRIx64 ").", + function, + file_offset, + file_offset ); + + return( -1 ); + } + data_handle->current_offset += read_size; + + return( (ssize_t) read_size ); +} + +/* Seeks a certain offset of the data + * Callback for the data stream + * Returns the offset if seek is successful or -1 on error + */ +off64_t libewf_section_data_handle_seek_segment_offset( + libewf_section_data_handle_t *data_handle, + intptr_t *file_io_handle LIBEWF_ATTRIBUTE_UNUSED, + int segment_index, + int segment_file_index LIBEWF_ATTRIBUTE_UNUSED, + off64_t segment_offset, + libcerror_error_t **error ) +{ + static char *function = "libewf_section_data_handle_seek_segment_offset"; + + LIBEWF_UNREFERENCED_PARAMETER( file_io_handle ) + LIBEWF_UNREFERENCED_PARAMETER( segment_file_index ) + + if( data_handle == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data handle.", + function ); + + return( -1 ); + } + if( segment_index != 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid segment index value out of bounds.", + function ); + + return( -1 ); + } + if( segment_offset < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid segment offset value out of bounds.", + function ); + + return( -1 ); + } + data_handle->current_offset = segment_offset; + + return( segment_offset ); +} + diff --git a/libewf/libewf_section_data_handle.h b/libewf/libewf_section_data_handle.h new file mode 100644 index 000000000..176fa1c1c --- /dev/null +++ b/libewf/libewf_section_data_handle.h @@ -0,0 +1,86 @@ +/* + * The section data handle functions + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBEWF_SECTION_DATA_HANDLE_H ) +#define _LIBEWF_SECTION_DATA_HANDLE_H + +#include +#include + +#include "libewf_libbfio.h" +#include "libewf_libcerror.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +typedef struct libewf_section_data_handle libewf_section_data_handle_t; + +struct libewf_section_data_handle +{ + /* The current offset + */ + off64_t current_offset; + + /* The (section) data offset + */ + off64_t data_offset; + + /* The (section) data size + */ + size64_t data_size; +}; + +int libewf_section_data_handle_initialize( + libewf_section_data_handle_t **data_handle, + off64_t data_offset, + size64_t data_size, + libcerror_error_t **error ); + +int libewf_section_data_handle_free( + libewf_section_data_handle_t **data_handle, + libcerror_error_t **error ); + +ssize_t libewf_section_data_handle_read_segment_data( + libewf_section_data_handle_t *data_handle, + libbfio_pool_t *file_io_pool, + int segment_index, + int file_io_pool_entry, + uint8_t *segment_data, + size_t segment_data_size, + uint32_t segment_flags, + uint8_t read_flags, + libcerror_error_t **error ); + +off64_t libewf_section_data_handle_seek_segment_offset( + libewf_section_data_handle_t *data_handle, + intptr_t *file_io_handle, + int segment_index, + int segment_file_index, + off64_t segment_offset, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBEWF_SECTION_DATA_HANDLE_H ) */ + diff --git a/libewf/libewf_section_descriptor.c b/libewf/libewf_section_descriptor.c index 5a40028f9..d681bb049 100644 --- a/libewf/libewf_section_descriptor.c +++ b/libewf/libewf_section_descriptor.c @@ -1451,3 +1451,51 @@ ssize_t libewf_section_descriptor_write_file_io_pool( return( -1 ); } +/* Retrieves the section data offset + * Returns 1 if successful, 0 if the section contains no data or -1 on error + */ +int libewf_section_descriptor_get_data_offset( + libewf_section_descriptor_t *section_descriptor, + uint8_t format_version, + off64_t *data_offset, + libcerror_error_t **error ) +{ + static char *function = "libewf_section_descriptor_get_data_offset"; + + if( section_descriptor == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid section descriptor.", + function ); + + return( -1 ); + } + if( data_offset == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data offset.", + function ); + + return( -1 ); + } + if( section_descriptor->data_size == 0 ) + { + return( 0 ); + } + if( format_version == 1 ) + { + *data_offset = section_descriptor->start_offset + sizeof( ewf_section_descriptor_v1_t ); + } + else + { + *data_offset = section_descriptor->start_offset; + } + return( 1 ); +} + diff --git a/libewf/libewf_section_descriptor.h b/libewf/libewf_section_descriptor.h index d09dc9c21..5d96b0d5a 100644 --- a/libewf/libewf_section_descriptor.h +++ b/libewf/libewf_section_descriptor.h @@ -132,6 +132,12 @@ ssize_t libewf_section_descriptor_write_file_io_pool( uint8_t format_version, libcerror_error_t **error ); +int libewf_section_descriptor_get_data_offset( + libewf_section_descriptor_t *section_descriptor, + uint8_t format_version, + off64_t *data_offset, + libcerror_error_t **error ); + #if defined( __cplusplus ) } #endif diff --git a/libewf/libewf_segment_file.c b/libewf/libewf_segment_file.c index b2177f0a1..4794ba2f8 100644 --- a/libewf/libewf_segment_file.c +++ b/libewf/libewf_segment_file.c @@ -6537,7 +6537,7 @@ int libewf_segment_file_read_element_data( goto on_error; } - result = libewf_section_get_data_offset( + result = libewf_section_descriptor_get_data_offset( section_descriptor, segment_file->major_version, §ion_data_offset, diff --git a/libewf/libewf_single_files.c b/libewf/libewf_single_files.c index 824151c39..482acd871 100644 --- a/libewf/libewf_single_files.c +++ b/libewf/libewf_single_files.c @@ -29,11 +29,14 @@ #include "libewf_lef_permission.h" #include "libewf_lef_source.h" #include "libewf_lef_subject.h" +#include "libewf_libbfio.h" #include "libewf_libcdata.h" #include "libewf_libcerror.h" #include "libewf_libcnotify.h" +#include "libewf_libfdata.h" #include "libewf_libfvalue.h" #include "libewf_libuna.h" +#include "libewf_line_reader.h" #include "libewf_permission_group.h" #include "libewf_single_files.h" @@ -173,56 +176,50 @@ int libewf_single_files_free( } if( *single_files != NULL ) { - if( ( *single_files )->permission_groups != NULL ) + if( ( *single_files )->file_entry_tree_root_node != NULL ) { - if( libcdata_array_free( - &( ( *single_files )->permission_groups ), - (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, + if( libcdata_tree_node_free( + &( ( *single_files )->file_entry_tree_root_node ), + (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free permission groups array.", + "%s: unable to free file entry tree root node.", function ); result = -1; } } - if( ( *single_files )->sources != NULL ) + if( libcdata_array_free( + &( ( *single_files )->sources ), + (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_source_free, + error ) != 1 ) { - if( libcdata_array_free( - &( ( *single_files )->sources ), - (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_source_free, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free sources array.", - function ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free sources array.", + function ); - result = -1; - } + result = -1; } - if( ( *single_files )->file_entry_tree_root_node != NULL ) + if( libcdata_array_free( + &( ( *single_files )->permission_groups ), + (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, + error ) != 1 ) { - if( libcdata_tree_node_free( - &( ( *single_files )->file_entry_tree_root_node ), - (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free file entry tree root node.", - function ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free permission groups array.", + function ); - result = -1; - } + result = -1; } memory_free( *single_files ); @@ -348,94 +345,12 @@ int libewf_single_files_clone( return( -1 ); } -/* Parses a line - * Returns 1 if successful or -1 on error - */ -int libewf_single_files_parse_line( - libfvalue_split_utf8_string_t *lines, - int line_index, - uint8_t **line_string, - size_t *line_string_size, - libcerror_error_t **error ) -{ - uint8_t *safe_line_string = NULL; - static char *function = "libewf_single_files_parse_line"; - size_t safe_line_string_size = 0; - - if( line_string == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line string.", - function ); - - return( -1 ); - } - if( line_string_size == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line string size.", - function ); - - return( -1 ); - } - if( libfvalue_split_utf8_string_get_segment_by_index( - lines, - line_index, - &safe_line_string, - &safe_line_string_size, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", - function, - line_index ); - - return( -1 ); - } - if( safe_line_string == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing line string: %d.", - function, - line_index ); - - return( -1 ); - } - /* Remove trailing carriage return - */ - if( safe_line_string_size >= 2 ) - { - if( safe_line_string[ safe_line_string_size - 2 ] == (uint8_t) '\r' ) - { - safe_line_string[ safe_line_string_size - 2 ] = 0; - - safe_line_string_size -= 1; - } - } - *line_string = safe_line_string; - *line_string_size = safe_line_string_size; - - return( 1 ); -} - /* Parses the number of entries in a category * Returns 1 if successful or -1 on error */ int libewf_single_files_parse_category_number_of_entries( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, int *number_of_entries, libcerror_error_t **error ) { @@ -447,15 +362,25 @@ int libewf_single_files_parse_category_number_of_entries( size_t value_string_size = 0; uint64_t value_64bit = 0; int number_of_values = 0; - int safe_line_index = 0; - if( line_index == NULL ) + if( single_files == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid single files.", + function ); + + return( -1 ); + } + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", function ); return( -1 ); @@ -471,22 +396,19 @@ int libewf_single_files_parse_category_number_of_entries( return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -503,12 +425,10 @@ int libewf_single_files_parse_category_number_of_entries( LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to split line: %d string into values.", function, - safe_line_index ); + line_reader->line_index - 1 ); goto on_error; } - safe_line_index += 1; - if( libfvalue_split_utf8_string_get_number_of_segments( values, &number_of_values, @@ -620,7 +540,6 @@ int libewf_single_files_parse_category_number_of_entries( goto on_error; } - *line_index = safe_line_index; *number_of_entries = (int) value_64bit; return( 1 ); @@ -639,43 +558,50 @@ int libewf_single_files_parse_category_number_of_entries( * Returns 1 if successful or -1 on error */ int libewf_single_files_parse_category_types( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, libfvalue_split_utf8_string_t **types, libcerror_error_t **error ) { uint8_t *line_string = NULL; static char *function = "libewf_single_files_parse_category_types"; size_t line_string_size = 0; - int safe_line_index = 0; - if( line_index == NULL ) + if( single_files == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid single files.", function ); return( -1 ); } - safe_line_index = *line_index; + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", + function ); - if( libewf_single_files_parse_line( - lines, - safe_line_index, + return( -1 ); + } + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); return( -1 ); } @@ -691,14 +617,11 @@ int libewf_single_files_parse_category_types( LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to split line: %d into types.", - function ); + function, + line_reader->line_index - 1 ); return( -1 ); } - safe_line_index += 1; - - *line_index = safe_line_index; - return( 1 ); } @@ -706,8 +629,8 @@ int libewf_single_files_parse_category_types( * Returns 1 if successful or -1 on error */ int libewf_single_files_parse_number_of_entries( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, int *number_of_entries, libcerror_error_t **error ) { @@ -719,15 +642,25 @@ int libewf_single_files_parse_number_of_entries( size_t value_string_size = 0; uint64_t value_64bit = 0; int number_of_values = 0; - int safe_line_index = 0; - if( line_index == NULL ) + if( single_files == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid single files.", + function ); + + return( -1 ); + } + if( line_reader == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid line reader.", function ); return( -1 ); @@ -743,24 +676,21 @@ int libewf_single_files_parse_number_of_entries( return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); - goto on_error; + return( -1 ); } if( libfvalue_utf8_string_split( line_string, @@ -775,12 +705,10 @@ int libewf_single_files_parse_number_of_entries( LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to split line: %d string into values.", function, - safe_line_index ); + line_reader->line_index - 1 ); goto on_error; } - safe_line_index += 1; - if( libfvalue_split_utf8_string_get_number_of_segments( values, &number_of_values, @@ -892,7 +820,6 @@ int libewf_single_files_parse_number_of_entries( goto on_error; } - *line_index = safe_line_index; *number_of_entries = (int) value_64bit; return( 1 ); @@ -1013,15 +940,13 @@ int libewf_single_files_parse_format( */ int libewf_single_files_parse_rec_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, size64_t *media_size, libcerror_error_t **error ) { uint8_t *line_string = NULL; static char *function = "libewf_single_files_parse_rec_category"; size_t line_string_size = 0; - int safe_line_index = 0; if( single_files == NULL ) { @@ -1034,38 +959,33 @@ int libewf_single_files_parse_rec_category( return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); return( -1 ); } - safe_line_index += 1; - if( ( line_string_size != 4 ) || ( line_string[ 0 ] != (uint8_t) 'r' ) || ( line_string[ 1 ] != (uint8_t) 'e' ) @@ -1081,8 +1001,8 @@ int libewf_single_files_parse_rec_category( return( -1 ); } if( libewf_single_files_parse_record_values( - lines, - &safe_line_index, + single_files, + line_reader, media_size, error ) != 1 ) { @@ -1097,20 +1017,19 @@ int libewf_single_files_parse_rec_category( } /* The category should be followed by an empty line */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); return( -1 ); } @@ -1123,14 +1042,10 @@ int libewf_single_files_parse_rec_category( LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported empty line string: %d - not empty.", function, - safe_line_index ); + line_reader->line_index ); return( -1 ); } - safe_line_index += 1; - - *line_index = safe_line_index; - return( 1 ); } @@ -1138,8 +1053,8 @@ int libewf_single_files_parse_rec_category( * Returns 1 if successful or -1 on error */ int libewf_single_files_parse_record_values( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, size64_t *media_size, libcerror_error_t **error ) { @@ -1155,16 +1070,26 @@ int libewf_single_files_parse_record_values( uint64_t value_64bit = 0; int number_of_types = 0; int number_of_values = 0; - int safe_line_index = 0; int value_index = 0; - if( line_index == NULL ) + if( single_files == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid single files.", + function ); + + return( -1 ); + } + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); @@ -1180,27 +1105,22 @@ int libewf_single_files_parse_record_values( return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( libfvalue_utf8_string_split( line_string, line_string_size, @@ -1231,25 +1151,22 @@ int libewf_single_files_parse_record_values( goto on_error; } - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( libfvalue_utf8_string_split( line_string, line_string_size, @@ -1440,8 +1357,6 @@ int libewf_single_files_parse_record_values( goto on_error; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -1465,8 +1380,7 @@ int libewf_single_files_parse_record_values( */ int libewf_single_files_parse_perm_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, libcerror_error_t **error ) { libewf_lef_permission_t *lef_permission = NULL; @@ -1479,7 +1393,6 @@ int libewf_single_files_parse_perm_category( int entry_index = 0; int number_of_permission_groups = 0; int permission_group_index = 0; - int safe_line_index = 0; if( single_files == NULL ) { @@ -1492,38 +1405,33 @@ int libewf_single_files_parse_perm_category( return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( ( line_string_size != 5 ) || ( line_string[ 0 ] != (uint8_t) 'p' ) || ( line_string[ 1 ] != (uint8_t) 'e' ) @@ -1540,8 +1448,8 @@ int libewf_single_files_parse_perm_category( goto on_error; } if( libewf_single_files_parse_category_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_permission_groups, error ) != 1 ) { @@ -1551,13 +1459,13 @@ int libewf_single_files_parse_perm_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of permission groups in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_category_types( - lines, - &safe_line_index, + single_files, + line_reader, &types, error ) != 1 ) { @@ -1567,13 +1475,13 @@ int libewf_single_files_parse_perm_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse types in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, ©_of_number_of_permission_groups, error ) != 1 ) { @@ -1583,7 +1491,7 @@ int libewf_single_files_parse_perm_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of permission groups in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -1600,20 +1508,19 @@ int libewf_single_files_parse_perm_category( } /* Parse the category root entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -1641,13 +1548,11 @@ int libewf_single_files_parse_perm_category( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, - "%s: unable to read permission", + "%s: unable to read permission.", function ); goto on_error; } - safe_line_index += 1; - if( lef_permission->property_type != 10 ) { libcerror_error_set( @@ -1691,9 +1596,8 @@ int libewf_single_files_parse_perm_category( } if( libewf_single_files_parse_permission_group( single_files, + line_reader, types, - lines, - &safe_line_index, permission_group, error ) != 1 ) { @@ -1727,20 +1631,19 @@ int libewf_single_files_parse_perm_category( } /* The category should be followed by an empty line */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -1753,12 +1656,10 @@ int libewf_single_files_parse_perm_category( LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported empty line string: %d - not empty.", function, - safe_line_index ); + line_reader->line_index - 1 ); goto on_error; } - safe_line_index += 1; - if( libfvalue_split_utf8_string_free( &types, error ) != 1 ) @@ -1772,8 +1673,6 @@ int libewf_single_files_parse_perm_category( goto on_error; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -1803,9 +1702,8 @@ int libewf_single_files_parse_perm_category( */ int libewf_single_files_parse_permission_group( libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, libfvalue_split_utf8_string_t *types, - libfvalue_split_utf8_string_t *lines, - int *line_index, libewf_permission_group_t *permission_group, libcerror_error_t **error ) { @@ -1816,7 +1714,6 @@ int libewf_single_files_parse_permission_group( int number_of_entries = 0; int number_of_permissions = 0; int permission_index = 0; - int safe_line_index = 0; if( single_files == NULL ) { @@ -1829,22 +1726,20 @@ int libewf_single_files_parse_permission_group( return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; - if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_permissions, error ) != 1 ) { @@ -1854,26 +1749,25 @@ int libewf_single_files_parse_permission_group( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of permissions in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } /* Parse the permission group entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -1906,8 +1800,6 @@ int libewf_single_files_parse_permission_group( goto on_error; } - safe_line_index += 1; - if( lef_permission->property_type != 10 ) { libcerror_error_set( @@ -1937,8 +1829,8 @@ int libewf_single_files_parse_permission_group( permission_index++ ) { if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_entries, error ) != 1 ) { @@ -1948,7 +1840,7 @@ int libewf_single_files_parse_permission_group( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of entries in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -1965,20 +1857,19 @@ int libewf_single_files_parse_permission_group( } /* Parse the permission entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2013,8 +1904,6 @@ int libewf_single_files_parse_permission_group( goto on_error; } - safe_line_index += 1; - if( libewf_permission_group_append_permission( permission_group, lef_permission, @@ -2032,8 +1921,6 @@ int libewf_single_files_parse_permission_group( } lef_permission = NULL; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -2051,8 +1938,7 @@ int libewf_single_files_parse_permission_group( */ int libewf_single_files_parse_srce_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, libcerror_error_t **error ) { libewf_lef_source_t *lef_source = NULL; @@ -2064,7 +1950,6 @@ int libewf_single_files_parse_srce_category( int entry_index = 0; int number_of_entries = 0; int number_of_sources = 0; - int safe_line_index = 0; int source_identifier = 0; int source_index = 0; @@ -2079,38 +1964,33 @@ int libewf_single_files_parse_srce_category( return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( ( line_string_size != 5 ) || ( line_string[ 0 ] != (uint8_t) 's' ) || ( line_string[ 1 ] != (uint8_t) 'r' ) @@ -2127,8 +2007,8 @@ int libewf_single_files_parse_srce_category( goto on_error; } if( libewf_single_files_parse_category_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_sources, error ) != 1 ) { @@ -2138,13 +2018,13 @@ int libewf_single_files_parse_srce_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of sources in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_category_types( - lines, - &safe_line_index, + single_files, + line_reader, &types, error ) != 1 ) { @@ -2154,13 +2034,13 @@ int libewf_single_files_parse_srce_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse types in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, ©_of_number_of_sources, error ) != 1 ) { @@ -2170,7 +2050,7 @@ int libewf_single_files_parse_srce_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of sources in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2187,20 +2067,19 @@ int libewf_single_files_parse_srce_category( } /* Parse the category root entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2233,8 +2112,6 @@ int libewf_single_files_parse_srce_category( goto on_error; } - safe_line_index += 1; - /* Append the category root so that the source identifiers and array entries align */ if( libcdata_array_append_entry( @@ -2259,8 +2136,8 @@ int libewf_single_files_parse_srce_category( source_index++ ) { if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_entries, error ) != 1 ) { @@ -2270,7 +2147,7 @@ int libewf_single_files_parse_srce_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of entries in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2287,20 +2164,19 @@ int libewf_single_files_parse_srce_category( } /* Parse the source entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2335,8 +2211,6 @@ int libewf_single_files_parse_srce_category( goto on_error; } - safe_line_index += 1; - if( libewf_lef_source_get_identifier( lef_source, &source_identifier, @@ -2348,7 +2222,7 @@ int libewf_single_files_parse_srce_category( LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve source: %d identifier.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2383,20 +2257,19 @@ int libewf_single_files_parse_srce_category( } /* The category should be followed by an empty line */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2409,12 +2282,10 @@ int libewf_single_files_parse_srce_category( LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported empty line string: %d - not empty.", function, - safe_line_index ); + line_reader->line_index - 1 ); goto on_error; } - safe_line_index += 1; - if( libfvalue_split_utf8_string_free( &types, error ) != 1 ) @@ -2428,8 +2299,6 @@ int libewf_single_files_parse_srce_category( goto on_error; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -2453,8 +2322,7 @@ int libewf_single_files_parse_srce_category( */ int libewf_single_files_parse_sub_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, libcerror_error_t **error ) { libewf_lef_subject_t *lef_subject = NULL; @@ -2465,7 +2333,6 @@ int libewf_single_files_parse_sub_category( int copy_of_number_of_subjects = 0; int number_of_entries = 0; int number_of_subjects = 0; - int safe_line_index = 0; int subject_index = 0; if( single_files == NULL ) @@ -2479,38 +2346,33 @@ int libewf_single_files_parse_sub_category( return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( ( line_string_size != 4 ) || ( line_string[ 0 ] != (uint8_t) 's' ) || ( line_string[ 1 ] != (uint8_t) 'u' ) @@ -2526,8 +2388,8 @@ int libewf_single_files_parse_sub_category( goto on_error; } if( libewf_single_files_parse_category_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_subjects, error ) != 1 ) { @@ -2537,13 +2399,13 @@ int libewf_single_files_parse_sub_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of subjects in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_category_types( - lines, - &safe_line_index, + single_files, + line_reader, &types, error ) != 1 ) { @@ -2553,13 +2415,13 @@ int libewf_single_files_parse_sub_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse types in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, ©_of_number_of_subjects, error ) != 1 ) { @@ -2569,7 +2431,7 @@ int libewf_single_files_parse_sub_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of subjects in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2586,20 +2448,19 @@ int libewf_single_files_parse_sub_category( } /* Parse the category root entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2632,9 +2493,7 @@ int libewf_single_files_parse_sub_category( goto on_error; } - safe_line_index += 1; - -/* TODO */ +/* TODO implement */ if( libewf_lef_subject_free( &lef_subject, @@ -2654,8 +2513,8 @@ int libewf_single_files_parse_sub_category( subject_index++ ) { if( libewf_single_files_parse_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_entries, error ) != 1 ) { @@ -2665,7 +2524,7 @@ int libewf_single_files_parse_sub_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of entries in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2682,20 +2541,19 @@ int libewf_single_files_parse_sub_category( } /* Parse the subject entry */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2730,8 +2588,6 @@ int libewf_single_files_parse_sub_category( goto on_error; } - safe_line_index += 1; - /* TODO implement append subject to array */ if( libewf_lef_subject_free( @@ -2750,20 +2606,19 @@ int libewf_single_files_parse_sub_category( } /* The category should be followed by an empty line */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2776,12 +2631,10 @@ int libewf_single_files_parse_sub_category( LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported empty line string: %d - not empty.", function, - safe_line_index ); + line_reader->line_index - 1 ); goto on_error; } - safe_line_index += 1; - if( libfvalue_split_utf8_string_free( &types, error ) != 1 ) @@ -2795,8 +2648,6 @@ int libewf_single_files_parse_sub_category( goto on_error; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -2820,8 +2671,7 @@ int libewf_single_files_parse_sub_category( */ int libewf_single_files_parse_entry_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, uint8_t *format, libcerror_error_t **error ) { @@ -2830,7 +2680,6 @@ int libewf_single_files_parse_entry_category( static char *function = "libewf_single_files_parse_entry_category"; size_t line_string_size = 0; int number_of_sub_entries = 0; - int safe_line_index = 0; if( single_files == NULL ) { @@ -2854,38 +2703,33 @@ int libewf_single_files_parse_entry_category( return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( ( line_string_size != 6 ) || ( line_string[ 0 ] != (uint8_t) 'e' ) || ( line_string[ 1 ] != (uint8_t) 'n' ) @@ -2903,8 +2747,8 @@ int libewf_single_files_parse_entry_category( goto on_error; } if( libewf_single_files_parse_category_number_of_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_sub_entries, error ) != 1 ) { @@ -2914,13 +2758,13 @@ int libewf_single_files_parse_entry_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse number of entries in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } if( libewf_single_files_parse_category_types( - lines, - &safe_line_index, + single_files, + line_reader, &types, error ) != 1 ) { @@ -2930,7 +2774,7 @@ int libewf_single_files_parse_entry_category( LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to parse types in line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -2962,10 +2806,10 @@ int libewf_single_files_parse_entry_category( goto on_error; } if( libewf_single_files_parse_file_entry( + single_files, + line_reader, single_files->file_entry_tree_root_node, types, - lines, - &safe_line_index, error ) != 1 ) { libcerror_error_set( @@ -2979,20 +2823,19 @@ int libewf_single_files_parse_entry_category( } /* The category should be followed by an empty line */ - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } @@ -3005,12 +2848,10 @@ int libewf_single_files_parse_entry_category( LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported empty line string: %d - not empty.", function, - safe_line_index ); + line_reader->line_index - 1 ); goto on_error; } - safe_line_index += 1; - if( libfvalue_split_utf8_string_free( &types, error ) != 1 ) @@ -3024,8 +2865,6 @@ int libewf_single_files_parse_entry_category( goto on_error; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -3049,10 +2888,10 @@ int libewf_single_files_parse_entry_category( * Returns 1 if successful or -1 on error */ int libewf_single_files_parse_file_entry( + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, libcdata_tree_node_t *parent_file_entry_node, libfvalue_split_utf8_string_t *types, - libfvalue_split_utf8_string_t *lines, - int *line_index, libcerror_error_t **error ) { libcdata_tree_node_t *file_entry_node = NULL; @@ -3061,38 +2900,45 @@ int libewf_single_files_parse_file_entry( uint8_t *line_string = NULL; static char *function = "libewf_single_files_parse_file_entry"; size_t line_string_size = 0; - int number_of_lines = 0; int number_of_sub_entries = 0; - int safe_line_index = 0; int sub_entry_index = 0; - if( parent_file_entry_node == NULL ) + if( single_files == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid parent file entry node.", + "%s: invalid single files.", function ); return( -1 ); } - if( line_index == NULL ) + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); } - safe_line_index = *line_index; + if( parent_file_entry_node == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid parent file entry node.", + function ); + return( -1 ); + } if( libewf_single_files_parse_file_entry_number_of_sub_entries( - lines, - &safe_line_index, + single_files, + line_reader, &number_of_sub_entries, error ) != 1 ) { @@ -3105,25 +2951,22 @@ int libewf_single_files_parse_file_entry( goto on_error; } - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( libewf_lef_file_entry_initialize( &lef_file_entry, error ) != 1 ) @@ -3169,32 +3012,6 @@ int libewf_single_files_parse_file_entry( } lef_file_entry = NULL; - if( libfvalue_split_utf8_string_get_number_of_segments( - lines, - &number_of_lines, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve number of lines", - function ); - - goto on_error; - } - if( ( safe_line_index > number_of_lines ) - || ( number_of_sub_entries > ( number_of_lines - safe_line_index ) ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: number of sub entries exceed the number of available lines.", - function ); - - goto on_error; - } for( sub_entry_index = 0; sub_entry_index < number_of_sub_entries; sub_entry_index++ ) @@ -3214,10 +3031,10 @@ int libewf_single_files_parse_file_entry( goto on_error; } if( libewf_single_files_parse_file_entry( + single_files, + line_reader, file_entry_node, types, - lines, - &safe_line_index, error ) != 1 ) { libcerror_error_set( @@ -3247,8 +3064,6 @@ int libewf_single_files_parse_file_entry( } file_entry_node = NULL; } - *line_index = safe_line_index; - return( 1 ); on_error: @@ -3278,8 +3093,8 @@ int libewf_single_files_parse_file_entry( * Returns 1 if successful or -1 on error */ int libewf_single_files_parse_file_entry_number_of_sub_entries( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, int *number_of_sub_entries, libcerror_error_t **error ) { @@ -3291,15 +3106,25 @@ int libewf_single_files_parse_file_entry_number_of_sub_entries( size_t value_string_size = 0; uint64_t value_64bit = 0; int number_of_values = 0; - int safe_line_index = 0; - if( line_index == NULL ) + if( single_files == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid single files.", + function ); + + return( -1 ); + } + if( line_reader == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid line index.", + "%s: invalid line reader.", function ); return( -1 ); @@ -3315,27 +3140,22 @@ int libewf_single_files_parse_file_entry_number_of_sub_entries( return( -1 ); } - safe_line_index = *line_index; - - if( libewf_single_files_parse_line( - lines, - safe_line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - safe_line_index ); + line_reader->line_index ); goto on_error; } - safe_line_index += 1; - if( libfvalue_utf8_string_split( line_string, line_string_size, @@ -3506,7 +3326,6 @@ int libewf_single_files_parse_file_entry_number_of_sub_entries( goto on_error; } - *line_index = safe_line_index; *number_of_sub_entries = (int) value_64bit; return( 1 ); @@ -3521,22 +3340,21 @@ int libewf_single_files_parse_file_entry_number_of_sub_entries( return( -1 ); } -/* Parses an UTF-8 encoded single files string +/* Reads the single files * Returns 1 if successful or -1 on error */ -int libewf_single_files_parse_utf8_string( +int libewf_single_files_read_data_stream( libewf_single_files_t *single_files, - const uint8_t *utf8_string, - size_t utf8_string_size, + libfdata_stream_t *data_stream, + libbfio_pool_t *file_io_pool, size64_t *media_size, uint8_t *format, libcerror_error_t **error ) { - libfvalue_split_utf8_string_t *lines = NULL; - uint8_t *line_string = NULL; - static char *function = "libewf_single_files_parse_utf8_string"; - size_t line_string_size = 0; - int line_index = 0; + libewf_line_reader_t *line_reader = NULL; + uint8_t *line_string = NULL; + static char *function = "libewf_single_files_read_data_stream"; + size_t line_string_size = 0; if( single_files == NULL ) { @@ -3549,36 +3367,34 @@ int libewf_single_files_parse_utf8_string( return( -1 ); } - if( libfvalue_utf8_string_split( - utf8_string, - utf8_string_size, - (uint8_t) '\n', - &lines, + if( libewf_line_reader_initialize( + &line_reader, + data_stream, + file_io_pool, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to split string into lines.", + "%s: unable to create line reader.", function ); goto on_error; } - if( libewf_single_files_parse_line( - lines, - line_index, + if( libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve line string: %d.", + LIBCERROR_ERROR_DOMAIN_IO, + LIBCERROR_IO_ERROR_READ_FAILED, + "%s: unable to read line: %d.", function, - line_index ); + line_reader->line_index ); goto on_error; } @@ -3594,12 +3410,9 @@ int libewf_single_files_parse_utf8_string( goto on_error; } - line_index += 1; - if( libewf_single_files_parse_rec_category( single_files, - lines, - &line_index, + line_reader, media_size, error ) != 1 ) { @@ -3614,8 +3427,7 @@ int libewf_single_files_parse_utf8_string( } if( libewf_single_files_parse_perm_category( single_files, - lines, - &line_index, + line_reader, error ) != 1 ) { libcerror_error_set( @@ -3629,8 +3441,7 @@ int libewf_single_files_parse_utf8_string( } if( libewf_single_files_parse_srce_category( single_files, - lines, - &line_index, + line_reader, error ) != 1 ) { libcerror_error_set( @@ -3644,8 +3455,7 @@ int libewf_single_files_parse_utf8_string( } if( libewf_single_files_parse_sub_category( single_files, - lines, - &line_index, + line_reader, error ) != 1 ) { libcerror_error_set( @@ -3659,8 +3469,7 @@ int libewf_single_files_parse_utf8_string( } if( libewf_single_files_parse_entry_category( single_files, - lines, - &line_index, + line_reader, format, error ) != 1 ) { @@ -3673,15 +3482,15 @@ int libewf_single_files_parse_utf8_string( goto on_error; } - if( libfvalue_split_utf8_string_free( - &lines, + if( libewf_line_reader_free( + &line_reader, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free split lines.", + "%s: unable to free line reader.", function ); goto on_error; @@ -3689,131 +3498,15 @@ int libewf_single_files_parse_utf8_string( return( 1 ); on_error: - if( lines != NULL ) + if( line_reader != NULL ) { - libfvalue_split_utf8_string_free( - &lines, + libewf_line_reader_free( + &line_reader, NULL ); } return( -1 ); } -/* Reads the single files - * Returns 1 if successful or -1 on error - */ -int libewf_single_files_read_data( - libewf_single_files_t *single_files, - const uint8_t *data, - size_t data_size, - size64_t *media_size, - uint8_t *format, - libcerror_error_t **error ) -{ - uint8_t *utf8_string = NULL; - static char *function = "libewf_single_files_read_data"; - size_t utf8_string_size = 0; - - if( single_files == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid single files.", - function ); - - return( -1 ); - } - if( libuna_utf8_string_size_from_utf16_stream( - data, - data_size, - LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, - &utf8_string_size, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_CONVERSION, - LIBCERROR_CONVERSION_ERROR_GENERIC, - "%s: unable to determine UTF-8 string size.", - function ); - - goto on_error; - } - if( ( utf8_string_size == 0 ) - || ( utf8_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid UTF-8 string size value out of bounds.", - function ); - - goto on_error; - } - utf8_string = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * (size_t) utf8_string_size ); - - if( utf8_string == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create UTF-8 string.", - function ); - - goto on_error; - } - if( libuna_utf8_string_copy_from_utf16_stream( - utf8_string, - utf8_string_size, - data, - data_size, - LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_CONVERSION, - LIBCERROR_CONVERSION_ERROR_GENERIC, - "%s: unable to set UTF-8 string.", - function ); - - goto on_error; - } - if( libewf_single_files_parse_utf8_string( - single_files, - utf8_string, - utf8_string_size, - media_size, - format, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_CONVERSION, - LIBCERROR_CONVERSION_ERROR_GENERIC, - "%s: unable to parse UTF-8 string.", - function ); - - goto on_error; - } - memory_free( - utf8_string ); - - return( 1 ); - -on_error: - if( utf8_string != NULL ) - { - memory_free( - utf8_string ); - } - return( -1 ); -} - /* Retrieves the file entry tree root node * Returns 1 if successful or -1 on error */ diff --git a/libewf/libewf_single_files.h b/libewf/libewf_single_files.h index c762743db..0d6e70c50 100644 --- a/libewf/libewf_single_files.h +++ b/libewf/libewf_single_files.h @@ -28,9 +28,12 @@ #include "libewf_extern.h" #include "libewf_lef_file_entry.h" #include "libewf_lef_source.h" +#include "libewf_libbfio.h" #include "libewf_libcdata.h" #include "libewf_libcerror.h" +#include "libewf_libfdata.h" #include "libewf_libfvalue.h" +#include "libewf_line_reader.h" #include "libewf_permission_group.h" #include "libewf_types.h" @@ -68,28 +71,21 @@ int libewf_single_files_clone( libewf_single_files_t *source_single_files, libcerror_error_t **error ); -int libewf_single_files_parse_line( - libfvalue_split_utf8_string_t *lines, - int line_index, - uint8_t **line_string, - size_t *line_string_size, - libcerror_error_t **error ); - int libewf_single_files_parse_category_number_of_entries( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, int *number_of_entries, libcerror_error_t **error ); int libewf_single_files_parse_category_types( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, libfvalue_split_utf8_string_t **types, libcerror_error_t **error ); int libewf_single_files_parse_number_of_entries( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, int *number_of_entries, libcerror_error_t **error ); @@ -100,75 +96,61 @@ int libewf_single_files_parse_format( int libewf_single_files_parse_rec_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, size64_t *media_size, libcerror_error_t **error ); int libewf_single_files_parse_record_values( - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, size64_t *media_size, libcerror_error_t **error ); int libewf_single_files_parse_perm_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, libcerror_error_t **error ); int libewf_single_files_parse_permission_group( libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, libfvalue_split_utf8_string_t *types, - libfvalue_split_utf8_string_t *lines, - int *line_index, libewf_permission_group_t *permission_group, libcerror_error_t **error ); int libewf_single_files_parse_srce_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, libcerror_error_t **error ); int libewf_single_files_parse_sub_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, libcerror_error_t **error ); int libewf_single_files_parse_entry_category( libewf_single_files_t *single_files, - libfvalue_split_utf8_string_t *lines, - int *line_index, + libewf_line_reader_t *line_reader, uint8_t *format, libcerror_error_t **error ); int libewf_single_files_parse_file_entry( + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader, libcdata_tree_node_t *parent_file_entry_node, libfvalue_split_utf8_string_t *types, - libfvalue_split_utf8_string_t *lines, - int *line_index, libcerror_error_t **error ); int libewf_single_files_parse_file_entry_number_of_sub_entries( - libfvalue_split_utf8_string_t *lines, - int *line_index, - int *number_of_sub_entries, - libcerror_error_t **error ); - -int libewf_single_files_parse_utf8_string( libewf_single_files_t *single_files, - const uint8_t *utf8_string, - size_t utf8_string_size, - size64_t *media_size, - uint8_t *format, + libewf_line_reader_t *line_reader, + int *number_of_sub_entries, libcerror_error_t **error ); -int libewf_single_files_read_data( +int libewf_single_files_read_data_stream( libewf_single_files_t *single_files, - const uint8_t *data, - size_t data_size, + libfdata_stream_t *data_stream, + libbfio_pool_t *file_io_pool, size64_t *media_size, uint8_t *format, libcerror_error_t **error ); diff --git a/libewf/libewf_source.c b/libewf/libewf_source.c index d4e164426..dd207f39e 100644 --- a/libewf/libewf_source.c +++ b/libewf/libewf_source.c @@ -162,6 +162,8 @@ int libewf_source_free( internal_source = (libewf_internal_source_t *) *source; *source = NULL; + /* The lef_source reference is freed elsewhere + */ #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_free( &( internal_source->read_write_lock ), @@ -177,8 +179,6 @@ int libewf_source_free( result = -1; } #endif - /* The lef_source references is freed elsewhere - */ memory_free( internal_source ); } diff --git a/libewf/libewf_write_io_handle.c b/libewf/libewf_write_io_handle.c index aede1ef07..3ef579b82 100644 --- a/libewf/libewf_write_io_handle.c +++ b/libewf/libewf_write_io_handle.c @@ -235,6 +235,22 @@ int libewf_write_io_handle_free( result = -1; } + if( ( *write_io_handle )->managed_segment_file != NULL ) + { + if( libewf_segment_file_free( + &( ( *write_io_handle )->managed_segment_file ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free managed segment file.", + function ); + + result = -1; + } + } memory_free( *write_io_handle ); @@ -322,6 +338,7 @@ int libewf_write_io_handle_clone( ( *destination_write_io_handle )->chunks_section = NULL; ( *destination_write_io_handle )->current_file_io_pool_entry = -1; ( *destination_write_io_handle )->current_segment_file = NULL; + ( *destination_write_io_handle )->managed_segment_file = NULL; if( source_write_io_handle->case_data != NULL ) { @@ -3478,6 +3495,17 @@ ssize_t libewf_write_io_handle_write_new_chunk_create_chunk( return( -1 ); } + if( write_io_handle->current_segment_file == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid write IO handle - missing current segment file.", + function ); + + return( -1 ); + } if( segment_file == NULL ) { libcerror_error_set( @@ -3598,10 +3626,11 @@ ssize_t libewf_write_io_handle_write_new_chunk( size_t input_data_size, libcerror_error_t **error ) { - static char *function = "libewf_write_io_handle_write_new_chunk"; - ssize_t total_write_count = 0; - ssize_t write_count = 0; - int result = 0; + libewf_segment_file_t *safe_segment_file = NULL; + static char *function = "libewf_write_io_handle_write_new_chunk"; + ssize_t total_write_count = 0; + ssize_t write_count = 0; + int result = 0; if( write_io_handle == NULL ) { @@ -3694,7 +3723,7 @@ ssize_t libewf_write_io_handle_write_new_chunk( header_values, write_io_handle->current_segment_number, &( write_io_handle->current_file_io_pool_entry ), - &( write_io_handle->current_segment_file ), + &safe_segment_file, error ); if( write_count < 0 ) @@ -3707,8 +3736,11 @@ ssize_t libewf_write_io_handle_write_new_chunk( function, write_io_handle->current_segment_number ); - return( -1 ); + goto on_error; } + write_io_handle->current_segment_file = safe_segment_file; + write_io_handle->managed_segment_file = safe_segment_file; + total_write_count += write_count; } /* Check if a chunks section should be created @@ -3734,7 +3766,7 @@ ssize_t libewf_write_io_handle_write_new_chunk( function, write_io_handle->current_segment_number ); - return( -1 ); + goto on_error; } total_write_count += write_count; } @@ -3761,7 +3793,7 @@ ssize_t libewf_write_io_handle_write_new_chunk( chunk_index, write_io_handle->current_segment_number ); - return( -1 ); + goto on_error; } total_write_count += write_count; @@ -3769,6 +3801,17 @@ ssize_t libewf_write_io_handle_write_new_chunk( */ write_io_handle->remaining_segment_file_size -= write_io_handle->chunk_table_entries_reserved_size; + if( write_io_handle->current_segment_file == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid write IO handle - missing current segment file.", + function ); + + return( -1 ); + } /* Check if the current chunks section is full, if so close the current section */ result = libewf_write_io_handle_test_chunks_section_full( @@ -3788,7 +3831,7 @@ ssize_t libewf_write_io_handle_write_new_chunk( "%s: unable to determine if chunks section is full.", function ); - return( -1 ); + goto on_error; } if( result == 1 ) { @@ -3809,7 +3852,7 @@ ssize_t libewf_write_io_handle_write_new_chunk( "%s: unable to write chunks section end.", function ); - return( -1 ); + goto on_error; } total_write_count += write_count; @@ -3834,7 +3877,7 @@ ssize_t libewf_write_io_handle_write_new_chunk( "%s: unable to determine if segment file is full.", function ); - return( -1 ); + goto on_error; } else if( result == 1 ) { @@ -3879,17 +3922,45 @@ ssize_t libewf_write_io_handle_write_new_chunk( function, write_io_handle->current_segment_number ); - return( -1 ); + goto on_error; } total_write_count += write_count; + if( write_io_handle->managed_segment_file != NULL ) + { + if( libewf_segment_file_free( + &( write_io_handle->managed_segment_file ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free managed segment file.", + function ); + + goto on_error; + } + } write_io_handle->current_file_io_pool_entry = -1; - write_io_handle->current_segment_file = NULL; write_io_handle->current_segment_number += 1; + write_io_handle->current_segment_file = NULL; } } } return( total_write_count ); + +on_error: + if( safe_segment_file != NULL ) + { + libewf_segment_file_free( + &safe_segment_file, + NULL ); + + write_io_handle->current_segment_file = NULL; + write_io_handle->managed_segment_file = NULL; + } + return( -1 ); } /* Corrects sections after streamed write diff --git a/libewf/libewf_write_io_handle.h b/libewf/libewf_write_io_handle.h index e470a9a4e..c22b12fc2 100644 --- a/libewf/libewf_write_io_handle.h +++ b/libewf/libewf_write_io_handle.h @@ -173,6 +173,10 @@ struct libewf_write_io_handle */ libewf_segment_file_t *current_segment_file; + /* The managed segment file + */ + libewf_segment_file_t *managed_segment_file; + /* The number of chunks written of the current segment file */ uint64_t number_of_chunks_written_to_segment_file; diff --git a/msvscpp/Makefile.am b/msvscpp/Makefile.am index be047858f..70f86de0f 100644 --- a/msvscpp/Makefile.am +++ b/msvscpp/Makefile.am @@ -5,6 +5,7 @@ MSVSCPP_FILES = \ ewf_test_analytical_data/ewf_test_analytical_data.vcproj \ ewf_test_attribute/ewf_test_attribute.vcproj \ ewf_test_bit_stream/ewf_test_bit_stream.vcproj \ + ewf_test_buffer_data_handle/ewf_test_buffer_data_handle.vcproj \ ewf_test_case_data/ewf_test_case_data.vcproj \ ewf_test_case_data_section/ewf_test_case_data_section.vcproj \ ewf_test_checksum/ewf_test_checksum.vcproj \ @@ -37,6 +38,7 @@ MSVSCPP_FILES = \ ewf_test_lef_permission/ewf_test_lef_permission.vcproj \ ewf_test_lef_source/ewf_test_lef_source.vcproj \ ewf_test_lef_subject/ewf_test_lef_subject.vcproj \ + ewf_test_line_reader/ewf_test_line_reader.vcproj \ ewf_test_ltree_section/ewf_test_ltree_section.vcproj \ ewf_test_md5_hash_section/ewf_test_md5_hash_section.vcproj \ ewf_test_media_values/ewf_test_media_values.vcproj \ @@ -44,6 +46,7 @@ MSVSCPP_FILES = \ ewf_test_permission_group/ewf_test_permission_group.vcproj \ ewf_test_read_io_handle/ewf_test_read_io_handle.vcproj \ ewf_test_restart_data/ewf_test_restart_data.vcproj \ + ewf_test_section_data_handle/ewf_test_section_data_handle.vcproj \ ewf_test_section_descriptor/ewf_test_section_descriptor.vcproj \ ewf_test_sector_range/ewf_test_sector_range.vcproj \ ewf_test_sector_range_list/ewf_test_sector_range_list.vcproj \ diff --git a/msvscpp/ewf_test_buffer_data_handle/ewf_test_buffer_data_handle.vcproj b/msvscpp/ewf_test_buffer_data_handle/ewf_test_buffer_data_handle.vcproj new file mode 100644 index 000000000..788bebcc5 --- /dev/null +++ b/msvscpp/ewf_test_buffer_data_handle/ewf_test_buffer_data_handle.vcproj @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/ewf_test_file_entry/ewf_test_file_entry.vcproj b/msvscpp/ewf_test_file_entry/ewf_test_file_entry.vcproj index abf3c3698..97087ff37 100644 --- a/msvscpp/ewf_test_file_entry/ewf_test_file_entry.vcproj +++ b/msvscpp/ewf_test_file_entry/ewf_test_file_entry.vcproj @@ -201,6 +201,10 @@ RelativePath="..\..\tests\ewf_test_libewf.h" > + + diff --git a/msvscpp/ewf_test_line_reader/ewf_test_line_reader.vcproj b/msvscpp/ewf_test_line_reader/ewf_test_line_reader.vcproj new file mode 100644 index 000000000..ccba0614b --- /dev/null +++ b/msvscpp/ewf_test_line_reader/ewf_test_line_reader.vcproj @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/ewf_test_ltree_section/ewf_test_ltree_section.vcproj b/msvscpp/ewf_test_ltree_section/ewf_test_ltree_section.vcproj index 453f2307b..cb9d54f9c 100644 --- a/msvscpp/ewf_test_ltree_section/ewf_test_ltree_section.vcproj +++ b/msvscpp/ewf_test_ltree_section/ewf_test_ltree_section.vcproj @@ -209,6 +209,10 @@ RelativePath="..\..\tests\ewf_test_libewf.h" > + + diff --git a/msvscpp/ewf_test_section_data_handle/ewf_test_section_data_handle.vcproj b/msvscpp/ewf_test_section_data_handle/ewf_test_section_data_handle.vcproj new file mode 100644 index 000000000..2114b6a49 --- /dev/null +++ b/msvscpp/ewf_test_section_data_handle/ewf_test_section_data_handle.vcproj @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/ewf_test_single_file_tree/ewf_test_single_file_tree.vcproj b/msvscpp/ewf_test_single_file_tree/ewf_test_single_file_tree.vcproj index f92641fe3..39ae6df60 100644 --- a/msvscpp/ewf_test_single_file_tree/ewf_test_single_file_tree.vcproj +++ b/msvscpp/ewf_test_single_file_tree/ewf_test_single_file_tree.vcproj @@ -193,6 +193,10 @@ RelativePath="..\..\tests\ewf_test_libewf.h" > + + diff --git a/msvscpp/ewf_test_single_files/ewf_test_single_files.vcproj b/msvscpp/ewf_test_single_files/ewf_test_single_files.vcproj index 056b8eb8e..f0318ca29 100644 --- a/msvscpp/ewf_test_single_files/ewf_test_single_files.vcproj +++ b/msvscpp/ewf_test_single_files/ewf_test_single_files.vcproj @@ -197,6 +197,10 @@ RelativePath="..\..\tests\ewf_test_libewf.h" > + + diff --git a/msvscpp/libewf.sln b/msvscpp/libewf.sln index 4982b77bd..fa0a24030 100644 --- a/msvscpp/libewf.sln +++ b/msvscpp/libewf.sln @@ -74,6 +74,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_attribute", "ewf_t {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_buffer_data_handle", "ewf_test_buffer_data_handle\ewf_test_buffer_data_handle.vcproj", "{91899A5C-3A5A-4CAB-9606-D74BF66DCECF}" + ProjectSection(ProjectDependencies) = postProject + {41C2387C-9D7F-42B9-9998-3430FBC95AE7} = {41C2387C-9D7F-42B9-9998-3430FBC95AE7} + {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_bit_stream", "ewf_test_bit_stream\ewf_test_bit_stream.vcproj", "{536630A9-1462-479C-8153-D807E3C24167}" ProjectSection(ProjectDependencies) = postProject {41C2387C-9D7F-42B9-9998-3430FBC95AE7} = {41C2387C-9D7F-42B9-9998-3430FBC95AE7} @@ -244,6 +250,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_error2_section", " EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_file_entry", "ewf_test_file_entry\ewf_test_file_entry.vcproj", "{C1C9020C-3ED9-4F89-BC24-09F76390BABC}" ProjectSection(ProjectDependencies) = postProject + {F94DCC2D-2B49-453E-89B3-FD81992677D0} = {F94DCC2D-2B49-453E-89B3-FD81992677D0} {41C2387C-9D7F-42B9-9998-3430FBC95AE7} = {41C2387C-9D7F-42B9-9998-3430FBC95AE7} {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} EndProjectSection @@ -376,8 +383,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_lef_subject", "ewf {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_line_reader", "ewf_test_line_reader\ewf_test_line_reader.vcproj", "{492B5652-7E6B-4133-A9D8-66FFBAE9E983}" + ProjectSection(ProjectDependencies) = postProject + {F94DCC2D-2B49-453E-89B3-FD81992677D0} = {F94DCC2D-2B49-453E-89B3-FD81992677D0} + {41C2387C-9D7F-42B9-9998-3430FBC95AE7} = {41C2387C-9D7F-42B9-9998-3430FBC95AE7} + {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_ltree_section", "ewf_test_ltree_section\ewf_test_ltree_section.vcproj", "{890B3C60-F8DB-458D-B933-3E08A837CBD7}" ProjectSection(ProjectDependencies) = postProject + {F94DCC2D-2B49-453E-89B3-FD81992677D0} = {F94DCC2D-2B49-453E-89B3-FD81992677D0} {41CFAFBF-A1C8-4704-AFEF-31979E6452B9} = {41CFAFBF-A1C8-4704-AFEF-31979E6452B9} {3FFB9C05-1145-45A7-9ADE-5C8D70FBD7CA} = {3FFB9C05-1145-45A7-9ADE-5C8D70FBD7CA} {4C93BDD3-1804-47F3-9B34-F2DE0CAE1AE0} = {4C93BDD3-1804-47F3-9B34-F2DE0CAE1AE0} @@ -434,6 +449,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_restart_data", "ew {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_section_data_handle", "ewf_test_section_data_handle\ewf_test_section_data_handle.vcproj", "{C45BDCCA-B761-4823-AFDD-F4CBB5DBAF2F}" + ProjectSection(ProjectDependencies) = postProject + {41C2387C-9D7F-42B9-9998-3430FBC95AE7} = {41C2387C-9D7F-42B9-9998-3430FBC95AE7} + {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_section_descriptor", "ewf_test_section_descriptor\ewf_test_section_descriptor.vcproj", "{92F5212D-C2CF-44C6-85F3-92530392134C}" ProjectSection(ProjectDependencies) = postProject {41CFAFBF-A1C8-4704-AFEF-31979E6452B9} = {41CFAFBF-A1C8-4704-AFEF-31979E6452B9} @@ -517,6 +538,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_sha1_hash_section" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_single_file_tree", "ewf_test_single_file_tree\ewf_test_single_file_tree.vcproj", "{6CB6381D-A10D-4798-A6AC-049636879243}" ProjectSection(ProjectDependencies) = postProject + {F94DCC2D-2B49-453E-89B3-FD81992677D0} = {F94DCC2D-2B49-453E-89B3-FD81992677D0} {B9332DC8-7594-47DF-80C1-38922E0F4DFB} = {B9332DC8-7594-47DF-80C1-38922E0F4DFB} {41C2387C-9D7F-42B9-9998-3430FBC95AE7} = {41C2387C-9D7F-42B9-9998-3430FBC95AE7} {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} @@ -526,6 +548,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ewf_test_single_files", "ew ProjectSection(ProjectDependencies) = postProject {85005D62-6AA7-4D8A-86CB-4061B23D7C6C} = {85005D62-6AA7-4D8A-86CB-4061B23D7C6C} {95F707BA-7F1D-4EE0-BDC1-71AC6BEF7048} = {95F707BA-7F1D-4EE0-BDC1-71AC6BEF7048} + {F94DCC2D-2B49-453E-89B3-FD81992677D0} = {F94DCC2D-2B49-453E-89B3-FD81992677D0} {0DAB8FC8-C315-4020-8030-54EE30A8CA0F} = {0DAB8FC8-C315-4020-8030-54EE30A8CA0F} {BC27FF34-C859-4A1A-95D6-FC89952E1910} = {BC27FF34-C859-4A1A-95D6-FC89952E1910} {5304AD69-D449-4589-B2C9-E4607E56A51D} = {5304AD69-D449-4589-B2C9-E4607E56A51D} @@ -1103,6 +1126,10 @@ Global {F01092C4-0BAE-493F-8BE5-AC50759E7368}.Release|Win32.Build.0 = Release|Win32 {F01092C4-0BAE-493F-8BE5-AC50759E7368}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {F01092C4-0BAE-493F-8BE5-AC50759E7368}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {91899A5C-3A5A-4CAB-9606-D74BF66DCECF}.Release|Win32.ActiveCfg = Release|Win32 + {91899A5C-3A5A-4CAB-9606-D74BF66DCECF}.Release|Win32.Build.0 = Release|Win32 + {91899A5C-3A5A-4CAB-9606-D74BF66DCECF}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {91899A5C-3A5A-4CAB-9606-D74BF66DCECF}.VSDebug|Win32.Build.0 = VSDebug|Win32 {536630A9-1462-479C-8153-D807E3C24167}.Release|Win32.ActiveCfg = Release|Win32 {536630A9-1462-479C-8153-D807E3C24167}.Release|Win32.Build.0 = Release|Win32 {536630A9-1462-479C-8153-D807E3C24167}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 @@ -1235,6 +1262,10 @@ Global {9323E14F-0C21-4314-8F3D-62F16E29584C}.Release|Win32.Build.0 = Release|Win32 {9323E14F-0C21-4314-8F3D-62F16E29584C}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {9323E14F-0C21-4314-8F3D-62F16E29584C}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {492B5652-7E6B-4133-A9D8-66FFBAE9E983}.Release|Win32.ActiveCfg = Release|Win32 + {492B5652-7E6B-4133-A9D8-66FFBAE9E983}.Release|Win32.Build.0 = Release|Win32 + {492B5652-7E6B-4133-A9D8-66FFBAE9E983}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {492B5652-7E6B-4133-A9D8-66FFBAE9E983}.VSDebug|Win32.Build.0 = VSDebug|Win32 {890B3C60-F8DB-458D-B933-3E08A837CBD7}.Release|Win32.ActiveCfg = Release|Win32 {890B3C60-F8DB-458D-B933-3E08A837CBD7}.Release|Win32.Build.0 = Release|Win32 {890B3C60-F8DB-458D-B933-3E08A837CBD7}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 @@ -1263,6 +1294,10 @@ Global {8242F203-D045-4C7E-A5F0-70C10A12D34D}.Release|Win32.Build.0 = Release|Win32 {8242F203-D045-4C7E-A5F0-70C10A12D34D}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {8242F203-D045-4C7E-A5F0-70C10A12D34D}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {C45BDCCA-B761-4823-AFDD-F4CBB5DBAF2F}.Release|Win32.ActiveCfg = Release|Win32 + {C45BDCCA-B761-4823-AFDD-F4CBB5DBAF2F}.Release|Win32.Build.0 = Release|Win32 + {C45BDCCA-B761-4823-AFDD-F4CBB5DBAF2F}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {C45BDCCA-B761-4823-AFDD-F4CBB5DBAF2F}.VSDebug|Win32.Build.0 = VSDebug|Win32 {92F5212D-C2CF-44C6-85F3-92530392134C}.Release|Win32.ActiveCfg = Release|Win32 {92F5212D-C2CF-44C6-85F3-92530392134C}.Release|Win32.Build.0 = Release|Win32 {92F5212D-C2CF-44C6-85F3-92530392134C}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 diff --git a/msvscpp/libewf/libewf.vcproj b/msvscpp/libewf/libewf.vcproj index 6d9986c06..39dec906d 100644 --- a/msvscpp/libewf/libewf.vcproj +++ b/msvscpp/libewf/libewf.vcproj @@ -189,6 +189,10 @@ RelativePath="..\..\libewf\libewf_bit_stream.c" > + + @@ -225,6 +229,10 @@ RelativePath="..\..\libewf\libewf_data_chunk.c" > + + @@ -317,6 +325,10 @@ RelativePath="..\..\libewf\libewf_lef_subject.c" > + + @@ -349,6 +361,10 @@ RelativePath="..\..\libewf\libewf_section.c" > + + @@ -475,6 +491,10 @@ RelativePath="..\..\libewf\libewf_bit_stream.h" > + + @@ -515,6 +535,10 @@ RelativePath="..\..\libewf\libewf_data_chunk.h" > + + @@ -667,6 +691,10 @@ RelativePath="..\..\libewf\libewf_libuna.h" > + + @@ -699,6 +727,10 @@ RelativePath="..\..\libewf\libewf_section.h" > + + diff --git a/tests/Makefile.am b/tests/Makefile.am index 609a4175d..6b664db6e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -83,6 +83,7 @@ check_PROGRAMS = \ ewf_test_access_control_entry \ ewf_test_analytical_data \ ewf_test_attribute \ + ewf_test_buffer_data_handle \ ewf_test_bit_stream \ ewf_test_case_data \ ewf_test_case_data_section \ @@ -116,6 +117,7 @@ check_PROGRAMS = \ ewf_test_lef_permission \ ewf_test_lef_source \ ewf_test_lef_subject \ + ewf_test_line_reader \ ewf_test_ltree_section \ ewf_test_md5_hash_section \ ewf_test_media_values \ @@ -123,6 +125,7 @@ check_PROGRAMS = \ ewf_test_permission_group \ ewf_test_read_io_handle \ ewf_test_restart_data \ + ewf_test_section_data_handle \ ewf_test_section_descriptor \ ewf_test_sector_range \ ewf_test_sector_range_list \ @@ -216,6 +219,18 @@ ewf_test_bit_stream_LDADD = \ ../libewf/libewf.la \ @LIBCERROR_LIBADD@ +ewf_test_buffer_data_handle_SOURCES = \ + ewf_test_buffer_data_handle.c \ + ewf_test_libcerror.h \ + ewf_test_libewf.h \ + ewf_test_macros.h \ + ewf_test_memory.c ewf_test_memory.h \ + ewf_test_unused.h + +ewf_test_buffer_data_handle_LDADD = \ + ../libewf/libewf.la \ + @LIBCERROR_LIBADD@ + ewf_test_case_data_SOURCES = \ ewf_test_case_data.c \ ewf_test_libcerror.h \ @@ -495,11 +510,13 @@ ewf_test_file_entry_SOURCES = \ ewf_test_libcdata.h \ ewf_test_libcerror.h \ ewf_test_libewf.h \ + ewf_test_libfdata.h \ ewf_test_macros.h \ ewf_test_memory.c ewf_test_memory.h \ ewf_test_unused.h ewf_test_file_entry_LDADD = \ + @LIBFDATA_LIBADD@ \ ../libewf/libewf.la \ @LIBCERROR_LIBADD@ @@ -723,17 +740,33 @@ ewf_test_lef_subject_LDADD = \ ../libewf/libewf.la \ @LIBCERROR_LIBADD@ +ewf_test_line_reader_SOURCES = \ + ewf_test_libcerror.h \ + ewf_test_libewf.h \ + ewf_test_libfdata.h \ + ewf_test_line_reader.c \ + ewf_test_macros.h \ + ewf_test_memory.c ewf_test_memory.h \ + ewf_test_unused.h + +ewf_test_line_reader_LDADD = \ + @LIBFDATA_LIBADD@ \ + ../libewf/libewf.la \ + @LIBCERROR_LIBADD@ + ewf_test_ltree_section_SOURCES = \ ewf_test_functions.c ewf_test_functions.h \ ewf_test_libbfio.h \ ewf_test_libcerror.h \ ewf_test_libewf.h \ + ewf_test_libfdata.h \ ewf_test_ltree_section.c \ ewf_test_macros.h \ ewf_test_memory.c ewf_test_memory.h \ ewf_test_unused.h ewf_test_ltree_section_LDADD = \ + @LIBFDATA_LIBADD@ \ @LIBBFIO_LIBADD@ \ @LIBCPATH_LIBADD@ \ @LIBCFILE_LIBADD@ \ @@ -826,6 +859,18 @@ ewf_test_restart_data_LDADD = \ ../libewf/libewf.la \ @LIBCERROR_LIBADD@ +ewf_test_section_data_handle_SOURCES = \ + ewf_test_libcerror.h \ + ewf_test_libewf.h \ + ewf_test_macros.h \ + ewf_test_memory.c ewf_test_memory.h \ + ewf_test_section_data_handle.c \ + ewf_test_unused.h + +ewf_test_section_data_handle_LDADD = \ + ../libewf/libewf.la \ + @LIBCERROR_LIBADD@ + ewf_test_section_descriptor_SOURCES = \ ewf_test_functions.c ewf_test_functions.h \ ewf_test_libbfio.h \ @@ -968,11 +1013,13 @@ ewf_test_sha1_hash_section_LDADD = \ ewf_test_single_file_tree_SOURCES = \ ewf_test_libcerror.h \ ewf_test_libewf.h \ + ewf_test_libfdata.h \ ewf_test_macros.h \ ewf_test_single_file_tree.c \ ewf_test_unused.h ewf_test_single_file_tree_LDADD = \ + @LIBFDATA_LIBADD@ \ @LIBCDATA_LIBADD@ \ ../libewf/libewf.la \ @LIBCERROR_LIBADD@ @@ -980,6 +1027,7 @@ ewf_test_single_file_tree_LDADD = \ ewf_test_single_files_SOURCES = \ ewf_test_libcerror.h \ ewf_test_libewf.h \ + ewf_test_libfdata.h \ ewf_test_libfvalue.h \ ewf_test_macros.h \ ewf_test_memory.c ewf_test_memory.h \ @@ -989,6 +1037,7 @@ ewf_test_single_files_SOURCES = \ ewf_test_single_files_LDADD = \ @LIBFVALUE_LIBADD@ \ @LIBFGUID_LIBADD@ \ + @LIBFDATA_LIBADD@ \ @LIBFDATETIME_LIBADD@ \ @LIBUNA_LIBADD@ \ @LIBCNOTIFY_LIBADD@ \ diff --git a/tests/data/single_files.2 b/tests/data/single_files.2 deleted file mode 100644 index 3ed068246..000000000 --- a/tests/data/single_files.2 +++ /dev/null @@ -1,45 +0,0 @@ -5 -rec -tb cl n fp pg lg ig cd wd md ad -261992470 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 - -perm -1 1 -p n s pr nta nti -0 1 -1 10 -0 0 -1 10 - -srce -1 1 -p n id ev do loc se mfr mo tb lo po ah sh gu pgu aq ip si ma dt -0 1 -1 -1 -1 00000000000000000000000000000000 0000000000000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 000000000000 f -0 0 - F 1 Љ_0 Flash Disk 262144000 -1 -1 00000000000000000000000000000000 0000000000000000000000000000000000000000 77900B92A58C87C480A30FBC59E31A65 77900B92A58C87C480A30FBC59E31A65 000000000000 r - -sub -0 1 -p n id nu co gu -0 0 - 1 00000000000000000000000000000000 - -entry -6 1 -mid ls be id cr ac wr mo dl sig ha sha ent snh p n du lo po pm oes spth opr src sub cid jq alt ep aq cfi sg ea lpt -26 6 -AD1C41BB3F1B748C90E484D2F17C139D 0 00000000000000000000000000000000 0000000000000000000000000000000000000000 B 1 1 LogicalEntries -1 1 00000000000000000000000000000000 -26 0 -580BA30DB842A98E9DF1124047FB606A 1 0 1 1577689768 1577660400 1577689768 8 1b D41D8CD98F00B204E9800998ECF8427E DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 E 1 Test 1 80000000ffffffff 80000000ffffffff 43 1 1 00000000000000000000000000000000 -26 0 -A9FBD2DAB10EA8838F6529FA4E4D97A8 20 1 1 14 1 1577689823 1577660400 1577689816 8 8 5DD39CAB1C53C2C77CD352983F9641E1 0000000000000000000000000000000000000000 B 13 TESTFILE.TXT testfile.txt 286720 1 14 1000 46000 230 43 1 46000 1000 3 1 230 8 1 4194312 1 00000000000000000000000000000000 -26 0 -AD9965F44604378C9EE0C003FD2314E4 4096 1 15 1000 8 1b C90A3A35F185AEC78AC16F114D8648A2 0000000000000000000000000000000000000000 B 1 Volume Boot 1 1000 1000 53 1 1000 80000000ffffffff 80000000ffffffff 8 1 4194304 1 00000000000000000000000000000000 -26 0 -D1FE6EB9039E888DA85D20A173CC1CAB 131072 1 1015 20000 8 1b 7F2F1868C300D65D210349E3FCCFF355 0000000000000000000000000000000000000000 B 1 Primary FAT 4096 1 20000 20000 1000 8 53 1 1000 20000 80000000ffffffff 80000000ffffffff 8 100 1 4194304 1 00000000000000000000000000000000 -26 0 -59BB940C19895D89B21447B7D587E732 131072 1 21015 1 8 1b 7F2F1868C300D65D210349E3FCCFF355 0000000000000000000000000000000000000000 B 1 Secondary FAT 4117 135168 1 20000 20000 21000 108 53 1 21000 20000 80000000ffffffff 80000000ffffffff 108 100 1 71303168 1 00000000000000000000000000000000 -26 0 -70C77635D29EEB8286793E8B7ED76406 261857280 1 21016 f9ba000 8 1b 2997DD61908D3D180678D31AD5EB42A8 0000000000000000000000000000000000000000 B 1 Unallocated Clusters 282624 1 f9ba000 f9ba000 45000 228 43 2 45000 1000 2 1 228 8 47000 f9b9000 4 f9b9 238 7cdc8 1 6291456 1 00000000000000000000000000000000 - diff --git a/tests/ewf_test_buffer_data_handle.c b/tests/ewf_test_buffer_data_handle.c new file mode 100644 index 000000000..6c38b1ebf --- /dev/null +++ b/tests/ewf_test_buffer_data_handle.c @@ -0,0 +1,888 @@ +/* + * Library buffer_data_handle type test program + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "ewf_test_libcerror.h" +#include "ewf_test_libewf.h" +#include "ewf_test_macros.h" +#include "ewf_test_memory.h" +#include "ewf_test_unused.h" + +#include "../libewf/libewf_buffer_data_handle.h" + +uint8_t ewf_test_buffer_data_handle_data1[ 16 ] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + +/* Tests the libewf_buffer_data_handle_initialize function + * Returns 1 if successful or 0 if not + */ +int ewf_test_buffer_data_handle_initialize( + void ) +{ + libcerror_error_t *error = NULL; + libewf_buffer_data_handle_t *buffer_data_handle = NULL; + int result = 0; + +#if defined( HAVE_EWF_TEST_MEMORY ) + int number_of_malloc_fail_tests = 1; + int number_of_memset_fail_tests = 1; + int test_number = 0; +#endif + + /* Test regular cases + */ + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_buffer_data_handle_free( + &buffer_data_handle, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + NULL, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_buffer_data_handle_free( + &buffer_data_handle, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libewf_buffer_data_handle_initialize( + NULL, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + buffer_data_handle = (libewf_buffer_data_handle_t *) 0x12345678UL; + + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + buffer_data_handle = NULL; + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + NULL, + 16, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + (size_t) SSIZE_MAX + 1, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_EWF_TEST_MEMORY ) + + for( test_number = 0; + test_number < number_of_malloc_fail_tests; + test_number++ ) + { + /* Test libewf_buffer_data_handle_initialize with malloc failing + */ + ewf_test_malloc_attempts_before_fail = test_number; + + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + if( ewf_test_malloc_attempts_before_fail != -1 ) + { + ewf_test_malloc_attempts_before_fail = -1; + + if( buffer_data_handle != NULL ) + { + libewf_buffer_data_handle_free( + &buffer_data_handle, + NULL ); + } + } + else + { + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } + for( test_number = 0; + test_number < number_of_memset_fail_tests; + test_number++ ) + { + /* Test libewf_buffer_data_handle_initialize with memset failing + */ + ewf_test_memset_attempts_before_fail = test_number; + + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + if( ewf_test_memset_attempts_before_fail != -1 ) + { + ewf_test_memset_attempts_before_fail = -1; + + if( buffer_data_handle != NULL ) + { + libewf_buffer_data_handle_free( + &buffer_data_handle, + NULL ); + } + } + else + { + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } +#endif /* defined( HAVE_EWF_TEST_MEMORY ) */ + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( buffer_data_handle != NULL ) + { + libewf_buffer_data_handle_free( + &buffer_data_handle, + NULL ); + } + return( 0 ); +} + +/* Tests the libewf_buffer_data_handle_free function + * Returns 1 if successful or 0 if not + */ +int ewf_test_buffer_data_handle_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libewf_buffer_data_handle_free( + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the libewf_buffer_data_handle_read_segment_data function + * Returns 1 if successful or 0 if not + */ +int ewf_test_buffer_data_handle_read_segment_data( + void ) +{ + uint8_t segment_data[ 16 ]; + + libcerror_error_t *error = NULL; + libewf_buffer_data_handle_t *buffer_data_handle = NULL; + ssize_t read_count = 0; + off64_t offset = 0; + int result = 0; + + /* Initialize test + */ + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + segment_data, + 12, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) 12 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = memory_compare( + segment_data, + ewf_test_buffer_data_handle_data1, + 12 ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + + /* Read buffer on last segment boundary + */ + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + segment_data, + 8, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) 4 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = memory_compare( + segment_data, + &( ewf_test_buffer_data_handle_data1[ 12 ] ), + 4 ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + + /* Read buffer beyond last segment + */ + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) 0 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Initialize test + */ + offset = libewf_buffer_data_handle_seek_segment_offset( + buffer_data_handle, + NULL, + 0, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) 0 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + read_count = libewf_buffer_data_handle_read_segment_data( + NULL, + NULL, + 0, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + buffer_data_handle->current_offset = -1; + + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + buffer_data_handle->current_offset = 0; + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + -1, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + NULL, + 16, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + segment_data, + (size_t) SSIZE_MAX + 1, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_EWF_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) + + /* Test libewf_buffer_data_handle_read_segment_data with memcpy failing + */ + ewf_test_memcpy_attempts_before_fail = 0; + + read_count = libewf_buffer_data_handle_read_segment_data( + buffer_data_handle, + NULL, + 0, + 0, + segment_data, + 12, + 0, + 0, + &error ); + + if( ewf_test_memcpy_attempts_before_fail != -1 ) + { + ewf_test_memcpy_attempts_before_fail = -1; + } + else + { + EWF_TEST_ASSERT_EQUAL_INT64( + "read_count", + read_count, + (ssize_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } +#endif /* defined( HAVE_EWF_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) */ + + /* Clean up + */ + result = libewf_buffer_data_handle_free( + &buffer_data_handle, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( buffer_data_handle != NULL ) + { + libewf_buffer_data_handle_free( + &buffer_data_handle, + NULL ); + } + return( 0 ); +} + +/* Tests the libewf_buffer_data_handle_seek_segment_offset function + * Returns 1 if successful or 0 if not + */ +int ewf_test_buffer_data_handle_seek_segment_offset( + void ) +{ + libcerror_error_t *error = NULL; + libewf_buffer_data_handle_t *buffer_data_handle = NULL; + off64_t offset = 0; + int result = 0; + + /* Initialize test + */ + result = libewf_buffer_data_handle_initialize( + &buffer_data_handle, + ewf_test_buffer_data_handle_data1, + 16, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + offset = libewf_buffer_data_handle_seek_segment_offset( + buffer_data_handle, + NULL, + 0, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) 0 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + offset = libewf_buffer_data_handle_seek_segment_offset( + NULL, + NULL, + 0, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + offset = libewf_buffer_data_handle_seek_segment_offset( + buffer_data_handle, + NULL, + -1, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + offset = libewf_buffer_data_handle_seek_segment_offset( + buffer_data_handle, + NULL, + 0, + 0, + -1, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + /* Clean up + */ + result = libewf_buffer_data_handle_free( + &buffer_data_handle, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "buffer_data_handle", + buffer_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( buffer_data_handle != NULL ) + { + libewf_buffer_data_handle_free( + &buffer_data_handle, + NULL ); + } + return( 0 ); +} + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + EWF_TEST_UNREFERENCED_PARAMETER( argc ) + EWF_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + + EWF_TEST_RUN( + "libewf_buffer_data_handle_initialize", + ewf_test_buffer_data_handle_initialize ); + + EWF_TEST_RUN( + "libewf_buffer_data_handle_free", + ewf_test_buffer_data_handle_free ); + + EWF_TEST_RUN( + "libewf_buffer_data_handle_read_segment_data", + ewf_test_buffer_data_handle_read_segment_data ); + + EWF_TEST_RUN( + "libewf_buffer_data_handle_seek_segment_offset", + ewf_test_buffer_data_handle_seek_segment_offset ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + + return( EXIT_SUCCESS ); + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + +on_error: + return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ +} + diff --git a/tests/ewf_test_chunk_data.c b/tests/ewf_test_chunk_data.c index 30ec1d443..2f02e0837 100644 --- a/tests/ewf_test_chunk_data.c +++ b/tests/ewf_test_chunk_data.c @@ -1835,6 +1835,48 @@ int ewf_test_chunk_data_pack_with_compression( "error", error ); + /* Clean up + */ + result = libewf_chunk_data_free( + &chunk_data, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "chunk_data", + chunk_data ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Initialize test + */ + result = libewf_chunk_data_initialize( + &chunk_data, + 512, + 1, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "chunk_data", + chunk_data ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + chunk_data->data_size = 512; + /* Test error cases */ result = libewf_chunk_data_pack_with_compression( diff --git a/tests/ewf_test_file_entry.c b/tests/ewf_test_file_entry.c index eff106bea..0b8013174 100644 --- a/tests/ewf_test_file_entry.c +++ b/tests/ewf_test_file_entry.c @@ -36,11 +36,13 @@ #include "ewf_test_libcdata.h" #include "ewf_test_libcerror.h" #include "ewf_test_libewf.h" +#include "ewf_test_libfdata.h" #include "ewf_test_libfvalue.h" #include "ewf_test_macros.h" #include "ewf_test_memory.h" #include "ewf_test_unused.h" +#include "../libewf/libewf_data_stream.h" #include "../libewf/libewf_file_entry.h" #include "../libewf/libewf_single_files.h" @@ -417,6 +419,7 @@ int ewf_test_file_entry_initialize( libcerror_error_t *error = NULL; libewf_file_entry_t *file_entry = NULL; libewf_single_files_t *single_files = NULL; + libfdata_stream_t *data_stream = NULL; size64_t media_size = 0; uint8_t format = 0; int result = 0; @@ -446,10 +449,29 @@ int ewf_test_file_entry_initialize( "error", error ); - result = libewf_single_files_read_data( - single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_file_entry_data1, 5700, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_single_files_read_data_stream( + single_files, + data_stream, + NULL, &media_size, &format, &error ); @@ -463,6 +485,23 @@ int ewf_test_file_entry_initialize( "error", error ); + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + result = libewf_single_files_get_file_entry_tree_root_node( single_files, &file_entry_tree_node, @@ -710,6 +749,12 @@ int ewf_test_file_entry_initialize( &file_entry, NULL ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( single_files != NULL ) { libewf_single_files_free( @@ -2913,6 +2958,7 @@ int main( libcerror_error_t *error = NULL; libewf_file_entry_t *file_entry = NULL; libewf_single_files_t *single_files = NULL; + libfdata_stream_t *data_stream = NULL; size64_t media_size = 0; uint8_t format = 0; int result = 0; @@ -2956,10 +3002,29 @@ int main( "error", error ); - result = libewf_single_files_read_data( - single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_file_entry_data1, 5700, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_single_files_read_data_stream( + single_files, + data_stream, + NULL, &media_size, &format, &error ); @@ -2973,6 +3038,23 @@ int main( "error", error ); + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + result = libewf_single_files_get_file_entry_tree_root_node( single_files, &file_entry_tree_node, @@ -3221,6 +3303,12 @@ int main( &file_entry, NULL ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( single_files != NULL ) { libewf_single_files_free( diff --git a/tests/ewf_test_libfdata.h b/tests/ewf_test_libfdata.h new file mode 100644 index 000000000..9e467f1d4 --- /dev/null +++ b/tests/ewf_test_libfdata.h @@ -0,0 +1,54 @@ +/* + * The libfdata header wrapper + * + * Copyright (C) 2006-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _EWF_TEST_LIBFDATA_H ) +#define _EWF_TEST_LIBFDATA_H + +#include + +/* Define HAVE_LOCAL_LIBFDATA for local use of libfdata + */ +#if defined( HAVE_LOCAL_LIBFDATA ) + +#include +#include +#include +#include +#include +#include +#include +#include + +#else + +/* If libtool DLL support is enabled set LIBFDATA_DLL_IMPORT + * before including libfdata.h + */ +#if defined( _WIN32 ) && defined( DLL_IMPORT ) +#define LIBFDATA_DLL_IMPORT +#endif + +#include + +#endif /* defined( HAVE_LOCAL_LIBFDATA ) */ + +#endif /* !defined( _EWF_TEST_LIBFDATA_H ) */ + diff --git a/tests/ewf_test_line_reader.c b/tests/ewf_test_line_reader.c new file mode 100644 index 000000000..f8acf20a0 --- /dev/null +++ b/tests/ewf_test_line_reader.c @@ -0,0 +1,567 @@ +/* + * Library line_reader type test program + * + * Copyright (C) 2010-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "ewf_test_libcerror.h" +#include "ewf_test_libewf.h" +#include "ewf_test_libfdata.h" +#include "ewf_test_macros.h" +#include "ewf_test_memory.h" +#include "ewf_test_unused.h" + +#include "../libewf/libewf_data_stream.h" +#include "../libewf/libewf_line_reader.h" + +uint8_t ewf_test_line_reader_data1[ 16 ] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + +/* Tests the libewf_line_reader_initialize function + * Returns 1 if successful or 0 if not + */ +int ewf_test_line_reader_initialize( + void ) +{ + libcerror_error_t *error = NULL; + libewf_line_reader_t *line_reader = NULL; + libfdata_stream_t *data_stream = NULL; + int result = 0; + +#if defined( HAVE_EWF_TEST_MEMORY ) + int number_of_malloc_fail_tests = 3; + int number_of_memset_fail_tests = 1; + int test_number = 0; +#endif + + /* Initialize test + */ + result = libewf_data_stream_initialize_from_buffer( + &data_stream, + ewf_test_line_reader_data1, + 16, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + result = libewf_line_reader_initialize( + &line_reader, + data_stream, + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "line_reader", + line_reader ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_line_reader_free( + &line_reader, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "line_reader", + line_reader ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libewf_line_reader_initialize( + NULL, + data_stream, + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + line_reader = (libewf_line_reader_t *) 0x12345678UL; + + result = libewf_line_reader_initialize( + &line_reader, + data_stream, + NULL, + &error ); + + line_reader = NULL; + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libewf_line_reader_initialize( + &line_reader, + NULL, + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_EWF_TEST_MEMORY ) + + for( test_number = 0; + test_number < number_of_malloc_fail_tests; + test_number++ ) + { + /* Test libewf_line_reader_initialize with malloc failing + */ + ewf_test_malloc_attempts_before_fail = test_number; + + result = libewf_line_reader_initialize( + &line_reader, + data_stream, + NULL, + &error ); + + if( ewf_test_malloc_attempts_before_fail != -1 ) + { + ewf_test_malloc_attempts_before_fail = -1; + + if( line_reader != NULL ) + { + libewf_line_reader_free( + &line_reader, + NULL ); + } + } + else + { + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NULL( + "line_reader", + line_reader ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } + for( test_number = 0; + test_number < number_of_memset_fail_tests; + test_number++ ) + { + /* Test libewf_line_reader_initialize with memset failing + */ + ewf_test_memset_attempts_before_fail = test_number; + + result = libewf_line_reader_initialize( + &line_reader, + data_stream, + NULL, + &error ); + + if( ewf_test_memset_attempts_before_fail != -1 ) + { + ewf_test_memset_attempts_before_fail = -1; + + if( line_reader != NULL ) + { + libewf_line_reader_free( + &line_reader, + NULL ); + } + } + else + { + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NULL( + "line_reader", + line_reader ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } +#endif /* defined( HAVE_EWF_TEST_MEMORY ) */ + + /* Clean up + */ + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( line_reader != NULL ) + { + libewf_line_reader_free( + &line_reader, + NULL ); + } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } + return( 0 ); +} + +/* Tests the libewf_line_reader_free function + * Returns 1 if successful or 0 if not + */ +int ewf_test_line_reader_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libewf_line_reader_free( + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +#ifdef TODO + +/* Tests the libewf_line_reader_read_line function + * Returns 1 if successful or 0 if not + */ +int ewf_test_line_reader_read_line( + void ) +{ + libcerror_error_t *error = NULL; + libfvalue_split_utf8_string_t *lines = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int result = 0; + + /* Initialize test + */ + result = libfvalue_utf8_string_split( + ewf_test_single_files_data2, + 2851, + (uint8_t) '\n', + &lines, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "lines", + lines ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + result = libewf_line_reader_read_line( + lines, + 1, + &line_string, + &line_string_size, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libewf_line_reader_read_line( + NULL, + 1, + &line_string, + &line_string_size, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libewf_line_reader_read_line( + lines, + -1, + &line_string, + &line_string_size, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libewf_line_reader_read_line( + lines, + 1, + NULL, + &line_string_size, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libewf_line_reader_read_line( + lines, + 1, + &line_string, + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + /* Clean up + */ + result = libfvalue_split_utf8_string_free( + &lines, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "lines", + lines ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( lines != NULL ) + { + libfvalue_split_utf8_string_free( + &lines, + NULL ); + } + return( 0 ); +} +#endif /* TODO */ + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + EWF_TEST_UNREFERENCED_PARAMETER( argc ) + EWF_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + + EWF_TEST_RUN( + "libewf_line_reader_initialize", + ewf_test_line_reader_initialize ); + + EWF_TEST_RUN( + "libewf_line_reader_free", + ewf_test_line_reader_free ); + + /* TODO add tests for libewf_line_reader_read_line + + EWF_TEST_RUN( + "libewf_line_reader_read_line", + ewf_test_line_reader_read_line ); + + */ + + /* TODO add tests for libewf_line_reader_finalize */ + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + + return( EXIT_SUCCESS ); + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + +on_error: + return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ +} + diff --git a/tests/ewf_test_ltree_section.c b/tests/ewf_test_ltree_section.c index cb261f2ce..64aa8fb50 100644 --- a/tests/ewf_test_ltree_section.c +++ b/tests/ewf_test_ltree_section.c @@ -32,6 +32,7 @@ #include "ewf_test_libbfio.h" #include "ewf_test_libcerror.h" #include "ewf_test_libewf.h" +#include "ewf_test_libfdata.h" #include "ewf_test_macros.h" #include "ewf_test_memory.h" #include "ewf_test_unused.h" @@ -404,27 +405,21 @@ uint8_t ewf_test_ltree_section_data1[ 5748 ] = { #if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) -/* Tests the libewf_ltree_section_read_data function +/* Tests the libewf_ltree_section_read_header_data function * Returns 1 if successful or 0 if not */ -int ewf_test_ltree_section_read_data( +int ewf_test_ltree_section_read_header_data( void ) { - libcerror_error_t *error = NULL; - uint8_t *single_files_data = NULL; - size_t single_files_data_size = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint64_t single_files_data_size = 0; + int result = 0; /* Test regular cases */ - single_files_data = NULL; - single_files_data_size = 0; - - result = libewf_ltree_section_read_data( + result = libewf_ltree_section_read_header_data( ewf_test_ltree_section_data1, 5748, - 1, - &single_files_data, &single_files_data_size, &error ); @@ -433,20 +428,20 @@ int ewf_test_ltree_section_read_data( result, 1 ); + EWF_TEST_ASSERT_EQUAL_UINT64( + "single_files_data_size", + single_files_data_size, + (uint64_t) 5700 ); + EWF_TEST_ASSERT_IS_NULL( "error", error ); /* Test error cases */ - single_files_data = NULL; - single_files_data_size = 0; - - result = libewf_ltree_section_read_data( + result = libewf_ltree_section_read_header_data( NULL, 5748, - 1, - &single_files_data, &single_files_data_size, &error ); @@ -462,11 +457,9 @@ int ewf_test_ltree_section_read_data( libcerror_error_free( &error ); - result = libewf_ltree_section_read_data( + result = libewf_ltree_section_read_header_data( ewf_test_ltree_section_data1, (size_t) SSIZE_MAX + 1, - 1, - &single_files_data, &single_files_data_size, &error ); @@ -482,78 +475,12 @@ int ewf_test_ltree_section_read_data( libcerror_error_free( &error ); - result = libewf_ltree_section_read_data( + result = libewf_ltree_section_read_header_data( ewf_test_ltree_section_data1, 0, - 1, - &single_files_data, - &single_files_data_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - result = libewf_ltree_section_read_data( - ewf_test_ltree_section_data1, - 5748, - 0, - &single_files_data, - &single_files_data_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - result = libewf_ltree_section_read_data( - ewf_test_ltree_section_data1, - 5748, - 1, - NULL, - &single_files_data_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - single_files_data = (uint8_t *) 0x12345678UL; - - result = libewf_ltree_section_read_data( - ewf_test_ltree_section_data1, - 5748, - 1, - &single_files_data, &single_files_data_size, &error ); - single_files_data = NULL; - EWF_TEST_ASSERT_EQUAL_INT( "result", result, @@ -566,11 +493,9 @@ int ewf_test_ltree_section_read_data( libcerror_error_free( &error ); - result = libewf_ltree_section_read_data( + result = libewf_ltree_section_read_header_data( ewf_test_ltree_section_data1, 5748, - 1, - &single_files_data, NULL, &error ); @@ -586,65 +511,6 @@ int ewf_test_ltree_section_read_data( libcerror_error_free( &error ); - result = libewf_ltree_section_read_data( - ewf_test_ltree_section_data1, - 0, - 1, - &single_files_data, - &single_files_data_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - -/* TODO disabled for now, since this test causes a SIGSEGV within openssl */ -#if defined( SKIP_TEST ) - -#if defined( HAVE_EWF_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) - - /* Test libewf_ltree_section_read_data with memcpy failing - */ - ewf_test_memcpy_attempts_before_fail = 0; - - result = libewf_ltree_section_read_data( - ewf_test_ltree_section_data1, - 5748, - 1, - &single_files_data, - &single_files_data_size, - &error ); - - if( ewf_test_memcpy_attempts_before_fail != -1 ) - { - ewf_test_memcpy_attempts_before_fail = -1; - } - else - { - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - } -#endif /* defined( HAVE_EWF_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) */ - -#endif /* defined( SKIP_TEST ) */ - return( 1 ); on_error: @@ -666,10 +532,7 @@ int ewf_test_ltree_section_read_file_io_pool( libcerror_error_t *error = NULL; libewf_io_handle_t *io_handle = NULL; libewf_section_descriptor_t *section_descriptor = NULL; - uint8_t *section_data = NULL; - uint8_t *single_files_data = NULL; - size_t section_data_size = 0; - size_t single_files_data_size = 0; + libfdata_stream_t *data_stream = NULL; ssize_t read_count = 0; int result = 0; @@ -735,38 +598,44 @@ int ewf_test_ltree_section_read_file_io_pool( /* Test regular cases */ - single_files_data = NULL; - single_files_data_size = 0; - read_count = libewf_ltree_section_read_file_io_pool( section_descriptor, io_handle, file_io_pool, 0, 2, - §ion_data, - §ion_data_size, - &single_files_data, - &single_files_data_size, + &data_stream, &error ); EWF_TEST_ASSERT_EQUAL_SSIZE( "read_count", read_count, - (ssize_t) 5748 ); + (ssize_t) 0 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "section_data", - section_data ); + "data_stream", + data_stream ); EWF_TEST_ASSERT_IS_NULL( "error", error ); - memory_free( - section_data ); + result = libfdata_stream_free( + &data_stream, + &error ); - section_data = NULL; + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); /* Test error cases */ @@ -776,10 +645,7 @@ int ewf_test_ltree_section_read_file_io_pool( file_io_pool, 0, 2, - §ion_data, - §ion_data_size, - &single_files_data, - &single_files_data_size, + &data_stream, &error ); EWF_TEST_ASSERT_EQUAL_SSIZE( @@ -804,10 +670,7 @@ int ewf_test_ltree_section_read_file_io_pool( file_io_pool, 0, 2, - §ion_data, - §ion_data_size, - &single_files_data, - &single_files_data_size, + &data_stream, &error ); section_descriptor->data_size = 5748; @@ -1186,8 +1049,8 @@ int main( #if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) EWF_TEST_RUN( - "libewf_ltree_section_read_data", - ewf_test_ltree_section_read_data ); + "libewf_ltree_section_read_header_data", + ewf_test_ltree_section_read_header_data ); EWF_TEST_RUN( "libewf_ltree_section_read_file_io_pool", diff --git a/tests/ewf_test_section_data_handle.c b/tests/ewf_test_section_data_handle.c new file mode 100644 index 000000000..ed07212d6 --- /dev/null +++ b/tests/ewf_test_section_data_handle.c @@ -0,0 +1,477 @@ +/* + * Library section_data_handle type test program + * + * Copyright (C) 2010-2023, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "ewf_test_libcerror.h" +#include "ewf_test_libewf.h" +#include "ewf_test_macros.h" +#include "ewf_test_memory.h" +#include "ewf_test_unused.h" + +#include "../libewf/libewf_section_data_handle.h" + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + +/* Tests the libewf_section_data_handle_initialize function + * Returns 1 if successful or 0 if not + */ +int ewf_test_section_data_handle_initialize( + void ) +{ + libcerror_error_t *error = NULL; + libewf_section_data_handle_t *section_data_handle = NULL; + int result = 0; + +#if defined( HAVE_EWF_TEST_MEMORY ) + int number_of_malloc_fail_tests = 1; + int number_of_memset_fail_tests = 1; + int test_number = 0; +#endif + + /* Test regular cases + */ + result = libewf_section_data_handle_initialize( + §ion_data_handle, + 0, + 1024, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "section_data_handle", + section_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_section_data_handle_free( + §ion_data_handle, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "section_data_handle", + section_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libewf_section_data_handle_initialize( + NULL, + 0, + 1024, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + section_data_handle = (libewf_section_data_handle_t *) 0x12345678UL; + + result = libewf_section_data_handle_initialize( + §ion_data_handle, + 0, + 1024, + &error ); + + section_data_handle = NULL; + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_EWF_TEST_MEMORY ) + + for( test_number = 0; + test_number < number_of_malloc_fail_tests; + test_number++ ) + { + /* Test libewf_section_data_handle_initialize with malloc failing + */ + ewf_test_malloc_attempts_before_fail = test_number; + + result = libewf_section_data_handle_initialize( + §ion_data_handle, + 0, + 1024, + &error ); + + if( ewf_test_malloc_attempts_before_fail != -1 ) + { + ewf_test_malloc_attempts_before_fail = -1; + + if( section_data_handle != NULL ) + { + libewf_section_data_handle_free( + §ion_data_handle, + NULL ); + } + } + else + { + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NULL( + "section_data_handle", + section_data_handle ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } + for( test_number = 0; + test_number < number_of_memset_fail_tests; + test_number++ ) + { + /* Test libewf_section_data_handle_initialize with memset failing + */ + ewf_test_memset_attempts_before_fail = test_number; + + result = libewf_section_data_handle_initialize( + §ion_data_handle, + 0, + 1024, + &error ); + + if( ewf_test_memset_attempts_before_fail != -1 ) + { + ewf_test_memset_attempts_before_fail = -1; + + if( section_data_handle != NULL ) + { + libewf_section_data_handle_free( + §ion_data_handle, + NULL ); + } + } + else + { + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NULL( + "section_data_handle", + section_data_handle ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } +#endif /* defined( HAVE_EWF_TEST_MEMORY ) */ + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( section_data_handle != NULL ) + { + libewf_section_data_handle_free( + §ion_data_handle, + NULL ); + } + return( 0 ); +} + +/* Tests the libewf_section_data_handle_free function + * Returns 1 if successful or 0 if not + */ +int ewf_test_section_data_handle_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libewf_section_data_handle_free( + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the libewf_section_data_handle_seek_segment_offset function + * Returns 1 if successful or 0 if not + */ +int ewf_test_section_data_handle_seek_segment_offset( + void ) +{ + libcerror_error_t *error = NULL; + libewf_section_data_handle_t *section_data_handle = NULL; + off64_t offset = 0; + int result = 0; + + /* Initialize test + */ + result = libewf_section_data_handle_initialize( + §ion_data_handle, + 0, + 1024, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "section_data_handle", + section_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + offset = libewf_section_data_handle_seek_segment_offset( + section_data_handle, + NULL, + 0, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) 0 ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + offset = libewf_section_data_handle_seek_segment_offset( + NULL, + NULL, + 0, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + offset = libewf_section_data_handle_seek_segment_offset( + section_data_handle, + NULL, + -1, + 0, + 0, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + offset = libewf_section_data_handle_seek_segment_offset( + section_data_handle, + NULL, + 0, + 0, + -1, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT64( + "offset", + offset, + (int64_t) -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + /* Clean up + */ + result = libewf_section_data_handle_free( + §ion_data_handle, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "section_data_handle", + section_data_handle ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( section_data_handle != NULL ) + { + libewf_section_data_handle_free( + §ion_data_handle, + NULL ); + } + return( 0 ); +} + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + EWF_TEST_UNREFERENCED_PARAMETER( argc ) + EWF_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + + EWF_TEST_RUN( + "libewf_section_data_handle_initialize", + ewf_test_section_data_handle_initialize ); + + EWF_TEST_RUN( + "libewf_section_data_handle_free", + ewf_test_section_data_handle_free ); + + /* TODO add tests for libewf_section_data_handle_read_segment_data */ + + EWF_TEST_RUN( + "libewf_section_data_handle_seek_segment_offset", + ewf_test_section_data_handle_seek_segment_offset ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + + return( EXIT_SUCCESS ); + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + +on_error: + return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ +} + diff --git a/tests/ewf_test_section_descriptor.c b/tests/ewf_test_section_descriptor.c index 0faf3655f..06b36ed91 100644 --- a/tests/ewf_test_section_descriptor.c +++ b/tests/ewf_test_section_descriptor.c @@ -1509,11 +1509,17 @@ int main( "libewf_section_descriptor_write_file_io_pool", ewf_test_section_descriptor_write_file_io_pool ); +/* TODO add tests for libewf_section_descriptor_get_data_offset */ + #endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ return( EXIT_SUCCESS ); +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + on_error: return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ } diff --git a/tests/ewf_test_single_file_tree.c b/tests/ewf_test_single_file_tree.c index 71b7d09da..6293f2b69 100644 --- a/tests/ewf_test_single_file_tree.c +++ b/tests/ewf_test_single_file_tree.c @@ -30,9 +30,11 @@ #include "ewf_test_libcdata.h" #include "ewf_test_libcerror.h" #include "ewf_test_libewf.h" +#include "ewf_test_libfdata.h" #include "ewf_test_macros.h" #include "ewf_test_unused.h" +#include "../libewf/libewf_data_stream.h" #include "../libewf/libewf_lef_file_entry.h" #include "../libewf/libewf_single_file_tree.h" #include "../libewf/libewf_single_files.h" @@ -413,6 +415,7 @@ int ewf_test_single_file_tree_get_sub_node_by_utf8_name( libcerror_error_t *error = NULL; libewf_lef_file_entry_t *sub_lef_file_entry = NULL; libewf_single_files_t *single_files = NULL; + libfdata_stream_t *data_stream = NULL; size64_t media_size = 0; uint8_t format = 0; int result = 0; @@ -436,10 +439,29 @@ int ewf_test_single_file_tree_get_sub_node_by_utf8_name( "error", error ); - result = libewf_single_files_read_data( - single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_single_files_data1, 5700, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_single_files_read_data_stream( + single_files, + data_stream, + NULL, &media_size, &format, &error ); @@ -453,6 +475,23 @@ int ewf_test_single_file_tree_get_sub_node_by_utf8_name( "error", error ); + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + result = libewf_single_files_get_file_entry_tree_root_node( single_files, &root_node, @@ -607,6 +646,12 @@ int ewf_test_single_file_tree_get_sub_node_by_utf8_name( libcerror_error_free( &error ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( single_files != NULL ) { libewf_single_files_free( @@ -629,6 +674,7 @@ int ewf_test_single_file_tree_get_sub_node_by_utf16_name( libcerror_error_t *error = NULL; libewf_lef_file_entry_t *sub_lef_file_entry = NULL; libewf_single_files_t *single_files = NULL; + libfdata_stream_t *data_stream = NULL; size64_t media_size = 0; uint8_t format = 0; int result = 0; @@ -652,10 +698,29 @@ int ewf_test_single_file_tree_get_sub_node_by_utf16_name( "error", error ); - result = libewf_single_files_read_data( - single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_single_files_data1, 5700, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_single_files_read_data_stream( + single_files, + data_stream, + NULL, &media_size, &format, &error ); @@ -669,6 +734,23 @@ int ewf_test_single_file_tree_get_sub_node_by_utf16_name( "error", error ); + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + result = libewf_single_files_get_file_entry_tree_root_node( single_files, &root_node, @@ -823,6 +905,12 @@ int ewf_test_single_file_tree_get_sub_node_by_utf16_name( libcerror_error_free( &error ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( single_files != NULL ) { libewf_single_files_free( @@ -863,7 +951,11 @@ int main( return( EXIT_SUCCESS ); +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + on_error: return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ } diff --git a/tests/ewf_test_single_files.c b/tests/ewf_test_single_files.c index 528598276..4fad9e871 100644 --- a/tests/ewf_test_single_files.c +++ b/tests/ewf_test_single_files.c @@ -30,11 +30,14 @@ #include "ewf_test_libcdata.h" #include "ewf_test_libcerror.h" #include "ewf_test_libewf.h" +#include "ewf_test_libfdata.h" #include "ewf_test_libfvalue.h" #include "ewf_test_macros.h" #include "ewf_test_memory.h" #include "ewf_test_unused.h" +#include "../libewf/libewf_data_stream.h" +#include "../libewf/libewf_line_reader.h" #include "../libewf/libewf_single_files.h" /* UTF-16 little-endian encoded single files data @@ -398,189 +401,6 @@ uint8_t ewf_test_single_files_data1[ 5700 ] = { 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x09, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x0a, 0x00 }; -/* UTF-8 encoded single files data - */ -uint8_t ewf_test_single_files_data2[ 2851 ] = { - 0x35, 0x0a, 0x72, 0x65, 0x63, 0x0a, 0x74, 0x62, 0x09, 0x63, 0x6c, 0x09, 0x6e, 0x09, 0x66, 0x70, - 0x09, 0x70, 0x67, 0x09, 0x6c, 0x67, 0x09, 0x69, 0x67, 0x09, 0x63, 0x64, 0x09, 0x77, 0x64, 0x09, - 0x6d, 0x64, 0x09, 0x61, 0x64, 0x0a, 0x32, 0x36, 0x31, 0x39, 0x39, 0x32, 0x34, 0x37, 0x30, 0x09, - 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x09, 0x09, 0x0a, 0x0a, 0x70, 0x65, 0x72, 0x6d, 0x0a, - 0x31, 0x09, 0x31, 0x0a, 0x70, 0x09, 0x6e, 0x09, 0x73, 0x09, 0x70, 0x72, 0x09, 0x6e, 0x74, 0x61, - 0x09, 0x6e, 0x74, 0x69, 0x0a, 0x30, 0x09, 0x31, 0x0a, 0x31, 0x09, 0x09, 0x09, 0x31, 0x30, 0x09, - 0x09, 0x0a, 0x30, 0x09, 0x30, 0x0a, 0x31, 0x09, 0x09, 0x09, 0x31, 0x30, 0x09, 0x09, 0x0a, 0x0a, - 0x73, 0x72, 0x63, 0x65, 0x0a, 0x31, 0x09, 0x31, 0x0a, 0x70, 0x09, 0x6e, 0x09, 0x69, 0x64, 0x09, - 0x65, 0x76, 0x09, 0x64, 0x6f, 0x09, 0x6c, 0x6f, 0x63, 0x09, 0x73, 0x65, 0x09, 0x6d, 0x66, 0x72, - 0x09, 0x6d, 0x6f, 0x09, 0x74, 0x62, 0x09, 0x6c, 0x6f, 0x09, 0x70, 0x6f, 0x09, 0x61, 0x68, 0x09, - 0x73, 0x68, 0x09, 0x67, 0x75, 0x09, 0x70, 0x67, 0x75, 0x09, 0x61, 0x71, 0x09, 0x69, 0x70, 0x09, - 0x73, 0x69, 0x09, 0x6d, 0x61, 0x09, 0x64, 0x74, 0x0a, 0x30, 0x09, 0x31, 0x0a, 0x31, 0x09, 0x09, - 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x31, 0x09, 0x2d, 0x31, 0x09, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x66, 0x0a, 0x30, 0x09, 0x30, 0x0a, - 0x09, 0x46, 0x09, 0x31, 0x09, 0x09, 0x09, 0x09, 0xd0, 0x89, 0x5f, 0x30, 0x09, 0x09, 0x46, 0x6c, - 0x61, 0x73, 0x68, 0x20, 0x44, 0x69, 0x73, 0x6b, 0x09, 0x32, 0x36, 0x32, 0x31, 0x34, 0x34, 0x30, - 0x30, 0x30, 0x09, 0x2d, 0x31, 0x09, 0x2d, 0x31, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x09, 0x37, 0x37, 0x39, 0x30, 0x30, 0x42, 0x39, 0x32, 0x41, 0x35, 0x38, 0x43, 0x38, - 0x37, 0x43, 0x34, 0x38, 0x30, 0x41, 0x33, 0x30, 0x46, 0x42, 0x43, 0x35, 0x39, 0x45, 0x33, 0x31, - 0x41, 0x36, 0x35, 0x09, 0x37, 0x37, 0x39, 0x30, 0x30, 0x42, 0x39, 0x32, 0x41, 0x35, 0x38, 0x43, - 0x38, 0x37, 0x43, 0x34, 0x38, 0x30, 0x41, 0x33, 0x30, 0x46, 0x42, 0x43, 0x35, 0x39, 0x45, 0x33, - 0x31, 0x41, 0x36, 0x35, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x09, 0x72, 0x0a, 0x0a, 0x73, 0x75, 0x62, 0x0a, 0x30, 0x09, 0x31, 0x0a, - 0x70, 0x09, 0x6e, 0x09, 0x69, 0x64, 0x09, 0x6e, 0x75, 0x09, 0x63, 0x6f, 0x09, 0x67, 0x75, 0x0a, - 0x30, 0x09, 0x30, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x31, 0x20, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x0a, 0x65, 0x6e, 0x74, - 0x72, 0x79, 0x0a, 0x36, 0x09, 0x31, 0x0a, 0x6d, 0x69, 0x64, 0x09, 0x6c, 0x73, 0x09, 0x62, 0x65, - 0x09, 0x69, 0x64, 0x09, 0x63, 0x72, 0x09, 0x61, 0x63, 0x09, 0x77, 0x72, 0x09, 0x6d, 0x6f, 0x09, - 0x64, 0x6c, 0x09, 0x73, 0x69, 0x67, 0x09, 0x68, 0x61, 0x09, 0x73, 0x68, 0x61, 0x09, 0x65, 0x6e, - 0x74, 0x09, 0x73, 0x6e, 0x68, 0x09, 0x70, 0x09, 0x6e, 0x09, 0x64, 0x75, 0x09, 0x6c, 0x6f, 0x09, - 0x70, 0x6f, 0x09, 0x70, 0x6d, 0x09, 0x6f, 0x65, 0x73, 0x09, 0x73, 0x70, 0x74, 0x68, 0x09, 0x6f, - 0x70, 0x72, 0x09, 0x73, 0x72, 0x63, 0x09, 0x73, 0x75, 0x62, 0x09, 0x63, 0x69, 0x64, 0x09, 0x6a, - 0x71, 0x09, 0x61, 0x6c, 0x74, 0x09, 0x65, 0x70, 0x09, 0x61, 0x71, 0x09, 0x63, 0x66, 0x69, 0x09, - 0x73, 0x67, 0x09, 0x65, 0x61, 0x09, 0x6c, 0x70, 0x74, 0x0a, 0x32, 0x36, 0x09, 0x36, 0x0a, 0x41, - 0x44, 0x31, 0x43, 0x34, 0x31, 0x42, 0x42, 0x33, 0x46, 0x31, 0x42, 0x37, 0x34, 0x38, 0x43, 0x39, - 0x30, 0x45, 0x34, 0x38, 0x34, 0x44, 0x32, 0x46, 0x31, 0x37, 0x43, 0x31, 0x33, 0x39, 0x44, 0x09, - 0x09, 0x30, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x09, 0x42, 0x09, 0x31, 0x20, 0x09, 0x31, 0x09, 0x4c, 0x6f, 0x67, 0x69, 0x63, - 0x61, 0x6c, 0x45, 0x6e, 0x74, 0x72, 0x69, 0x65, 0x73, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x31, 0x09, - 0x09, 0x31, 0x20, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x0a, - 0x32, 0x36, 0x09, 0x30, 0x0a, 0x35, 0x38, 0x30, 0x42, 0x41, 0x33, 0x30, 0x44, 0x42, 0x38, 0x34, - 0x32, 0x41, 0x39, 0x38, 0x45, 0x39, 0x44, 0x46, 0x31, 0x31, 0x32, 0x34, 0x30, 0x34, 0x37, 0x46, - 0x42, 0x36, 0x30, 0x36, 0x41, 0x09, 0x09, 0x31, 0x20, 0x30, 0x20, 0x31, 0x09, 0x09, 0x31, 0x35, - 0x37, 0x37, 0x36, 0x38, 0x39, 0x37, 0x36, 0x38, 0x09, 0x31, 0x35, 0x37, 0x37, 0x36, 0x36, 0x30, - 0x34, 0x30, 0x30, 0x09, 0x31, 0x35, 0x37, 0x37, 0x36, 0x38, 0x39, 0x37, 0x36, 0x38, 0x09, 0x09, - 0x09, 0x38, 0x20, 0x31, 0x62, 0x09, 0x44, 0x34, 0x31, 0x44, 0x38, 0x43, 0x44, 0x39, 0x38, 0x46, - 0x30, 0x30, 0x42, 0x32, 0x30, 0x34, 0x45, 0x39, 0x38, 0x30, 0x30, 0x39, 0x39, 0x38, 0x45, 0x43, - 0x46, 0x38, 0x34, 0x32, 0x37, 0x45, 0x09, 0x44, 0x41, 0x33, 0x39, 0x41, 0x33, 0x45, 0x45, 0x35, - 0x45, 0x36, 0x42, 0x34, 0x42, 0x30, 0x44, 0x33, 0x32, 0x35, 0x35, 0x42, 0x46, 0x45, 0x46, 0x39, - 0x35, 0x36, 0x30, 0x31, 0x38, 0x39, 0x30, 0x41, 0x46, 0x44, 0x38, 0x30, 0x37, 0x30, 0x39, 0x09, - 0x45, 0x09, 0x31, 0x20, 0x09, 0x09, 0x54, 0x65, 0x73, 0x74, 0x09, 0x09, 0x09, 0x09, 0x09, 0x31, - 0x20, 0x20, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x66, 0x20, 0x20, 0x34, 0x33, 0x20, 0x09, 0x31, 0x20, 0x09, 0x09, 0x31, 0x09, - 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x0a, 0x32, 0x36, 0x09, 0x30, 0x0a, 0x41, - 0x39, 0x46, 0x42, 0x44, 0x32, 0x44, 0x41, 0x42, 0x31, 0x30, 0x45, 0x41, 0x38, 0x38, 0x33, 0x38, - 0x46, 0x36, 0x35, 0x32, 0x39, 0x46, 0x41, 0x34, 0x45, 0x34, 0x44, 0x39, 0x37, 0x41, 0x38, 0x09, - 0x32, 0x30, 0x09, 0x31, 0x20, 0x31, 0x20, 0x31, 0x34, 0x09, 0x31, 0x09, 0x31, 0x35, 0x37, 0x37, - 0x36, 0x38, 0x39, 0x38, 0x32, 0x33, 0x09, 0x31, 0x35, 0x37, 0x37, 0x36, 0x36, 0x30, 0x34, 0x30, - 0x30, 0x09, 0x31, 0x35, 0x37, 0x37, 0x36, 0x38, 0x39, 0x38, 0x31, 0x36, 0x09, 0x09, 0x09, 0x38, - 0x20, 0x38, 0x09, 0x35, 0x44, 0x44, 0x33, 0x39, 0x43, 0x41, 0x42, 0x31, 0x43, 0x35, 0x33, 0x43, - 0x32, 0x43, 0x37, 0x37, 0x43, 0x44, 0x33, 0x35, 0x32, 0x39, 0x38, 0x33, 0x46, 0x39, 0x36, 0x34, - 0x31, 0x45, 0x31, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x42, 0x09, 0x31, - 0x33, 0x20, 0x54, 0x45, 0x53, 0x54, 0x46, 0x49, 0x4c, 0x45, 0x2e, 0x54, 0x58, 0x54, 0x09, 0x09, - 0x74, 0x65, 0x73, 0x74, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, 0x09, 0x09, 0x09, 0x32, - 0x38, 0x36, 0x37, 0x32, 0x30, 0x09, 0x09, 0x31, 0x20, 0x31, 0x34, 0x20, 0x31, 0x30, 0x30, 0x30, - 0x20, 0x34, 0x36, 0x30, 0x30, 0x30, 0x20, 0x32, 0x33, 0x30, 0x20, 0x20, 0x34, 0x33, 0x20, 0x31, - 0x20, 0x34, 0x36, 0x30, 0x30, 0x30, 0x20, 0x31, 0x30, 0x30, 0x30, 0x20, 0x33, 0x20, 0x31, 0x20, - 0x32, 0x33, 0x30, 0x20, 0x38, 0x09, 0x31, 0x20, 0x09, 0x34, 0x31, 0x39, 0x34, 0x33, 0x31, 0x32, - 0x09, 0x31, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x0a, 0x32, 0x36, 0x09, - 0x30, 0x0a, 0x41, 0x44, 0x39, 0x39, 0x36, 0x35, 0x46, 0x34, 0x34, 0x36, 0x30, 0x34, 0x33, 0x37, - 0x38, 0x43, 0x39, 0x45, 0x45, 0x30, 0x43, 0x30, 0x30, 0x33, 0x46, 0x44, 0x32, 0x33, 0x31, 0x34, - 0x45, 0x34, 0x09, 0x34, 0x30, 0x39, 0x36, 0x09, 0x31, 0x20, 0x31, 0x35, 0x20, 0x31, 0x30, 0x30, - 0x30, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x38, 0x20, 0x31, 0x62, 0x09, 0x43, 0x39, 0x30, - 0x41, 0x33, 0x41, 0x33, 0x35, 0x46, 0x31, 0x38, 0x35, 0x41, 0x45, 0x43, 0x37, 0x38, 0x41, 0x43, - 0x31, 0x36, 0x46, 0x31, 0x31, 0x34, 0x44, 0x38, 0x36, 0x34, 0x38, 0x41, 0x32, 0x09, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x42, 0x09, 0x31, 0x20, 0x09, 0x09, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x20, 0x42, 0x6f, 0x6f, 0x74, 0x09, 0x09, 0x09, 0x09, 0x09, 0x31, 0x20, 0x31, - 0x30, 0x30, 0x30, 0x20, 0x31, 0x30, 0x30, 0x30, 0x20, 0x20, 0x20, 0x20, 0x35, 0x33, 0x20, 0x31, - 0x20, 0x20, 0x31, 0x30, 0x30, 0x30, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x66, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x20, 0x20, 0x38, 0x09, 0x31, 0x20, 0x09, 0x34, - 0x31, 0x39, 0x34, 0x33, 0x30, 0x34, 0x09, 0x31, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x09, 0x09, 0x0a, 0x32, 0x36, 0x09, 0x30, 0x0a, 0x44, 0x31, 0x46, 0x45, 0x36, 0x45, 0x42, 0x39, - 0x30, 0x33, 0x39, 0x45, 0x38, 0x38, 0x38, 0x44, 0x41, 0x38, 0x35, 0x44, 0x32, 0x30, 0x41, 0x31, - 0x37, 0x33, 0x43, 0x43, 0x31, 0x43, 0x41, 0x42, 0x09, 0x31, 0x33, 0x31, 0x30, 0x37, 0x32, 0x09, - 0x31, 0x20, 0x31, 0x30, 0x31, 0x35, 0x20, 0x32, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x09, 0x09, - 0x09, 0x09, 0x09, 0x38, 0x20, 0x31, 0x62, 0x09, 0x37, 0x46, 0x32, 0x46, 0x31, 0x38, 0x36, 0x38, - 0x43, 0x33, 0x30, 0x30, 0x44, 0x36, 0x35, 0x44, 0x32, 0x31, 0x30, 0x33, 0x34, 0x39, 0x45, 0x33, - 0x46, 0x43, 0x43, 0x46, 0x46, 0x33, 0x35, 0x35, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x09, 0x42, 0x09, 0x31, 0x20, 0x09, 0x09, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x20, - 0x46, 0x41, 0x54, 0x09, 0x09, 0x09, 0x34, 0x30, 0x39, 0x36, 0x09, 0x09, 0x31, 0x20, 0x32, 0x30, - 0x30, 0x30, 0x30, 0x20, 0x32, 0x30, 0x30, 0x30, 0x30, 0x20, 0x31, 0x30, 0x30, 0x30, 0x20, 0x38, - 0x20, 0x20, 0x35, 0x33, 0x20, 0x31, 0x20, 0x31, 0x30, 0x30, 0x30, 0x20, 0x32, 0x30, 0x30, 0x30, - 0x30, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x66, 0x66, 0x66, 0x66, 0x66, - 0x66, 0x66, 0x66, 0x20, 0x38, 0x20, 0x31, 0x30, 0x30, 0x09, 0x31, 0x20, 0x09, 0x34, 0x31, 0x39, - 0x34, 0x33, 0x30, 0x34, 0x09, 0x31, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, - 0x0a, 0x32, 0x36, 0x09, 0x30, 0x0a, 0x35, 0x39, 0x42, 0x42, 0x39, 0x34, 0x30, 0x43, 0x31, 0x39, - 0x38, 0x39, 0x35, 0x44, 0x38, 0x39, 0x42, 0x32, 0x31, 0x34, 0x34, 0x37, 0x42, 0x37, 0x44, 0x35, - 0x38, 0x37, 0x45, 0x37, 0x33, 0x32, 0x09, 0x31, 0x33, 0x31, 0x30, 0x37, 0x32, 0x09, 0x31, 0x20, - 0x32, 0x31, 0x30, 0x31, 0x35, 0x20, 0x31, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x38, 0x20, - 0x31, 0x62, 0x09, 0x37, 0x46, 0x32, 0x46, 0x31, 0x38, 0x36, 0x38, 0x43, 0x33, 0x30, 0x30, 0x44, - 0x36, 0x35, 0x44, 0x32, 0x31, 0x30, 0x33, 0x34, 0x39, 0x45, 0x33, 0x46, 0x43, 0x43, 0x46, 0x46, - 0x33, 0x35, 0x35, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x42, 0x09, 0x31, - 0x20, 0x09, 0x09, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x20, 0x46, 0x41, 0x54, - 0x09, 0x34, 0x31, 0x31, 0x37, 0x09, 0x09, 0x31, 0x33, 0x35, 0x31, 0x36, 0x38, 0x09, 0x09, 0x31, - 0x20, 0x32, 0x30, 0x30, 0x30, 0x30, 0x20, 0x32, 0x30, 0x30, 0x30, 0x30, 0x20, 0x32, 0x31, 0x30, - 0x30, 0x30, 0x20, 0x31, 0x30, 0x38, 0x20, 0x20, 0x35, 0x33, 0x20, 0x31, 0x20, 0x32, 0x31, 0x30, - 0x30, 0x30, 0x20, 0x32, 0x30, 0x30, 0x30, 0x30, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x20, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x20, 0x31, 0x30, 0x38, 0x20, 0x31, - 0x30, 0x30, 0x09, 0x31, 0x20, 0x09, 0x37, 0x31, 0x33, 0x30, 0x33, 0x31, 0x36, 0x38, 0x09, 0x31, - 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x09, 0x0a, 0x32, 0x36, 0x09, 0x30, 0x0a, - 0x37, 0x30, 0x43, 0x37, 0x37, 0x36, 0x33, 0x35, 0x44, 0x32, 0x39, 0x45, 0x45, 0x42, 0x38, 0x32, - 0x38, 0x36, 0x37, 0x39, 0x33, 0x45, 0x38, 0x42, 0x37, 0x45, 0x44, 0x37, 0x36, 0x34, 0x30, 0x36, - 0x09, 0x32, 0x36, 0x31, 0x38, 0x35, 0x37, 0x32, 0x38, 0x30, 0x09, 0x31, 0x20, 0x32, 0x31, 0x30, - 0x31, 0x36, 0x20, 0x66, 0x39, 0x62, 0x61, 0x30, 0x30, 0x30, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, - 0x09, 0x38, 0x20, 0x31, 0x62, 0x09, 0x32, 0x39, 0x39, 0x37, 0x44, 0x44, 0x36, 0x31, 0x39, 0x30, - 0x38, 0x44, 0x33, 0x44, 0x31, 0x38, 0x30, 0x36, 0x37, 0x38, 0x44, 0x33, 0x31, 0x41, 0x44, 0x35, - 0x45, 0x42, 0x34, 0x32, 0x41, 0x38, 0x09, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, - 0x42, 0x09, 0x31, 0x20, 0x09, 0x09, 0x55, 0x6e, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x65, - 0x64, 0x20, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x73, 0x09, 0x09, 0x09, 0x32, 0x38, 0x32, - 0x36, 0x32, 0x34, 0x09, 0x09, 0x31, 0x20, 0x66, 0x39, 0x62, 0x61, 0x30, 0x30, 0x30, 0x20, 0x66, - 0x39, 0x62, 0x61, 0x30, 0x30, 0x30, 0x20, 0x34, 0x35, 0x30, 0x30, 0x30, 0x20, 0x32, 0x32, 0x38, - 0x20, 0x20, 0x34, 0x33, 0x20, 0x32, 0x20, 0x34, 0x35, 0x30, 0x30, 0x30, 0x20, 0x31, 0x30, 0x30, - 0x30, 0x20, 0x32, 0x20, 0x31, 0x20, 0x32, 0x32, 0x38, 0x20, 0x38, 0x20, 0x34, 0x37, 0x30, 0x30, - 0x30, 0x20, 0x66, 0x39, 0x62, 0x39, 0x30, 0x30, 0x30, 0x20, 0x34, 0x20, 0x66, 0x39, 0x62, 0x39, - 0x20, 0x32, 0x33, 0x38, 0x20, 0x37, 0x63, 0x64, 0x63, 0x38, 0x09, 0x31, 0x20, 0x09, 0x36, 0x32, - 0x39, 0x31, 0x34, 0x35, 0x36, 0x09, 0x31, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, - 0x09, 0x0a, 0x0a }; - #if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) /* Tests the libewf_single_files_initialize function @@ -825,6 +645,7 @@ int ewf_test_single_files_clone( libcerror_error_t *error = NULL; libewf_single_files_t *destination_single_files = NULL; libewf_single_files_t *source_single_files = NULL; + libfdata_stream_t *data_stream = NULL; size64_t media_size = 0; uint8_t format = 0; int result = 0; @@ -857,10 +678,29 @@ int ewf_test_single_files_clone( "error", error ); - result = libewf_single_files_read_data( - source_single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_single_files_data1, 5700, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libewf_single_files_read_data_stream( + source_single_files, + data_stream, + NULL, &media_size, &format, &error ); @@ -874,6 +714,23 @@ int ewf_test_single_files_clone( "error", error ); + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); + /* Test regular cases */ result = libewf_single_files_clone( @@ -1095,6 +952,12 @@ int ewf_test_single_files_clone( &destination_single_files, NULL ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( source_single_files != NULL ) { libewf_single_files_free( @@ -1104,197 +967,39 @@ int ewf_test_single_files_clone( return( 0 ); } -/* Tests the libewf_single_files_parse_line function +/* Tests the libewf_single_files_parse_category_number_of_entries function * Returns 1 if successful or 0 if not */ -int ewf_test_single_files_parse_line( - void ) +int ewf_test_single_files_parse_category_number_of_entries( + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - uint8_t *line_string = NULL; - size_t line_string_size = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int number_of_entries = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test regular cases - */ - result = libewf_single_files_parse_line( - lines, - 1, - &line_string, - &line_string_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test error cases - */ - result = libewf_single_files_parse_line( - NULL, - 1, - &line_string, - &line_string_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - result = libewf_single_files_parse_line( - lines, - -1, + result = libewf_line_reader_read_line( + line_reader, &line_string, &line_string_size, &error ); - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - result = libewf_single_files_parse_line( - lines, - 1, - NULL, - &line_string_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - result = libewf_single_files_parse_line( - lines, - 1, - &line_string, - NULL, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - /* Clean up - */ - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - - return( 1 ); - -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - return( 0 ); -} - -/* Tests the libewf_single_files_parse_category_number_of_entries function - * Returns 1 if successful or 0 if not - */ -int ewf_test_single_files_parse_category_number_of_entries( - void ) -{ - libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - int line_index = 0; - int number_of_entries = 0; - int result = 0; - - /* Initialize test - */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - EWF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -1302,13 +1007,15 @@ int ewf_test_single_files_parse_category_number_of_entries( /* Test regular cases */ - line_index = 6; + line_reader->buffer_offset = 0x140; + line_reader->line_index = 6; result = libewf_single_files_parse_category_number_of_entries( - lines, - &line_index, + single_files, + line_reader, &number_of_entries, &error ); +EWF_TEST_FPRINT_ERROR( error ); EWF_TEST_ASSERT_EQUAL_INT( "result", @@ -1321,11 +1028,12 @@ int ewf_test_single_files_parse_category_number_of_entries( /* Test error cases */ - line_index = 6; + line_reader->buffer_offset = 0x140; + line_reader->line_index = 6; result = libewf_single_files_parse_category_number_of_entries( NULL, - &line_index, + line_reader, &number_of_entries, &error ); @@ -1342,7 +1050,7 @@ int ewf_test_single_files_parse_category_number_of_entries( &error ); result = libewf_single_files_parse_category_number_of_entries( - lines, + single_files, NULL, &number_of_entries, &error ); @@ -1360,8 +1068,8 @@ int ewf_test_single_files_parse_category_number_of_entries( &error ); result = libewf_single_files_parse_category_number_of_entries( - lines, - &line_index, + single_files, + line_reader, NULL, &error ); @@ -1377,21 +1085,6 @@ int ewf_test_single_files_parse_category_number_of_entries( libcerror_error_free( &error ); - /* Clean up - */ - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -1400,12 +1093,6 @@ int ewf_test_single_files_parse_category_number_of_entries( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } return( 0 ); } @@ -1413,21 +1100,25 @@ int ewf_test_single_files_parse_category_number_of_entries( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_category_types( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; libfvalue_split_utf8_string_t *types = NULL; - int line_index = 0; + uint8_t *line_string = NULL; + size_t line_string_size = 0; int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; + + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -1436,8 +1127,8 @@ int ewf_test_single_files_parse_category_types( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -1445,11 +1136,12 @@ int ewf_test_single_files_parse_category_types( /* Test regular cases */ - line_index = 7; + line_reader->buffer_offset = 0x148; + line_reader->line_index = 7; result = libewf_single_files_parse_category_types( - lines, - &line_index, + single_files, + line_reader, &types, &error ); @@ -1479,11 +1171,12 @@ int ewf_test_single_files_parse_category_types( /* Test error cases */ - line_index = 7; + line_reader->buffer_offset = 0x148; + line_reader->line_index = 7; result = libewf_single_files_parse_category_types( NULL, - &line_index, + line_reader, &types, &error ); @@ -1500,7 +1193,7 @@ int ewf_test_single_files_parse_category_types( &error ); result = libewf_single_files_parse_category_types( - lines, + single_files, NULL, &types, &error ); @@ -1518,8 +1211,8 @@ int ewf_test_single_files_parse_category_types( &error ); result = libewf_single_files_parse_category_types( - lines, - &line_index, + single_files, + line_reader, NULL, &error ); @@ -1535,21 +1228,6 @@ int ewf_test_single_files_parse_category_types( libcerror_error_free( &error ); - /* Clean up - */ - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -1564,12 +1242,6 @@ int ewf_test_single_files_parse_category_types( &types, NULL ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } return( 0 ); } @@ -1577,21 +1249,25 @@ int ewf_test_single_files_parse_category_types( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_number_of_entries( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - int line_index = 0; - int number_of_entries = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int number_of_entries = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; + + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -1600,8 +1276,8 @@ int ewf_test_single_files_parse_number_of_entries( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -1609,11 +1285,12 @@ int ewf_test_single_files_parse_number_of_entries( /* Test regular cases */ - line_index = 8; + line_reader->buffer_offset = 0x16a; + line_reader->line_index = 8; result = libewf_single_files_parse_number_of_entries( - lines, - &line_index, + single_files, + line_reader, &number_of_entries, &error ); @@ -1628,11 +1305,12 @@ int ewf_test_single_files_parse_number_of_entries( /* Test error cases */ - line_index = 8; + line_reader->buffer_offset = 0x16a; + line_reader->line_index = 8; result = libewf_single_files_parse_number_of_entries( NULL, - &line_index, + line_reader, &number_of_entries, &error ); @@ -1649,7 +1327,7 @@ int ewf_test_single_files_parse_number_of_entries( &error ); result = libewf_single_files_parse_number_of_entries( - lines, + single_files, NULL, &number_of_entries, &error ); @@ -1667,8 +1345,8 @@ int ewf_test_single_files_parse_number_of_entries( &error ); result = libewf_single_files_parse_number_of_entries( - lines, - &line_index, + single_files, + line_reader, NULL, &error ); @@ -1684,21 +1362,6 @@ int ewf_test_single_files_parse_number_of_entries( libcerror_error_free( &error ); - /* Clean up - */ - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -1707,12 +1370,6 @@ int ewf_test_single_files_parse_number_of_entries( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } return( 0 ); } @@ -1720,22 +1377,26 @@ int ewf_test_single_files_parse_number_of_entries( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_format( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; libfvalue_split_utf8_string_t *types = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; uint8_t format = 0; - int line_index = 0; int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; + + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -1744,18 +1405,19 @@ int ewf_test_single_files_parse_format( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", error ); - line_index = 7; + line_reader->buffer_offset = 0x148; + line_reader->line_index = 7; result = libewf_single_files_parse_category_types( - lines, - &line_index, + single_files, + line_reader, &types, &error ); @@ -1835,20 +1497,7 @@ int ewf_test_single_files_parse_format( "types", types ); - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - - return( 1 ); + return( 1 ); on_error: if( error != NULL ) @@ -1862,12 +1511,6 @@ int ewf_test_single_files_parse_format( &types, NULL ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } return( 0 ); } @@ -1875,39 +1518,25 @@ int ewf_test_single_files_parse_format( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_rec_category( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - size64_t media_size = 0; - int line_index = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size64_t media_size = 0; + size_t line_string_size = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libewf_single_files_initialize( - &single_files, + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -1916,8 +1545,8 @@ int ewf_test_single_files_parse_rec_category( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -1925,12 +1554,12 @@ int ewf_test_single_files_parse_rec_category( /* Test regular cases */ - line_index = 1; + line_reader->buffer_offset = 0x4; + line_reader->line_index = 1; result = libewf_single_files_parse_rec_category( single_files, - lines, - &line_index, + line_reader, &media_size, &error ); @@ -1945,31 +1574,12 @@ int ewf_test_single_files_parse_rec_category( /* Test error cases */ - line_index = 1; - - result = libewf_single_files_parse_rec_category( - NULL, - lines, - &line_index, - &media_size, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); + line_reader->buffer_offset = 0x4; + line_reader->line_index = 1; result = libewf_single_files_parse_rec_category( - single_files, NULL, - &line_index, + line_reader, &media_size, &error ); @@ -1987,7 +1597,6 @@ int ewf_test_single_files_parse_rec_category( result = libewf_single_files_parse_rec_category( single_files, - lines, NULL, &media_size, &error ); @@ -2006,8 +1615,7 @@ int ewf_test_single_files_parse_rec_category( result = libewf_single_files_parse_rec_category( single_files, - lines, - &line_index, + line_reader, NULL, &error ); @@ -2025,12 +1633,12 @@ int ewf_test_single_files_parse_rec_category( /* Test unsupported category header */ - line_index = 5; + line_reader->buffer_offset = 0x136; + line_reader->line_index = 5; result = libewf_single_files_parse_rec_category( single_files, - lines, - &line_index, + line_reader, &media_size, &error ); @@ -2046,38 +1654,6 @@ int ewf_test_single_files_parse_rec_category( libcerror_error_free( &error ); - /* Clean up - */ - result = libewf_single_files_free( - &single_files, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "single_files", - single_files ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -2086,18 +1662,6 @@ int ewf_test_single_files_parse_rec_category( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - if( single_files != NULL ) - { - libewf_single_files_free( - &single_files, - NULL ); - } return( 0 ); } @@ -2105,21 +1669,25 @@ int ewf_test_single_files_parse_rec_category( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_record_values( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - size64_t media_size = 0; - int line_index = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size64_t media_size = 0; + size_t line_string_size = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; + + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2128,8 +1696,8 @@ int ewf_test_single_files_parse_record_values( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -2137,11 +1705,12 @@ int ewf_test_single_files_parse_record_values( /* Test regular cases */ - line_index = 2; + line_reader->buffer_offset = 0xc; + line_reader->line_index = 2; result = libewf_single_files_parse_record_values( - lines, - &line_index, + single_files, + line_reader, &media_size, &error ); @@ -2156,11 +1725,12 @@ int ewf_test_single_files_parse_record_values( /* Test error cases */ - line_index = 2; + line_reader->buffer_offset = 0xc; + line_reader->line_index = 2; result = libewf_single_files_parse_record_values( NULL, - &line_index, + line_reader, &media_size, &error ); @@ -2177,7 +1747,7 @@ int ewf_test_single_files_parse_record_values( &error ); result = libewf_single_files_parse_record_values( - lines, + single_files, NULL, &media_size, &error ); @@ -2195,8 +1765,8 @@ int ewf_test_single_files_parse_record_values( &error ); result = libewf_single_files_parse_record_values( - lines, - &line_index, + single_files, + line_reader, NULL, &error ); @@ -2212,21 +1782,6 @@ int ewf_test_single_files_parse_record_values( libcerror_error_free( &error ); - /* Clean up - */ - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -2235,12 +1790,6 @@ int ewf_test_single_files_parse_record_values( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } return( 0 ); } @@ -2248,38 +1797,24 @@ int ewf_test_single_files_parse_record_values( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_perm_category( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - int line_index = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - result = libewf_single_files_initialize( - &single_files, + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2288,8 +1823,8 @@ int ewf_test_single_files_parse_perm_category( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -2297,12 +1832,12 @@ int ewf_test_single_files_parse_perm_category( /* Test regular cases */ - line_index = 5; + line_reader->buffer_offset = 0x136; + line_reader->line_index = 5; result = libewf_single_files_parse_perm_category( single_files, - lines, - &line_index, + line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2316,30 +1851,12 @@ int ewf_test_single_files_parse_perm_category( /* Test error cases */ - line_index = 5; - - result = libewf_single_files_parse_perm_category( - NULL, - lines, - &line_index, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); + line_reader->buffer_offset = 0x136; + line_reader->line_index = 5; result = libewf_single_files_parse_perm_category( - single_files, NULL, - &line_index, + line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2356,7 +1873,6 @@ int ewf_test_single_files_parse_perm_category( result = libewf_single_files_parse_perm_category( single_files, - lines, NULL, &error ); @@ -2372,38 +1888,6 @@ int ewf_test_single_files_parse_perm_category( libcerror_error_free( &error ); - /* Clean up - */ - result = libewf_single_files_free( - &single_files, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "single_files", - single_files ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -2412,18 +1896,6 @@ int ewf_test_single_files_parse_perm_category( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - if( single_files != NULL ) - { - libewf_single_files_free( - &single_files, - NULL ); - } return( 0 ); } @@ -2431,40 +1903,26 @@ int ewf_test_single_files_parse_perm_category( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_permission_group( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { libcerror_error_t *error = NULL; libewf_permission_group_t *permission_group = NULL; - libewf_single_files_t *single_files = NULL; - libfvalue_split_utf8_string_t *lines = NULL; libfvalue_split_utf8_string_t *types = NULL; - int line_index = 0; + uint8_t *line_string = NULL; + size_t line_string_size = 0; int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - result = libewf_single_files_initialize( - &single_files, + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2473,8 +1931,8 @@ int ewf_test_single_files_parse_permission_group( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -2486,13 +1944,13 @@ int ewf_test_single_files_parse_permission_group( /* Test error cases */ - line_index = 7; + line_reader->buffer_offset = 0x148; + line_reader->line_index = 7; result = libewf_single_files_parse_permission_group( single_files, - lines, + line_reader, types, - &line_index, permission_group, &error ); @@ -2510,9 +1968,8 @@ int ewf_test_single_files_parse_permission_group( result = libewf_single_files_parse_permission_group( NULL, - lines, + line_reader, types, - NULL, permission_group, &error ); @@ -2528,57 +1985,70 @@ int ewf_test_single_files_parse_permission_group( libcerror_error_free( &error ); - /* Clean up - */ - result = libewf_single_files_free( - &single_files, + result = libewf_single_files_parse_permission_group( + single_files, + NULL, + types, + permission_group, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "single_files", - single_files ); + -1 ); - EWF_TEST_ASSERT_IS_NULL( + EWF_TEST_ASSERT_IS_NOT_NULL( "error", error ); - result = libfvalue_split_utf8_string_free( - &lines, + libcerror_error_free( + &error ); + + result = libewf_single_files_parse_permission_group( + single_files, + line_reader, + NULL, + permission_group, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - 1 ); + -1 ); - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); - return( 1 ); + libcerror_error_free( + &error ); -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - if( single_files != NULL ) + result = libewf_single_files_parse_permission_group( + single_files, + line_reader, + types, + NULL, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EWF_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) { - libewf_single_files_free( - &single_files, - NULL ); + libcerror_error_free( + &error ); } return( 0 ); } @@ -2587,38 +2057,24 @@ int ewf_test_single_files_parse_permission_group( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_srce_category( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - int line_index = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - result = libewf_single_files_initialize( - &single_files, + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2627,8 +2083,8 @@ int ewf_test_single_files_parse_srce_category( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -2636,12 +2092,12 @@ int ewf_test_single_files_parse_srce_category( /* Test regular cases */ - line_index = 13; + line_reader->buffer_offset = 0x1a0; + line_reader->line_index = 13; result = libewf_single_files_parse_srce_category( single_files, - lines, - &line_index, + line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2655,30 +2111,12 @@ int ewf_test_single_files_parse_srce_category( /* Test error cases */ - line_index = 13; - - result = libewf_single_files_parse_srce_category( - NULL, - lines, - &line_index, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); + line_reader->buffer_offset = 0x1a0; + line_reader->line_index = 13; result = libewf_single_files_parse_srce_category( - single_files, NULL, - &line_index, + line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2695,7 +2133,6 @@ int ewf_test_single_files_parse_srce_category( result = libewf_single_files_parse_srce_category( single_files, - lines, NULL, &error ); @@ -2711,38 +2148,6 @@ int ewf_test_single_files_parse_srce_category( libcerror_error_free( &error ); - /* Clean up - */ - result = libewf_single_files_free( - &single_files, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "single_files", - single_files ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -2751,18 +2156,6 @@ int ewf_test_single_files_parse_srce_category( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - if( single_files != NULL ) - { - libewf_single_files_free( - &single_files, - NULL ); - } return( 0 ); } @@ -2770,38 +2163,24 @@ int ewf_test_single_files_parse_srce_category( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_sub_category( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - int line_index = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - result = libewf_single_files_initialize( - &single_files, + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2810,8 +2189,8 @@ int ewf_test_single_files_parse_sub_category( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -2819,12 +2198,12 @@ int ewf_test_single_files_parse_sub_category( /* Test regular cases */ - line_index = 21; + line_reader->buffer_offset = 0x52e; + line_reader->line_index = 21; result = libewf_single_files_parse_sub_category( single_files, - lines, - &line_index, + line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2838,30 +2217,12 @@ int ewf_test_single_files_parse_sub_category( /* Test error cases */ - line_index = 21; - - result = libewf_single_files_parse_sub_category( - NULL, - lines, - &line_index, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); + line_reader->buffer_offset = 0x52e; + line_reader->line_index = 21; result = libewf_single_files_parse_sub_category( - single_files, NULL, - &line_index, + line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2878,7 +2239,6 @@ int ewf_test_single_files_parse_sub_category( result = libewf_single_files_parse_sub_category( single_files, - lines, NULL, &error ); @@ -2894,38 +2254,6 @@ int ewf_test_single_files_parse_sub_category( libcerror_error_free( &error ); - /* Clean up - */ - result = libewf_single_files_free( - &single_files, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "single_files", - single_files ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -2934,18 +2262,6 @@ int ewf_test_single_files_parse_sub_category( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - if( single_files != NULL ) - { - libewf_single_files_free( - &single_files, - NULL ); - } return( 0 ); } @@ -2953,39 +2269,25 @@ int ewf_test_single_files_parse_sub_category( * Returns 1 if successful or 0 if not */ int ewf_test_single_files_parse_entry_category( - void ) + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) { - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - uint8_t format = 0; - int line_index = 0; - int result = 0; + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + uint8_t format = 0; + int result = 0; /* Initialize test */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; - result = libewf_single_files_initialize( - &single_files, + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -2994,8 +2296,8 @@ int ewf_test_single_files_parse_entry_category( 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); + "line_string", + line_string ); EWF_TEST_ASSERT_IS_NULL( "error", @@ -3003,12 +2305,12 @@ int ewf_test_single_files_parse_entry_category( /* Test regular cases */ - line_index = 27; + line_reader->buffer_offset = 0x5b8; + line_reader->line_index = 27; result = libewf_single_files_parse_entry_category( single_files, - lines, - &line_index, + line_reader, &format, &error ); @@ -3023,12 +2325,12 @@ int ewf_test_single_files_parse_entry_category( /* Test error cases */ - line_index = 27; + line_reader->buffer_offset = 0x5b8; + line_reader->line_index = 27; result = libewf_single_files_parse_entry_category( NULL, - lines, - &line_index, + line_reader, &format, &error ); @@ -3047,7 +2349,6 @@ int ewf_test_single_files_parse_entry_category( result = libewf_single_files_parse_entry_category( single_files, NULL, - &line_index, &format, &error ); @@ -3065,9 +2366,8 @@ int ewf_test_single_files_parse_entry_category( result = libewf_single_files_parse_entry_category( single_files, - lines, + line_reader, NULL, - &format, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3082,122 +2382,64 @@ int ewf_test_single_files_parse_entry_category( libcerror_error_free( &error ); - result = libewf_single_files_parse_entry_category( - single_files, - lines, - &line_index, - NULL, + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the libewf_single_files_parse_file_entry_number_of_sub_entries function + * Returns 1 if successful or 0 if not + */ +int ewf_test_single_files_parse_file_entry_number_of_sub_entries( + libewf_single_files_t *single_files, + libewf_line_reader_t *line_reader ) +{ + libcerror_error_t *error = NULL; + uint8_t *line_string = NULL; + size_t line_string_size = 0; + int number_of_sub_entries = 0; + int result = 0; + + /* Initialize test + */ + line_reader->stream_offset = 0; + line_reader->buffer_offset = 0; + line_reader->line_index = 0; + + result = libewf_line_reader_read_line( + line_reader, + &line_string, + &line_string_size, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( + "line_string", + line_string ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); - - /* Clean up + /* Test regular cases */ - result = libewf_single_files_free( - &single_files, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "single_files", - single_files ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - - return( 1 ); - -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } - if( single_files != NULL ) - { - libewf_single_files_free( - &single_files, - NULL ); - } - return( 0 ); -} - -/* Tests the libewf_single_files_parse_file_entry_number_of_sub_entries function - * Returns 1 if successful or 0 if not - */ -int ewf_test_single_files_parse_file_entry_number_of_sub_entries( - void ) -{ - libcerror_error_t *error = NULL; - libfvalue_split_utf8_string_t *lines = NULL; - int line_index = 0; - int number_of_sub_entries = 0; - int result = 0; - - /* Initialize test - */ - result = libfvalue_utf8_string_split( - ewf_test_single_files_data2, - 2851, - (uint8_t) '\n', - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "lines", - lines ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test regular cases - */ - line_index = 36; - - result = libewf_single_files_parse_file_entry_number_of_sub_entries( - lines, - &line_index, - &number_of_sub_entries, + line_reader->buffer_offset = 0xcb8; + line_reader->line_index = 36; + + result = libewf_single_files_parse_file_entry_number_of_sub_entries( + single_files, + line_reader, + &number_of_sub_entries, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3211,11 +2453,12 @@ int ewf_test_single_files_parse_file_entry_number_of_sub_entries( /* Test error cases */ - line_index = 36; + line_reader->buffer_offset = 0xcb8; + line_reader->line_index = 36; result = libewf_single_files_parse_file_entry_number_of_sub_entries( NULL, - &line_index, + line_reader, &number_of_sub_entries, &error ); @@ -3232,7 +2475,7 @@ int ewf_test_single_files_parse_file_entry_number_of_sub_entries( &error ); result = libewf_single_files_parse_file_entry_number_of_sub_entries( - lines, + single_files, NULL, &number_of_sub_entries, &error ); @@ -3250,8 +2493,8 @@ int ewf_test_single_files_parse_file_entry_number_of_sub_entries( &error ); result = libewf_single_files_parse_file_entry_number_of_sub_entries( - lines, - &line_index, + single_files, + line_reader, NULL, &error ); @@ -3267,21 +2510,6 @@ int ewf_test_single_files_parse_file_entry_number_of_sub_entries( libcerror_error_free( &error ); - /* Clean up - */ - result = libfvalue_split_utf8_string_free( - &lines, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NULL( - "lines", - lines ); - return( 1 ); on_error: @@ -3290,23 +2518,18 @@ int ewf_test_single_files_parse_file_entry_number_of_sub_entries( libcerror_error_free( &error ); } - if( lines != NULL ) - { - libfvalue_split_utf8_string_free( - &lines, - NULL ); - } return( 0 ); } -/* Tests the libewf_single_files_parse_utf8_string function +/* Tests the libewf_single_files_read_data_stream function * Returns 1 if successful or 0 if not */ -int ewf_test_single_files_parse_utf8_string( +int ewf_test_single_files_read_data_stream( void ) { libcerror_error_t *error = NULL; libewf_single_files_t *single_files = NULL; + libfdata_stream_t *data_stream = NULL; size64_t media_size = 0; uint8_t format = 0; int result = 0; @@ -3330,14 +2553,10 @@ int ewf_test_single_files_parse_utf8_string( "error", error ); - /* Test regular cases - */ - result = libewf_single_files_parse_utf8_string( - single_files, - ewf_test_single_files_data2, - 2851, - &media_size, - &format, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, + ewf_test_single_files_data1, + 5700, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3345,16 +2564,20 @@ int ewf_test_single_files_parse_utf8_string( result, 1 ); + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + EWF_TEST_ASSERT_IS_NULL( "error", error ); - /* Test error cases + /* Test regular cases */ - result = libewf_single_files_parse_utf8_string( + result = libewf_single_files_read_data_stream( + single_files, + data_stream, NULL, - ewf_test_single_files_data2, - 2851, &media_size, &format, &error ); @@ -3362,19 +2585,18 @@ int ewf_test_single_files_parse_utf8_string( EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); - EWF_TEST_ASSERT_IS_NOT_NULL( + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); - - result = libewf_single_files_parse_utf8_string( - single_files, + /* Test error cases + */ + result = libewf_single_files_read_data_stream( + NULL, + data_stream, NULL, - 2851, &media_size, &format, &error ); @@ -3391,10 +2613,10 @@ int ewf_test_single_files_parse_utf8_string( libcerror_error_free( &error ); - result = libewf_single_files_parse_utf8_string( + result = libewf_single_files_read_data_stream( single_files, - ewf_test_single_files_data2, - (size_t) SSIZE_MAX + 1, + NULL, + NULL, &media_size, &format, &error ); @@ -3411,11 +2633,11 @@ int ewf_test_single_files_parse_utf8_string( libcerror_error_free( &error ); - result = libewf_single_files_parse_utf8_string( + result = libewf_single_files_read_data_stream( single_files, - ewf_test_single_files_data2, - 0, - &media_size, + data_stream, + NULL, + NULL, &format, &error ); @@ -3431,12 +2653,12 @@ int ewf_test_single_files_parse_utf8_string( libcerror_error_free( &error ); - result = libewf_single_files_parse_utf8_string( + result = libewf_single_files_read_data_stream( single_files, - ewf_test_single_files_data2, - 2851, + data_stream, + NULL, + &media_size, NULL, - &format, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3451,28 +2673,25 @@ int ewf_test_single_files_parse_utf8_string( libcerror_error_free( &error ); - result = libewf_single_files_parse_utf8_string( - single_files, - ewf_test_single_files_data2, - 2851, - &media_size, - NULL, + /* Clean up + */ + result = libfdata_stream_free( + &data_stream, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); - EWF_TEST_ASSERT_IS_NOT_NULL( + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); - - /* Clean up - */ result = libewf_single_files_free( &single_files, &error ); @@ -3498,6 +2717,12 @@ int ewf_test_single_files_parse_utf8_string( libcerror_error_free( &error ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( single_files != NULL ) { libewf_single_files_free( @@ -3507,45 +2732,21 @@ int ewf_test_single_files_parse_utf8_string( return( 0 ); } -/* Tests the libewf_single_files_read_data function +/* Tests the libewf_single_files_get_file_entry_tree_root_node function * Returns 1 if successful or 0 if not */ -int ewf_test_single_files_read_data( - void ) +int ewf_test_single_files_get_file_entry_tree_root_node( + libewf_single_files_t *single_files ) { - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - size64_t media_size = 0; - uint8_t format = 0; - int result = 0; - - /* Initialize test - */ - result = libewf_single_files_initialize( - &single_files, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "single_files", - single_files ); - - EWF_TEST_ASSERT_IS_NULL( - "error", - error ); + libcdata_tree_node_t *root_node = NULL; + libcerror_error_t *error = NULL; + int result = 0; /* Test regular cases */ - result = libewf_single_files_read_data( + result = libewf_single_files_get_file_entry_tree_root_node( single_files, - ewf_test_single_files_data1, - 5700, - &media_size, - &format, + &root_node, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3553,18 +2754,19 @@ int ewf_test_single_files_read_data( result, 1 ); + EWF_TEST_ASSERT_IS_NOT_NULL( + "root_node", + root_node ); + EWF_TEST_ASSERT_IS_NULL( "error", error ); /* Test error cases */ - result = libewf_single_files_read_data( + result = libewf_single_files_get_file_entry_tree_root_node( NULL, - ewf_test_single_files_data1, - 5700, - &media_size, - &format, + &root_node, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3579,12 +2781,9 @@ int ewf_test_single_files_read_data( libcerror_error_free( &error ); - result = libewf_single_files_read_data( + result = libewf_single_files_get_file_entry_tree_root_node( single_files, NULL, - 5700, - &media_size, - &format, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3599,88 +2798,231 @@ int ewf_test_single_files_read_data( libcerror_error_free( &error ); - result = libewf_single_files_read_data( - single_files, - ewf_test_single_files_data1, - (size_t) SSIZE_MAX + 1, - &media_size, - &format, + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EWF_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) +#endif +{ +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + + libcerror_error_t *error = NULL; + libewf_line_reader_t *line_reader = NULL; + libewf_single_files_t *single_files = NULL; + libfdata_stream_t *data_stream = NULL; + size64_t media_size = 0; + uint8_t format = 0; + int result = 0; + +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + + EWF_TEST_UNREFERENCED_PARAMETER( argc ) + EWF_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) + + EWF_TEST_RUN( + "libewf_single_files_initialize", + ewf_test_single_files_initialize ); + + EWF_TEST_RUN( + "libewf_single_files_free", + ewf_test_single_files_free ); + + EWF_TEST_RUN( + "libewf_single_files_clone", + ewf_test_single_files_clone ); + +#if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) + + /* Initialize single_files for tests + */ + result = libewf_single_files_initialize( + &single_files, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( + "single_files", + single_files ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); - - result = libewf_single_files_read_data( - single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_single_files_data1, - 0, - &media_size, - &format, + 5700, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); - - result = libewf_single_files_read_data( - single_files, - ewf_test_single_files_data1, - 5700, + result = libewf_line_reader_initialize( + &line_reader, + data_stream, NULL, - &format, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); EWF_TEST_ASSERT_IS_NOT_NULL( + "line_reader", + line_reader ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); + /* Run tests + */ + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_category_number_of_entries", + ewf_test_single_files_parse_category_number_of_entries, + single_files, + line_reader ); - result = libewf_single_files_read_data( - single_files, - ewf_test_single_files_data1, - 5700, - &media_size, - NULL, + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_category_types", + ewf_test_single_files_parse_category_types, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_number_of_entries", + ewf_test_single_files_parse_number_of_entries, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_format", + ewf_test_single_files_parse_format, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_rec_category", + ewf_test_single_files_parse_rec_category, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_record_values", + ewf_test_single_files_parse_record_values, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_perm_category", + ewf_test_single_files_parse_perm_category, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_permission_group", + ewf_test_single_files_parse_permission_group, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_srce_category", + ewf_test_single_files_parse_srce_category, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_sub_category", + ewf_test_single_files_parse_sub_category, + single_files, + line_reader ); + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_entry_category", + ewf_test_single_files_parse_entry_category, + single_files, + line_reader ); + + /* TODO: add tests for libewf_single_files_parse_file_entry */ + + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_parse_file_entry_number_of_sub_entries", + ewf_test_single_files_parse_file_entry_number_of_sub_entries, + single_files, + line_reader ); + + /* Clean up + */ + result = libewf_line_reader_free( + &line_reader, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); - EWF_TEST_ASSERT_IS_NOT_NULL( + EWF_TEST_ASSERT_IS_NULL( + "line_reader", + line_reader ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); + result = libfdata_stream_free( + &data_stream, + &error ); + + EWF_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( + "error", + error ); - /* Clean up - */ result = libewf_single_files_free( &single_files, &error ); @@ -3698,37 +3040,15 @@ int ewf_test_single_files_read_data( "error", error ); - return( 1 ); +#endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */ -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( single_files != NULL ) - { - libewf_single_files_free( - &single_files, - NULL ); - } - return( 0 ); -} + EWF_TEST_RUN( + "libewf_single_files_read_data_stream", + ewf_test_single_files_read_data_stream ); -/* Tests the libewf_single_files_get_file_entry_tree_root_node function - * Returns 1 if successful or 0 if not - */ -int ewf_test_single_files_get_file_entry_tree_root_node( - void ) -{ - libcdata_tree_node_t *root_node = NULL; - libcerror_error_t *error = NULL; - libewf_single_files_t *single_files = NULL; - size64_t media_size = 0; - uint8_t format = 0; - int result = 0; +#if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) - /* Initialize test + /* Initialize single_files for tests */ result = libewf_single_files_initialize( &single_files, @@ -3747,12 +3067,10 @@ int ewf_test_single_files_get_file_entry_tree_root_node( "error", error ); - result = libewf_single_files_read_data( - single_files, + result = libewf_data_stream_initialize_from_buffer( + &data_stream, ewf_test_single_files_data1, 5700, - &media_size, - &format, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3760,15 +3078,20 @@ int ewf_test_single_files_get_file_entry_tree_root_node( result, 1 ); + EWF_TEST_ASSERT_IS_NOT_NULL( + "data_stream", + data_stream ); + EWF_TEST_ASSERT_IS_NULL( "error", error ); - /* Test regular cases - */ - result = libewf_single_files_get_file_entry_tree_root_node( + result = libewf_single_files_read_data_stream( single_files, - &root_node, + data_stream, + NULL, + &media_size, + &format, &error ); EWF_TEST_ASSERT_EQUAL_INT( @@ -3776,52 +3099,38 @@ int ewf_test_single_files_get_file_entry_tree_root_node( result, 1 ); - EWF_TEST_ASSERT_IS_NOT_NULL( - "root_node", - root_node ); - EWF_TEST_ASSERT_IS_NULL( "error", error ); - /* Test error cases + /* Run tests */ - result = libewf_single_files_get_file_entry_tree_root_node( - NULL, - &root_node, - &error ); - - EWF_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - EWF_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); + EWF_TEST_RUN_WITH_ARGS( + "libewf_single_files_get_file_entry_tree_root_node", + ewf_test_single_files_get_file_entry_tree_root_node, + single_files ); - libcerror_error_free( - &error ); + /* TODO: add tests for libewf_single_files_get_source_by_index */ - result = libewf_single_files_get_file_entry_tree_root_node( - single_files, - NULL, + /* Clean up + */ + result = libfdata_stream_free( + &data_stream, &error ); EWF_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); - EWF_TEST_ASSERT_IS_NOT_NULL( + EWF_TEST_ASSERT_IS_NULL( + "data_stream", + data_stream ); + + EWF_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); - - /* Clean up - */ result = libewf_single_files_free( &single_files, &error ); @@ -3839,129 +3148,30 @@ int ewf_test_single_files_get_file_entry_tree_root_node( "error", error ); - return( 1 ); +#endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */ +#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ + return( EXIT_SUCCESS ); + +#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) on_error: if( error != NULL ) { libcerror_error_free( &error ); } + if( data_stream != NULL ) + { + libfdata_stream_free( + &data_stream, + NULL ); + } if( single_files != NULL ) { libewf_single_files_free( &single_files, NULL ); } - return( 0 ); -} - -#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ - -/* The main program - */ -#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) -int wmain( - int argc EWF_TEST_ATTRIBUTE_UNUSED, - wchar_t * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) -#else -int main( - int argc EWF_TEST_ATTRIBUTE_UNUSED, - char * const argv[] EWF_TEST_ATTRIBUTE_UNUSED ) -#endif -{ - EWF_TEST_UNREFERENCED_PARAMETER( argc ) - EWF_TEST_UNREFERENCED_PARAMETER( argv ) - -#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) - - EWF_TEST_RUN( - "libewf_single_files_initialize", - ewf_test_single_files_initialize ); - - EWF_TEST_RUN( - "libewf_single_files_free", - ewf_test_single_files_free ); - - EWF_TEST_RUN( - "libewf_single_files_clone", - ewf_test_single_files_clone ); - - EWF_TEST_RUN( - "libewf_single_files_parse_line", - ewf_test_single_files_parse_line ); - - EWF_TEST_RUN( - "libewf_single_files_parse_category_number_of_entries", - ewf_test_single_files_parse_category_number_of_entries ); - - EWF_TEST_RUN( - "libewf_single_files_parse_category_types", - ewf_test_single_files_parse_category_types ); - - EWF_TEST_RUN( - "libewf_single_files_parse_number_of_entries", - ewf_test_single_files_parse_number_of_entries ); - - EWF_TEST_RUN( - "libewf_single_files_parse_format", - ewf_test_single_files_parse_format ); - - EWF_TEST_RUN( - "libewf_single_files_parse_rec_category", - ewf_test_single_files_parse_rec_category ); - - EWF_TEST_RUN( - "libewf_single_files_parse_record_values", - ewf_test_single_files_parse_record_values ); - - EWF_TEST_RUN( - "libewf_single_files_parse_perm_category", - ewf_test_single_files_parse_perm_category ); - - EWF_TEST_RUN( - "libewf_single_files_parse_permission_group", - ewf_test_single_files_parse_permission_group ); - - EWF_TEST_RUN( - "libewf_single_files_parse_srce_category", - ewf_test_single_files_parse_srce_category ); - - EWF_TEST_RUN( - "libewf_single_files_parse_sub_category", - ewf_test_single_files_parse_sub_category ); - - EWF_TEST_RUN( - "libewf_single_files_parse_entry_category", - ewf_test_single_files_parse_entry_category ); - - /* TODO: add tests for libewf_single_files_parse_file_entry */ - - EWF_TEST_RUN( - "libewf_single_files_parse_file_entry_number_of_sub_entries", - ewf_test_single_files_parse_file_entry_number_of_sub_entries ); - - EWF_TEST_RUN( - "libewf_single_files_parse_utf8_string", - ewf_test_single_files_parse_utf8_string ); - - EWF_TEST_RUN( - "libewf_single_files_read_data", - ewf_test_single_files_read_data ); - - EWF_TEST_RUN( - "libewf_single_files_get_file_entry_tree_root_node", - ewf_test_single_files_get_file_entry_tree_root_node ); - - /* TODO: add tests for libewf_single_files_get_source_by_index */ - -#endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ - - return( EXIT_SUCCESS ); - -#if defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) - -on_error: return( EXIT_FAILURE ); #endif /* defined( __GNUC__ ) && !defined( LIBEWF_DLL_IMPORT ) */ diff --git a/tests/test_library.ps1 b/tests/test_library.ps1 index 9694234c5..73612fb23 100644 --- a/tests/test_library.ps1 +++ b/tests/test_library.ps1 @@ -6,7 +6,7 @@ $ExitSuccess = 0 $ExitFailure = 1 $ExitIgnore = 77 -$LibraryTests = "access_control_entry analytical_data attribute bit_stream case_data case_data_section checksum chunk_data chunk_descriptor chunk_group chunk_table compression data_chunk date_time date_time_values deflate device_information device_information_section digest_section error error2_section file_entry filename hash_sections hash_values header_sections header_values huffman_tree io_handle lef_extended_attribute lef_file_entry lef_permission lef_source lef_subject ltree_section md5_hash_section media_values notify permission_group read_io_handle restart_data section_descriptor sector_range sector_range_list segment_file segment_table serialized_string session_section sha1_hash_section single_file_tree single_files source table_section value_table volume_section write_io_handle" +$LibraryTests = "access_control_entry analytical_data attribute bit_stream buffer_data_handle case_data case_data_section checksum chunk_data chunk_descriptor chunk_group chunk_table compression data_chunk date_time date_time_values deflate device_information device_information_section digest_section error error2_section file_entry filename hash_sections hash_values header_sections header_values huffman_tree io_handle lef_extended_attribute lef_file_entry lef_permission lef_source lef_subject line_reader ltree_section md5_hash_section media_values notify permission_group read_io_handle restart_data section_data_handle section_descriptor sector_range sector_range_list segment_file segment_table serialized_string session_section sha1_hash_section single_file_tree single_files source table_section value_table volume_section write_io_handle" $LibraryTestsWithInput = "handle support" $OptionSets = "" diff --git a/tests/test_library.sh b/tests/test_library.sh index 6c7dbacfa..de2efc7d7 100755 --- a/tests/test_library.sh +++ b/tests/test_library.sh @@ -7,7 +7,7 @@ EXIT_SUCCESS=0; EXIT_FAILURE=1; EXIT_IGNORE=77; -LIBRARY_TESTS="access_control_entry analytical_data attribute bit_stream case_data case_data_section checksum chunk_data chunk_descriptor chunk_group chunk_table compression data_chunk date_time date_time_values deflate device_information device_information_section digest_section error error2_section file_entry filename hash_sections hash_values header_sections header_values huffman_tree io_handle lef_extended_attribute lef_file_entry lef_permission lef_source lef_subject ltree_section md5_hash_section media_values notify permission_group read_io_handle restart_data section_descriptor sector_range sector_range_list segment_file segment_table serialized_string session_section sha1_hash_section single_file_tree single_files source table_section value_table volume_section write_io_handle"; +LIBRARY_TESTS="access_control_entry analytical_data attribute bit_stream buffer_data_handle case_data case_data_section checksum chunk_data chunk_descriptor chunk_group chunk_table compression data_chunk date_time date_time_values deflate device_information device_information_section digest_section error error2_section file_entry filename hash_sections hash_values header_sections header_values huffman_tree io_handle lef_extended_attribute lef_file_entry lef_permission lef_source lef_subject line_reader ltree_section md5_hash_section media_values notify permission_group read_io_handle restart_data section_data_handle section_descriptor sector_range sector_range_list segment_file segment_table serialized_string session_section sha1_hash_section single_file_tree single_files source table_section value_table volume_section write_io_handle"; LIBRARY_TESTS_WITH_INPUT="handle support"; OPTION_SETS="";