/* Retrieves the size of the UTF-16 encoded name * The returned size includes the end of string character * Returns 1 if successful or -1 on error */ int libfsntfs_volume_name_values_get_utf16_name_size( libfsntfs_volume_name_values_t *volume_name_values, size_t *utf16_name_size, libcerror_error_t **error ) { static char *function = "libfsntfs_volume_name_values_get_utf16_name_size"; if( volume_name_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume name values.", function ); return( -1 ); } if( volume_name_values->name_size == 0 ) { if( utf16_name_size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-16 name size.", function ); return( -1 ); } *utf16_name_size = 0; } else { if( libuna_utf16_string_size_from_utf16_stream( volume_name_values->name, (size_t) volume_name_values->name_size, LIBUNA_ENDIAN_LITTLE, utf16_name_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve UTF-16 string size.", function ); return( -1 ); } } return( 1 ); }
/* Retrieves the size of the UTF-16 formatted fallback language * Returns 1 if successful, 0 if not available or -1 on error */ int libwrc_mui_get_utf16_fallback_language_size( libwrc_resource_t *resource, uint32_t language_identifier, size_t *utf16_string_size, libcerror_error_t **error ) { libwrc_mui_values_t *mui_values = NULL; static char *function = "libwrc_mui_get_utf16_fallback_language_size"; if( libwrc_resource_get_value_by_language_identifier( resource, LIBWRC_RESOURCE_TYPE_MUI, language_identifier, 0, (intptr_t **) &mui_values, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve MUI values.", function ); return( -1 ); } /* TODO move to mui values function */ if( mui_values->fallback_language_size == 0 ) { return( 0 ); } if( libuna_utf16_string_size_from_utf16_stream( mui_values->fallback_language, mui_values->fallback_language_size, LIBUNA_ENDIAN_LITTLE, utf16_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine size of fallback language string.", function ); return( -1 ); } return( 1 ); }
/* Determines the UTF-16 string size from the value data * Returns 1 if successful or -1 on error */ int libregf_value_type_get_utf16_string_size( uint8_t *value_data, size_t value_data_size, size_t *utf16_string_size, libcerror_error_t **error ) { static char *function = "libregf_value_type_get_utf16_string_size"; if( utf16_string_size == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-16 string size.", function ); return( -1 ); } /* Internally an empty string is represented by a NULL reference */ if( value_data == NULL ) { *utf16_string_size = 0; } else { if( libuna_utf16_string_size_from_utf16_stream( value_data, value_data_size, LIBUNA_ENDIAN_LITTLE, utf16_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine UTF-16 string size.", function ); return( -1 ); } } return( 1 ); }
/* Retrieves the size of the UTF-16 encoded print name * The returned size includes the end of string character * Returns 1 if successful, 0 if not available or -1 on error */ int libfsntfs_reparse_point_values_get_utf16_print_name_size( libfsntfs_reparse_point_values_t *reparse_point_values, size_t *utf16_name_size, libcerror_error_t **error ) { static char *function = "libfsntfs_reparse_point_values_get_utf16_print_name_size"; if( reparse_point_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid reparse point values.", function ); return( -1 ); } if( reparse_point_values->print_name_size == 0 ) { return( 0 ); } if( libuna_utf16_string_size_from_utf16_stream( &( reparse_point_values->reparse_data[ reparse_point_values->print_name_offset ] ), (size_t) reparse_point_values->print_name_size, LIBUNA_ENDIAN_LITTLE, utf16_name_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve UTF-16 string size.", function ); return( -1 ); } return( 1 ); }
/* Retrieves the size of the UTF-16 encoded device path * The returned size includes the end of string character * Returns 1 if successful or -1 on error */ int libscca_volume_information_get_utf16_device_path_size( libscca_volume_information_t *volume_information, size_t *utf16_string_size, libcerror_error_t **error ) { libscca_internal_volume_information_t *internal_volume_information = NULL; static char *function = "libscca_volume_information_get_utf16_device_path_size"; if( volume_information == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume information.", function ); return( -1 ); } internal_volume_information = (libscca_internal_volume_information_t *) volume_information; if( libuna_utf16_string_size_from_utf16_stream( internal_volume_information->device_path, internal_volume_information->device_path_size, LIBUNA_ENDIAN_LITTLE, utf16_string_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve device path UTF-16 string size.", function ); return( -1 ); } return( 1 ); }
/* Prints an UTF-16 string value * Returns 1 if successful or -1 on error */ int libregf_debug_print_utf16_string_value( const char *function_name, const char *value_name, const uint8_t *byte_stream, size_t byte_stream_size, int byte_order, libcerror_error_t **error ) { system_character_t *string = NULL; static char *function = "libregf_debug_print_utf16_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_utf16_stream( byte_stream, byte_stream_size, byte_order, &string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( byte_stream, byte_stream_size, byte_order, &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_utf16_stream( (libuna_utf16_character_t *) string, string_size, byte_stream, byte_stream_size, byte_order, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) string, string_size, byte_stream, byte_stream_size, byte_order, 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 ); }
/* Retrieves the UTF-16 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_utf16_string_size( libpff_name_to_id_map_entry_t *name_to_id_map_entry, size_t *utf16_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_utf16_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_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, utf16_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-16 string size.", function ); return( -1 ); } } else { if( libuna_utf16_string_size_from_byte_stream( internal_name_to_id_map_entry->string_value, internal_name_to_id_map_entry->value_size, LIBUNA_CODEPAGE_ASCII, utf16_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-16 string size.", function ); return( -1 ); } } return( 1 ); }
/* Reads the compressed folder values * Returns the number of bytes read if successful, 0 if not able to read or -1 on error */ ssize_t libfwsi_compressed_folder_values_read( libfwsi_compressed_folder_values_t *compressed_folder_values, const uint8_t *shell_item_data, size_t shell_item_data_size, libcerror_error_t **error ) { static char *function = "libfwsi_compressed_folder_values_read"; size_t shell_item_data_offset = 0; uint32_t string_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t date_time_string[ 32 ]; libcstring_system_character_t *value_string = NULL; libfdatetime_fat_date_time_t *fat_date_time = NULL; size_t value_string_size = 0; uint64_t value_64bit = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; int result = 0; #endif if( compressed_folder_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid compressed folder 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 < 6 ) { return( 0 ); } /* Do not try to parse unknown class type indicators */ if( shell_item_data[ 2 ] != 0x52 ) { return( 0 ); } /* TODO: other variants not supported yet */ if( ( shell_item_data[ 3 ] != 0x67 ) || ( shell_item_data[ 4 ] != 0xb1 ) || ( shell_item_data[ 5 ] != 0xac ) ) { return( 0 ); } if( ( shell_item_data[ 3 ] == 0x67 ) && ( shell_item_data[ 4 ] == 0xb1 ) && ( shell_item_data[ 5 ] == 0xac ) ) { if( shell_item_data_size < 50 ) { return( 0 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", function, shell_item_data[ 3 ] ); byte_stream_copy_to_uint16_little_endian( &( shell_item_data[ 4 ] ), value_16bit ); libcnotify_printf( "%s: unknown2\t\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 6 ] ), value_32bit ); libcnotify_printf( "%s: unknown3\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint64_little_endian( &( shell_item_data[ 10 ] ), value_64bit ); libcnotify_printf( "%s: unknown4\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 18 ] ), value_32bit ); libcnotify_printf( "%s: unknown5\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 22 ] ), value_32bit ); libcnotify_printf( "%s: unknown6\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( libfdatetime_fat_date_time_initialize( &fat_date_time, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create FAT date time.", function ); goto on_error; } if( libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, &( shell_item_data[ 26 ] ), 4, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to FAT date time.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy FAT date time to string.", function ); goto on_error; } libcnotify_printf( "%s: unknown time\t\t\t: %" PRIs_LIBCSTRING_SYSTEM " UTC\n", function, date_time_string ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 30 ] ), value_32bit ); libcnotify_printf( "%s: unknown7\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); if( libfdatetime_fat_date_time_copy_from_byte_stream( fat_date_time, &( shell_item_data[ 34 ] ), 4, LIBFDATETIME_ENDIAN_LITTLE, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy byte stream to FAT date time.", function ); goto on_error; } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libfdatetime_fat_date_time_copy_to_utf16_string( fat_date_time, (uint16_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #else result = libfdatetime_fat_date_time_copy_to_utf8_string( fat_date_time, (uint8_t *) date_time_string, 32, LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy FAT date time to string.", function ); goto on_error; } libcnotify_printf( "%s: unknown time\t\t\t: %" PRIs_LIBCSTRING_SYSTEM " UTC\n", function, date_time_string ); if( libfdatetime_fat_date_time_free( &fat_date_time, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free FAT date time.", function ); goto on_error; } byte_stream_copy_to_uint64_little_endian( &( shell_item_data[ 38 ] ), value_64bit ); libcnotify_printf( "%s: unknown8\t\t\t\t: 0x%08" PRIx64 "\n", function, value_64bit ); } #endif shell_item_data_offset = 46; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_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_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_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_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_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_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ shell_item_data_offset ] ), string_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: string size\t\t\t: %" PRIu32 "\n", function, string_size ); } #endif shell_item_data_offset += 4; string_size *= 2; if( ( string_size > 0 ) && ( string_size <= shell_item_data_size ) && ( shell_item_data_offset <= ( shell_item_data_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_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: string\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( (ssize_t) shell_item_data_offset ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } if( fat_date_time != NULL ) { libfdatetime_fat_date_time_free( &fat_date_time, NULL ); } #endif return( -1 ); }
/* Retrieves the size of the UTF-16 encoded name of the referenced item * The returned size includes the end of string character * Returns 1 if successful or -1 on error */ int libolecf_item_get_utf16_name_size( libolecf_item_t *item, size_t *utf16_name_size, libcerror_error_t **error ) { libolecf_internal_item_t *internal_item = NULL; static char *function = "libolecf_item_get_utf16_name_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 = (libolecf_internal_item_t *) item; if( internal_item->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid item - missing IO handle.", function ); return( -1 ); } if( internal_item->directory_entry == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid item - missing directory entry.", function ); return( -1 ); } if( libuna_utf16_string_size_from_utf16_stream( internal_item->directory_entry->name, internal_item->directory_entry->name_size, internal_item->io_handle->byte_order, utf16_name_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine UTF-16 name size.", function ); return( -1 ); } return( 1 ); }
/* Reads the volume name values * Returns 1 if successful or -1 on error */ int libfsntfs_volume_name_values_read( libfsntfs_volume_name_values_t *volume_name_values, const uint8_t *data, size_t data_size, libcerror_error_t **error ) { static char *function = "libfsntfs_volume_name_values_read"; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t *value_string = NULL; size_t value_string_size = 0; int result = 0; #endif if( volume_name_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume name values.", function ); return( -1 ); } /* The size of the data can be 0 if the name is not set. */ if( data_size == 0 ) { return( 1 ); } if( data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid data.", function ); goto on_error; } if( data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid data size value out of bounds.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: volume name data:\n", function ); libcnotify_print_data( data, data_size, 0 ); } #endif if( data_size > 0 ) { volume_name_values->name = (uint8_t *) memory_allocate( sizeof( uint8_t ) * data_size ); if( volume_name_values->name == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create name.", function ); goto on_error; } volume_name_values->name_size = data_size; if( memory_copy( volume_name_values->name, data, volume_name_values->name_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy volume name.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( volume_name_values->name, volume_name_values->name_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( volume_name_values->name, volume_name_values->name_size, 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 name string.", 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 name 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, volume_name_values->name, volume_name_values->name_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, volume_name_values->name, volume_name_values->name_size, 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 name string.", function ); goto on_error; } libcnotify_printf( "%s: name\t\t\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; libcnotify_printf( "\n" ); } #endif } return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } #endif if( volume_name_values->name != NULL ) { memory_free( volume_name_values->name ); volume_name_values->name = NULL; } volume_name_values->name_size = 0; 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 ); }
/* 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 ); }
/* Retrieves the size of the UTF-16 formatted localized name * Returns 1 if successful, 0 if not available or -1 on error */ int libfwsi_file_entry_extension_get_utf16_localized_name_size( libfwsi_extension_block_t *extension_block, size_t *utf16_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_utf16_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_utf16_string_size_from_utf16_stream( file_entry_extension_values->localized_name, file_entry_extension_values->localized_name_size, LIBUNA_ENDIAN_LITTLE, utf16_string_size, error ); } else if( internal_extension_block->version >= 3 ) { result = libuna_utf16_string_size_from_byte_stream( file_entry_extension_values->localized_name, file_entry_extension_values->localized_name_size, file_entry_extension_values->ascii_codepage, utf16_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-16 string.", function ); return( -1 ); } return( 1 ); }
/* Reads the channel * Returns 1 if successful or -1 on error */ int libfwevt_channel_read( libfwevt_channel_t *channel, const uint8_t *data, size_t data_size, size_t data_offset, libcerror_error_t **error ) { libfwevt_internal_channel_t *internal_channel = NULL; fwevt_template_channel_t *wevt_channel = NULL; static char *function = "libfwevt_channel_read"; uint32_t channel_data_offset = 0; uint32_t channel_data_size = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t *value_string = NULL; size_t value_string_size = 0; uint32_t value_32bit = 0; int result = 0; #endif if( channel == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid channel.", function ); return( -1 ); } internal_channel = (libfwevt_internal_channel_t *) channel; if( data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid data.", function ); return( -1 ); } if( data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid data size value exceeds maximum.", function ); return( -1 ); } if( data_offset >= data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid data offset value out of bounds.", function ); return( -1 ); } if( ( data_size < sizeof( fwevt_template_channel_t ) ) || ( data_offset > ( data_size - sizeof( fwevt_template_channel_t ) ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: invalid data value too small.", function ); return( -1 ); } wevt_channel = (fwevt_template_channel_t *) &( data[ data_offset ] ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: channel data:\n", function ); libcnotify_print_data( (uint8_t *) wevt_channel, sizeof( fwevt_template_channel_t ), 0 ); } #endif byte_stream_copy_to_uint32_little_endian( wevt_channel->identifier, internal_channel->identifier ); byte_stream_copy_to_uint32_little_endian( wevt_channel->data_offset, channel_data_offset ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: identifier\t\t\t\t\t: %" PRIu32 "\n", function, internal_channel->identifier ); libcnotify_printf( "%s: data offset\t\t\t\t\t: 0x%08" PRIx32 "\n", function, channel_data_offset ); byte_stream_copy_to_uint32_little_endian( wevt_channel->unknown1, value_32bit ); libcnotify_printf( "%s: unknown1\t\t\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( wevt_channel->message_identifier, value_32bit ); libcnotify_printf( "%s: message identifier\t\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); } #endif if( channel_data_offset > 0 ) { if( channel_data_offset >= data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid channel data offset value out of bounds.", function ); goto on_error; } if( ( channel_data_size > data_size ) || ( ( channel_data_offset + channel_data_size ) > data_size ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid channel data size value out of bounds.", function ); goto on_error; } byte_stream_copy_to_uint32_little_endian( &( data[ channel_data_offset ] ), channel_data_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: data:\n", function ); libcnotify_print_data( &( data[ channel_data_offset ] ), channel_data_size, 0 ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: data size\t\t\t\t\t: %" PRIu32 "\n", function, channel_data_size ); } channel_data_offset += 4; channel_data_size -= 4; #endif #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( data[ channel_data_offset ] ), channel_data_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( data[ channel_data_offset ] ), channel_data_size, 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 data 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 data 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 data 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[ channel_data_offset ] ), channel_data_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( data[ channel_data_offset ] ), channel_data_size, 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 data string.", function ); goto on_error; } libcnotify_printf( "%s: name\t\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 ) { libcnotify_printf( "\n" ); } #endif return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } #endif return( -1 ); }
/* Reads the control panel CPL file values * Returns the number of bytes read if successful, 0 if not able to read or -1 on error */ ssize_t libfwsi_control_panel_cpl_file_values_read( libfwsi_control_panel_cpl_file_values_t *control_panel_cpl_file_values, const uint8_t *shell_item_data, size_t shell_item_data_size, libcerror_error_t **error ) { static char *function = "libfwsi_control_panel_cpl_file_values_read"; size_t shell_item_data_offset = 0; size_t string_size = 0; uint32_t signature = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t *value_string = NULL; size_t value_string_size = 0; uint32_t value_32bit = 0; uint16_t value_16bit = 0; int result = 0; #endif if( control_panel_cpl_file_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid control panel CPL file 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 < 24 ) { return( 0 ); } /* Do not try to parse unsupported shell item signatures */ byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 4 ] ), signature ); if( signature != 0xffffff38UL ) { return( 0 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: class type indicator\t: 0x%02" PRIx8 "\n", function, shell_item_data[ 2 ] ); libcnotify_printf( "%s: unknown1\t\t\t: 0x%02" PRIx8 "\n", function, shell_item_data[ 3 ] ); libcnotify_printf( "%s: signature\t\t\t: 0x%08" PRIx32 "\n", function, signature ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 8 ] ), value_32bit ); libcnotify_printf( "%s: unknown2\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 12 ] ), value_32bit ); libcnotify_printf( "%s: unknown3\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint32_little_endian( &( shell_item_data[ 16 ] ), value_32bit ); libcnotify_printf( "%s: unknown4\t\t\t: 0x%08" PRIx32 "\n", function, value_32bit ); byte_stream_copy_to_uint16_little_endian( &( shell_item_data[ 20 ] ), value_16bit ); libcnotify_printf( "%s: unknown5\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); byte_stream_copy_to_uint16_little_endian( &( shell_item_data[ 22 ] ), value_16bit ); libcnotify_printf( "%s: unknown6\t\t\t: 0x%04" PRIx16 "\n", function, value_16bit ); } #endif shell_item_data_offset = 24; if( shell_item_data_offset <= ( shell_item_data_size - 2 ) ) { for( string_size = shell_item_data_offset; string_size < shell_item_data_size; string_size += 2 ) { if( shell_item_data[ string_size ] == 0 ) { string_size += 2; break; } } string_size -= shell_item_data_offset; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: CPL file path\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } if( shell_item_data_offset <= ( shell_item_data_size - 2 ) ) { for( string_size = shell_item_data_offset; string_size < shell_item_data_size; string_size += 2 ) { if( shell_item_data[ string_size ] == 0 ) { string_size += 2; break; } } string_size -= shell_item_data_offset; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: name\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } if( shell_item_data_offset <= ( shell_item_data_size - 2 ) ) { for( string_size = shell_item_data_offset; string_size < shell_item_data_size; string_size += 2 ) { if( shell_item_data[ string_size ] == 0 ) { string_size += 2; break; } } string_size -= shell_item_data_offset; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value 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 value 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 value 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, &( shell_item_data[ shell_item_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( shell_item_data[ shell_item_data_offset ] ), string_size, 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 value string.", function ); goto on_error; } libcnotify_printf( "%s: comments\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif shell_item_data_offset += string_size; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( (ssize_t) shell_item_data_offset ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } #endif return( -1 ); }
/* Prints the UTF-16 data to the notify stream * Returns 1 if successful or -1 on error */ int libewf_debug_utf16_stream_print( const char *header_string, const uint8_t *utf16_stream, size_t utf16_stream_size, libcerror_error_t **error ) { libcstring_system_character_t *string = NULL; static char *function = "libewf_debug_utf16_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( utf16_stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid UTF-16 stream.", function ); return( -1 ); } #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( utf16_stream, utf16_stream_size, LIBUNA_ENDIAN_LITTLE, &string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( utf16_stream, utf16_stream_size, LIBUNA_ENDIAN_LITTLE, &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_utf16_stream( (uint16_t *) string, string_size, utf16_stream, utf16_stream_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (uint8_t *) string, string_size, utf16_stream, utf16_stream_size, LIBUNA_ENDIAN_LITTLE, error ); #endif if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy string from UTF-16 stream.", function ); memory_free( string ); return( -1 ); } libcnotify_printf( "%s:\n" "%" PRIs_LIBCSTRING_SYSTEM "", header_string, string ); memory_free( string ); return( 1 ); }
/* Reads the reparse point values * Returns 1 if successful or -1 on error */ int libfsntfs_reparse_point_values_read_data( libfsntfs_reparse_point_values_t *reparse_point_values, const uint8_t *data, size_t data_size, libcerror_error_t **error ) { static char *function = "libfsntfs_reparse_point_values_read_data"; uint32_t flags = 0; #if defined( HAVE_DEBUG_OUTPUT ) system_character_t *value_string = NULL; size_t value_string_size = 0; int result = 0; #endif if( reparse_point_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid reparse point values.", function ); return( -1 ); } if( data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid data.", function ); return( -1 ); } if( data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid data size value out of bounds.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: reparse point data:\n", function ); libcnotify_print_data( data, data_size, 0 ); } #endif byte_stream_copy_to_uint32_little_endian( ( (fsntfs_reparse_point_t *) data )->tag, reparse_point_values->tag ); byte_stream_copy_to_uint16_little_endian( ( (fsntfs_reparse_point_t *) data )->reparse_data_size, reparse_point_values->reparse_data_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: tag\t\t\t\t: 0x%08" PRIx32 "\n", function, reparse_point_values->tag ); libfsntfs_debug_print_reparse_point_tag( reparse_point_values->tag ); libcnotify_printf( "\n" ); libcnotify_printf( "%s: reparse data size\t\t: %" PRIu16 "\n", function, reparse_point_values->reparse_data_size ); libcnotify_printf( "\n" ); } #endif if( reparse_point_values->reparse_data_size > 0 ) { if( ( sizeof( fsntfs_reparse_point_t ) > data_size ) || ( (size_t) reparse_point_values->reparse_data_size > ( data_size - sizeof( fsntfs_reparse_point_t ) ) ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid reparse data size value out of bounds.", function ); goto on_error; } reparse_point_values->reparse_data = (uint8_t *) memory_allocate( sizeof( uint8_t ) * reparse_point_values->reparse_data_size ); if( reparse_point_values->reparse_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create reparse data.", function ); goto on_error; } if( memory_copy( reparse_point_values->reparse_data, &( data[ sizeof( fsntfs_reparse_point_t ) ] ), (size_t) reparse_point_values->reparse_data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy reparse data.", function ); goto on_error; } } if( ( reparse_point_values->tag == 0xa0000003 ) || ( reparse_point_values->tag == 0xa000000c ) ) { byte_stream_copy_to_uint16_little_endian( ( (fsntfs_mount_point_reparse_data_t *) reparse_point_values->reparse_data )->substitute_name_offset, reparse_point_values->substitute_name_offset ); byte_stream_copy_to_uint16_little_endian( ( (fsntfs_mount_point_reparse_data_t *) reparse_point_values->reparse_data )->substitute_name_size, reparse_point_values->substitute_name_size ); byte_stream_copy_to_uint16_little_endian( ( (fsntfs_mount_point_reparse_data_t *) reparse_point_values->reparse_data )->print_name_offset, reparse_point_values->print_name_offset ); byte_stream_copy_to_uint16_little_endian( ( (fsntfs_mount_point_reparse_data_t *) reparse_point_values->reparse_data )->print_name_size, reparse_point_values->print_name_size ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: substitute name offset\t: 0x%04" PRIx16 "\n", function, reparse_point_values->substitute_name_offset ); libcnotify_printf( "%s: substitute name size\t\t: %" PRIu16 "\n", function, reparse_point_values->substitute_name_size ); libcnotify_printf( "%s: print name offset\t\t: 0x%04" PRIx16 "\n", function, reparse_point_values->print_name_offset ); libcnotify_printf( "%s: print name size\t\t: %" PRIu16 "\n", function, reparse_point_values->print_name_size ); } #endif } if( reparse_point_values->tag == 0xa0000003 ) { reparse_point_values->substitute_name_offset += sizeof( fsntfs_mount_point_reparse_data_t ); reparse_point_values->print_name_offset += sizeof( fsntfs_mount_point_reparse_data_t ); } else if( reparse_point_values->tag == 0xa000000c ) { byte_stream_copy_to_uint32_little_endian( ( (fsntfs_symbolic_link_reparse_data_t *) reparse_point_values->reparse_data )->flags, flags ); #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "%s: flags\t\t\t: 0x%08" PRIx32 "\n", function, flags ); } #endif reparse_point_values->substitute_name_offset += sizeof( fsntfs_symbolic_link_reparse_data_t ); reparse_point_values->print_name_offset += sizeof( fsntfs_symbolic_link_reparse_data_t ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( ( reparse_point_values->tag == 0xa0000003 ) || ( reparse_point_values->tag == 0xa000000c ) ) { libcnotify_printf( "\n" ); } else { libcnotify_printf( "%s: unusupported reparse point tag: 0x%08" PRIx32 "\n", function, reparse_point_values->tag ); } } #endif if( reparse_point_values->substitute_name_size > 0 ) { if( reparse_point_values->substitute_name_offset >= reparse_point_values->reparse_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid substitute name offset value out of bounds.", function ); goto on_error; } if( reparse_point_values->substitute_name_size > ( reparse_point_values->reparse_data_size - reparse_point_values->substitute_name_offset ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid substitute name size value out of bounds.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( reparse_point_values->reparse_data[ reparse_point_values->substitute_name_offset ] ), (size_t) reparse_point_values->substitute_name_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( reparse_point_values->reparse_data[ reparse_point_values->substitute_name_offset ] ), (size_t) reparse_point_values->substitute_name_size, 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 substitute name string.", function ); goto on_error; } value_string = 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 substitute name string.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, &( reparse_point_values->reparse_data[ reparse_point_values->substitute_name_offset ] ), (size_t) reparse_point_values->substitute_name_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( reparse_point_values->reparse_data[ reparse_point_values->substitute_name_offset ] ), (size_t) reparse_point_values->substitute_name_size, 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 substitute name string.", function ); goto on_error; } libcnotify_printf( "%s: substitute name\t\t: %" PRIs_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif } if( reparse_point_values->print_name_size > 0 ) { if( reparse_point_values->print_name_offset >= reparse_point_values->reparse_data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid print name offset value out of bounds.", function ); goto on_error; } if( reparse_point_values->print_name_size > ( reparse_point_values->reparse_data_size - reparse_point_values->print_name_offset ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid print name size value out of bounds.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( reparse_point_values->reparse_data[ reparse_point_values->print_name_offset ] ), (size_t) reparse_point_values->print_name_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( reparse_point_values->reparse_data[ reparse_point_values->print_name_offset ] ), (size_t) reparse_point_values->print_name_size, 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 print name string.", function ); goto on_error; } value_string = 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 print name string.", function ); goto on_error; } #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_copy_from_utf16_stream( (libuna_utf16_character_t *) value_string, value_string_size, &( reparse_point_values->reparse_data[ reparse_point_values->print_name_offset ] ), (size_t) reparse_point_values->print_name_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( reparse_point_values->reparse_data[ reparse_point_values->print_name_offset ] ), (size_t) reparse_point_values->print_name_size, 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 print name string.", function ); goto on_error; } libcnotify_printf( "%s: print name\t\t\t: %" PRIs_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( 1 ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } #endif if( reparse_point_values->reparse_data != NULL ) { memory_free( reparse_point_values->reparse_data ); reparse_point_values->reparse_data = NULL; } reparse_point_values->reparse_data_size = 0; return( -1 ); }
/* Reads the extension block 0xbeef0006 values * Returns the number of bytes read or -1 on error */ ssize_t libfwsi_extension_block_0xbeef0006_values_read( libfwsi_extension_block_0xbeef0006_values_t *extension_block_0xbeef0006_values, const uint8_t *extension_block_data, size_t extension_block_data_size, libcerror_error_t **error ) { static char *function = "libfwsi_extension_block_0xbeef0006_values_read"; size_t extension_block_data_offset = 0; size_t string_size = 0; uint32_t signature = 0; #if defined( HAVE_DEBUG_OUTPUT ) libcstring_system_character_t *value_string = NULL; size_t value_string_size = 0; int result = 0; #endif if( extension_block_0xbeef0006_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid extension block 0xbeef0006 values.", function ); return( -1 ); } if( extension_block_data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid extension block data.", function ); return( -1 ); } if( extension_block_data_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: extension block data size exceeds maximum.", function ); return( -1 ); } /* Do not try to parse unsupported extension block data sizes */ if( extension_block_data_size < 12 ) { return( 0 ); } /* Do not try to parse unsupported extension block signatures */ byte_stream_copy_to_uint32_little_endian( &( extension_block_data[ 4 ] ), signature ); if( signature != 0xbeef0006 ) { return( 0 ); } extension_block_data_offset = 8; for( string_size = extension_block_data_offset; ( string_size + 1 ) < extension_block_data_size - 2; string_size += 2 ) { if( ( extension_block_data[ string_size ] == 0 ) && ( extension_block_data[ string_size + 1 ] == 0 ) ) { string_size += 2; break; } } string_size -= extension_block_data_offset; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) result = libuna_utf16_string_size_from_utf16_stream( &( extension_block_data[ extension_block_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, &value_string_size, error ); #else result = libuna_utf8_string_size_from_utf16_stream( &( extension_block_data[ extension_block_data_offset ] ), string_size, 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 username 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 username 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 username 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, &( extension_block_data[ extension_block_data_offset ] ), string_size, LIBUNA_ENDIAN_LITTLE, error ); #else result = libuna_utf8_string_copy_from_utf16_stream( (libuna_utf8_character_t *) value_string, value_string_size, &( extension_block_data[ extension_block_data_offset ] ), string_size, 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 username string.", function ); goto on_error; } libcnotify_printf( "%s: username\t\t\t: %" PRIs_LIBCSTRING_SYSTEM "\n", function, value_string ); memory_free( value_string ); value_string = NULL; } #endif extension_block_data_offset += string_size; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "\n" ); } #endif return( (ssize_t) extension_block_data_offset ); on_error: #if defined( HAVE_DEBUG_OUTPUT ) if( value_string != NULL ) { memory_free( value_string ); } #endif return( -1 ); }