/* Retrieves the size of the UTF-8 encoded string string of the catalog definition template name * The returned size includes the end of string character * Returns 1 if successful or -1 on error */ int libesedb_catalog_definition_get_utf8_template_name_size( libesedb_catalog_definition_t *catalog_definition, size_t *utf8_string_size, int ascii_codepage, libcerror_error_t **error ) { static char *function = "libesedb_catalog_definition_get_utf8_template_name_size"; int result = 0; if( catalog_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid catalog definition.", function ); return( -1 ); } if( catalog_definition->template_name == NULL ) { if( utf8_string_size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-8 string size.", function ); return( -1 ); } *utf8_string_size = 0; } else { result = libuna_utf8_string_size_from_byte_stream( catalog_definition->template_name, catalog_definition->template_name_size, ascii_codepage, utf8_string_size, error ); if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve UTF-8 string size.", function ); return( -1 ); } } return( 1 ); }
/* Retrieves the size of the UTF-8 formatted comments * Returns 1 if successful, 0 if not available or -1 on error */ int libfwsi_network_location_get_utf8_comments_size( libfwsi_item_t *item, size_t *utf8_string_size, libcerror_error_t **error ) { libfwsi_internal_item_t *internal_item = NULL; libfwsi_network_location_values_t *network_location_values = NULL; static char *function = "libfwsi_network_location_get_utf8_comments_size"; if( item == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid item.", function ); return( -1 ); } internal_item = (libfwsi_internal_item_t *) item; if( ( internal_item->class_type & 0x70 ) != LIBFWSI_CLASS_TYPE_NETWORK_LOCATION ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported class type.", function ); return( -1 ); } if( internal_item->value == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid item - missing value.", function ); return( -1 ); } network_location_values = (libfwsi_network_location_values_t *) internal_item->value; if( ( network_location_values->comments == NULL ) || ( network_location_values->comments_size == 0 ) ) { return( 0 ); } if( libuna_utf8_string_size_from_byte_stream( network_location_values->comments, network_location_values->comments_size, network_location_values->ascii_codepage, utf8_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of UTF-8 string.", function ); return( -1 ); } return( 1 ); }
/* Prints a string value * Returns 1 if successful or -1 on error */ int libregf_debug_print_string_value( const char *function_name, const char *value_name, const uint8_t *byte_stream, size_t byte_stream_size, int ascii_codepage, libcerror_error_t **error ) { system_character_t *string = NULL; static char *function = "libregf_debug_print_string_value"; size_t string_size = 0; int result = 0; if( ( byte_stream == NULL ) || ( byte_stream_size == 0 ) ) { libcnotify_printf( "%s: %s: \n", function_name, value_name ); return( 1 ); } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( byte_stream, byte_stream_size, ascii_codepage, &string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( byte_stream, byte_stream_size, ascii_codepage, &string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of string.", function ); goto on_error; } if( ( string_size > (size_t) SSIZE_MAX ) || ( ( sizeof( system_character_t ) * string_size ) > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid string size value exceeds maximum.", function ); goto on_error; } string = system_string_allocate( string_size ); if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create string.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) string, string_size, byte_stream, byte_stream_size, ascii_codepage, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) string, string_size, byte_stream, byte_stream_size, ascii_codepage, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set string.", function ); goto on_error; } libcnotify_printf( "%s: %s: %s\n", function_name, value_name, string ); memory_free( string ); return( 1 ); on_error: if( string != NULL ) { memory_free( string ); } return( -1 ); }
/* Determines the UTF-8 string size from the system string * Returns 1 if successful or -1 on error */ int libcsystem_string_size_to_utf8_string( const libcstring_system_character_t *string, size_t string_size, size_t *utf8_string_size, libcerror_error_t **error ) { static char *function = "libcsystem_string_size_to_utf8_string"; if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid string.", function ); return( -1 ); } if( string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid string size value exceeds maximum.", function ); return( -1 ); } if( utf8_string_size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-8 string size.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) #if SIZEOF_WCHAR_T == 4 if( libuna_utf8_string_size_from_utf32( (libuna_utf32_character_t *) string, string_size, utf8_string_size, error ) != 1 ) #elif SIZEOF_WCHAR_T == 2 if( libuna_utf8_string_size_from_utf16( (libuna_utf16_character_t *) string, string_size, utf8_string_size, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to determine UTF-8 string size.", function ); return( -1 ); } #else if( libclocale_codepage == 0 ) { *utf8_string_size = 1 + libcstring_system_string_length( string ); } else if( libuna_utf8_string_size_from_byte_stream( (uint8_t *) string, string_size, libclocale_codepage, 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 ); return( -1 ); } #endif return( 1 ); }
/* Retrieves the size of the UTF-8 formatted localized name * Returns 1 if successful, 0 if not available or -1 on error */ int libfwsi_file_entry_extension_get_utf8_localized_name_size( libfwsi_extension_block_t *extension_block, size_t *utf8_string_size, libcerror_error_t **error ) { libfwsi_internal_extension_block_t *internal_extension_block = NULL; libfwsi_file_entry_extension_values_t *file_entry_extension_values = NULL; static char *function = "libfwsi_file_entry_extension_get_utf8_localized_name_size"; int result = 0; if( extension_block == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid extension block.", function ); return( -1 ); } internal_extension_block = (libfwsi_internal_extension_block_t *) extension_block; if( internal_extension_block->signature != 0xbeef0004UL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported extension block signature.", function ); return( -1 ); } if( internal_extension_block->value == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid extension block - missing value.", function ); return( -1 ); } file_entry_extension_values = (libfwsi_file_entry_extension_values_t *) internal_extension_block->value; if( ( file_entry_extension_values->localized_name == NULL ) || ( file_entry_extension_values->localized_name_size == 0 ) ) { return( 0 ); } if( internal_extension_block->version >= 7 ) { result = libuna_utf8_string_size_from_utf16_stream( file_entry_extension_values->localized_name, file_entry_extension_values->localized_name_size, LIBUNA_ENDIAN_LITTLE, utf8_string_size, error ); } else if( internal_extension_block->version >= 3 ) { result = libuna_utf8_string_size_from_byte_stream( file_entry_extension_values->localized_name, file_entry_extension_values->localized_name_size, file_entry_extension_values->ascii_codepage, utf8_string_size, error ); } else { return( 0 ); } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of UTF-8 string.", function ); return( -1 ); } return( 1 ); }
/* Reads the catalog definition from the definition data * Returns 1 if successful or -1 on error */ int libesedb_catalog_definition_read( libesedb_catalog_definition_t *catalog_definition, uint8_t *definition_data, size_t definition_data_size, int ascii_codepage LIBESEDB_ATTRIBUTE_UNUSED, libcerror_error_t **error ) { uint8_t *fixed_size_data_type_value_data = NULL; uint8_t *variable_size_data_type_size_data = NULL; uint8_t *variable_size_data_type_value_data = NULL; static char *function = "libesedb_catalog_definition_read"; uint16_t calculated_variable_size_data_types_offset = 0; uint16_t data_type_number = 0; uint16_t previous_variable_size_data_type_size = 0; uint16_t variable_size_data_type_size = 0; uint16_t variable_size_data_types_offset = 0; uint8_t last_fixed_size_data_type = 0; uint8_t last_variable_size_data_type = 0; uint8_t number_of_variable_size_data_types = 0; uint8_t variable_size_data_type_iterator = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t *value_string = 0; size_t value_string_size = 0; uint32_t value_32bit = 0; uint16_t record_offset = 0; uint16_t value_16bit = 0; int result = 0; #endif LIBESEDB_UNREFERENCED_PARAMETER( ascii_codepage ) if( catalog_definition == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid catalog definition.", function ); return( -1 ); } if( definition_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid definition data.", function ); return( -1 ); } if( definition_data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid definition data size value exceeds maximum.", function ); return( -1 ); } if( definition_data_size < sizeof( esedb_data_definition_header_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: definition data too small.", function ); return( -1 ); } last_fixed_size_data_type = ( (esedb_data_definition_header_t *) definition_data )->last_fixed_size_data_type; last_variable_size_data_type = ( (esedb_data_definition_header_t *) definition_data )->last_variable_size_data_type; byte_stream_copy_to_uint16_little_endian( ( (esedb_data_definition_header_t *) definition_data )->variable_size_data_types_offset, variable_size_data_types_offset ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: last fixed size data type\t\t\t\t: %" PRIu8 "\n", function, last_fixed_size_data_type ); libcnotify_printf( "%s: last variable size data type\t\t\t\t: %" PRIu8 "\n", function, last_variable_size_data_type ); libcnotify_printf( "%s: variable size data types offset\t\t\t: %" PRIu16 "\n", function, variable_size_data_types_offset ); } #endif /* As far as the documentation states * the column data FIELD structure is 16 bytes of size */ if( last_fixed_size_data_type < 5 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: last fixed size data type too small.", function ); return( -1 ); } if( last_fixed_size_data_type > 11 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported last fixed size data type: %" PRIu8 ".", function, last_fixed_size_data_type ); return( -1 ); } if( last_variable_size_data_type > 127 ) { number_of_variable_size_data_types = last_variable_size_data_type - 127; } calculated_variable_size_data_types_offset += sizeof( esedb_data_definition_header_t ); /* Use a fall through to determine the size of the fixed size data types */ switch( last_fixed_size_data_type ) { case 11: calculated_variable_size_data_types_offset += 2; case 10: calculated_variable_size_data_types_offset += 4; case 9: calculated_variable_size_data_types_offset += 2; case 8: if( last_variable_size_data_type > 127 ) { calculated_variable_size_data_types_offset += 1 * number_of_variable_size_data_types; } case 7: calculated_variable_size_data_types_offset += 4; case 6: calculated_variable_size_data_types_offset += 4; case 5: calculated_variable_size_data_types_offset += 4; case 4: calculated_variable_size_data_types_offset += 4; case 3: calculated_variable_size_data_types_offset += 4; case 2: calculated_variable_size_data_types_offset += 2; case 1: calculated_variable_size_data_types_offset += 4; break; } if( variable_size_data_types_offset > definition_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: variable size data types offset exceeds definition data.", function ); return( -1 ); } fixed_size_data_type_value_data = &( definition_data[ sizeof( esedb_data_definition_header_t ) ] ); byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->father_data_page_object_identifier, catalog_definition->father_data_page_object_identifier ); byte_stream_copy_to_uint16_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->type, catalog_definition->type ); byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->identifier, catalog_definition->identifier ); if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_COLUMN ) { byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->column_type, catalog_definition->column_type ); } else { byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->father_data_page_number, catalog_definition->father_data_page_number ); } byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->space_usage, catalog_definition->size ); if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_COLUMN ) { byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->codepage, catalog_definition->codepage ); } if( last_fixed_size_data_type >= 10 ) { byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->lc_map_flags, catalog_definition->lcmap_flags ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { data_type_number = 1; libcnotify_printf( "%s: (%03" PRIu16 ") father data page (FDP) object identifier\t: %" PRIu32 "\n", function, data_type_number++, catalog_definition->father_data_page_object_identifier ); libcnotify_printf( "%s: (%03" PRIu16 ") type\t\t\t\t\t\t: 0x%04" PRIx16 " ", function, data_type_number++, catalog_definition->type ); libesedb_debug_print_page_value_definition_type( catalog_definition->type ); libcnotify_printf( "\n" ); libcnotify_printf( "%s: (%03" PRIu16 ") identifier\t\t\t\t\t: %" PRIu32 "\n", function, data_type_number++, catalog_definition->identifier ); if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_COLUMN ) { libcnotify_printf( "%s: (%03" PRIu16 ") column type\t\t\t\t\t: %" PRIu32 " (%s) %s\n", function, data_type_number++, catalog_definition->column_type, libesedb_column_type_get_identifier( catalog_definition->column_type ), libesedb_column_type_get_description( catalog_definition->column_type ) ); } else { libcnotify_printf( "%s: (%03" PRIu16 ") father data page (FDP) number\t\t\t: %" PRIu32 "\n", function, data_type_number++, catalog_definition->father_data_page_number ); } libcnotify_printf( "%s: (%03" PRIu16 ") space usage\t\t\t\t\t: %" PRIu32 "\n", function, data_type_number++, catalog_definition->size ); byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->flags, value_32bit ); if( last_fixed_size_data_type >= 6 ) { if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_COLUMN ) { libcnotify_printf( "%s: (%03" PRIu16 ") flags\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, data_type_number++, value_32bit ); libesedb_debug_print_column_group_of_bits( value_32bit ); libcnotify_printf( "\n" ); } else if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_INDEX ) { libcnotify_printf( "%s: (%03" PRIu16 ") flags\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, data_type_number++, value_32bit ); libesedb_debug_print_index_group_of_bits( value_32bit ); libcnotify_printf( "\n" ); } else { libcnotify_printf( "%s: (%03" PRIu16 ") flags\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, data_type_number++, value_32bit ); } } if( last_fixed_size_data_type >= 7 ) { if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_COLUMN ) { libcnotify_printf( "%s: (%03" PRIu16 ") codepage\t\t\t\t\t: %" PRIu32 "", function, data_type_number++, catalog_definition->codepage ); if( catalog_definition->codepage != 0 ) { libcnotify_printf( " (%s) %s", libesedb_codepage_get_identifier( catalog_definition->codepage ), libesedb_codepage_get_description( catalog_definition->codepage ) ); } libcnotify_printf( "\n" ); } else if( catalog_definition->type == LIBESEDB_CATALOG_DEFINITION_TYPE_INDEX ) { byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->locale_identifier, value_32bit ); libcnotify_printf( "%s: (%03" PRIu16 ") locale identifier\t\t\t\t: 0x%08" PRIx32 " (%s)\n", function, data_type_number++, value_32bit, libesedb_lcid_language_tag_get_identifier( (uint16_t) value_32bit ), libesedb_lcid_language_tag_get_description( (uint16_t) value_32bit ) ); } else { byte_stream_copy_to_uint32_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->number_of_pages, value_32bit ); libcnotify_printf( "%s: (%03" PRIu16 ") number of pages\t\t\t\t\t: %" PRIu32 "\n", function, data_type_number++, value_32bit ); } } if( last_fixed_size_data_type >= 8 ) { libcnotify_printf( "%s: (%03" PRIu16 ") root flag\t\t\t\t\t: 0x%02" PRIx8 "\n", function, data_type_number++, ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->root_flag ); } if( last_fixed_size_data_type >= 9 ) { byte_stream_copy_to_uint16_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->record_offset, record_offset ); libcnotify_printf( "%s: (%03" PRIu16 ") record offset\t\t\t\t\t: %" PRIu16 "\n", function, data_type_number++, record_offset ); } if( last_fixed_size_data_type >= 10 ) { libcnotify_printf( "%s: (%03" PRIu16 ") locale map (LCMAP) flags\t\t\t: 0x%08" PRIx32 "\n", function, data_type_number++, catalog_definition->lcmap_flags ); libesedb_debug_print_lcmap_flags( catalog_definition->lcmap_flags ); libcnotify_printf( "\n" ); } if( last_fixed_size_data_type >= 11 ) { byte_stream_copy_to_uint16_little_endian( ( (esedb_data_definition_t *) fixed_size_data_type_value_data )->key_most, value_16bit ); libcnotify_printf( "%s: (%03" PRIu16 ") key most\t\t\t\t\t: 0x04%" PRIx16 "\n", function, data_type_number++, value_16bit ); } libcnotify_printf( "\n" ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( ( libcnotify_verbose != 0 ) && ( variable_size_data_types_offset > calculated_variable_size_data_types_offset ) ) { libcnotify_printf( "%s: trailing data:\n", function ); libcnotify_print_data( &( definition_data[ calculated_variable_size_data_types_offset ] ), variable_size_data_types_offset - calculated_variable_size_data_types_offset, 0 ); } #endif if( number_of_variable_size_data_types > 0 ) { variable_size_data_type_size_data = &( definition_data[ variable_size_data_types_offset ] ); variable_size_data_type_value_data = &( variable_size_data_type_size_data[ number_of_variable_size_data_types * 2 ] ); data_type_number = 128; for( variable_size_data_type_iterator = 0; variable_size_data_type_iterator < number_of_variable_size_data_types; variable_size_data_type_iterator++ ) { byte_stream_copy_to_uint16_little_endian( variable_size_data_type_size_data, variable_size_data_type_size ); variable_size_data_type_size_data += 2; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: (%03" PRIu16 ") variable size data type size\t\t\t: 0x%04" PRIx16 " (%" PRIu16 ")\n", function, data_type_number, variable_size_data_type_size, ( ( variable_size_data_type_size & 0x8000 ) != 0 ) ? 0 : ( variable_size_data_type_size & 0x7fff ) - previous_variable_size_data_type_size ); } #endif switch( data_type_number ) { case 128: /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { catalog_definition->name_size = (size_t) ( variable_size_data_type_size - previous_variable_size_data_type_size ); catalog_definition->name = (uint8_t *) memory_allocate( sizeof( uint8_t ) * catalog_definition->name_size ); if( catalog_definition->name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create name.", function ); catalog_definition->name_size = 0; return( -1 ); } if( memory_copy( catalog_definition->name, &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), catalog_definition->name_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set name.", function ); memory_free( catalog_definition->name ); catalog_definition->name = NULL; catalog_definition->name_size = 0; return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( catalog_definition->name, catalog_definition->name_size, ascii_codepage, &value_string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( catalog_definition->name, catalog_definition->name_size, ascii_codepage, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of name string.", function ); return( -1 ); } catalog_definition->name_string = libcstring_system_string_allocate( value_string_size ); if( catalog_definition->name_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create name string.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) catalog_definition->name_string, value_string_size, catalog_definition->name, catalog_definition->name_size, ascii_codepage, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) catalog_definition->name_string, value_string_size, catalog_definition->name, catalog_definition->name_size, ascii_codepage, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set name string.", function ); memory_free( catalog_definition->name_string ); catalog_definition->name_string = NULL; return( -1 ); } libcnotify_printf( "%s: (%03" PRIu8 ") name\t\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, data_type_number, catalog_definition->name_string ); } #endif } #if defined( HAVE_DEBUG_OUTPUT ) else if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") name\t\t\t\t\t\t: <NULL>\n", function, data_type_number ); } #endif break; #if defined( HAVE_DEBUG_OUTPUT ) case 129: if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") stats:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu8 ") stats\t\t\t\t\t\t: <NULL>\n", function, data_type_number ); } } break; #endif case 130: /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { catalog_definition->template_name_size = (size_t) ( variable_size_data_type_size - previous_variable_size_data_type_size ); catalog_definition->template_name = (uint8_t *) memory_allocate( sizeof( uint8_t ) * catalog_definition->template_name_size ); if( catalog_definition->template_name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create template name.", function ); catalog_definition->template_name_size = 0; return( -1 ); } if( memory_copy( catalog_definition->template_name, &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), catalog_definition->template_name_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set template name.", function ); memory_free( catalog_definition->template_name ); catalog_definition->template_name = NULL; catalog_definition->template_name_size = 0; return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( catalog_definition->template_name, catalog_definition->template_name_size, ascii_codepage, &value_string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( catalog_definition->template_name, catalog_definition->template_name_size, ascii_codepage, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of template name string.", function ); return( -1 ); } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create template name string.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) value_string, value_string_size, catalog_definition->template_name, catalog_definition->template_name_size, ascii_codepage, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) value_string, value_string_size, catalog_definition->template_name, catalog_definition->template_name_size, ascii_codepage, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set template name string.", function ); memory_free( value_string ); return( -1 ); } libcnotify_printf( "%s: (%03" PRIu8 ") template name\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, data_type_number, value_string ); memory_free( value_string ); } #endif } #if defined( HAVE_DEBUG_OUTPUT ) else if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") template name\t\t\t\t\t: <NULL>\n", function, data_type_number ); } #endif break; case 131: /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { catalog_definition->default_value_size = (size_t) ( variable_size_data_type_size - previous_variable_size_data_type_size ); catalog_definition->default_value = (uint8_t *) memory_allocate( sizeof( uint8_t ) * catalog_definition->default_value_size ); if( catalog_definition->default_value == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create default value.", function ); catalog_definition->default_value_size = 0; return( -1 ); } if( memory_copy( catalog_definition->default_value, &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), catalog_definition->default_value_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set default value.", function ); memory_free( catalog_definition->default_value ); catalog_definition->default_value = NULL; catalog_definition->default_value_size = 0; return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") default value:\n", function, data_type_number ); libcnotify_print_data( catalog_definition->default_value, catalog_definition->default_value_size, 0 ); } #endif } #if defined( HAVE_DEBUG_OUTPUT ) else if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") default value\t\t\t\t\t: <NULL>\n", function, data_type_number ); } #endif break; #if defined( HAVE_DEBUG_OUTPUT ) case 132: if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") KeyFldIDs:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu8 ") KeyFldIDs\t\t\t\t\t: <NULL>\n", function, data_type_number ); } } break; case 133: if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") VarSegMac:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu8 ") VarSegMac\t\t\t\t\t: <NULL>\n", function, data_type_number ); } } break; case 134: if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") ConditionalColumns:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu8 ") ConditionalColumns\t\t\t\t: <NULL>\n", function, data_type_number ); } } break; case 135: if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") TupleLimits:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu8 ") TupleLimits\t\t\t\t\t: <NULL>\n", function, data_type_number ); } } break; case 136: if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu8 ") Version:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu8 ") Version\t\t\t\t\t\t: <NULL>\n", function, data_type_number ); } } break; #endif default: #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { libcnotify_printf( "%s: (%03" PRIu16 ") variable size data type:\n", function, data_type_number ); libcnotify_print_data( &( variable_size_data_type_value_data[ previous_variable_size_data_type_size ] ), variable_size_data_type_size - previous_variable_size_data_type_size, 0 ); } else { libcnotify_printf( "%s: (%03" PRIu16 ") variable size data type\t\t\t: <NULL>\n", function, data_type_number ); } } #endif break; } /* The MSB signifies that the variable size data type is empty */ if( ( variable_size_data_type_size & 0x8000 ) == 0 ) { previous_variable_size_data_type_size = variable_size_data_type_size; } data_type_number++; } } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( 1 ); }
/* Retrieves the UTF-8 string size * The returned size includes the end of string character * Returns 1 if successful or -1 on error */ int libpff_name_to_id_map_entry_get_utf8_string_size( libpff_name_to_id_map_entry_t *name_to_id_map_entry, size_t *utf8_string_size, libcerror_error_t **error ) { libpff_internal_name_to_id_map_entry_t *internal_name_to_id_map_entry = NULL; static char *function = "libpff_name_to_id_map_entry_get_utf8_string_size"; if( name_to_id_map_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid name to id map entry.", function ); return( -1 ); } internal_name_to_id_map_entry = (libpff_internal_name_to_id_map_entry_t *) name_to_id_map_entry; if( internal_name_to_id_map_entry->type != LIBPFF_NAME_TO_ID_MAP_ENTRY_TYPE_STRING ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported name to id map entry type.", function ); return( -1 ); } if( internal_name_to_id_map_entry->is_ascii_string == 0 ) { if( libuna_utf8_string_size_from_utf16_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBPFF_ENDIAN_LITTLE, utf8_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine name to id map entry UTF-8 string size.", function ); return( -1 ); } } else { if( libuna_utf8_string_size_from_byte_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBUNA_CODEPAGE_ASCII, utf8_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine name to id map entry UTF-8 string size.", function ); return( -1 ); } } return( 1 ); }
/* Read the name to id map entry * Returns 1 if successful or -1 on error */ int libpff_name_to_id_map_entry_read( libpff_name_to_id_map_entry_t *name_to_id_map_entry, uint8_t *name_to_id_map_entry_data, size_t name_to_id_map_entry_data_size LIBPFF_ATTRIBUTE_UNUSED, uint8_t *name_to_id_map_class_identifiers_data, size_t name_to_id_map_class_identifiers_data_size, uint8_t *name_to_id_map_strings_data, size_t name_to_id_map_strings_data_size, libcerror_error_t **error ) { libpff_internal_name_to_id_map_entry_t *internal_name_to_id_map_entry = NULL; uint8_t *name_to_id_map_string_data = NULL; static char *function = "libpff_name_to_id_map_entry_read"; uint32_t name_to_id_map_entry_value = 0; uint32_t name_to_id_map_string_size = 0; uint16_t name_to_id_map_class_identifier_index = 0; uint16_t name_to_id_map_entry_type = 0; uint16_t name_to_id_map_entry_number = 0; int result = 0; #if defined( HAVE_DEBUG_OUTPUT ) uint32_t name_to_id_map_entry_index = 0; #endif LIBPFF_UNREFERENCED_PARAMETER( name_to_id_map_entry_data_size ) if( name_to_id_map_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid name to id map entry.", function ); return( -1 ); } internal_name_to_id_map_entry = (libpff_internal_name_to_id_map_entry_t *) name_to_id_map_entry; if( name_to_id_map_entry_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid name to id map entry data.", function ); return( -1 ); } if( name_to_id_map_class_identifiers_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid name to id map class identifier data.", function ); return( -1 ); } byte_stream_copy_to_uint32_little_endian( ( (pff_name_to_id_map_entry_t *) name_to_id_map_entry_data )->entry_value, name_to_id_map_entry_value ); byte_stream_copy_to_uint16_little_endian( ( (pff_name_to_id_map_entry_t *) name_to_id_map_entry_data )->entry_type, name_to_id_map_entry_type ); byte_stream_copy_to_uint16_little_endian( ( (pff_name_to_id_map_entry_t *) name_to_id_map_entry_data )->entry_number, name_to_id_map_entry_number ); internal_name_to_id_map_entry->identifier = name_to_id_map_entry_number + 0x8000; if( name_to_id_map_entry_type > 5 ) { name_to_id_map_class_identifier_index = (uint16_t) ( ( name_to_id_map_entry_type / 2 ) - 3 ); if( (size_t) ( name_to_id_map_class_identifier_index * 16 ) > name_to_id_map_class_identifiers_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid name to id map class identifier index value exceeds class identifiers data size.", function ); goto on_error; } if( memory_copy( internal_name_to_id_map_entry->guid, &( name_to_id_map_class_identifiers_data[ name_to_id_map_class_identifier_index * 16 ] ), 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy name to id map class identifier.", function ); goto on_error; } } else if( name_to_id_map_entry_type == 5 ) { if( memory_copy( internal_name_to_id_map_entry->guid, libfmapi_guid_public_strings, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set public strings class identifier.", function ); goto on_error; } } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: entry: %03d name to id map entry value\t\t: 0x%08" PRIx32 "\n", function, name_to_id_map_entry_index, name_to_id_map_entry_value ); if( name_to_id_map_entry_type > 5 ) { libcnotify_printf( "%s: entry: %03d name to id map entry type\t\t: 0x%04" PRIx16 " (class identifier: %02" PRIu16 ", class: %s)\n", function, name_to_id_map_entry_index, name_to_id_map_entry_type, name_to_id_map_class_identifier_index, libfmapi_class_identifier_get_name( internal_name_to_id_map_entry->guid ) ); } else if( name_to_id_map_entry_type == 5 ) { libcnotify_printf( "%s: entry: %03d name to id map entry type\t\t: 0x%04" PRIx16 " (class: %s)\n", function, name_to_id_map_entry_index, name_to_id_map_entry_type, libfmapi_class_identifier_get_name( internal_name_to_id_map_entry->guid ) ); } else { libcnotify_printf( "%s: entry: %03d name to id map entry type\t\t: 0x%04" PRIx16 "\n", function, name_to_id_map_entry_index, name_to_id_map_entry_type ); } libcnotify_printf( "%s: entry: %03d name to id map entry number\t: 0x%04" PRIx16 " (0x%04" PRIx32 ")\n", function, name_to_id_map_entry_index, name_to_id_map_entry_number, internal_name_to_id_map_entry->identifier ); } #endif /* The lowest bit of the name to id map entry type signifies * that the name to id map entry value refers to the name to id map string table or the item values */ if( ( name_to_id_map_entry_type & 0x0001 ) != 0 ) { if( internal_name_to_id_map_entry->string_value != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid name to id map entry - string value already set.", function ); goto on_error; } /* The strings data can be NULL and therefore these bounds are checked on demand */ if( name_to_id_map_strings_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid name to id map strings data.", function ); goto on_error; } if( ( name_to_id_map_strings_data_size == 0 ) || ( name_to_id_map_strings_data_size > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid name to id map strings data size value out of bounds.", function ); goto on_error; } if( name_to_id_map_entry_value > name_to_id_map_strings_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid name to id map entry value exceeds strings data size.", function ); goto on_error; } name_to_id_map_string_data = &( name_to_id_map_strings_data[ name_to_id_map_entry_value ] ); byte_stream_copy_to_uint32_little_endian( name_to_id_map_string_data, name_to_id_map_string_size ); name_to_id_map_string_data += 4; internal_name_to_id_map_entry->type = LIBPFF_NAME_TO_ID_MAP_ENTRY_TYPE_STRING; if( (size_t) name_to_id_map_string_size <= ( name_to_id_map_strings_data_size - name_to_id_map_entry_value ) ) { result = libpff_value_type_string_contains_zero_bytes( name_to_id_map_string_data, (size_t) name_to_id_map_string_size, error ) ; if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine name to id map entry string contains zero bytes.", function ); goto on_error; } else if( result == 0 ) { internal_name_to_id_map_entry->is_ascii_string = 1; } internal_name_to_id_map_entry->value_size = (size_t) name_to_id_map_string_size; internal_name_to_id_map_entry->string_value = (uint8_t *) memory_allocate( sizeof( uint8_t ) * internal_name_to_id_map_entry->value_size ); if( internal_name_to_id_map_entry->string_value == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create name to id map entry string.", function ); goto on_error; } if( memory_copy( internal_name_to_id_map_entry->string_value, name_to_id_map_string_data, internal_name_to_id_map_entry->value_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set name to id map entry string.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_name_to_id_map_entry->is_ascii_string == 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBPFF_ENDIAN_LITTLE, &( internal_name_to_id_map_entry->debug_string_size ), error ); #else result = libuna_utf8_string_size_from_utf16_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBPFF_ENDIAN_LITTLE, &( internal_name_to_id_map_entry->debug_string_size ), error ); #endif } else { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf8_string_size_from_byte_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBUNA_CODEPAGE_ASCII, &( internal_name_to_id_map_entry->debug_string_size ), error ); #else result = libuna_utf8_string_size_from_byte_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBUNA_CODEPAGE_ASCII, &( internal_name_to_id_map_entry->debug_string_size ), error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine name to id map entry string size.", function ); goto on_error; } internal_name_to_id_map_entry->debug_string = libcstring_system_string_allocate( internal_name_to_id_map_entry->debug_string_size ); if( internal_name_to_id_map_entry->debug_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create UTF-8 name to id map entry string.", function ); goto on_error; } if( internal_name_to_id_map_entry->is_ascii_string == 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) internal_name_to_id_map_entry->debug_string, internal_name_to_id_map_entry->debug_string_size, internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBPFF_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) internal_name_to_id_map_entry->debug_string, internal_name_to_id_map_entry->debug_string_size, internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBPFF_ENDIAN_LITTLE, error ); #endif } else { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) internal_name_to_id_map_entry->debug_string, internal_name_to_id_map_entry->debug_string_size, internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBUNA_CODEPAGE_ASCII, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) internal_name_to_id_map_entry->debug_string, internal_name_to_id_map_entry->debug_string_size, internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBUNA_CODEPAGE_ASCII, error ); #endif } if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_CONVERSION, LIBCERROR_CONVERSION_ERROR_GENERIC, "%s: unable to set name to id map entry string.", function ); goto on_error; } libcnotify_printf( "%s: entry: %03d name to id map entry string\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, name_to_id_map_entry_index, internal_name_to_id_map_entry->debug_string ); } #endif } else { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: invalid name to id map string size value out of bounds.\n", function ); } #endif /* Since the string does not contain an end-of-string character and the size * does not contain a sane value mark the name to ID map entry as corrupted. */ internal_name_to_id_map_entry->flags |= LIBPFF_NAME_TO_ID_MAP_ENTRY_FLAG_IS_CORRUPTED; } } else { internal_name_to_id_map_entry->type = LIBPFF_NAME_TO_ID_MAP_ENTRY_TYPE_NUMERIC; internal_name_to_id_map_entry->numeric_value = name_to_id_map_entry_value; internal_name_to_id_map_entry->value_size = 4; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( internal_name_to_id_map_entry->debug_string != NULL ) { memory_free( internal_name_to_id_map_entry->debug_string ); internal_name_to_id_map_entry->debug_string = NULL; } #endif return( -1 ); }
/* Reads the volume values * Returns the number of bytes read, 0 if not able to read or -1 on error */ ssize_t libfwsi_volume_values_read( libfwsi_volume_values_t *volume_values, const uint8_t *shell_item_data, size_t shell_item_data_size, int ascii_codepage, libcerror_error_t **error ) { static char *function = "libfwsi_volume_values_read"; size_t shell_item_data_offset = 0; size_t string_size = 0; uint8_t class_type_indicator = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t guid_string[ 48 ]; libcstring_system_character_t *value_string = NULL; libfguid_identifier_t *guid = NULL; size_t value_string_size = 0; uint16_t value_16bit = 0; int result = 0; #endif if( volume_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume values.", function ); return( -1 ); } if( shell_item_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid shell item data.", function ); return( -1 ); } if( shell_item_data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: shell item data size exceeds maximum.", function ); return( -1 ); } /* Do not try to parse unsupported shell item data sizes */ if( shell_item_data_size < 20 ) { return( 0 ); } /* Do not try to parse unknown class type indicators */ if( ( shell_item_data[ 2 ] != 0x23 ) && ( shell_item_data[ 2 ] != 0x25 ) && ( shell_item_data[ 2 ] != 0x29 ) && ( shell_item_data[ 2 ] != 0x2a ) && ( shell_item_data[ 2 ] != 0x2e ) && ( shell_item_data[ 2 ] != 0x2f ) ) { return( 0 ); } class_type_indicator = shell_item_data[ 2 ]; volume_values->ascii_codepage = ascii_codepage; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( libfguid_identifier_initialize( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create GUID.", function ); goto on_error; } } #endif if( class_type_indicator == 0x2e ) { #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unknown1\t\t\t\t\t: 0x%02" PRIx8 "\n", function, shell_item_data[ 3 ] ); } #endif volume_values->has_name = 0; if( memory_copy( volume_values->identifier, &( shell_item_data[ 4 ] ), 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy volume identifier.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( libfguid_identifier_copy_from_byte_stream( guid, volume_values->identifier, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } libcnotify_printf( "%s: shell folder identifier\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); libcnotify_printf( "%s: shell folder name\t\t\t\t: %s\n", function, libfwsi_shell_folder_identifier_get_name( volume_values->identifier ) ); } #endif shell_item_data_offset = 20; } else { /* Do not try to parse unsupported shell item data sizes */ if( shell_item_data_size < 25 ) { return( 0 ); } volume_values->has_name = 1; if( memory_copy( volume_values->name, &( shell_item_data[ 3 ] ), 20 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy volume name.", function ); goto on_error; } for( string_size = 0; string_size < 20; string_size++ ) { if( volume_values->name[ string_size ] == 0 ) { break; } } volume_values->name_size = string_size; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( volume_values->name, volume_values->name_size, volume_values->ascii_codepage, &value_string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( volume_values->name, volume_values->name_size, volume_values->ascii_codepage, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of volume name string.", function ); goto on_error; } if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( libcstring_system_character_t ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid volume name string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create volume name string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) value_string, value_string_size, volume_values->name, volume_values->name_size, volume_values->ascii_codepage, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) value_string, value_string_size, volume_values->name, volume_values->name_size, volume_values->ascii_codepage, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set volume name string.", function ); goto on_error; } libcnotify_printf( "%s: volume name\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { byte_stream_copy_to_uint16_little_endian( &( shell_item_data[ 23 ] ), value_16bit ); libcnotify_printf( "%s: unknown2\t\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); } #endif shell_item_data_offset = 25; if( shell_item_data_offset <= ( shell_item_data_size - 16 ) ) { if( memory_copy( volume_values->shell_folder_identifier, &( shell_item_data[ shell_item_data_offset ] ), 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy shell folder identifier.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( libfguid_identifier_copy_from_byte_stream( guid, volume_values->shell_folder_identifier, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } libcnotify_printf( "%s: shell folder identifier\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); libcnotify_printf( "%s: shell folder name\t\t\t\t: %s\n", function, libfwsi_shell_folder_identifier_get_name( &( shell_item_data[ shell_item_data_offset ] ) ) ); } #endif shell_item_data_offset += 16; } } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( libfguid_identifier_free( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free GUID.", function ); goto on_error; } libcnotify_printf( "\n" ); } #endif return( (ssize_t) shell_item_data_offset ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( guid != NULL ) { libfguid_identifier_free( &guid, NULL ); } if( value_string != NULL ) { memory_free( value_string ); } #endif return( -1 ); }
/* Prints the byte stream data to the notify stream * Returns 1 if successful or -1 on error */ int libewf_debug_byte_stream_print( const char *header_string, const uint8_t *byte_stream, size_t byte_stream_size, libcerror_error_t **error ) { libcstring_system_character_t *string = NULL; static char *function = "libewf_debug_byte_stream_print"; size_t string_size = 0; int result = 0; if( header_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid header string.", function ); return( -1 ); } if( byte_stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid byte stream.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( byte_stream, byte_stream_size, LIBUNA_CODEPAGE_ASCII, &string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( byte_stream, byte_stream_size, LIBUNA_CODEPAGE_ASCII, &string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine string size.", function ); return( -1 ); } string = libcstring_system_string_allocate( string_size ); if( string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create string.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (uint16_t *) string, string_size, byte_stream, byte_stream_size, LIBUNA_CODEPAGE_ASCII, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (uint8_t *) string, string_size, byte_stream, byte_stream_size, LIBUNA_CODEPAGE_ASCII, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy string from byte stream.", function ); memory_free( string ); return( -1 ); } libcnotify_printf( "%s:\n" "%" PRIs_LIBCSTRING_SYSTEM "", header_string, string ); memory_free( string ); return( 1 ); }
/* Reads a data block strings * Returns the number of bytes read if successful or -1 on error */ int liblnk_data_block_strings_read( liblnk_data_string_t *data_string, liblnk_data_block_t *data_block, liblnk_io_handle_t *io_handle, libcerror_error_t **error ) { lnk_data_block_strings_t *data_block_strings_data = NULL; static char *function = "liblnk_data_block_strings_read"; size_t string_size = 0; size_t unicode_string_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t *value_string = NULL; size_t value_string_size = 0; int result = 0; #endif if( data_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid data string.", function ); return( -1 ); } if( data_string->data != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid data string - data already set.", function ); return( -1 ); } if( data_block == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid data block.", function ); return( -1 ); } if( data_block->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid data block - missing data.", function ); return( -1 ); } if( data_block->data_size < sizeof( lnk_data_block_strings_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid data block - data size too small.", function ); return( -1 ); } data_block_strings_data = (lnk_data_block_strings_t *) data_block->data; if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } for( string_size = 0; string_size < 260; string_size++ ) { if( data_block_strings_data->string[ string_size ] == 0 ) { break; } } if( ( string_size == 260 ) || ( data_block_strings_data->string[ string_size ] != 0 ) ) { #if defined( HAVE_VERBOSE_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unsupported data block strings\n" ); } #endif string_size = 0; } else { string_size += 1; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string data:\n", function ); libcnotify_print_data( data_block_strings_data->string, 260, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( data_block_strings_data->string, 260, io_handle->ascii_codepage, &value_string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( data_block_strings_data->string, 260, io_handle->ascii_codepage, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of string.", function ); goto on_error; } if( ( value_string_size > (size_t) SSIZE_MAX ) || ( ( sizeof( libcstring_system_character_t ) * value_string_size ) > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) value_string, value_string_size, data_block_strings_data->string, 260, io_handle->ascii_codepage, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) value_string, value_string_size, data_block_strings_data->string, 260, io_handle->ascii_codepage, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif for( unicode_string_size = 0; unicode_string_size < 520; unicode_string_size += 2 ) { if( ( data_block_strings_data->unicode_string[ unicode_string_size ] == 0 ) && ( data_block_strings_data->unicode_string[ unicode_string_size + 1 ] == 0 ) ) { break; } } if( ( unicode_string_size == 520 ) || ( data_block_strings_data->unicode_string[ unicode_string_size ] != 0 ) || ( data_block_strings_data->unicode_string[ unicode_string_size + 1 ] != 0 ) ) { #if defined( HAVE_VERBOSE_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unsupported unicode string\n" ); } #endif unicode_string_size = 0; } else { unicode_string_size += 2; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unicode string data:\n", function ); libcnotify_print_data( data_block_strings_data->unicode_string, 520, LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( data_block_strings_data->unicode_string, 520, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( data_block_strings_data->unicode_string, 520, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of unicode string.", function ); goto on_error; } if( ( value_string_size > (size_t) SSIZE_MAX ) || ( ( sizeof( libcstring_system_character_t ) * value_string_size ) > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid unicode string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create unicode string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, data_block_strings_data->unicode_string, 520, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, data_block_strings_data->unicode_string, 520, LIBUNA_ENDIAN_LITTLE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set unicode string.", function ); goto on_error; } libcnotify_printf( "%s: unicode string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; libcnotify_printf( "\n" ); } #endif if( unicode_string_size > 0 ) { data_string->data_size = unicode_string_size; data_string->data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * data_string->data_size ); if( data_string->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create data string data.", function ); goto on_error; } if( memory_copy( data_string->data, data_block_strings_data->unicode_string, data_string->data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy unicode string data.", function ); goto on_error; } data_string->is_unicode = 1; } else if( string_size > 0 ) { data_string->data_size = string_size; data_string->data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * data_string->data_size ); if( data_string->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create data string data.", function ); goto on_error; } if( memory_copy( data_string->data, data_block_strings_data->string, data_string->data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy string data.", function ); goto on_error; } data_string->is_unicode = 0; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( data_block->data_size > sizeof( lnk_data_block_strings_t ) ) { libcnotify_printf( "%s: trailing data:\n", function ); libcnotify_print_data( &( data_block->data[ sizeof( lnk_data_block_strings_t ) ] ), data_block->data_size - sizeof( lnk_data_block_strings_t ), LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } } #endif return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } #endif if( data_string->data != NULL ) { memory_free( data_string->data ); data_string->data = NULL; } data_string->data_size = 0; return( -1 ); }
/* Retrieves the size of the UTF-8 formatted name * The returned size includes the end of string character * Returns 1 if successful or -1 on error */ int libexe_section_get_utf8_name_size( libexe_section_t *section, size_t *utf8_string_size, libcerror_error_t **error ) { libexe_internal_section_t *internal_section = NULL; static char *function = "libexe_section_get_utf8_name_size"; if( section == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid section.", function ); return( -1 ); } internal_section = (libexe_internal_section_t *) section; if( internal_section->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid section - missing IO handle.", function ); return( -1 ); } if( internal_section->section_descriptor == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid section - missing section descriptor.", function ); return( -1 ); } if( libuna_utf8_string_size_from_byte_stream( (uint8_t *) internal_section->section_descriptor->name, internal_section->section_descriptor->name_size, internal_section->io_handle->ascii_codepage, utf8_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve UTF-8 string size.", function ); return( -1 ); } return( 1 ); }
/* Reads distributed link tracker properties * Returns the number of bytes read if successful or -1 on error */ int liblnk_distributed_link_tracker_properties_read( liblnk_distributed_link_tracker_properties_t *distributed_link_tracker_properties, liblnk_data_block_t *data_block, liblnk_io_handle_t *io_handle, libcerror_error_t **error ) { lnk_data_block_distributed_link_tracker_properties_t *distributed_link_tracker_properties_data = NULL; static char *function = "liblnk_distributed_link_tracker_properties_read"; uint32_t data_size = 0; uint32_t data_version = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t guid_string[ 48 ]; libcstring_system_character_t *value_string = NULL; libfguid_identifier_t *guid = NULL; size_t value_string_size = 0; int result = 0; #endif if( distributed_link_tracker_properties == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid distributed link tracker properties.", function ); return( -1 ); } if( data_block == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid data block.", function ); return( -1 ); } if( data_block->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid data block - missing data.", function ); return( -1 ); } if( data_block->data_size < sizeof( lnk_data_block_distributed_link_tracker_properties_t ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid data block - data size too small.", function ); return( -1 ); } distributed_link_tracker_properties_data = (lnk_data_block_distributed_link_tracker_properties_t *) data_block->data; if( io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid IO handle.", function ); return( -1 ); } byte_stream_copy_to_uint32_little_endian( distributed_link_tracker_properties_data->data_size, data_size ); byte_stream_copy_to_uint32_little_endian( distributed_link_tracker_properties_data->data_version, data_version ); if( data_version != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported data version: %" PRIu32 ".", function, data_version ); goto on_error; } /* TODO check if data size matches data block size */ if( data_size < 88 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: unsupported data size: %" PRIu32 ".", function, data_size ); goto on_error; } if( memory_copy( distributed_link_tracker_properties->machine_identifier_string, distributed_link_tracker_properties_data->machine_identifier_string, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy machine identifier string.", function ); goto on_error; } if( memory_copy( distributed_link_tracker_properties->droid_volume_identifier, distributed_link_tracker_properties_data->droid_volume_identifier, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy droid volume identifier.", function ); goto on_error; } if( memory_copy( distributed_link_tracker_properties->droid_file_identifier, distributed_link_tracker_properties_data->droid_file_identifier, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy droid file identifier.", function ); goto on_error; } if( memory_copy( distributed_link_tracker_properties->birth_droid_volume_identifier, distributed_link_tracker_properties_data->birth_droid_volume_identifier, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy birth droid volume identifier.", function ); goto on_error; } if( memory_copy( distributed_link_tracker_properties->birth_droid_file_identifier, distributed_link_tracker_properties_data->birth_droid_file_identifier, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy birth droid file identifier.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: data size\t\t\t: %" PRIu32 "\n", function, data_size ); libcnotify_printf( "%s: data version\t\t\t: %" PRIu32 "\n", function, data_version ); libcnotify_printf( "%s: machine identifier string data:\n", function ); libcnotify_print_data( distributed_link_tracker_properties_data->machine_identifier_string, 16, 0 ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_byte_stream( distributed_link_tracker_properties_data->machine_identifier_string, 16, io_handle->ascii_codepage, &value_string_size, error ); #else result = libuna_utf8_string_size_from_byte_stream( distributed_link_tracker_properties_data->machine_identifier_string, 16, io_handle->ascii_codepage, &value_string_size, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of machine identifier string.", function ); goto on_error; } if( ( value_string_size > (size_t) SSIZE_MAX ) || ( ( sizeof( libcstring_system_character_t ) * value_string_size ) > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid machine identifier string size value exceeds maximum.", function ); goto on_error; } value_string = libcstring_system_string_allocate( value_string_size ); if( value_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create machine identifier string.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_byte_stream( (libuna_utf16_character_t *) value_string, value_string_size, distributed_link_tracker_properties_data->machine_identifier_string, 16, io_handle->ascii_codepage, error ); #else result = libuna_utf8_string_copy_from_byte_stream( (libuna_utf8_character_t *) value_string, value_string_size, distributed_link_tracker_properties_data->machine_identifier_string, 16, io_handle->ascii_codepage, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set machine identifier string.", function ); goto on_error; } libcnotify_printf( "%s: machine identifier string\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; if( libfguid_identifier_initialize( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create GUID.", function ); goto on_error; } if( libfguid_identifier_copy_from_byte_stream( guid, distributed_link_tracker_properties->droid_volume_identifier, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } libcnotify_printf( "%s: droid volume identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); if( libfguid_identifier_copy_from_byte_stream( guid, distributed_link_tracker_properties->droid_file_identifier, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } libcnotify_printf( "%s: droid file identifier\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); if( libfguid_identifier_copy_from_byte_stream( guid, distributed_link_tracker_properties->birth_droid_volume_identifier, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } libcnotify_printf( "%s: birth droid volume identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); if( libfguid_identifier_copy_from_byte_stream( guid, distributed_link_tracker_properties->birth_droid_file_identifier, 16, LIBFGUID_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to GUID.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfguid_identifier_copy_to_utf16_string( guid, (uint16_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #else result = libfguid_identifier_copy_to_utf8_string( guid, (uint8_t *) guid_string, 48, LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy GUID to string.", function ); goto on_error; } libcnotify_printf( "%s: birth droid file identifier\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, guid_string ); libcnotify_printf( "\n" ); if( libfguid_identifier_free( &guid, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free GUID.", function ); goto on_error; } } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( data_block->data_size > sizeof( lnk_data_block_distributed_link_tracker_properties_t ) ) { libcnotify_printf( "%s: trailing data:\n", function ); libcnotify_print_data( &( data_block->data[ sizeof( lnk_data_block_distributed_link_tracker_properties_t ) ] ), data_block->data_size - sizeof( lnk_data_block_distributed_link_tracker_properties_t ), 0 ); } } #endif return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( guid != NULL ) { libfguid_identifier_free( &guid, NULL ); } if( value_string != NULL ) { memory_free( value_string ); } #endif return( -1 ); }