Coverage Report

Created: 2025-06-24 07:14

/src/libewf/libewf/libewf_value_table.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Value table 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 <types.h>
24
25
#include "libewf_libcerror.h"
26
#include "libewf_libfvalue.h"
27
#include "libewf_value_table.h"
28
29
/* Retrieves the UTF-8 encoded string length of a table value
30
 * Returns 1 if successful or -1 on error
31
 */
32
int libewf_value_table_get_value_utf8_string_length(
33
     libfvalue_table_t *value_table,
34
     const uint8_t *identifier,
35
     size_t identifier_length,
36
     size_t *utf8_string_length,
37
     libcerror_error_t **error )
38
0
{
39
0
  libfvalue_value_t *value = NULL;
40
0
  static char *function    = "libewf_value_table_get_value_utf8_string_length";
41
0
  size_t utf8_string_size  = 0;
42
0
  int result               = 0;
43
44
0
  if( identifier == NULL )
45
0
  {
46
0
    libcerror_error_set(
47
0
     error,
48
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
49
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
50
0
     "%s: invalid identifier.",
51
0
     function );
52
53
0
    return( -1 );
54
0
  }
55
0
  if( utf8_string_length == NULL )
56
0
  {
57
0
    libcerror_error_set(
58
0
     error,
59
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
60
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
61
0
     "%s: invalid UTF-8 string length.",
62
0
     function );
63
64
0
    return( -1 );
65
0
  }
66
0
  result = libfvalue_table_get_value_by_identifier(
67
0
            value_table,
68
0
            identifier,
69
0
            identifier_length,
70
0
            &value,
71
0
            0,
72
0
            error );
73
74
0
  if( result == -1 )
75
0
  {
76
0
    libcerror_error_set(
77
0
     error,
78
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
79
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
80
0
     "%s: unable to retrieve table value: %s.",
81
0
     function,
82
0
     identifier );
83
84
0
    return( -1 );
85
0
  }
86
0
  else if( result != 0 )
87
0
  {
88
0
    result = libfvalue_value_get_utf8_string_size(
89
0
              value,
90
0
              0,
91
0
              &utf8_string_size,
92
0
              error );
93
94
0
    if( result == -1 )
95
0
    {
96
0
      libcerror_error_set(
97
0
       error,
98
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
99
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
100
0
       "%s: unable to retrieve UTF-8 string size of table value: %s.",
101
0
       function,
102
0
       identifier );
103
104
0
      return( -1 );
105
0
    }
106
0
    else if( result != 0 )
107
0
    {
108
0
      if( utf8_string_size > 0 )
109
0
      {
110
0
        utf8_string_size -= 1;
111
0
      }
112
0
    }
113
0
  }
114
0
  *utf8_string_length = utf8_string_size;
115
116
0
  return( 1 );
117
0
}
118
119
/* Copies a table value to an UTF-8 encoded string
120
 * Returns 1 if successful or -1 on error
121
 */
122
int libewf_value_table_get_value_copy_to_utf8_string_with_index(
123
     libfvalue_table_t *value_table,
124
     const uint8_t *identifier,
125
     size_t identifier_length,
126
     uint8_t *utf8_string,
127
     size_t utf8_string_size,
128
     size_t *utf8_string_index,
129
     libcerror_error_t **error )
