From bd01ca2e2084ea1b3ff02ef4b8bda6dddfa49935 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Mon, 23 Nov 2020 15:39:11 +0100 Subject: [PATCH] Changes to libmfdata for EWF write --- ewftools/device_handle.c | 30 +- ewftools/device_handle.h | 3 +- ewftools/ewfacquire.c | 30 +- ewftools/imaging_handle.c | 4 +- libewf/ewf_definitions.h | 2 +- libewf/libewf_compression.c | 2 +- libewf/libewf_deflate.h | 2 +- libewf/libewf_section.c | 16 +- libewf/libewf_write_io_handle.c | 2 +- libmfdata/Makefile.am | 2 +- libmfdata/libmfdata_array.c | 765 ++++++++++++++++++++++++++++ libmfdata/libmfdata_array.h | 114 +++++ libmfdata/libmfdata_definitions.h | 8 +- libmfdata/libmfdata_file_list.c | 34 +- libmfdata/libmfdata_file_list.h | 4 +- libmfdata/libmfdata_libcdata.h | 54 -- libmfdata/libmfdata_list.c | 76 +-- libmfdata/libmfdata_list.h | 4 +- libmfdata/libmfdata_segment_table.c | 50 +- libmfdata/libmfdata_segment_table.h | 4 +- msvscpp/libmfdata/libmfdata.vcproj | 12 +- 21 files changed, 1028 insertions(+), 190 deletions(-) create mode 100644 libmfdata/libmfdata_array.c create mode 100644 libmfdata/libmfdata_array.h delete mode 100644 libmfdata/libmfdata_libcdata.h diff --git a/ewftools/device_handle.c b/ewftools/device_handle.c index 49c9e8d..bba668e 100644 --- a/ewftools/device_handle.c +++ b/ewftools/device_handle.c @@ -2811,13 +2811,13 @@ int device_handle_media_information_fprint( */ int device_handle_read_errors_fprint( device_handle_t *device_handle, + uint32_t bytes_per_sector, FILE *stream, libcerror_error_t **error ) { static char *function = "device_handle_read_errors_fprint"; off64_t read_error_offset = 0; size64_t read_error_size = 0; - uint32_t bytes_per_sector = 0; int number_of_read_errors = 0; int read_error_index = 0; int result = 1; @@ -2833,38 +2833,24 @@ int device_handle_read_errors_fprint( return( -1 ); } - if( stream == NULL ) + if( bytes_per_sector == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid stream.", - function ); - - return( -1 ); - } - if( device_handle_get_bytes_per_sector( - device_handle, - &bytes_per_sector, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve bytes per sector.", + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid bytes per sector value out of bounds.", function ); return( -1 ); } - if( bytes_per_sector == 0 ) + if( stream == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid bytes per sector returned.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid stream.", function ); return( -1 ); diff --git a/ewftools/device_handle.h b/ewftools/device_handle.h index e0080af..946d149 100644 --- a/ewftools/device_handle.h +++ b/ewftools/device_handle.h @@ -277,6 +277,7 @@ int device_handle_media_information_fprint( int device_handle_read_errors_fprint( device_handle_t *device_handle, + uint32_t bytes_per_sector, FILE *stream, libcerror_error_t **error ); @@ -294,5 +295,5 @@ int device_handle_tracks_fprint( } #endif -#endif +#endif /* !defined( _DEVICE_HANDLE_H ) */ diff --git a/ewftools/ewfacquire.c b/ewftools/ewfacquire.c index 87ab95f..1585066 100644 --- a/ewftools/ewfacquire.c +++ b/ewftools/ewfacquire.c @@ -624,7 +624,7 @@ int ewfacquire_read_input( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid imaging handle - acquire size value exceeds maximum.", + "%s: invalid imaging handle - acquiry size value exceeds maximum.", function ); return( -1 ); @@ -640,14 +640,13 @@ int ewfacquire_read_input( return( -1 ); } - if( ( imaging_handle->acquiry_size > imaging_handle->input_media_size ) - || ( imaging_handle->acquiry_size > (ssize64_t) INT64_MAX ) ) + if( imaging_handle->acquiry_size > imaging_handle->input_media_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid acquire size value out of bounds.", + "%s: invalid acquiry size value exceeds input media size.", function ); return( -1 ); @@ -1191,6 +1190,7 @@ int ewfacquire_read_input( { if( device_handle_read_errors_fprint( device_handle, + ewfacquire_imaging_handle->bytes_per_sector, imaging_handle->notify_stream, error ) != 1 ) { @@ -1221,6 +1221,7 @@ int ewfacquire_read_input( { if( device_handle_read_errors_fprint( device_handle, + ewfacquire_imaging_handle->bytes_per_sector, log_handle->log_stream, error ) != 1 ) { @@ -2007,11 +2008,20 @@ int main( int argc, char * const argv[] ) &( ewfacquire_imaging_handle->bytes_per_sector ), &error ) != 1 ) { + ewfacquire_imaging_handle->bytes_per_sector = 512; + fprintf( stderr, - "Unable to retrieve bytes per sector from device.\n" ); + "Unable to retrieve bytes per sector from device defaulting to: %" PRIu32 ".\n", + ewfacquire_imaging_handle->bytes_per_sector ); + +#if defined( HAVE_VERBOSE_OUTPUT ) + libcnotify_print_error_backtrace( + error ); +#endif + libcerror_error_free( + &error ); - goto on_error; } } if( option_sectors_per_chunk != NULL ) @@ -2175,6 +2185,14 @@ int main( int argc, char * const argv[] ) */ if( ewfacquire_imaging_handle->acquiry_size == 0 ) { + if( ewfacquire_imaging_handle->input_media_size == 0 ) + { + fprintf( + stderr, + "Unable to determine input media size.\n" ); + + goto on_error; + } ewfacquire_imaging_handle->acquiry_size = ewfacquire_imaging_handle->input_media_size - ewfacquire_imaging_handle->acquiry_offset; } diff --git a/ewftools/imaging_handle.c b/ewftools/imaging_handle.c index 243d82c..270913b 100644 --- a/ewftools/imaging_handle.c +++ b/ewftools/imaging_handle.c @@ -3052,10 +3052,10 @@ int imaging_handle_set_compression_values( const system_character_t *string, libcerror_error_t **error ) { - system_character_t *string_segment = NULL; + system_character_t *string_segment = NULL; static char *function = "imaging_handle_set_compression_values"; - size_t string_segment_size = 0; size_t string_length = 0; + size_t string_segment_size = 0; int number_of_segments = 0; int result = 0; int segment_index = 0; diff --git a/libewf/ewf_definitions.h b/libewf/ewf_definitions.h index 47bc74a..a7fc846 100644 --- a/libewf/ewf_definitions.h +++ b/libewf/ewf_definitions.h @@ -60,5 +60,5 @@ */ #define EWF_MAXIMUM_OFFSETS_IN_TABLE_ENCASE6 65534 -#endif +#endif /* !defined( _EWF_DEFINIONS_H ) */ diff --git a/libewf/libewf_compression.c b/libewf/libewf_compression.c index dd9e26b..f274a6e 100644 --- a/libewf/libewf_compression.c +++ b/libewf/libewf_compression.c @@ -384,7 +384,7 @@ int libewf_decompress_data( result = -1; } #else - result = libewf_deflate_decompress( + result = libewf_deflate_decompress_zlib( compressed_data, compressed_data_size, uncompressed_data, diff --git a/libewf/libewf_deflate.h b/libewf/libewf_deflate.h index a388f62..e619b22 100644 --- a/libewf/libewf_deflate.h +++ b/libewf/libewf_deflate.h @@ -36,7 +36,7 @@ extern "C" { enum LIBEWF_DEFLATE_BLOCK_TYPES { LIBEWF_DEFLATE_BLOCK_TYPE_UNCOMPRESSED = 0x00, - LIBEWF_DEFLATE_BLOCK_TYPE_HUFFMAN_FIXED = 0x01, + LIBEWF_DEFLATE_BLOCK_TYPE_HUFFMAN_FIXED = 0x01, LIBEWF_DEFLATE_BLOCK_TYPE_HUFFMAN_DYNAMIC = 0x02, LIBEWF_DEFLATE_BLOCK_TYPE_RESERVED = 0x03 }; diff --git a/libewf/libewf_section.c b/libewf/libewf_section.c index afaaf17..8e2705a 100644 --- a/libewf/libewf_section.c +++ b/libewf/libewf_section.c @@ -6702,42 +6702,42 @@ ssize_t libewf_section_volume_e01_write( if( libcnotify_verbose != 0 ) { libcnotify_printf( - "%s: media type\t\t\t\t\t: 0x%02" PRIx8 "\n", + "%s: media type\t\t\t\t: 0x%02" PRIx8 "\n", function, media_values->media_type ); libcnotify_printf( - "%s: number of chunks\t\t\t\t: %" PRIu32 "\n", + "%s: number of chunks\t\t\t: %" PRIu32 "\n", function, media_values->number_of_chunks ); libcnotify_printf( - "%s: sectors per chunk\t\t\t\t: %" PRIu32 "\n", + "%s: sectors per chunk\t\t\t: %" PRIu32 "\n", function, media_values->sectors_per_chunk ); libcnotify_printf( - "%s: bytes per sector\t\t\t\t: %" PRIu32 "\n", + "%s: bytes per sector\t\t\t: %" PRIu32 "\n", function, media_values->bytes_per_sector ); libcnotify_printf( - "%s: number of sectors\t\t: %" PRIu64 "\n", + "%s: number of sectors\t\t\t: %" PRIu64 "\n", function, media_values->number_of_sectors ); libcnotify_printf( - "%s: media flags\t\t\t\t\t: 0x%02" PRIx8 "\n", + "%s: media flags\t\t\t\t: 0x%02" PRIx8 "\n", function, media_values->media_flags ); libcnotify_printf( - "%s: compression level\t\t\t\t: 0x%02" PRIx8 "\n", + "%s: compression level\t\t\t: 0x%02" PRIx8 "\n", function, io_handle->compression_level ); libcnotify_printf( - "%s: error granularity\t\t\t\t: %" PRIu32 "\n", + "%s: error granularity\t\t\t: %" PRIu32 "\n", function, media_values->error_granularity ); diff --git a/libewf/libewf_write_io_handle.c b/libewf/libewf_write_io_handle.c index 0161c7a..378d5b3 100644 --- a/libewf/libewf_write_io_handle.c +++ b/libewf/libewf_write_io_handle.c @@ -931,7 +931,7 @@ int libewf_write_io_handle_initialize_resume( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: number of unusable chunk cannot be greater than number of chunk.", + "%s: number of unusable chunks cannot be greater than number of chunks.", function ); return( -1 ); diff --git a/libmfdata/Makefile.am b/libmfdata/Makefile.am index 45be3a0..bf21b1a 100644 --- a/libmfdata/Makefile.am +++ b/libmfdata/Makefile.am @@ -15,6 +15,7 @@ AM_CPPFLAGS = \ noinst_LTLIBRARIES = libmfdata.la libmfdata_la_SOURCES = \ + libmfdata_array.c libmfdata_array.h \ libmfdata_date_time.h \ libmfdata_definitions.h \ libmfdata_error.c libmfdata_error.h \ @@ -24,7 +25,6 @@ libmfdata_la_SOURCES = \ libmfdata_group.c libmfdata_group.h \ libmfdata_inline.h \ libmfdata_libbfio.h \ - libmfdata_libcdata.h \ libmfdata_libcerror.h \ libmfdata_libcnotify.h \ libmfdata_libfcache.h \ diff --git a/libmfdata/libmfdata_array.c b/libmfdata/libmfdata_array.c new file mode 100644 index 0000000..cab4cd8 --- /dev/null +++ b/libmfdata/libmfdata_array.c @@ -0,0 +1,765 @@ +/* + * Array functions + * + * Copyright (c) 2010-2013, 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 "libmfdata_array.h" +#include "libmfdata_definitions.h" +#include "libmfdata_libcerror.h" +#include "libmfdata_types.h" + +/* Creates an array + * Make sure the value array is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_initialize( + libmfdata_array_t **array, + int number_of_entries, + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_initialize"; + size_t entries_size = 0; + int number_of_allocated_entries = 0; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( *array != NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, + "%s: invalid array value already set.", + function ); + + return( -1 ); + } + if( number_of_entries < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, + "%s: invalid number of entries value less than zero.", + function ); + + return( -1 ); + } + *array = memory_allocate_structure( + libmfdata_array_t ); + + if( *array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create array.", + function ); + + goto on_error; + } + if( memory_set( + *array, + 0, + sizeof( libmfdata_array_t ) ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to clear array.", + function ); + + memory_free( + *array ); + + *array = NULL; + + return( -1 ); + } + /* Pre-allocate in blocks of 16 entries + */ + if( number_of_entries >= (int) ( INT_MAX - 16 ) ) + { + number_of_allocated_entries = INT_MAX; + } + else + { + number_of_allocated_entries = ( number_of_entries & ~( 15 ) ) + 16; + } +#if SIZEOF_INT <= SIZEOF_SIZE_T + if( (size_t) number_of_allocated_entries > (size_t) ( SSIZE_MAX / sizeof( intptr_t * ) ) ) +#else + if( number_of_allocated_entries > (int) ( SSIZE_MAX / sizeof( intptr_t * ) ) ) +#endif + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid number of allocated entries value exceeds maximum.", + function ); + + goto on_error; + } + entries_size = sizeof( intptr_t * ) * number_of_allocated_entries; + + if( entries_size > (size_t) LIBMFDATA_ARRAY_ENTRIES_MEMORY_LIMIT ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid entries size value exceeds maximum.", + function ); + + goto on_error; + } + ( *array )->entries = (intptr_t **) memory_allocate( + entries_size ); + + if( ( *array )->entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create array entries.", + function ); + + goto on_error; + } + if( memory_set( + ( *array )->entries, + 0, + entries_size ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to clear array entries.", + function ); + + goto on_error; + } + ( *array )->number_of_allocated_entries = number_of_allocated_entries; + ( *array )->number_of_entries = number_of_entries; + + return( 1 ); + +on_error: + if( *array != NULL ) + { + if( ( *array )->entries != NULL ) + { + memory_free( + ( *array )->entries ); + } + memory_free( + *array ); + + *array = NULL; + } + return( -1 ); +} + +/* Frees an array + * The entries are freed using the entry_free_function + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_free( + libmfdata_array_t **array, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_free"; + int result = 1; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( *array != NULL ) + { + if( ( *array )->entries != NULL ) + { + if( libmfdata_array_clear( + *array, + entry_free_function, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to clear array.", + function ); + + result = -1; + } + memory_free( + ( *array )->entries ); + } + memory_free( + *array ); + + *array = NULL; + } + return( result ); +} + +/* Empties an array and frees its entries + * The entries are freed using the entry_free_function + * If the entry_free_function fails for a specific entry it is not freed and kept in the array + * + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_empty( + libmfdata_array_t *array, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_empty"; + int result = 1; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( libmfdata_array_clear( + array, + entry_free_function, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to clear array.", + function ); + + result = -1; + } + else + { + array->number_of_entries = 0; + } + return( result ); +} + +/* Clears an array and frees its entries + * The entries are freed using the entry_free_function + * If the entry_free_function fails for a specific entry it is not freed and kept in the array + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_clear( + libmfdata_array_t *array, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_clear"; + int entry_free_result = 0; + int entry_iterator = 0; + int result = 1; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( array->entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid array - missing entries.", + function ); + + return( -1 ); + } + for( entry_iterator = 0; + entry_iterator < array->number_of_entries; + entry_iterator++ ) + { + if( array->entries[ entry_iterator ] != NULL ) + { + if( entry_free_function == NULL ) + { + entry_free_result = 1; + } + else + { + entry_free_result = entry_free_function( + &( array->entries[ entry_iterator ] ), + error ); + } + if( entry_free_result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free array entry: %d.", + function, + entry_iterator ); + + result = -1; + } + else + { + array->entries[ entry_iterator ] = NULL; + } + } + } + return( result ); +} + +/* Resizes an array + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_resize( + libmfdata_array_t *array, + int number_of_entries, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_resize"; + void *reallocation = NULL; + size_t entries_size = 0; + int entry_iterator = 0; + int number_of_allocated_entries = 0; + int result = 1; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( array->entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid array - missing entries.", + function ); + + return( -1 ); + } + if( number_of_entries < 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, + "%s: invalid number of entries value less than zero.", + function ); + + return( -1 ); + } + if( number_of_entries > array->number_of_allocated_entries ) + { + /* Pre-allocate in blocks of 16 entries + */ + if( number_of_entries >= (int) ( INT_MAX - 16 ) ) + { + number_of_allocated_entries = INT_MAX; + } + else + { + number_of_allocated_entries = ( number_of_entries & ~( 15 ) ) + 16; + } +#if SIZEOF_INT <= SIZEOF_SIZE_T + if( (size_t) number_of_allocated_entries > (size_t) ( SSIZE_MAX / sizeof( intptr_t * ) ) ) +#else + if( number_of_allocated_entries > (int) ( SSIZE_MAX / sizeof( intptr_t * ) ) ) +#endif + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid number of allocated entries value exceeds maximum.", + function ); + + return( -1 ); + } + entries_size = sizeof( intptr_t * ) * number_of_allocated_entries; + + if( entries_size > (size_t) LIBMFDATA_ARRAY_ENTRIES_MEMORY_LIMIT ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid entries size value exceeds maximum.", + function ); + + return( -1 ); + } + reallocation = memory_reallocate( + array->entries, + entries_size ); + + if( reallocation == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to resize array entries.", + function ); + + return( -1 ); + } + array->entries = (intptr_t **) reallocation; + + /* Cannot use memset reliably here. The loop below will be removed + * when memset is used and the code is optimized. Therefore the loop + * is not executed when memset fails. + */ + for( entry_iterator = array->number_of_allocated_entries; + entry_iterator < number_of_allocated_entries; + entry_iterator++ ) + { + array->entries[ entry_iterator ] = NULL; + } + array->number_of_allocated_entries = number_of_allocated_entries; + array->number_of_entries = number_of_entries; + } + else if( number_of_entries > array->number_of_entries ) + { + array->number_of_entries = number_of_entries; + } + else if( array->entries != NULL ) + { + for( entry_iterator = number_of_entries; + entry_iterator < array->number_of_entries; + entry_iterator++ ) + { + if( array->entries[ entry_iterator ] != NULL ) + { + if( entry_free_function == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid entry free function.", + function ); + + return( -1 ); + } + if( entry_free_function( + &( array->entries[ entry_iterator ] ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free array entry: %d.", + function, + entry_iterator ); + + result = -1; + } + array->entries[ entry_iterator ] = NULL; + } + } + array->number_of_entries = number_of_entries; + } + return( result ); +} + +/* Retrieves the number of entries in the array + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_get_number_of_entries( + libmfdata_array_t *array, + int *number_of_entries, + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_get_number_of_entries"; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( number_of_entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid number of entries.", + function ); + + return( -1 ); + } + *number_of_entries = array->number_of_entries; + + return( 1 ); +} + +/* Retrieves a specific entry from the array + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_get_entry_by_index( + libmfdata_array_t *array, + int entry_index, + intptr_t **entry, + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_get_entry_by_index"; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( array->entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid array - missing entries.", + function ); + + return( -1 ); + } + if( ( entry_index < 0 ) + || ( entry_index >= array->number_of_entries ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid entry index value out of bounds.", + function ); + + return( -1 ); + } + if( entry == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid entry.", + function ); + + return( -1 ); + } + *entry = array->entries[ entry_index ]; + + return( 1 ); +} + +/* Sets a specific entry in the array + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_set_entry_by_index( + libmfdata_array_t *array, + int entry_index, + intptr_t *entry, + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_set_entry_by_index"; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( array->entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid array - missing entries.", + function ); + + return( -1 ); + } + if( ( entry_index < 0 ) + || ( entry_index >= array->number_of_entries ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid entry index value out of bounds.", + function ); + + return( -1 ); + } + array->entries[ entry_index ] = entry; + + return( 1 ); +} + +/* Appends an entry + * Sets the entry index to the newly appended entry + * Returns 1 if successful or -1 on error + */ +int libmfdata_array_append_entry( + libmfdata_array_t *array, + int *entry_index, + intptr_t *entry, + libcerror_error_t **error ) +{ + static char *function = "libmfdata_array_append_entry"; + int result = 0; + int safe_entry_index = 0; + + if( array == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid array.", + function ); + + return( -1 ); + } + if( array->entries == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid array - missing entries.", + function ); + + return( -1 ); + } + if( entry_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid entry index.", + function ); + + return( -1 ); + } + safe_entry_index = array->number_of_entries; + + result = libmfdata_array_resize( + array, + array->number_of_entries + 1, + NULL, + error ); + + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, + "%s: unable to resize array.", + function ); + + result = -1; + } + else + { + array->entries[ safe_entry_index ] = entry; + } + if( result == 1 ) + { + *entry_index = safe_entry_index; + } + return( result ); +} + diff --git a/libmfdata/libmfdata_array.h b/libmfdata/libmfdata_array.h new file mode 100644 index 0000000..9eb5c36 --- /dev/null +++ b/libmfdata/libmfdata_array.h @@ -0,0 +1,114 @@ +/* + * Array functions + * + * Copyright (c) 2010-2013, 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( _LIBMFDATA_ARRAY_H ) +#define _LIBMFDATA_ARRAY_H + +#include +#include + +#include "libmfdata_libcerror.h" +#include "libmfdata_types.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +typedef struct libmfdata_array libmfdata_array_t; + +struct libmfdata_array +{ + /* The number of allocated entries + */ + int number_of_allocated_entries; + + /* The number of entries + */ + int number_of_entries; + + /* The entries + */ + intptr_t **entries; +}; + +int libmfdata_array_initialize( + libmfdata_array_t **array, + int number_of_entries, + libcerror_error_t **error ); + +int libmfdata_array_free( + libmfdata_array_t **array, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ); + +int libmfdata_array_empty( + libmfdata_array_t *array, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ); + +int libmfdata_array_clear( + libmfdata_array_t *array, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ); + +int libmfdata_array_resize( + libmfdata_array_t *array, + int number_of_entries, + int (*entry_free_function)( + intptr_t **entry, + libcerror_error_t **error ), + libcerror_error_t **error ); + +int libmfdata_array_get_number_of_entries( + libmfdata_array_t *array, + int *number_of_entries, + libcerror_error_t **error ); + +int libmfdata_array_get_entry_by_index( + libmfdata_array_t *array, + int entry_index, + intptr_t **entry, + libcerror_error_t **error ); + +int libmfdata_array_set_entry_by_index( + libmfdata_array_t *array, + int entry_index, + intptr_t *entry, + libcerror_error_t **error ); + +int libmfdata_array_append_entry( + libmfdata_array_t *array, + int *entry_index, + intptr_t *entry, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBMFDATA_ARRAY_H ) */ + diff --git a/libmfdata/libmfdata_definitions.h b/libmfdata/libmfdata_definitions.h index 382b9c2..044b861 100644 --- a/libmfdata/libmfdata_definitions.h +++ b/libmfdata/libmfdata_definitions.h @@ -151,7 +151,11 @@ enum LIBMFDATA_SEGMENT_TABLE_FLAGS LIBMFDATA_SEGMENT_TABLE_FLAG_CALCULATE_VALUE_OFFSETS = 0x10, }; -#endif +/* Limiting the maximum size of the array entries to 1 GiB + */ +#define LIBMFDATA_ARRAY_ENTRIES_MEMORY_LIMIT 1024 * 1024 * 1024 + +#endif /* !defined( HAVE_LOCAL_LIBMFDATA ) */ -#endif +#endif /* !defined( _LIBMFDATA_INTERNAL_DEFINITIONS_H ) */ diff --git a/libmfdata/libmfdata_file_list.c b/libmfdata/libmfdata_file_list.c index dc3b264..fe99d02 100644 --- a/libmfdata/libmfdata_file_list.c +++ b/libmfdata/libmfdata_file_list.c @@ -23,12 +23,12 @@ #include #include +#include "libmfdata_array.h" #include "libmfdata_date_time.h" #include "libmfdata_definitions.h" #include "libmfdata_file.h" #include "libmfdata_file_list.h" #include "libmfdata_libbfio.h" -#include "libmfdata_libcdata.h" #include "libmfdata_libcerror.h" #include "libmfdata_libcnotify.h" #include "libmfdata_libfcache.h" @@ -130,7 +130,7 @@ int libmfdata_file_list_initialize( goto on_error; } - if( libcdata_array_initialize( + if( libmfdata_array_initialize( &( internal_file_list->files ), 0, error ) != 1 ) @@ -190,7 +190,7 @@ int libmfdata_file_list_free( internal_file_list = (libmfdata_internal_file_list_t *) *file_list; *file_list = NULL; - if( libcdata_array_free( + if( libmfdata_array_free( &( internal_file_list->files ), (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_file_free, error ) != 1 ) @@ -418,7 +418,7 @@ int libmfdata_file_list_clone_files( } internal_source_file_list = (libmfdata_internal_file_list_t *) source_file_list; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_source_file_list->files, &number_of_files, error ) != 1 ) @@ -432,7 +432,7 @@ int libmfdata_file_list_clone_files( goto on_error; } - if( libcdata_array_empty( + if( libmfdata_array_empty( internal_destination_file_list->files, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_file_free, error ) != 1 ) @@ -446,7 +446,7 @@ int libmfdata_file_list_clone_files( goto on_error; } - if( libcdata_array_resize( + if( libmfdata_array_resize( internal_destination_file_list->files, number_of_files, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_file_free, @@ -465,7 +465,7 @@ int libmfdata_file_list_clone_files( file_index < number_of_files; file_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_source_file_list->files, file_index, (intptr_t **) &internal_source_file, @@ -498,7 +498,7 @@ int libmfdata_file_list_clone_files( } internal_destination_file->file_io_pool_entry = internal_source_file->file_io_pool_entry; - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_destination_file_list->files, file_index, (intptr_t *) internal_destination_file, @@ -552,7 +552,7 @@ int libmfdata_file_list_resize( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_resize( + if( libmfdata_array_resize( internal_file_list->files, number_of_files, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_file_free, @@ -594,7 +594,7 @@ int libmfdata_file_list_get_number_of_files( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_file_list->files, number_of_files, error ) != 1 ) @@ -636,7 +636,7 @@ int libmfdata_file_list_get_file_item_by_index( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_file_list->files, file_index, (intptr_t **) file, @@ -681,7 +681,7 @@ int libmfdata_file_list_get_file_by_index( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_file_list->files, file_index, (intptr_t **) &file, @@ -753,7 +753,7 @@ int libmfdata_file_list_set_file_by_index( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_file_list->files, file_index, (intptr_t **) &file, @@ -804,7 +804,7 @@ int libmfdata_file_list_set_file_by_index( return( -1 ); } - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_file_list->files, file_index, (intptr_t *) file, @@ -898,7 +898,7 @@ int libmfdata_file_list_append_file( goto on_error; } - if( libcdata_array_append_entry( + if( libmfdata_array_append_entry( internal_file_list->files, file_index, (intptr_t *) file, @@ -1260,7 +1260,7 @@ int libmfdata_file_list_get_file_value_by_index( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_file_list->files, file_index, (intptr_t **) &file, @@ -1465,7 +1465,7 @@ int libmfdata_file_list_set_file_value_by_index( } internal_file_list = (libmfdata_internal_file_list_t *) file_list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_file_list->files, file_index, (intptr_t **) &file, diff --git a/libmfdata/libmfdata_file_list.h b/libmfdata/libmfdata_file_list.h index 4274fd3..dfee4e1 100644 --- a/libmfdata/libmfdata_file_list.h +++ b/libmfdata/libmfdata_file_list.h @@ -25,9 +25,9 @@ #include #include +#include "libmfdata_array.h" #include "libmfdata_extern.h" #include "libmfdata_libbfio.h" -#include "libmfdata_libcdata.h" #include "libmfdata_libcerror.h" #include "libmfdata_types.h" @@ -41,7 +41,7 @@ struct libmfdata_internal_file_list { /* The files (array) */ - libcdata_array_t *files; + libmfdata_array_t *files; /* The flags */ diff --git a/libmfdata/libmfdata_libcdata.h b/libmfdata/libmfdata_libcdata.h deleted file mode 100644 index fc7e04e..0000000 --- a/libmfdata/libmfdata_libcdata.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The internal libcdata header - * - * Copyright (c) 2010-2013, Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#if !defined( _LIBMFDATA_LIBCDATA_H ) -#define _LIBMFDATA_LIBCDATA_H - -#include - -/* Define HAVE_LOCAL_LIBCDATA for local use of libcdata - */ -#if defined( HAVE_LOCAL_LIBCDATA ) - -#include -#include -#include -#include -#include -#include -#include -#include - -#else - -/* If libtool DLL support is enabled set LIBCDATA_DLL_IMPORT - * before including libcdata.h - */ -#if defined( _WIN32 ) && defined( DLL_IMPORT ) -#define LIBCDATA_DLL_IMPORT -#endif - -#include - -#endif - -#endif - diff --git a/libmfdata/libmfdata_list.c b/libmfdata/libmfdata_list.c index 00c55dc..4d6654d 100644 --- a/libmfdata/libmfdata_list.c +++ b/libmfdata/libmfdata_list.c @@ -23,10 +23,10 @@ #include #include +#include "libmfdata_array.h" #include "libmfdata_date_time.h" #include "libmfdata_definitions.h" #include "libmfdata_libbfio.h" -#include "libmfdata_libcdata.h" #include "libmfdata_libcerror.h" #include "libmfdata_libcnotify.h" #include "libmfdata_libfcache.h" @@ -147,7 +147,7 @@ int libmfdata_list_initialize( goto on_error; } - if( libcdata_array_initialize( + if( libmfdata_array_initialize( &( internal_list->elements ), 0, error ) != 1 ) @@ -208,7 +208,7 @@ int libmfdata_list_free( internal_list = (libmfdata_internal_list_t *) *list; *list = NULL; - if( libcdata_array_free( + if( libmfdata_array_free( &( internal_list->elements ), (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_list_element_free, error ) != 1 ) @@ -440,7 +440,7 @@ int libmfdata_list_clone_elements( } internal_source_list = (libmfdata_internal_list_t *) source_list; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_source_list->elements, &number_of_elements, error ) != 1 ) @@ -454,7 +454,7 @@ int libmfdata_list_clone_elements( goto on_error; } - if( libcdata_array_empty( + if( libmfdata_array_empty( internal_destination_list->elements, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_list_element_free, error ) != 1 ) @@ -468,7 +468,7 @@ int libmfdata_list_clone_elements( goto on_error; } - if( libcdata_array_resize( + if( libmfdata_array_resize( internal_destination_list->elements, number_of_elements, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_list_element_free, @@ -487,7 +487,7 @@ int libmfdata_list_clone_elements( element_index < number_of_elements; element_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_source_list->elements, element_index, (intptr_t **) &source_list_element, @@ -566,7 +566,7 @@ int libmfdata_list_clone_elements( destination_group_element = destination_list_element; } } - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_destination_list->elements, element_index, (intptr_t *) destination_list_element, @@ -633,7 +633,7 @@ int libmfdata_list_resize( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_resize( + if( libmfdata_array_resize( internal_list->elements, number_of_elements, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_list_element_free, @@ -675,7 +675,7 @@ int libmfdata_list_get_number_of_elements( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_list->elements, number_of_elements, error ) != 1 ) @@ -717,7 +717,7 @@ int libmfdata_list_get_element_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) element, @@ -789,7 +789,7 @@ int libmfdata_list_get_element_by_offset( return( -1 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_list->elements, &number_of_elements, error ) != 1 ) @@ -807,7 +807,7 @@ int libmfdata_list_get_element_by_offset( *element_index < number_of_elements; *element_index += 1 ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, *element_index, (intptr_t **) element, @@ -886,7 +886,7 @@ int libmfdata_list_set_element_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -942,7 +942,7 @@ int libmfdata_list_set_element_by_index( } else if( result != 0 ) { - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_list->elements, element_index, NULL, @@ -995,7 +995,7 @@ int libmfdata_list_set_element_by_index( return( -1 ); } - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_list->elements, element_index, (intptr_t *) list_element, @@ -1084,7 +1084,7 @@ int libmfdata_list_append_element( goto on_error; } - if( libcdata_array_append_entry( + if( libmfdata_array_append_entry( internal_list->elements, element_index, (intptr_t *) list_element, @@ -1174,7 +1174,7 @@ int libmfdata_list_is_set( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_list->elements, &number_of_elements, error ) != 1 ) @@ -1193,7 +1193,7 @@ int libmfdata_list_is_set( { return( 0 ); } - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &element, @@ -1242,7 +1242,7 @@ int libmfdata_list_is_group( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &element, @@ -1311,7 +1311,7 @@ int libmfdata_list_get_group_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -1488,7 +1488,7 @@ int libmfdata_list_set_group_by_index( } while( number_of_elements > 0 ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -1526,7 +1526,7 @@ int libmfdata_list_set_group_by_index( } internal_list->value_size -= previous_size; } - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_list->elements, element_index, (intptr_t *) group_list_element, @@ -1682,7 +1682,7 @@ int libmfdata_list_append_group( } while( number_of_elements > 0 ) { - if( libcdata_array_append_entry( + if( libmfdata_array_append_entry( internal_list->elements, element_index, (intptr_t *) group_list_element, @@ -1975,7 +1975,7 @@ int libmfdata_list_get_data_range_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -2087,7 +2087,7 @@ int libmfdata_list_get_data_range_by_offset( return( -1 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_list->elements, &number_of_elements, error ) != 1 ) @@ -2105,7 +2105,7 @@ int libmfdata_list_get_data_range_by_offset( *element_index < number_of_elements; *element_index += 1 ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, *element_index, (intptr_t **) &list_element, @@ -2181,7 +2181,7 @@ int libmfdata_list_set_data_range_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -2273,7 +2273,7 @@ int libmfdata_list_get_backup_data_range_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -2339,7 +2339,7 @@ int libmfdata_list_set_backup_data_range_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -2461,7 +2461,7 @@ int libmfdata_list_get_element_index_at_value_offset( return( -1 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_list->elements, &number_of_elements, error ) != 1 ) @@ -2481,7 +2481,7 @@ int libmfdata_list_get_element_index_at_value_offset( calculated_element_index < number_of_elements; calculated_element_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, calculated_element_index, (intptr_t **) &list_element, @@ -2550,7 +2550,7 @@ int libmfdata_list_get_element_index_at_value_offset( calculated_element_index < number_of_elements; calculated_element_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, calculated_element_index, (intptr_t **) &list_element, @@ -2707,7 +2707,7 @@ int libmfdata_list_get_element_index_at_value_offset( calculated_element_index >= 0; calculated_element_index-- ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, calculated_element_index, (intptr_t **) &list_element, @@ -2965,7 +2965,7 @@ int libmfdata_list_get_element_index_at_value_index( return( -1 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_list->elements, &number_of_elements, error ) != 1 ) @@ -2983,7 +2983,7 @@ int libmfdata_list_get_element_index_at_value_index( calculated_element_index < number_of_elements; calculated_element_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, *element_index, (intptr_t **) &list_element, @@ -3399,7 +3399,7 @@ int libmfdata_list_get_element_value_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, @@ -3749,7 +3749,7 @@ int libmfdata_list_set_element_value_by_index( } internal_list = (libmfdata_internal_list_t *) list; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_list->elements, element_index, (intptr_t **) &list_element, diff --git a/libmfdata/libmfdata_list.h b/libmfdata/libmfdata_list.h index a38e39a..8e5b55b 100644 --- a/libmfdata/libmfdata_list.h +++ b/libmfdata/libmfdata_list.h @@ -25,9 +25,9 @@ #include #include +#include "libmfdata_array.h" #include "libmfdata_extern.h" #include "libmfdata_libbfio.h" -#include "libmfdata_libcdata.h" #include "libmfdata_libcerror.h" #include "libmfdata_libfcache.h" #include "libmfdata_types.h" @@ -46,7 +46,7 @@ struct libmfdata_internal_list /* The (list) elements (array) */ - libcdata_array_t *elements; + libmfdata_array_t *elements; /* The flags */ diff --git a/libmfdata/libmfdata_segment_table.c b/libmfdata/libmfdata_segment_table.c index f8f11df..a7abd82 100644 --- a/libmfdata/libmfdata_segment_table.c +++ b/libmfdata/libmfdata_segment_table.c @@ -23,9 +23,9 @@ #include #include +#include "libmfdata_array.h" #include "libmfdata_definitions.h" #include "libmfdata_libbfio.h" -#include "libmfdata_libcdata.h" #include "libmfdata_libcerror.h" #include "libmfdata_libcnotify.h" #include "libmfdata_segment.h" @@ -133,7 +133,7 @@ int libmfdata_segment_table_initialize( goto on_error; } - if( libcdata_array_initialize( + if( libmfdata_array_initialize( &( internal_segment_table->segments ), 0, error ) != 1 ) @@ -196,7 +196,7 @@ int libmfdata_segment_table_free( internal_segment_table = (libmfdata_internal_segment_table_t *) *segment_table; *segment_table = NULL; - if( libcdata_array_free( + if( libmfdata_array_free( &( internal_segment_table->segments ), (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_segment_free, error ) != 1 ) @@ -427,7 +427,7 @@ int libmfdata_segment_table_clone_segments( } internal_source_segment_table = (libmfdata_internal_segment_table_t *) source_segment_table; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_source_segment_table->segments, &number_of_segments, error ) != 1 ) @@ -441,7 +441,7 @@ int libmfdata_segment_table_clone_segments( return( -1 ); } - if( libcdata_array_empty( + if( libmfdata_array_empty( internal_destination_segment_table->segments, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_segment_free, error ) != 1 ) @@ -455,7 +455,7 @@ int libmfdata_segment_table_clone_segments( return( -1 ); } - if( libcdata_array_resize( + if( libmfdata_array_resize( internal_destination_segment_table->segments, number_of_segments, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_segment_free, @@ -474,7 +474,7 @@ int libmfdata_segment_table_clone_segments( segment_index < number_of_segments; segment_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_source_segment_table->segments, segment_index, (intptr_t **) &internal_source_segment, @@ -509,7 +509,7 @@ int libmfdata_segment_table_clone_segments( internal_destination_segment->size = internal_source_segment->size; internal_destination_segment->value_offset = internal_source_segment->value_offset; - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_destination_segment_table->segments, segment_index, (intptr_t *) internal_destination_segment, @@ -559,7 +559,7 @@ int libmfdata_segment_table_empty( } internal_segment_table = (libmfdata_internal_segment_table_t *) segment_table; - if( libcdata_array_empty( + if( libmfdata_array_empty( internal_segment_table->segments, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_segment_free, error ) != 1 ) @@ -600,7 +600,7 @@ int libmfdata_segment_table_resize( } internal_segment_table = (libmfdata_internal_segment_table_t *) segment_table; - if( libcdata_array_resize( + if( libmfdata_array_resize( internal_segment_table->segments, number_of_segments, (int (*)(intptr_t **, libcerror_error_t **)) &libmfdata_segment_free, @@ -802,7 +802,7 @@ int libmfdata_segment_table_get_number_of_segments( } internal_segment_table = (libmfdata_internal_segment_table_t *) segment_table; - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_segment_table->segments, number_of_segments, error ) != 1 ) @@ -844,7 +844,7 @@ int libmfdata_segment_table_get_segment_by_index( } internal_segment_table = (libmfdata_internal_segment_table_t *) segment_table; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, segment_index, (intptr_t **) segment, @@ -951,7 +951,7 @@ int libmfdata_segment_table_get_segment_at_value_offset( return( -1 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_segment_table->segments, &number_of_segments, error ) != 1 ) @@ -971,7 +971,7 @@ int libmfdata_segment_table_get_segment_at_value_offset( calculated_segment_index < number_of_segments; calculated_segment_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, calculated_segment_index, (intptr_t **) segment, @@ -1038,7 +1038,7 @@ int libmfdata_segment_table_get_segment_at_value_offset( calculated_segment_index < number_of_segments; calculated_segment_index++ ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, calculated_segment_index, (intptr_t **) segment, @@ -1111,7 +1111,7 @@ int libmfdata_segment_table_get_segment_at_value_offset( calculated_segment_index >= 0; calculated_segment_index-- ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, calculated_segment_index, (intptr_t **) segment, @@ -1234,7 +1234,7 @@ int libmfdata_segment_table_set_segment_by_index( } internal_segment_table = (libmfdata_internal_segment_table_t *) segment_table; - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, segment_index, (intptr_t **) &segment, @@ -1267,7 +1267,7 @@ int libmfdata_segment_table_set_segment_by_index( return( -1 ); } - if( libcdata_array_set_entry_by_index( + if( libmfdata_array_set_entry_by_index( internal_segment_table->segments, segment_index, (intptr_t *) segment, @@ -1409,7 +1409,7 @@ int libmfdata_segment_table_append_segment( return( -1 ); } - if( libcdata_array_append_entry( + if( libmfdata_array_append_entry( internal_segment_table->segments, segment_index, (intptr_t *) segment, @@ -1647,7 +1647,7 @@ ssize_t libmfdata_segment_table_read_buffer( { return( 0 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_segment_table->segments, &number_of_segments, error ) != 1 ) @@ -1661,7 +1661,7 @@ ssize_t libmfdata_segment_table_read_buffer( return( -1 ); } - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, internal_segment_table->segment_index, (intptr_t **) &segment, @@ -1790,7 +1790,7 @@ ssize_t libmfdata_segment_table_read_buffer( if( internal_segment_table->segment_index < number_of_segments ) { - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, internal_segment_table->segment_index, (intptr_t **) &segment, @@ -1938,7 +1938,7 @@ ssize_t libmfdata_segment_table_write_buffer( { return( 0 ); } - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_segment_table->segments, &number_of_segments, error ) != 1 ) @@ -2050,7 +2050,7 @@ ssize_t libmfdata_segment_table_write_buffer( } number_of_segments++; } - if( libcdata_array_get_entry_by_index( + if( libmfdata_array_get_entry_by_index( internal_segment_table->segments, internal_segment_table->segment_index, (intptr_t **) &segment, @@ -2344,7 +2344,7 @@ off64_t libmfdata_segment_table_seek_offset( } else { - if( libcdata_array_get_number_of_entries( + if( libmfdata_array_get_number_of_entries( internal_segment_table->segments, &segment_index, error ) != 1 ) diff --git a/libmfdata/libmfdata_segment_table.h b/libmfdata/libmfdata_segment_table.h index 922fa46..8655dbb 100644 --- a/libmfdata/libmfdata_segment_table.h +++ b/libmfdata/libmfdata_segment_table.h @@ -25,9 +25,9 @@ #include #include +#include "libmfdata_array.h" #include "libmfdata_extern.h" #include "libmfdata_libbfio.h" -#include "libmfdata_libcdata.h" #include "libmfdata_libcerror.h" #include "libmfdata_types.h" @@ -57,7 +57,7 @@ struct libmfdata_internal_segment_table /* The segments (array) */ - libcdata_array_t *segments; + libmfdata_array_t *segments; /* The flags */ diff --git a/msvscpp/libmfdata/libmfdata.vcproj b/msvscpp/libmfdata/libmfdata.vcproj index 1ee1089..3ec363e 100644 --- a/msvscpp/libmfdata/libmfdata.vcproj +++ b/msvscpp/libmfdata/libmfdata.vcproj @@ -150,6 +150,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + @@ -200,6 +204,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + @@ -236,10 +244,6 @@ RelativePath="..\..\libmfdata\libmfdata_libbfio.h" > - -