Coverage Report

Created: 2025-07-04 07:01

/src/libewf/libewf/libewf_lef_extended_attribute.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Logical Evidence File (LEF) extended attribute functions
3
 *
4
 * Copyright (C) 2006-2024, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libewf_debug.h"
28
#include "libewf_lef_extended_attribute.h"
29
#include "libewf_libcerror.h"
30
#include "libewf_libcnotify.h"
31
#include "libewf_libuna.h"
32
33
/* Creates an extended attribute
34
 * Make sure the value lef_extended_attribute is referencing, is set to NULL
35
 * Returns 1 if successful or -1 on error
36
 */
37
int libewf_lef_extended_attribute_initialize(
38
     libewf_lef_extended_attribute_t **lef_extended_attribute,
39
     libcerror_error_t **error )
40
0
{
41
0
  static char *function = "libewf_lef_extended_attribute_initialize";
42
43
0
  if( lef_extended_attribute == NULL )
44
0
  {
45
0
    libcerror_error_set(
46
0
     error,
47
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
48
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
49
0
     "%s: invalid extended attribute.",
50
0
     function );
51
52
0
    return( -1 );
53
0
  }
54
0
  if( *lef_extended_attribute != NULL )
55
0
  {
56
0
    libcerror_error_set(
57
0
     error,
58
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
59
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
60
0
     "%s: invalid extended attribute value already set.",
61
0
     function );
62
63
0
    return( -1 );
64
0
  }
65
0
  *lef_extended_attribute = memory_allocate_structure(
66
0
                             libewf_lef_extended_attribute_t );
67
68
0
  if( *lef_extended_attribute == NULL )
69
0
  {
70
0
    libcerror_error_set(
71
0
     error,
72
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
73
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
74
0
     "%s: unable to create extended attribute.",
75
0
     function );
76
77
0
    goto on_error;
78
0
  }
79
0
  if( memory_set(
80
0
       *lef_extended_attribute,
81
0
       0,
82
0
       sizeof( libewf_lef_extended_attribute_t ) ) == NULL )
83
0
  {
84
0
    libcerror_error_set(
85
0
     error,
86
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
87
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
88
0
     "%s: unable to clear extended attribute.",
89
0
     function );
90
91
0
    goto on_error;
92
0
  }
93
0
  return( 1 );
94
95
0
on_error:
96
0
  if( *lef_extended_attribute != NULL )
97
0
  {
98
0
    memory_free(
99
0
     *lef_extended_attribute );
100
101
0
    *lef_extended_attribute = NULL;
102
0
  }
103
0
  return( -1 );
104
0
}
105
106
/* Frees an extended attribute
107
 * Returns 1 if successful or -1 on error
108
 */
109
int libewf_lef_extended_attribute_free(
110
     libewf_lef_extended_attribute_t **lef_extended_attribute,
111
     libcerror_error_t **error )
112
0
{
113
0
  static char *function = "libewf_lef_extended_attribute_free";
114
115
0
  if( lef_extended_attribute == NULL )
116
0
  {
117
0
    libcerror_error_set(
118
0
     error,
119
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
120
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
121
0
     "%s: invalid extended attribute.",
122
0
     function );
123
124
0
    return( -1 );
125
0
  }
126
0
  if( *lef_extended_attribute != NULL )
127
0
  {
128
0
    if( ( *lef_extended_attribute )->name != NULL )
129
0
    {
130
0
      memory_free(
131
0
       ( *lef_extended_attribute )->name );
132
0
    }
133
0
    if( ( *lef_extended_attribute )->value != NULL )
134
0
    {
135
0
      memory_free(
136
0
       ( *lef_extended_attribute )->value );
137
0
    }
138
0
    memory_free(
139
0
     *lef_extended_attribute );
140
141
0
    *lef_extended_attribute = NULL;
142
0
  }
143
0
  return( 1 );
144
0
}
145
146
/* Clones the extended attribute
147
 * Returns 1 if successful or -1 on error
148
 */
149
int libewf_lef_extended_attribute_clone(
150
     libewf_lef_extended_attribute_t **destination_lef_extended_attribute,
151
     libewf_lef_extended_attribute_t *source_lef_extended_attribute,
152
     libcerror_error_t **error )