130
0
{
131
0
  libfvalue_value_t *value      = NULL;
132
0
  static char *function         = "libewf_value_table_get_value_copy_to_utf8_string_with_index";
133
0
  size_t safe_utf8_string_index = 0;
134
0
  int result                    = 0;
135
136
0
  if( identifier == NULL )
137
0
  {
138
0
    libcerror_error_set(
139
0
     error,
140
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
141
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
142
0
     "%s: invalid identifier.",
143
0
     function );
144
145
0
    return( -1 );
146
0
  }
147
0
  if( utf8_string_index == NULL )
148
0
  {
149
0
    libcerror_error_set(
150
0
     error,
151
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
152
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
153
0
     "%s: invalid UTF-8 string index.",
154
0
     function );
155
156
0
    return( -1 );
157
0
  }
158
0
  result = libfvalue_table_get_value_by_identifier(
159
0
            value_table,
160
0
            identifier,
161
0
            identifier_length,
162
0
            &value,
163
0
            0,
164
0
            error );
165
166
0
  if( result == -1 )
167
0
  {
168
0
    libcerror_error_set(
169
0
     error,
170
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
171
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
172
0
     "%s: unable to retrieve table value: %s.",
173
0
     function,
174
0
     identifier );
175
176
0
    return( -1 );
177
0
  }
178
0
  else if( result != 0 )
179
0
  {
180
0
    safe_utf8_string_index = *utf8_string_index;
181
182
0
    result = libfvalue_value_copy_to_utf8_string_with_index(
183
0
              value,
184
0
              0,
185
0
              utf8_string,
186
0
              utf8_string_size,
187
0
              &safe_utf8_string_index,
188
0
              error );
189
190
0
    if( result == -1 )
191
0
    {
192
0
      libcerror_error_set(
193
0
       error,
194
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
195
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
196
0
       "%s: unable to copy table value: %s to UTF-8 string.",
197
0
       function,
198
0
       identifier );
199
200
0
      return( -1 );
201
0
    }
202
0
    else if( result != 0 )
203
0
    {
204
0
      *utf8_string_index = safe_utf8_string_index - 1;
205
0
    }
206
0
  }
207
0
  return( 1 );
208
0
}
209
210
/* Sets a specific value in the table
211
 * Returns 1 if successful or -1 on error
212
 */
213
int libewf_value_table_set_value_by_index(
214
     libfvalue_table_t *value_table,
215
     int value_index,
216
     const uint8_t *identifier,
217
     size_t identifier_size,
218
     libcerror_error_t **error )
219
54.6k
{
220
54.6k
  libfvalue_value_t *value = NULL;
221
54.6k
  static char *function    = "libewf_value_table_set_value_by_index";
222
223
54.6k
  if( identifier == NULL )
224
0
  {
225
0
    libcerror_error_set(
226
0
     error,
227
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
228
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
229
0
     "%s: invalid identifier.",
230
0
     function );
231
232
0
    return( -1 );
233
0
  }
234
54.6k
  if( libfvalue_value_type_initialize(
235
54.6k
       &value,
236
54.6k
       LIBFVALUE_VALUE_TYPE_STRING_UTF8,
237
54.6k
       error ) != 1 )
238
0
  {
239
0
    libcerror_error_set(
240
0
     error,
241
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
242
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
243
0
     "%s: unable to create value.",
244
0
     function );
245
246
0
    goto on_error;
247
0
  }
248
54.6k
  if( libfvalue_value_set_identifier(
249
54.6k
       value,
250
54.6k
       identifier,
251
54.6k
       identifier_size,
252
54.6k
       LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
253
54.6k
       error ) != 1 )
254
0
  {
255
0
    libcerror_error_set(
256
0
     error,
257
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
258
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
259
0
     "%s: unable to set value: %s identifier.",
260
0
     function,
261
0
     (char *) identifier );
262
263
0
    goto on_error;
264
0
  }
265
54.6k
  if( libfvalue_table_set_value_by_index(
266
54.6k
       value_table,
267
54.6k
       value_index,
268
54.6k
       value,
269
54.6k
       error ) != 1 )
270
0
  {
271
0
    libcerror_error_set(
272
0
     error,
273
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
274
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
275
0
     "%s: unable to set value: %d in table.",
276
0
     function,
277
0
     value_index );
278
279
0
    goto on_error;
280
0
  }
281
54.6k
  return( 1 );
282
283
0
on_error:
284
0
  if( value != NULL )
285
0
  {
286
0
    libfvalue_value_free(
287
0
     &value,
288
0
     NULL );
289
0
  }
290
0
  return( -1 );
291
54.6k
}
292
293
/* Sets a value in the table specified by the identifier
294
 * Returns 1 if successful or -1 on error
295
 */
296
int libewf_value_table_set_value_by_identifier(
297
     libfvalue_table_t *value_table,
298
     const uint8_t *identifier,
299
     size_t identifier_size,
300
     const uint8_t *value_string,
301
     size_t value_string_size,
302
     libcerror_error_t **error )
303
6.11k
{
304
6.11k
  libfvalue_value_t *value = NULL;
305
6.11k
  static char *function    = "libewf_value_table_set_value_by_identifier";
306
307
6.11k
  if( libfvalue_value_type_initialize(
308
6.11k
       &value,
309
6.11k
       LIBFVALUE_VALUE_TYPE_STRING_UTF8,
310
6.11k
       error ) != 1 )
311
0
  {
312
0
    libcerror_error_set(
313
0
     error,
314
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
315
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
316
0
     "%s: unable to create value.",
317
0
     function );
318
319
0
    goto on_error;
320
0
  }
321
6.11k
  if( libfvalue_value_set_identifier(
322
6.11k
       value,
323
6.11k
       identifier,
324
6.11k
       identifier_size,
325
6.11k
       LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
326
6.11k
       error ) != 1 )
327
0
  {
328
0
    libcerror_error_set(
329
0
     error,
330
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
331
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
332
0
     "%s: unable to set value: %s identifier.",
333
0
     function,
334
0
     (char *) identifier );
335
336
0
    goto on_error;
337
0
  }
338
6.11k
  if( libfvalue_value_set_data(
339
6.11k
       value,
340
6.11k
       value_string,
341
6.11k
       value_string_size,
342
6.11k
       LIBFVALUE_CODEPAGE_UTF8,
343
6.11k
       LIBFVALUE_VALUE_DATA_FLAG_MANAGED,
344
6.11k
       error ) != 1 )
345
0
  {
346
0
    libcerror_error_set(
347
0
     error,
348
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
349
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
350
0
     "%s: unable to set value: %s data.",
351
0
     function,
352
0
     (char *) identifier );
353
354
0
    goto on_error;
355
0
  }
356
6.11k
  if( libfvalue_table_set_value(
357
6.11k
       value_table,
358
6.11k
       value,
359
6.11k
       error ) != 1 )
360
0
  {
361
0
    libcerror_error_set(
362
0
     error,
363
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
364
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
365
0
     "%s: unable to set value: %s in table.",
366
0
     function,
367
0
     (char *) identifier );
368
369
0
    goto on_error;
370
0
  }
371
6.11k
  return( 1 );
372
373
0
on_error:
374
0
  if( value != NULL )
375
0
  {
376
0
    libfvalue_value_free(
377
0
     &value,
378
0
     NULL );
379
0
  }
380
0
  return( -1 );
381
6.11k
}
382
383
/* Retrieves the size of the UTF-8 encoded value of an identifier
384
 * The string size includes the end of string character
385
 * Returns 1 if successful, 0 if not set or -1 on error
386
 */
387
int libewf_value_table_get_utf8_value_size(
388
     libfvalue_table_t *value_table,
389
     const uint8_t *identifier,
390
     size_t identifier_length,
391
     size_t *utf8_string_size,
392
     libcerror_error_t **error )