153
0
{
154
0
  static char *function = "libewf_lef_extended_attribute_clone";
155
156
0
  if( destination_lef_extended_attribute == NULL )
157
0
  {
158
0
    libcerror_error_set(
159
0
     error,
160
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
161
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
162
0
     "%s: invalid destination extended attribute.",
163
0
     function );
164
165
0
    return( -1 );
166
0
  }
167
0
  if( *destination_lef_extended_attribute != NULL )
168
0
  {
169
0
    libcerror_error_set(
170
0
     error,
171
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
172
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
173
0
     "%s: invalid destination extended attribute value already set.",
174
0
     function );
175
176
0
    return( -1 );
177
0
  }
178
0
  if( source_lef_extended_attribute == NULL )
179
0
  {
180
0
    *destination_lef_extended_attribute = NULL;
181
182
0
    return( 1 );
183
0
  }
184
0
  *destination_lef_extended_attribute = memory_allocate_structure(
185
0
                             libewf_lef_extended_attribute_t );
186
187
0
  if( *destination_lef_extended_attribute == NULL )
188
0
  {
189
0
    libcerror_error_set(
190
0
     error,
191
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
192
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
193
0
     "%s: unable to create destination extended attribute.",
194
0
     function );
195
196
0
    goto on_error;
197
0
  }
198
0
  ( *destination_lef_extended_attribute )->name  = NULL;
199
0
  ( *destination_lef_extended_attribute )->value = NULL;
200
201
0
  if( source_lef_extended_attribute->name != NULL )
202
0
  {
203
0
    ( *destination_lef_extended_attribute )->name = (uint8_t *) memory_allocate(
204
0
                                                                 sizeof( uint8_t ) * source_lef_extended_attribute->name_size );
205
206
0
    if( ( *destination_lef_extended_attribute )->name == NULL )
207
0
    {
208
0
      libcerror_error_set(
209
0
       error,
210
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
211
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
212
0
       "%s: unable to create destination name.",
213
0
       function );
214
215
0
      goto on_error;
216
0
    }
217
0
    if( memory_copy(
218
0
         ( *destination_lef_extended_attribute )->name,
219
0
         source_lef_extended_attribute->name,
220
0
         source_lef_extended_attribute->name_size ) == NULL )
221
0
    {
222
0
      libcerror_error_set(
223
0
       error,
224
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
225
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
226
0
       "%s: unable to copy source to destination name.",
227
0
       function );
228
229
0
      goto on_error;
230
0
    }
231
0
    ( *destination_lef_extended_attribute )->value_size = source_lef_extended_attribute->value_size;
232
0
  }
233
0
  if( source_lef_extended_attribute->value != NULL )
234
0
  {
235
0
    ( *destination_lef_extended_attribute )->value = (uint8_t *) memory_allocate(
236
0
                                                                  sizeof( uint8_t ) * source_lef_extended_attribute->value_size );
237
238
0
    if( ( *destination_lef_extended_attribute )->value == NULL )
239
0
    {
240
0
      libcerror_error_set(
241
0
       error,
242
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
243
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
244
0
       "%s: unable to create destination value.",
245
0
       function );
246
247
0
      goto on_error;
248
0
    }
249
0
    if( memory_copy(
250
0
         ( *destination_lef_extended_attribute )->value,
251
0
         source_lef_extended_attribute->value,
252
0
         source_lef_extended_attribute->value_size ) == NULL )
253
0
    {
254
0
      libcerror_error_set(
255
0
       error,
256
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
257
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
258
0
       "%s: unable to copy source to destination value.",
259
0
       function );
260
261
0
      goto on_error;
262
0
    }
263
0
    ( *destination_lef_extended_attribute )->value_size = source_lef_extended_attribute->value_size;
264
0
  }
265
0
  return( 1 );
266
267
0
on_error:
268
0
  if( *destination_lef_extended_attribute != NULL )
269
0
  {
270
0
    memory_free(
271
0
     *destination_lef_extended_attribute );
272
273
0
    *destination_lef_extended_attribute = NULL;
274
0
  }
275
0
  return( -1 );
276
0
}
277
278
/* Reads an extended attribute
279
 * Returns the number of bytes read or -1 on error
280
 */