393
0
{
394
0
  libfvalue_value_t *value = NULL;
395
0
  static char *function    = "libewf_value_table_get_utf8_value_size";
396
0
  int result               = 0;
397
398
0
  if( value_table == NULL )
399
0
  {
400
0
    libcerror_error_set(
401
0
     error,
402
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
403
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
404
0
     "%s: invalid value table.",
405
0
     function );
406
407
0
    return( -1 );
408
0
  }
409
0
  if( identifier == NULL )
410
0
  {
411
0
    libcerror_error_set(
412
0
     error,
413
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
414
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
415
0
     "%s: invalid indentifier.",
416
0
     function );
417
418
0
    return( -1 );
419
0
  }
420
0
  result = libfvalue_table_get_value_by_identifier(
421
0
            value_table,
422
0
            identifier,
423
0
            identifier_length + 1,
424
0
            &value,
425
0
            0,
426
0
            error );
427
428
0
  if( result == -1 )
429
0
  {
430
0
    libcerror_error_set(
431
0
     error,
432
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
433
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
434
0
     "%s: unable to retrieve value: %s.",
435
0
     function,
436
0
     (char *) identifier );
437
438
0
    return( -1 );
439
0
  }
440
0
  else if( result != 0 )
441
0
  {
442
0
    result = libfvalue_value_get_utf8_string_size(
443
0
              value,
444
0
              0,
445
0
              utf8_string_size,
446
0
              error );
447
448
0
    if( result == -1 )
449
0
    {
450
0
      libcerror_error_set(
451
0
       error,
452
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
453
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
454
0
       "%s: unable to retrieve UTF-8 string size of value.",
455
0
       function );
456
457
0
      return( -1 );
458
0
    }
459
0
  }
460
0
  return( result );
461
0
}
462
463
/* Retrieves the UTF-8 encoded value of an identifier
464
 * The string size should include the end of string character
465
 * Returns 1 if successful, 0 if not set or -1 on error
466
 */
467
int libewf_value_table_get_utf8_value(
468
     libfvalue_table_t *value_table,
469
     const uint8_t *identifier,
470
     size_t identifier_length,
471
     uint8_t *utf8_string,
472
     size_t utf8_string_size,
473
     libcerror_error_t **error )
474
0
{
475
0
  libfvalue_value_t *value = NULL;
476
0
  static char *function    = "libewf_value_table_get_utf8_value";
477
0
  int result               = 0;
478
479
0
  if( value_table == NULL )
480
0
  {
481
0
    libcerror_error_set(
482
0
     error,
483
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
484
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
485
0
     "%s: invalid value table.",
486
0
     function );
487
488
0
    return( -1 );
489
0
  }
490
0
  if( identifier == NULL )
491
0
  {
492
0
    libcerror_error_set(
493
0
     error,
494
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
495
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
496
0
     "%s: invalid indentifier.",
497
0
     function );
498
499
0
    return( -1 );
500
0
  }
501
0
  result = libfvalue_table_get_value_by_identifier(
502
0
            value_table,
503
0
            identifier,
504
0
            identifier_length + 1,
505
0
            &value,
506
0
            0,
507
0
            error );
508
509
0
  if( result == -1 )
510
0
  {
511
0
    libcerror_error_set(
512
0
     error,
513
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
514
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
515
0
     "%s: unable to retrieve value: %s.",
516
0
     function,
517
0
     (char *) identifier );
518
519
0
    return( -1 );
520
0
  }
521
0
  else if( result != 0 )
522
0
  {
523
0
    result = libfvalue_value_copy_to_utf8_string(
524
0
              value,
525
0
              0,
526
0
              utf8_string,
527
0
              utf8_string_size,
528
0
              error );
529
530
0
    if( result == -1 )
531
0
    {
532
0
      libcerror_error_set(
533
0
       error,
534
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
535
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
536
0
       "%s: unable to copy value to UTF-8 string.",
537
0
       function );
538
539
0
      return( -1 );
540
0
    }
541
0
  }
542
0
  return( result );
543
0
}
544
545
/* Copies a value specified by the identifier from an UTF-8 encoded string
546
 * Returns 1 if successful or -1 on error
547
 */
548
int libewf_value_table_copy_value_from_utf8_string(
549
     libfvalue_table_t *value_table,
550
     const uint8_t *identifier,
551
     size_t identifier_length,
552
     const uint8_t *utf8_string,
553
     size_t utf8_string_length,
554
     libcerror_error_t **error )
555
0
{
556
0
  libfvalue_value_t *safe_value = NULL;
557
0
  libfvalue_value_t *value      = NULL;
558
0
  static char *function         = "libewf_value_table_copy_value_from_utf8_string";
559
0
  int result                    = 0;
560
561
0
  if( value_table == NULL )
562
0
  {
563
0
    libcerror_error_set(
564
0
     error,
565
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
566
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
567
0
     "%s: invalid values.",
568
0
     function );
569
570
0
    return( -1 );
571
0
  }
572
0
  if( identifier == NULL )
573
0
  {
574
0
    libcerror_error_set(
575
0
     error,
576
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
577
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
578
0
     "%s: invalid identifier.",
579
0
     function );
580
581
0
    return( -1 );
582
0
  }
583
0
  if( identifier_length > (size_t) ( SSIZE_MAX - 1 ) )
584
0
  {
585
0
    libcerror_error_set(
586
0
     error,
587
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
588
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
589
0
     "%s: invalid identifier length value exceeds maximum.",
590
0
     function );
591
592
0
    return( -1 );
593
0
  }
594
0
  result = libfvalue_table_get_value_by_identifier(
595
0
            value_table,
596
0
            identifier,
597
0
            identifier_length + 1,
598
0
            &value,
599
0
            0,
600
0
            error );
601
602
0
  if( result == -1 )
603
0
  {
604
0
    libcerror_error_set(
605
0
     error,
606
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
607
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
608
0
     "%s: unable to retrieve value: %s.",
609
0
     function,
610
0
     (char *) identifier );
611
612
0
    goto on_error;
613
0
  }
614
0
  else if( result == 0 )
615
0
  {
616
0
    if( libfvalue_value_type_initialize(
617
0
         &safe_value,
618
0
         LIBFVALUE_VALUE_TYPE_STRING_UTF8,
619
0
         error ) != 1 )
620
0
    {
621
0
      libcerror_error_set(
622
0
       error,
623
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
624
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
625
0
       "%s: unable to create value.",
626
0
       function );
627
628
0
      goto on_error;
629
0
    }
630
0
    if( libfvalue_value_set_identifier(
631
0
         safe_value,
632
0
         identifier,
633
0
         identifier_length + 1,
634
0
         LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
635
0
         error ) != 1 )
636
0
    {
637
0
      libcerror_error_set(
638
0
       error,
639
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
640
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
641
0
       "%s: unable to set value: %s identifier.",
642
0
       function,
643
0
       (char *) identifier );
644
645
0
      goto on_error;
646
0
    }
647
0
    if( libfvalue_table_set_value(
648
0
         value_table,
649
0
         safe_value,
650
0
         error ) != 1 )
651
0
    {
652
0
      libcerror_error_set(
653
0
       error,
654
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
655
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
656
0
       "%s: unable to set value: %s in table.",
657
0
       function,
658
0
       (char *) identifier );
659
660
0
      goto on_error;
661
0
    }
662
0
    value      = safe_value;
663
0
    safe_value = NULL;
664
0
  }
665
0
  if( libfvalue_value_copy_from_utf8_string(
666
0
       value,
667
0
       0,
668
0
       utf8_string,
669
0
       utf8_string_length,
670
0
       error ) != 1 )
671
0
  {
672
0
    libcerror_error_set(
673
0
     error,
674
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
675
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
676
0
     "%s: unable to copy value from UTF-8 string.",
677
0
     function );
678
679
0
    goto on_error;
680
0
  }
681
0
  return( 1 );
682
683
0
on_error:
684
0
  if( safe_value != NULL )
685
0
  {
686
0
    libfvalue_value_free(
687
0
     &safe_value,
688
0
     NULL );
689
0
  }
690
0
  return( -1 );
691
0
}
692
693
/* Retrieves the size of the UTF-16 encoded value of an identifier
694
 * The string size includes the end of string character
695
 * Returns 1 if successful, 0 if not set or -1 on error
696
 */
697
int libewf_value_table_get_utf16_value_size(
698
     libfvalue_table_t *value_table,
699
     const uint8_t *identifier,
700
     size_t identifier_length,
701
     size_t *utf16_string_size,
702
     libcerror_error_t **error )