281
ssize_t libewf_lef_extended_attribute_read_data(
282
         libewf_lef_extended_attribute_t *lef_extended_attribute,
283
         const uint8_t *data,
284
         size_t data_size,
285
         libcerror_error_t **error )
286
0
{
287
0
  static char *function = "libewf_lef_extended_attribute_read_data";
288
0
  size_t data_offset    = 0;
289
0
  uint32_t name_size    = 0;
290
0
  uint32_t value_size   = 0;
291
292
#if defined( HAVE_DEBUG_OUTPUT )
293
  uint32_t value_32bit  = 0;
294
#endif
295
296
0
  if( lef_extended_attribute == NULL )
297
0
  {
298
0
    libcerror_error_set(
299
0
     error,
300
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
301
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
302
0
     "%s: invalid extended attribute.",
303
0
     function );
304
305
0
    return( -1 );
306
0
  }
307
0
  if( lef_extended_attribute->name != NULL )
308
0
  {
309
0
    libcerror_error_set(
310
0
     error,
311
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
312
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
313
0
     "%s: invalid extended attribute - name value already set.",
314
0
     function );
315
316
0
    return( -1 );
317
0
  }
318
0
  if( lef_extended_attribute->value != NULL )
319
0
  {
320
0
    libcerror_error_set(
321
0
     error,
322
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
323
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
324
0
     "%s: invalid extended attribute - value value already set.",
325
0
     function );
326
327
0
    return( -1 );
328
0
  }
329
0
  if( data == NULL )
330
0
  {
331
0
    libcerror_error_set(
332
0
     error,
333
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
334
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
335
0
     "%s: missing data.",
336
0
     function );
337
338
0
    return( -1 );
339
0
  }
340
0
  if( ( data_size < 13 )
341
0
   || ( data_size > (size_t) SSIZE_MAX ) )
342
0
  {
343
0
    libcerror_error_set(
344
0
     error,
345
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
346
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
347
0
     "%s: invalid data size value out of bounds.",
348
0
     function );
349
350
0
    return( -1 );
351
0
  }
352
0
  byte_stream_copy_to_uint32_little_endian(
353
0
   &( data[ 5 ] ),
354
0
   name_size );
355
356
0
  byte_stream_copy_to_uint32_little_endian(
357
0
   &( data[ 9 ] ),
358
0
   value_size );
359
360
0
  data_offset = 13;
361
362
0
  if( name_size > 0 )
363
0
  {
364
#if SIZEOF_SIZE_T < 4
365
    if( ( (uint32_t) name_size > ( (uint32_t) SSIZE_MAX / 2 ) )
366
     || ( name_size > (uint32_t) ( data_size - data_offset ) ) )
367
#elif SIZEOF_SIZE_T == 4
368
    if( ( (size_t) name_size > ( (size_t) SSIZE_MAX / 2 ) )
369
     || ( (size_t) name_size > ( data_size - data_offset ) ) )
370
#else
371
0
    if( (size_t) name_size > ( data_size - data_offset ) )
372
0
#endif
373
0
    {
374
0
      libcerror_error_set(
375
0
       error,
376
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
377
0
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
378
0
       "%s: invalid name size value out of bounds.",
379
0
       function );
380
381
0
      goto on_error;
382
0
    }
383
0
    name_size *= 2;
384
385
0
    data_offset += name_size;
386
0
  }
387
0
  if( value_size > 0 )
388
0
  {
389
#if SIZEOF_SIZE_T < 4
390
    if( ( (uint32_t) value_size > ( (uint32_t) SSIZE_MAX / 2 ) )
391
     || ( value_size > (uint32_t) ( data_size - data_offset ) ) )
392
#elif SIZEOF_SIZE_T == 4
393
    if( ( (size_t) value_size > ( (size_t) SSIZE_MAX / 2 ) )
394
     || ( (size_t) value_size > ( data_size - data_offset ) ) )
395
#else
396
0
    if( (size_t) value_size > ( data_size - data_offset ) )
397
0
#endif
398
0
    {
399
0
      libcerror_error_set(
400
0
       error,
401
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
402
0
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
403
0
       "%s: invalid value size value out of bounds.",
404
0
       function );
405
406
0
      goto on_error;
407
0
    }
408
0
    value_size *= 2;
409
410
0
    data_offset += value_size;
411
0
  }
412
#if defined( HAVE_DEBUG_OUTPUT )
413
  if( libcnotify_verbose != 0 )
414
  {
415
    libcnotify_printf(
416
     "%s: extended attribute data:\n",
417
     function );
418
    libcnotify_print_data(
419
     data,
420
     data_offset,
421
     0 );
422
  }
423
#endif
424
0
  lef_extended_attribute->is_branch = data[ 4 ];
425
426
#if defined( HAVE_DEBUG_OUTPUT )
427
  if( libcnotify_verbose != 0 )
428
  {
429
    byte_stream_copy_to_uint32_little_endian(
430
     data,
431
     value_32bit );
432
    libcnotify_printf(
433
     "%s: unknown1\t\t\t: 0x%08" PRIx32 "\n",
434
     function,
435
     value_32bit );
436
437
    libcnotify_printf(
438
     "%s: is branch\t\t\t: 0x%02" PRIx8 "\n",
439
     function,
440
     data[ 4 ] );
441
442
    libcnotify_printf(
443
     "%s: name size\t\t\t: %" PRIu32 "\n",
444
     function,
445
     name_size );
446
447
    libcnotify_printf(
448
     "%s: value size\t\t\t: %" PRIu32 "\n",
449
     function,
450
     value_size );
451
  }
452
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
453
454
0
  data_offset = 13;
455
456
0
  if( name_size > 0 )
457
0
  {
458
0
    if( name_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
459
0
    {
460
0
      libcerror_error_set(
461
0
       error,
462
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
463
0
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
464
0
       "%s: invalid name size value out of bounds.",
465
0
       function );
466
467
0
      goto on_error;
468
0
    }
469
0
    lef_extended_attribute->name = (uint8_t *) memory_allocate(
470
0
                                                sizeof( uint8_t ) * name_size );
471
472
0
    if( lef_extended_attribute->name == NULL )
473
0
    {
474
0
      libcerror_error_set(
475
0
       error,
476
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
477
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
478
0
       "%s: unable to create name.",
479
0
       function );
480
481
0
      goto on_error;
482
0
    }
483
0
    if( memory_copy(
484
0
         lef_extended_attribute->name,
485
0
         &( data[ data_offset ] ),
486
0
         name_size ) == NULL )
487
0
    {
488
0
      libcerror_error_set(
489
0
       error,
490
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
491
0
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
492
0
       "%s: unable to set name.",
493
0
       function );
494
495
0
      goto on_error;
496
0
    }
497
0
    lef_extended_attribute->name_size = name_size;
498
499
#if defined( HAVE_DEBUG_OUTPUT )
500
    if( libcnotify_verbose != 0 )
501
    {
502
      if( libewf_debug_print_utf16_string_value(
503
           function,
504
           "name\t\t\t\t",
505
           lef_extended_attribute->name,
506
           lef_extended_attribute->name_size,
507
           LIBUNA_ENDIAN_LITTLE,
508
           error ) != 1 )
509
      {
510
        libcerror_error_set(
511
         error,
512
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
513
         LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
514
         "%s: unable to print UTF-16 string value.",
515
         function );
516
517
        goto on_error;
518
      }
519
    }
520
#endif
521
0
    data_offset += name_size;
522
0
  }
523
0
  if( value_size > 0 )
524
0
  {
525
0
    if( value_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
526
0
    {
527
0
      libcerror_error_set(
528
0
       error,
529
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
530
0
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
531
0
       "%s: invalid value size value out of bounds.",
532
0
       function );
533
534
0
      goto on_error;
535
0
    }
536
0
    lef_extended_attribute->value = (uint8_t *) memory_allocate(
537
0
                                                 sizeof( uint8_t ) * value_size );
538
539
0
    if( lef_extended_attribute->value == NULL )
540
0
    {
541
0
      libcerror_error_set(
542
0
       error,
543
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
544
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
545
0
       "%s: unable to create value.",
546
0
       function );
547
548
0
      goto on_error;
549
0
    }
550
0
    if( memory_copy(
551
0
         lef_extended_attribute->value,
552
0
         &( data[ data_offset ] ),
553
0
         value_size ) == NULL )
554
0
    {
555
0
      libcerror_error_set(
556
0
       error,
557
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
558
0
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
559
0
       "%s: unable to set value.",
560
0
       function );
561
562
0
      goto on_error;
563
0
    }
564
0
    lef_extended_attribute->value_size = value_size;
565
566
#if defined( HAVE_DEBUG_OUTPUT )
567
    if( libcnotify_verbose != 0 )
568
    {
569
      if( libewf_debug_print_utf16_string_value(
570
           function,
571
           "value\t\t\t\t",
572
           lef_extended_attribute->value,
573
           lef_extended_attribute->value_size,
574
           LIBUNA_ENDIAN_LITTLE,
575
           error ) != 1 )
576
      {
577
        libcerror_error_set(
578
         error,
579
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
580
         LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
581
         "%s: unable to print UTF-16 string value.",
582
         function );
583
584
        goto on_error;
585
      }
586
    }
587
#endif
588
0
    data_offset += value_size;
589
0
  }
590
#if defined( HAVE_DEBUG_OUTPUT )
591
  if( libcnotify_verbose != 0 )
592
  {
593
    libcnotify_printf(
594
     "\n" );
595
  }
596
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
597
598
0
  return( (ssize_t) data_offset );
599
600
0
on_error:
601
0
  if( lef_extended_attribute->value != NULL )
602
0
  {
603
0
    memory_free(
604
0
     lef_extended_attribute->value );
605
606
0
    lef_extended_attribute->value = NULL;
607
0
  }
608
0
  lef_extended_attribute->value_size = 0;
609
610
0
  if( lef_extended_attribute->name != NULL )
611
0
  {
612
0
    memory_free(
613
0
     lef_extended_attribute->name );
614
615
0
    lef_extended_attribute->name = NULL;
616
0
  }
617
0
  lef_extended_attribute->name_size = 0;
618
619
0
  return( -1 );
620
0
}
621
622
/* Retrieves the size of the UTF-8 encoded name
623
 * The returned size includes the end of string character
624
 * Returns 1 if successful or -1 on error
625
 */
626
int libewf_lef_extended_attribute_get_utf8_name_size(
627
     libewf_lef_extended_attribute_t *lef_extended_attribute,
628
     size_t *utf8_string_size,
629
     libcerror_error_t **error )
630
0
{
631
0
  static char *function = "libewf_lef_extended_attribute_get_utf8_name_size";
632
633
0
  if( lef_extended_attribute == NULL )
634
0
  {
635
0
    libcerror_error_set(
636
0
     error,
637
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
638
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
639
0
     "%s: invalid extended_attribute.",
640
0
     function );
641
642
0
    return( -1 );
643
0
  }
644
0
  if( libuna_utf8_string_size_from_utf16_stream(
645
0
       lef_extended_attribute->name,
646
0
       lef_extended_attribute->name_size,
647
0
       LIBUNA_ENDIAN_LITTLE,
648
0
       utf8_string_size,
649
0
       error ) != 1 )
650
0
  {
651
0
    libcerror_error_set(
652
0
     error,
653
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
654
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
655
0
     "%s: unable to determine UTF-8 string size.",
656
0
     function );
657
658
0
    return( -1 );
659
0
  }
660
0
  return( 1 );
661
0
}
662
663
/* Retrieves the UTF-8 encoded name
664
 * The size should include the end of string character
665
 * Returns 1 if successful or -1 on error
666
 */
667
int libewf_lef_extended_attribute_get_utf8_name(
668
     libewf_lef_extended_attribute_t *lef_extended_attribute,
669
     uint8_t *utf8_string,
670
     size_t utf8_string_size,
671
     libcerror_error_t **error )
672
0
{
673
0
  static char *function = "libewf_lef_extended_attribute_get_utf8_name";
674
675
0
  if( lef_extended_attribute == NULL )
676
0
  {
677
0
    libcerror_error_set(
678
0
     error,
679
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
680
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
681
0
     "%s: invalid extended_attribute.",
682
0
     function );
683
684
0
    return( -1 );
685
0
  }
686
0
  if( libuna_utf8_string_copy_from_utf16_stream(
687
0
       utf8_string,
688
0
       utf8_string_size,
689
0
       lef_extended_attribute->name,
690
0
       lef_extended_attribute->name_size,
691
0
       LIBUNA_ENDIAN_LITTLE,
692
0
       error ) != 1 )
693
0
  {
694
0
    libcerror_error_set(
695
0
     error,
696
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
697
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
698
0
     "%s: unable to copy name to UTF-8 string.",
699
0
     function );
700
701
0
    return( -1 );
702
0
  }
703
0
  return( 1 );
704
0
}
705
706
/* Retrieves the size of the UTF-16 encoded name
707
 * The returned size includes the end of string character
708
 * Returns 1 if successful or -1 on error
709
 */
710
int libewf_lef_extended_attribute_get_utf16_name_size(
711
     libewf_lef_extended_attribute_t *lef_extended_attribute,
712
     size_t *utf16_string_size,
713
     libcerror_error_t **error )
714
0
{
715
0
  static char *function = "libewf_lef_extended_attribute_get_utf16_name_size";
716
717
0
  if( lef_extended_attribute == NULL )
718
0
  {
719
0
    libcerror_error_set(
720
0
     error,
721
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
722
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
723
0
     "%s: invalid extended_attribute.",
724
0
     function );
725
726
0
    return( -1 );
727
0
  }
728
0
  if( libuna_utf16_string_size_from_utf16_stream(
729
0
       lef_extended_attribute->name,
730
0
       lef_extended_attribute->name_size,
731
0
       LIBUNA_ENDIAN_LITTLE,
732
0
       utf16_string_size,
733
0
       error ) != 1 )
734
0
  {
735
0
    libcerror_error_set(
736
0
     error,
737
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
738
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
739
0
     "%s: unable to determine UTF-16 string size.",
740
0
     function );
741
742
0
    return( -1 );
743
0
  }
744
0
  return( 1 );
745
0
}
746
747
/* Retrieves the UTF-16 encoded name
748
 * The size should include the end of string character
749
 * Returns 1 if successful or -1 on error
750
 */
751
int libewf_lef_extended_attribute_get_utf16_name(
752
     libewf_lef_extended_attribute_t *lef_extended_attribute,
753
     uint16_t *utf16_string,
754
     size_t utf16_string_size,
755
     libcerror_error_t **error )
756
0
{
757
0
  static char *function = "libewf_lef_extended_attribute_get_utf16_name";
758
759
0
  if( lef_extended_attribute == NULL )
760
0
  {
761
0
    libcerror_error_set(
762
0
     error,
763
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
764
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
765
0
     "%s: invalid extended_attribute.",
766
0
     function );
767
768
0
    return( -1 );
769
0
  }
770
0
  if( libuna_utf16_string_copy_from_utf16_stream(
771
0
       utf16_string,
772
0
       utf16_string_size,
773
0
       lef_extended_attribute->name,
774
0
       lef_extended_attribute->name_size,
775
0
       LIBUNA_ENDIAN_LITTLE,
776
0
       error ) != 1 )
777
0
  {
778
0
    libcerror_error_set(
779
0
     error,
780
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
781
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
782
0
     "%s: unable to copy name to UTF-16 string.",
783
0
     function );
784
785
0
    return( -1 );
786
0
  }
787
0
  return( 1 );
788
0
}
789
790
/* Retrieves the size of the UTF-8 encoded value
791
 * The returned size includes the end of string character
792
 * Returns 1 if successful or -1 on error
793
 */
794
int libewf_lef_extended_attribute_get_utf8_value_size(
795
     libewf_lef_extended_attribute_t *lef_extended_attribute,
796
     size_t *utf8_string_size,
797
     libcerror_error_t **error )
798
0
{
799
0
  static char *function = "libewf_lef_extended_attribute_get_utf8_value_size";
800
801
0
  if( lef_extended_attribute == NULL )
802
0
  {
803
0
    libcerror_error_set(
804
0
     error,
805
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
806
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
807
0
     "%s: invalid extended_attribute.",
808
0
     function );
809
810
0
    return( -1 );
811
0
  }
812
0
  if( libuna_utf8_string_size_from_utf16_stream(
813
0
       lef_extended_attribute->value,
814
0
       lef_extended_attribute->value_size,
815
0
       LIBUNA_ENDIAN_LITTLE,
816
0
       utf8_string_size,
817
0
       error ) != 1 )
818
0
  {
819
0
    libcerror_error_set(
820
0
     error,
821
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
822
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
823
0
     "%s: unable to determine UTF-8 string size.",
824
0
     function );
825
826
0
    return( -1 );
827
0
  }
828
0
  return( 1 );
829
0
}
830
831
/* Retrieves the UTF-8 encoded value
832
 * The size should include the end of string character
833
 * Returns 1 if successful or -1 on error
834
 */
835
int libewf_lef_extended_attribute_get_utf8_value(
836
     libewf_lef_extended_attribute_t *lef_extended_attribute,
837
     uint8_t *utf8_string,
838
     size_t utf8_string_size,
839
     libcerror_error_t **error )
840
0
{
841
0
  static char *function = "libewf_lef_extended_attribute_get_utf8_value";
842
843
0
  if( lef_extended_attribute == NULL )
844
0
  {
845
0
    libcerror_error_set(
846
0
     error,
847
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
848
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
849
0
     "%s: invalid extended_attribute.",
850
0
     function );
851
852
0
    return( -1 );
853
0
  }
854
0
  if( libuna_utf8_string_copy_from_utf16_stream(
855
0
       utf8_string,
856
0
       utf8_string_size,
857
0
       lef_extended_attribute->value,
858
0
       lef_extended_attribute->value_size,
859
0
       LIBUNA_ENDIAN_LITTLE,
860
0
       error ) != 1 )
861
0
  {
862
0
    libcerror_error_set(
863
0
     error,
864
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
865
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
866
0
     "%s: unable to copy value to UTF-8 string.",
867
0
     function );
868
869
0
    return( -1 );
870
0
  }
871
0
  return( 1 );
872
0
}
873
874
/* Retrieves the size of the UTF-16 encoded value
875
 * The returned size includes the end of string character
876
 * Returns 1 if successful or -1 on error
877
 */
878
int libewf_lef_extended_attribute_get_utf16_value_size(
879
     libewf_lef_extended_attribute_t *lef_extended_attribute,
880
     size_t *utf16_string_size,
881
     libcerror_error_t **error )
882
0
{
883
0
  static char *function = "libewf_lef_extended_attribute_get_utf16_value_size";
884
885
0
  if( lef_extended_attribute == NULL )
886
0
  {
887
0
    libcerror_error_set(
888
0
     error,
889
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
890
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
891
0
     "%s: invalid extended_attribute.",
892
0
     function );
893
894
0
    return( -1 );
895
0
  }
896
0
  if( libuna_utf16_string_size_from_utf16_stream(
897
0
       lef_extended_attribute->value,
898
0
       lef_extended_attribute->value_size,
899
0
       LIBUNA_ENDIAN_LITTLE,
900
0
       utf16_string_size,
901
0
       error ) != 1 )
902
0
  {
903
0
    libcerror_error_set(
904
0
     error,
905
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
906
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
907
0
     "%s: unable to determine UTF-16 string size.",
908
0
     function );
909
910
0
    return( -1 );
911
0
  }
912
0
  return( 1 );
913
0
}
914
915
/* Retrieves the UTF-16 encoded value
916
 * The size should include the end of string character
917
 * Returns 1 if successful or -1 on error
918
 */
919
int libewf_lef_extended_attribute_get_utf16_value(
920
     libewf_lef_extended_attribute_t *lef_extended_attribute,
921
     uint16_t *utf16_string,
922
     size_t utf16_string_size,
923
     libcerror_error_t **error )
924
0
{
925
0
  static char *function = "libewf_lef_extended_attribute_get_utf16_value";
926
927
0
  if( lef_extended_attribute == NULL )
928
0
  {
929
0
    libcerror_error_set(
930
0
     error,
931
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
932
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
933
0
     "%s: invalid extended_attribute.",
934
0
     function );
935
936
0
    return( -1 );
937
0
  }
938
0
  if( libuna_utf16_string_copy_from_utf16_stream(
939
0
       utf16_string,
940
0
       utf16_string_size,
941
0
       lef_extended_attribute->value,
942
0
       lef_extended_attribute->value_size,
943
0
       LIBUNA_ENDIAN_LITTLE,
944
0
       error ) != 1 )
945
0
  {
946
0
    libcerror_error_set(
947
0
     error,
948
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
949
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
950
0
     "%s: unable to copy value to UTF-16 string.",
951
0
     function );
952
953
0
    return( -1 );
954
0
  }
955
0
  return( 1 );
956
0
}
957