703
0
{
704
0
  libfvalue_value_t *value = NULL;
705
0
  static char *function    = "libewf_value_table_get_utf16_value_size";
706
0
  int result               = 0;
707
708
0
  if( value_table == NULL )
709
0
  {
710
0
    libcerror_error_set(
711
0
     error,
712
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
713
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
714
0
     "%s: invalid value table.",
715
0
     function );
716
717
0
    return( -1 );
718
0
  }
719
0
  if( identifier == NULL )
720
0
  {
721
0
    libcerror_error_set(
722
0
     error,
723
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
724
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
725
0
     "%s: invalid indentifier.",
726
0
     function );
727
728
0
    return( -1 );
729
0
  }
730
0
  result = libfvalue_table_get_value_by_identifier(
731
0
            value_table,
732
0
            identifier,
733
0
            identifier_length + 1,
734
0
            &value,
735
0
            0,
736
0
            error );
737
738
0
  if( result == -1 )
739
0
  {
740
0
    libcerror_error_set(
741
0
     error,
742
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
743
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
744
0
     "%s: unable to retrieve value: %s.",
745
0
     function,
746
0
     (char *) identifier );
747
748
0
    return( -1 );
749
0
  }
750
0
  else if( result != 0 )
751
0
  {
752
0
    result = libfvalue_value_get_utf16_string_size(
753
0
              value,
754
0
              0,
755
0
              utf16_string_size,
756
0
              error );
757
758
0
    if( result == -1 )
759
0
    {
760
0
      libcerror_error_set(
761
0
       error,
762
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
763
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
764
0
       "%s: unable to retrieve UTF-16 string size of value.",
765
0
       function );
766
767
0
      return( -1 );
768
0
    }
769
0
  }
770
0
  return( result );
771
0
}
772
773
/* Retrieves the UTF-16 encoded value of an identifier
774
 * The string size should include the end of string character
775
 * Returns 1 if successful, 0 if not set or -1 on error
776
 */
777
int libewf_value_table_get_utf16_value(
778
     libfvalue_table_t *value_table,
779
     const uint8_t *identifier,
780
     size_t identifier_length,
781
     uint16_t *utf16_string,
782
     size_t utf16_string_size,
783
     libcerror_error_t **error )
784
0
{
785
0
  libfvalue_value_t *value = NULL;
786
0
  static char *function    = "libewf_value_table_get_utf16_value";
787
0
  int result               = 0;
788
789
0
  if( value_table == NULL )
790
0
  {
791
0
    libcerror_error_set(
792
0
     error,
793
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
794
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
795
0
     "%s: invalid value table.",
796
0
     function );
797
798
0
    return( -1 );
799
0
  }
800
0
  if( identifier == NULL )
801
0
  {
802
0
    libcerror_error_set(
803
0
     error,
804
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
805
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
806
0
     "%s: invalid indentifier.",
807
0
     function );
808
809
0
    return( -1 );
810
0
  }
811
0
  result = libfvalue_table_get_value_by_identifier(
812
0
            value_table,
813
0
            identifier,
814
0
            identifier_length + 1,
815
0
            &value,
816
0
            0,
817
0
            error );
818
819
0
  if( result == -1 )
820
0
  {
821
0
    libcerror_error_set(
822
0
     error,
823
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
824
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
825
0
     "%s: unable to retrieve value: %s.",
826
0
     function,
827
0
     (char *) identifier );
828
829
0
    return( -1 );
830
0
  }
831
0
  else if( result != 0 )
832
0
  {
833
0
    result = libfvalue_value_copy_to_utf16_string(
834
0
              value,
835
0
              0,
836
0
              utf16_string,
837
0
              utf16_string_size,
838
0
              error );
839
840
0
    if( result == -1 )
841
0
    {
842
0
      libcerror_error_set(
843
0
       error,
844
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
845
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
846
0
       "%s: unable to copy value to UTF-16 string.",
847
0
       function );
848
849
0
      return( -1 );
850
0
    }
851
0
  }
852
0
  return( result );
853
0
}
854
855
/* Copies a value specified by the identifier from an UTF-16 encoded string
856
 * Returns 1 if successful or -1 on error
857
 */
858
int libewf_value_table_copy_value_from_utf16_string(
859
     libfvalue_table_t *value_table,
860
     const uint8_t *identifier,
861
     size_t identifier_length,
862
     const uint16_t *utf16_string,
863
     size_t utf16_string_length,
864
     libcerror_error_t **error )
865
0
{
866
0
  libfvalue_value_t *safe_value = NULL;
867
0
  libfvalue_value_t *value      = NULL;
868
0
  static char *function         = "libewf_value_table_copy_value_from_utf16_string";
869
0
  int result                    = 0;
870
871
0
  if( value_table == NULL )
872
0
  {
873
0
    libcerror_error_set(
874
0
     error,
875
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
876
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
877
0
     "%s: invalid values.",
878
0
     function );
879
880
0
    return( -1 );
881
0
  }
882
0
  if( identifier == NULL )
883
0
  {
884
0
    libcerror_error_set(
885
0
     error,
886
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
887
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
888
0
     "%s: invalid identifier.",
889
0
     function );
890
891
0
    return( -1 );
892
0
  }
893
0
  if( identifier_length > (size_t) ( SSIZE_MAX - 1 ) )
894
0
  {
895
0
    libcerror_error_set(
896
0
     error,
897
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
898
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
899
0
     "%s: invalid identifier length value exceeds maximum.",
900
0
     function );
901
902
0
    return( -1 );
903
0
  }
904
0
  result = libfvalue_table_get_value_by_identifier(
905
0
            value_table,
906
0
            identifier,
907
0
            identifier_length + 1,
908
0
            &value,
909
0
            0,
910
0
            error );
911
912
0
  if( result == -1 )
913
0
  {
914
0
    libcerror_error_set(
915
0
     error,
916
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
917
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
918
0
     "%s: unable to retrieve value: %s.",
919
0
     function,
920
0
     (char *) identifier );
921
922
0
    goto on_error;
923
0
  }
924
0
  else if( result == 0 )
925
0
  {
926
0
    if( libfvalue_value_type_initialize(
927
0
         &safe_value,
928
0
         LIBFVALUE_VALUE_TYPE_STRING_UTF8,
929
0
         error ) != 1 )
930
0
    {
931
0
      libcerror_error_set(
932
0
       error,
933
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
934
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
935
0
       "%s: unable to create value.",
936
0
       function );
937
938
0
      goto on_error;
939
0
    }
940
0
    if( libfvalue_value_set_identifier(
941
0
         safe_value,
942
0
         identifier,
943
0
         identifier_length + 1,
944
0
         LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
945
0
         error ) != 1 )
946
0
    {
947
0
      libcerror_error_set(
948
0
       error,
949
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
950
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
951
0
       "%s: unable to set value: %s identifier.",
952
0
       function,
953
0
       (char *) identifier );
954
955
0
      goto on_error;
956
0
    }
957
0
    if( libfvalue_table_set_value(
958
0
         value_table,
959
0
         safe_value,
960
0
         error ) != 1 )
961
0
    {
962
0
      libcerror_error_set(
963
0
       error,
964
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
965
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
966
0
       "%s: unable to set value: %s in table.",
967
0
       function,
968
0
       (char *) identifier );
969
970
0
      goto on_error;
971
0
    }
972
0
    value      = safe_value;
973
0
    safe_value = NULL;
974
0
  }
975
0
  if( libfvalue_value_copy_from_utf16_string(
976
0
       value,
977
0
       0,
978
0
       utf16_string,
979
0
       utf16_string_length,
980
0
       error ) != 1 )
981
0
  {
982
0
    libcerror_error_set(
983
0
     error,
984
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
985
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
986
0
     "%s: unable to copy value from UTF-16 string.",
987
0
     function );
988
989
0
    goto on_error;
990
0
  }
991
0
  return( 1 );
992
993
0
on_error:
994
0
  if( safe_value != NULL )
995
0
  {
996
0
    libfvalue_value_free(
997
0
     &safe_value,
998
0
     NULL );
999
0
  }
1000
0
  return( -1 );
1001
0
}