Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libsmraw/libfvalue/libfvalue_value.c
Line
Count
Source
1
/*
2
 * Value functions
3
 *
4
 * Copyright (C) 2010-2026, 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 <file_stream.h>
24
#include <memory.h>
25
#include <narrow_string.h>
26
#include <system_string.h>
27
#include <types.h>
28
#include <wide_string.h>
29
30
#include "libfvalue_data_handle.h"
31
#include "libfvalue_definitions.h"
32
#include "libfvalue_libcdata.h"
33
#include "libfvalue_libcerror.h"
34
#include "libfvalue_libcnotify.h"
35
#include "libfvalue_types.h"
36
#include "libfvalue_value.h"
37
38
/* Creates a value
39
 * Make sure the value value is referencing, is set to NULL
40
 * Returns 1 if successful or -1 on error
41
 */
42
int libfvalue_value_initialize(
43
     libfvalue_value_t **value,
44
     const char *type_string,
45
     const char *type_description,
46
     libfvalue_data_handle_t *data_handle,
47
     int (*initialize_instance)(
48
           intptr_t **instance,
49
           libcerror_error_t **error ),
50
     int (*free_instance)(
51
           intptr_t **instance,
52
           libcerror_error_t **error ),
53
     int (*clone_instance)(
54
           intptr_t **destination_instance,
55
           intptr_t *source_instance,
56
           libcerror_error_t **error ),
57
     int (*copy_from_byte_stream)(
58
           intptr_t *instance,
59
           const uint8_t *byte_stream,
60
           size_t byte_stream_size,
61
           int encoding,
62
           libcerror_error_t **error ),
63
     int (*copy_to_byte_stream)(
64
           intptr_t *instance,
65
           uint8_t *byte_stream,
66
           size_t byte_stream_size,
67
           int encoding,
68
           libcerror_error_t **error ),
69
     int (*copy_from_integer)(
70
           intptr_t *instance,
71
           uint64_t integer_value,
72
           size_t integer_value_size,
73
           libcerror_error_t **error ),
74
     int (*copy_to_integer)(
75
           intptr_t *instance,
76
           uint64_t *integer_value,
77
           size_t *integer_value_size,
78
           libcerror_error_t **error ),
79
     int (*copy_from_floating_point)(
80
           intptr_t *instance,
81
           double floating_point_value,
82
           size_t floating_point_value_size,
83
           libcerror_error_t **error ),
84
     int (*copy_to_floating_point)(
85
           intptr_t *instance,
86
           double *floating_point_value,
87
           size_t *floating_point_value_size,
88
           libcerror_error_t **error ),
89
     int (*copy_from_utf8_string_with_index)(
90
           intptr_t *instance,
91
           const uint8_t *utf8_string,
92
           size_t utf8_string_length,
93
           size_t *utf8_string_index,
94
           uint32_t string_format_flags,
95
           libcerror_error_t **error ),
96
     int (*get_utf8_string_size)(
97
           intptr_t *instance,
98
           size_t *utf8_string_size,
99
           uint32_t string_format_flags,
100
           libcerror_error_t **error ),
101
     int (*copy_to_utf8_string_with_index)(
102
           intptr_t *instance,
103
           uint8_t *utf8_string,
104
           size_t utf8_string_size,
105
           size_t *utf8_string_index,
106
           uint32_t string_format_flags,
107
           libcerror_error_t **error ),
108
     int (*copy_from_utf16_string_with_index)(
109
           intptr_t *instance,
110
           const uint16_t *utf16_string,
111
           size_t utf16_string_length,
112
           size_t *utf16_string_index,
113
           uint32_t string_format_flags,
114
           libcerror_error_t **error ),
115
     int (*get_utf16_string_size)(
116
           intptr_t *instance,
117
           size_t *utf16_string_size,
118
           uint32_t string_format_flags,
119
           libcerror_error_t **error ),
120
     int (*copy_to_utf16_string_with_index)(
121
           intptr_t *instance,
122
           uint16_t *utf16_string,
123
           size_t utf16_string_size,
124
           size_t *utf16_string_index,
125
           uint32_t string_format_flags,
126
           libcerror_error_t **error ),
127
     int (*copy_from_utf32_string_with_index)(
128
           intptr_t *instance,
129
           const uint32_t *utf32_string,
130
           size_t utf32_string_length,
131
           size_t *utf32_string_index,
132
           uint32_t string_format_flags,
133
           libcerror_error_t **error ),
134
     int (*get_utf32_string_size)(
135
           intptr_t *instance,
136
           size_t *utf32_string_size,
137
           uint32_t string_format_flags,
138
           libcerror_error_t **error ),
139
     int (*copy_to_utf32_string_with_index)(
140
           intptr_t *instance,
141
           uint32_t *utf32_string,
142
           size_t utf32_string_size,
143
           size_t *utf32_string_index,
144
           uint32_t string_format_flags,
145
           libcerror_error_t **error ),
146
     uint8_t flags,
147
     libcerror_error_t **error )
148
84.2k
{
149
84.2k
  libfvalue_internal_value_t *internal_value = NULL;
150
84.2k
  static char *function                      = "libfvalue_value_initialize";
151
152
84.2k
  if( value == NULL )
153
0
  {
154
0
    libcerror_error_set(
155
0
     error,
156
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
157
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
158
0
     "%s: invalid value.",
159
0
     function );
160
161
0
    return( -1 );
162
0
  }
163
84.2k
  if( *value != NULL )
164
0
  {
165
0
    libcerror_error_set(
166
0
     error,
167
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
168
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
169
0
     "%s: invalid value value already set.",
170
0
     function );
171
172
0
    return( -1 );
173
0
  }
174
84.2k
  if( type_string == NULL )
175
0
  {
176
0
    libcerror_error_set(
177
0
     error,
178
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
179
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
180
0
     "%s: invalid type string",
181
0
     function );
182
183
0
    return( -1 );
184
0
  }
185
84.2k
  internal_value = memory_allocate_structure(
186
84.2k
                    libfvalue_internal_value_t );
187
188
84.2k
  if( internal_value == NULL )
189
0
  {
190
0
    libcerror_error_set(
191
0
     error,
192
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
193
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
194
0
     "%s: unable to create value.",
195
0
     function );
196
197
0
    goto on_error;
198
0
  }
199
84.2k
  if( memory_set(
200
84.2k
       internal_value,
201
84.2k
       0,
202
84.2k
       sizeof( libfvalue_internal_value_t ) ) == NULL )
203
0
  {
204
0
    libcerror_error_set(
205
0
     error,
206
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
207
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
208
0
     "%s: unable to clear value.",
209
0
     function );
210
211
0
    memory_free(
212
0
     internal_value );
213
214
0
    return( -1 );
215
0
  }
216
84.2k
  if( free_instance != NULL )
217
84.2k
  {
218
84.2k
    if( libcdata_array_initialize(
219
84.2k
         &( internal_value->value_instances ),
220
84.2k
         1,
221
84.2k
         error ) != 1 )
222
0
    {
223
0
      libcerror_error_set(
224
0
       error,
225
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
226
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
227
0
       "%s: unable to create value instances array.",
228
0
       function );
229
230
0
      goto on_error;
231
0
    }
232
84.2k
  }
233
84.2k
  if( data_handle == NULL )
234
63.8k
  {
235
/* TODO add read function ? */
236
63.8k
    if( libfvalue_data_handle_initialize(
237
63.8k
         &( internal_value->data_handle ),
238
63.8k
         NULL,
239
63.8k
         error ) != 1 )
240
0
    {
241
0
      libcerror_error_set(
242
0
       error,
243
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
244
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
245
0
       "%s: unable to create data handle.",
246
0
       function );
247
248
0
      goto on_error;
249
0
    }
250
63.8k
    internal_value->flags |= LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED;
251
63.8k
  }
252
20.3k
  else
253
20.3k
  {
254
20.3k
    internal_value->data_handle = data_handle;
255
20.3k
  }
256
84.2k
  internal_value->type_string                       = type_string;
257
84.2k
  internal_value->type_description                  = type_description;
258
259
84.2k
  internal_value->initialize_instance               = initialize_instance;
260
84.2k
  internal_value->free_instance                     = free_instance;
261
84.2k
  internal_value->clone_instance                    = clone_instance;
262
263
84.2k
  internal_value->copy_from_byte_stream             = copy_from_byte_stream;
264
84.2k
  internal_value->copy_to_byte_stream               = copy_to_byte_stream;
265
266
84.2k
  internal_value->copy_from_integer                 = copy_from_integer;
267
84.2k
  internal_value->copy_to_integer                   = copy_to_integer;
268
269
84.2k
  internal_value->copy_from_floating_point          = copy_from_floating_point;
270
84.2k
  internal_value->copy_to_floating_point            = copy_to_floating_point;
271
272
84.2k
  internal_value->copy_from_utf8_string_with_index  = copy_from_utf8_string_with_index;
273
84.2k
  internal_value->get_utf8_string_size              = get_utf8_string_size;
274
84.2k
  internal_value->copy_to_utf8_string_with_index    = copy_to_utf8_string_with_index;
275
276
84.2k
  internal_value->copy_from_utf16_string_with_index = copy_from_utf16_string_with_index;
277
84.2k
  internal_value->get_utf16_string_size             = get_utf16_string_size;
278
84.2k
  internal_value->copy_to_utf16_string_with_index   = copy_to_utf16_string_with_index;
279
280
84.2k
  internal_value->copy_from_utf32_string_with_index = copy_from_utf32_string_with_index;
281
84.2k
  internal_value->get_utf32_string_size             = get_utf32_string_size;
282
84.2k
  internal_value->copy_to_utf32_string_with_index   = copy_to_utf32_string_with_index;
283
284
84.2k
  internal_value->flags                            |= flags;
285
286
84.2k
  *value = (libfvalue_value_t *) internal_value;
287
288
84.2k
  return( 1 );
289
290
0
on_error:
291
0
  if( internal_value != NULL )
292
0
  {
293
0
    if( internal_value->value_instances != NULL )
294
0
    {
295
0
      libcdata_array_free(
296
0
       &( internal_value->value_instances ),
297
0
       NULL,
298
0
       NULL );
299
0
    }
300
0
    memory_free(
301
0
     internal_value );
302
0
  }
303
0
  return( -1 );
304
84.2k
}
305
306
/* Frees a value
307
 * Returns 1 if successful or -1 on error
308
 */
309
int libfvalue_value_free(
310
     libfvalue_value_t **value,
311
     libcerror_error_t **error )
312
84.2k
{
313
84.2k
  libfvalue_internal_value_t *internal_value = NULL;
314
84.2k
  static char *function                      = "libfvalue_value_free";
315
84.2k
  int result                                 = 1;
316
317
84.2k
  if( value == NULL )
318
0
  {
319
0
    libcerror_error_set(
320
0
     error,
321
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
322
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
323
0
     "%s: invalid value.",
324
0
     function );
325
326
0
    return( -1 );
327
0
  }
328
84.2k
  if( *value != NULL )
329
84.2k
  {
330
84.2k
    if( libfvalue_value_clear(
331
84.2k
         *value,
332
84.2k
         error ) != 1 )
333
0
    {
334
0
      libcerror_error_set(
335
0
       error,
336
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
337
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
338
0
       "%s: unable to free data handle.",
339
0
       function );
340
341
0
      result = -1;
342
0
    }
343
84.2k
    internal_value = (libfvalue_internal_value_t *) *value;
344
84.2k
    *value         = NULL;
345
346
84.2k
    if( internal_value->value_instances != NULL )
347
84.2k
    {
348
84.2k
      if( libcdata_array_free(
349
84.2k
           &( internal_value->value_instances ),
350
84.2k
           internal_value->free_instance,
351
84.2k
           error ) != 1 )
352
0
      {
353
0
        libcerror_error_set(
354
0
         error,
355
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
356
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
357
0
         "%s: unable to free value instances array.",
358
0
         function );
359
360
0
        result = -1;
361
0
      }
362
84.2k
    }
363
84.2k
    if( ( internal_value->flags & LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED ) != 0 )
364
84.2k
    {
365
84.2k
      if( libfvalue_data_handle_free(
366
84.2k
           &( internal_value->data_handle ),
367
84.2k
           error ) != 1 )
368
0
      {
369
0
        libcerror_error_set(
370
0
         error,
371
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
372
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
373
0
         "%s: unable to free data handle.",
374
0
         function );
375
376
0
        result = -1;
377
0
      }
378
84.2k
      internal_value->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED );
379
84.2k
    }
380
84.2k
    memory_free(
381
84.2k
     internal_value );
382
84.2k
  }
383
84.2k
  return( result );
384
84.2k
}
385
386
/* Clones a value
387
 * Returns 1 if successful or -1 on error
388
 */
389
int libfvalue_value_clone(
390
     libfvalue_value_t **destination_value,
391
     libfvalue_value_t *source_value,
392
     libcerror_error_t **error )
393
0
{
394
0
  libfvalue_internal_value_t *internal_source_value = NULL;
395
0
  libfvalue_data_handle_t *destination_data_handle  = NULL;
396
0
  static char *function                             = "libfvalue_value_clone";
397
398
0
  if( destination_value == 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 destination value.",
405
0
     function );
406
407
0
    return( -1 );
408
0
  }
409
0
  if( *destination_value != NULL )
410
0
  {
411
0
    libcerror_error_set(
412
0
     error,
413
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
414
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
415
0
     "%s: destination value already set.",
416
0
     function );
417
418
0
    return( -1 );
419
0
  }
420
0
  if( source_value == NULL )
421
0
  {
422
0
    *destination_value = NULL;
423
424
0
    return( 1 );
425
0
  }
426
0
  internal_source_value = (libfvalue_internal_value_t *) source_value;
427
428
0
  if( libfvalue_data_handle_clone(
429
0
       &destination_data_handle,
430
0
       internal_source_value->data_handle,
431
0
       error ) != 1 )
432
0
  {
433
0
    libcerror_error_set(
434
0
     error,
435
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
436
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
437
0
     "%s: unable to create destination data handle.",
438
0
     function );
439
440
0
    goto on_error;
441
0
  }
442
0
  if( libfvalue_value_initialize(
443
0
       destination_value,
444
0
       internal_source_value->type_string,
445
0
       internal_source_value->type_description,
446
0
       destination_data_handle,
447
0
       internal_source_value->initialize_instance,
448
0
       internal_source_value->free_instance,
449
0
       internal_source_value->clone_instance,
450
0
       internal_source_value->copy_from_byte_stream,
451
0
       internal_source_value->copy_to_byte_stream,
452
0
       internal_source_value->copy_from_integer,
453
0
       internal_source_value->copy_to_integer,
454
0
       internal_source_value->copy_from_floating_point,
455
0
       internal_source_value->copy_to_floating_point,
456
0
       internal_source_value->copy_from_utf8_string_with_index,
457
0
       internal_source_value->get_utf8_string_size,
458
0
       internal_source_value->copy_to_utf8_string_with_index,
459
0
       internal_source_value->copy_from_utf16_string_with_index,
460
0
       internal_source_value->get_utf16_string_size,
461
0
       internal_source_value->copy_to_utf16_string_with_index,
462
0
       internal_source_value->copy_from_utf32_string_with_index,
463
0
       internal_source_value->get_utf32_string_size,
464
0
       internal_source_value->copy_to_utf32_string_with_index,
465
0
       internal_source_value->flags | LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED,
466
0
       error ) != 1 )
467
0
  {
468
0
    libcerror_error_set(
469
0
     error,
470
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
471
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
472
0
     "%s: unable to create destination value.",
473
0
     function );
474
475
0
    goto on_error;
476
0
  }
477
0
  if( *destination_value == NULL )
478
0
  {
479
0
    libcerror_error_set(
480
0
     error,
481
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
482
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
483
0
     "%s: missing destination value.",
484
0
     function );
485
486
0
    goto on_error;
487
0
  }
488
0
  destination_data_handle = NULL;
489
490
0
  if( internal_source_value->identifier != NULL )
491
0
  {
492
0
    if( libfvalue_value_set_identifier(
493
0
         *destination_value,
494
0
         internal_source_value->identifier,
495
0
         internal_source_value->identifier_size,
496
0
         LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
497
0
         error ) != 1 )
498
0
    {
499
0
      libcerror_error_set(
500
0
       error,
501
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
502
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
503
0
       "%s: unable to set identifier in destination value.",
504
0
       function );
505
506
0
      goto on_error;
507
0
    }
508
0
  }
509
  /* The value instances are not cloned and are re-created on demand
510
   */
511
0
  return( 1 );
512
513
0
on_error:
514
0
  if( destination_data_handle != NULL )
515
0
  {
516
0
    libfvalue_data_handle_free(
517
0
     &destination_data_handle,
518
0
     NULL );
519
0
  }
520
0
  if( *destination_value != NULL )
521
0
  {
522
0
    libfvalue_value_free(
523
0
     destination_value,
524
0
     NULL );
525
0
  }
526
0
  return( -1 );
527
0
}
528
529
/* Clears a value
530
 * Returns 1 if successful or -1 on error
531
 */
532
int libfvalue_value_clear(
533
     libfvalue_value_t *value,
534
     libcerror_error_t **error )
535
84.2k
{
536
84.2k
  libfvalue_internal_value_t *internal_value = NULL;
537
84.2k
  static char *function                      = "libfvalue_value_clear";
538
539
84.2k
  if( value == NULL )
540
0
  {
541
0
    libcerror_error_set(
542
0
     error,
543
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
544
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
545
0
     "%s: invalid value.",
546
0
     function );
547
548
0
    return( -1 );
549
0
  }
550
84.2k
  internal_value = (libfvalue_internal_value_t *) value;
551
552
84.2k
  if( ( internal_value->flags & LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED ) != 0 )
553
62.6k
  {
554
62.6k
    if( internal_value->identifier != NULL )
555
62.6k
    {
556
62.6k
      memory_free(
557
62.6k
       internal_value->identifier );
558
62.6k
    }
559
62.6k
    internal_value->flags &= ~( LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED );
560
62.6k
  }
561
84.2k
  if( libfvalue_data_handle_clear(
562
84.2k
       internal_value->data_handle,
563
84.2k
       error ) != 1 )
564
0
  {
565
0
    libcerror_error_set(
566
0
     error,
567
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
568
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
569
0
     "%s: unable to clear data handle.",
570
0
     function );
571
572
0
    return( -1 );
573
0
  }
574
84.2k
  if( internal_value->value_instances != NULL )
575
84.2k
  {
576
84.2k
    if( internal_value->free_instance == NULL )
577
0
    {
578
0
      libcerror_error_set(
579
0
       error,
580
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
581
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
582
0
       "%s: invalid value - missing free instance function.",
583
0
       function );
584
585
0
      return( -1 );
586
0
    }
587
84.2k
    if( libcdata_array_empty(
588
84.2k
         internal_value->value_instances,
589
84.2k
         internal_value->free_instance,
590
84.2k
         error ) != 1 )
591
0
    {
592
0
      libcerror_error_set(
593
0
       error,
594
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
595
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
596
0
       "%s: unable to empty value instances array.",
597
0
       function );
598
599
0
      return( -1 );
600
0
    }
601
84.2k
  }
602
84.2k
  return( 1 );
603
84.2k
}
604
605
/* Retrieves the value type
606
 * Returns 1 if successful or -1 on error
607
 */
608
int libfvalue_value_get_type(
609
     libfvalue_value_t *value,
610
     int *value_type,
611
     libcerror_error_t **error )
612
0
{
613
0
  libfvalue_internal_value_t *internal_value = NULL;
614
0
  static char *function                      = "libfvalue_value_get_type";
615
616
0
  if( value == NULL )
617
0
  {
618
0
    libcerror_error_set(
619
0
     error,
620
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
621
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
622
0
     "%s: invalid value.",
623
0
     function );
624
625
0
    return( -1 );
626
0
  }
627
0
  internal_value = (libfvalue_internal_value_t *) value;
628
629
0
  if( value_type == NULL )
630
0
  {
631
0
    libcerror_error_set(
632
0
     error,
633
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
634
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
635
0
     "%s: invalid value type.",
636
0
     function );
637
638
0
    return( -1 );
639
0
  }
640
0
  *value_type = internal_value->type;
641
642
0
  return( 1 );
643
0
}
644
645
/* Compares two index values
646
 * Returns LIBCDATA_COMPARE_LESS, LIBCDATA_COMPARE_EQUAL, LIBCDATA_COMPARE_GREATER if successful or -1 on error
647
 */
648
int libfvalue_compare_identifier(
649
     intptr_t *first_value,
650
     intptr_t *second_value,
651
     libcerror_error_t **error )
652
0
{
653
0
  libfvalue_internal_value_t *internal_first_value  = NULL;
654
0
  libfvalue_internal_value_t *internal_second_value = NULL;
655
0
  static char *function                             = "libfvalue_compare_identifier";
656
0
  size_t compare_size                               = 0;
657
0
  int result                                        = 0;
658
659
0
  if( first_value == NULL )
660
0
  {
661
0
    libcerror_error_set(
662
0
     error,
663
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
664
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
665
0
     "%s: invalid first value.",
666
0
     function );
667
668
0
    return( -1 );
669
0
  }
670
0
  internal_first_value = (libfvalue_internal_value_t *) first_value;
671
672
0
  if( second_value == NULL )
673
0
  {
674
0
    libcerror_error_set(
675
0
     error,
676
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
677
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
678
0
     "%s: invalid second value.",
679
0
     function );
680
681
0
    return( -1 );
682
0
  }
683
0
  internal_second_value = (libfvalue_internal_value_t *) second_value;
684
685
0
  if( internal_first_value->identifier == NULL )
686
0
  {
687
0
    libcerror_error_set(
688
0
     error,
689
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
690
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
691
0
     "%s: invalid first value - missing identifier.",
692
0
     function );
693
694
0
    return( -1 );
695
0
  }
696
0
  if( internal_second_value->identifier == NULL )
697
0
  {
698
0
    libcerror_error_set(
699
0
     error,
700
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
701
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
702
0
     "%s: invalid second value - missing identifier.",
703
0
     function );
704
705
0
    return( -1 );
706
0
  }
707
0
  if( internal_first_value->identifier_size <= internal_second_value->identifier_size )
708
0
  {
709
0
    compare_size = internal_first_value->identifier_size;
710
0
  }
711
0
  else
712
0
  {
713
0
    compare_size = internal_second_value->identifier_size;
714
0
  }
715
0
  result = memory_compare(
716
0
            internal_first_value->identifier,
717
0
            internal_second_value->identifier,
718
0
            compare_size );
719
720
0
  if( result < 0 )
721
0
  {
722
0
    return( LIBCDATA_COMPARE_LESS );
723
0
  }
724
0
  else if( result > 0 )
725
0
  {
726
0
    return( LIBCDATA_COMPARE_GREATER );
727
0
  }
728
0
  if( internal_first_value->identifier_size < internal_second_value->identifier_size )
729
0
  {
730
0
    return( LIBCDATA_COMPARE_LESS );
731
0
  }
732
0
  else if( internal_first_value->identifier_size > internal_second_value->identifier_size )
733
0
  {
734
0
    return( LIBCDATA_COMPARE_GREATER );
735
0
  }
736
0
  return( LIBCDATA_COMPARE_EQUAL );
737
0
}
738
739
/* Retrieves the identifier
740
 * Returns 1 if successful or -1 on error
741
 */
742
int libfvalue_value_get_identifier(
743
     libfvalue_value_t *value,
744
     uint8_t **identifier,
745
     size_t *identifier_size,
746
     libcerror_error_t **error )
747
0
{
748
0
  libfvalue_internal_value_t *internal_value = NULL;
749
0
  static char *function                      = "libfvalue_value_get_identifier";
750
751
0
  if( value == NULL )
752
0
  {
753
0
    libcerror_error_set(
754
0
     error,
755
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
756
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
757
0
     "%s: invalid value.",
758
0
     function );
759
760
0
    return( -1 );
761
0
  }
762
0
  internal_value = (libfvalue_internal_value_t *) value;
763
764
0
  if( identifier == NULL )
765
0
  {
766
0
    libcerror_error_set(
767
0
     error,
768
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
769
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
770
0
     "%s: invalid identifier.",
771
0
     function );
772
773
0
    return( -1 );
774
0
  }
775
0
  if( identifier_size == NULL )
776
0
  {
777
0
    libcerror_error_set(
778
0
     error,
779
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
780
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
781
0
     "%s: invalid identifier size.",
782
0
     function );
783
784
0
    return( -1 );
785
0
  }
786
0
  *identifier      = internal_value->identifier;
787
0
  *identifier_size = internal_value->identifier_size;
788
789
0
  return( 1 );
790
0
}
791
792
/* Sets the identifier
793
 * Returns 1 if successful or -1 on error
794
 */
795
int libfvalue_value_set_identifier(
796
     libfvalue_value_t *value,
797
     const uint8_t *identifier,
798
     size_t identifier_size,
799
     uint8_t flags,
800
     libcerror_error_t **error )
801
62.6k
{
802
62.6k
  libfvalue_internal_value_t *internal_value = NULL;
803
62.6k
  static char *function                      = "libfvalue_value_set_identifier";
804
62.6k
  uint8_t supported_flags                    = 0;
805
806
62.6k
  if( value == NULL )
807
0
  {
808
0
    libcerror_error_set(
809
0
     error,
810
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
811
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
812
0
     "%s: invalid value.",
813
0
     function );
814
815
0
    return( -1 );
816
0
  }
817
62.6k
  internal_value = (libfvalue_internal_value_t *) value;
818
819
62.6k
  if( internal_value->identifier != NULL )
820
0
  {
821
0
    libcerror_error_set(
822
0
     error,
823
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
824
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
825
0
     "%s: invalid value - identifier already set.",
826
0
     function );
827
828
0
    return( -1 );
829
0
  }
830
62.6k
  if( identifier == NULL )
831
0
  {
832
0
    libcerror_error_set(
833
0
     error,
834
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
835
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
836
0
     "%s: invalid identifier.",
837
0
     function );
838
839
0
    return( -1 );
840
0
  }
841
62.6k
  if( ( identifier_size == 0 )
842
62.6k
   || ( identifier_size > (size_t) SSIZE_MAX ) )
843
0
  {
844
0
    libcerror_error_set(
845
0
     error,
846
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
847
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
848
0
     "%s: invalid identifier length value out of bounds.",
849
0
     function );
850
851
0
    return( -1 );
852
0
  }
853
62.6k
  supported_flags = LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED
854
62.6k
                  | LIBFVALUE_VALUE_IDENTIFIER_FLAG_CLONE_BY_REFERENCE;
855
856
62.6k
  if( ( flags & ~( supported_flags ) ) != 0 )
857
0
  {
858
0
    libcerror_error_set(
859
0
     error,
860
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
861
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
862
0
     "%s: unsupported flags: 0x%02" PRIx8 ".",
863
0
     function,
864
0
     flags );
865
866
0
    return( -1 );
867
0
  }
868
62.6k
  if( ( internal_value->flags & LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED ) != 0 )
869
0
  {
870
0
    if( internal_value->identifier != NULL )
871
0
    {
872
0
      memory_free(
873
0
       internal_value->identifier );
874
875
0
      internal_value->identifier      = NULL;
876
0
      internal_value->identifier_size = 0;
877
0
    }
878
0
    internal_value->flags &= ~( LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED );
879
0
  }
880
62.6k
  if( ( flags & LIBFVALUE_VALUE_IDENTIFIER_FLAG_CLONE_BY_REFERENCE ) != 0 )
881
0
  {
882
0
    internal_value->identifier = (uint8_t *) identifier;
883
884
0
    if( ( flags & LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED ) != 0 )
885
0
    {
886
0
      internal_value->flags |= LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED;
887
0
    }
888
0
  }
889
62.6k
  else
890
62.6k
  {
891
62.6k
    internal_value->identifier = (uint8_t *) memory_allocate(
892
62.6k
                                              sizeof( uint8_t ) * identifier_size );
893
894
62.6k
    if( internal_value->identifier == NULL )
895
0
    {
896
0
      libcerror_error_set(
897
0
       error,
898
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
899
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
900
0
       "%s: unable to create identifier.",
901
0
       function );
902
903
0
      goto on_error;
904
0
    }
905
62.6k
    if( memory_copy(
906
62.6k
         internal_value->identifier,
907
62.6k
         identifier,
908
62.6k
         identifier_size ) == NULL )
909
0
    {
910
0
      libcerror_error_set(
911
0
       error,
912
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
913
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
914
0
       "%s: unable to copy identifier.",
915
0
       function );
916
917
0
      goto on_error;
918
0
    }
919
62.6k
    internal_value->flags |= LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED;
920
62.6k
  }
921
62.6k
  internal_value->identifier_size = identifier_size;
922
923
62.6k
  return( 1 );
924
925
0
on_error:
926
0
  if( internal_value->identifier != NULL )
927
0
  {
928
0
    memory_free(
929
0
     internal_value->identifier );
930
931
0
    internal_value->identifier = NULL;
932
0
  }
933
0
  return( -1 );
934
62.6k
}
935
936
/* Retrieves the value data flags
937
 * Returns 1 if successful or -1 on error
938
 */
939
int libfvalue_value_get_data_flags(
940
     libfvalue_value_t *value,
941
     uint32_t *data_flags,
942
     libcerror_error_t **error )
943
0
{
944
0
  libfvalue_internal_value_t *internal_value = NULL;
945
0
  static char *function                      = "libfvalue_value_get_data_flags";
946
947
0
  if( value == NULL )
948
0
  {
949
0
    libcerror_error_set(
950
0
     error,
951
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
952
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
953
0
     "%s: invalid value.",
954
0
     function );
955
956
0
    return( -1 );
957
0
  }
958
0
  internal_value = (libfvalue_internal_value_t *) value;
959
960
0
  if( libfvalue_data_handle_get_data_flags(
961
0
       internal_value->data_handle,
962
0
       data_flags,
963
0
       error ) != 1 )
964
0
  {
965
0
    libcerror_error_set(
966
0
     error,
967
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
968
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
969
0
     "%s: unable to retrieve data flags from data handle.",
970
0
     function );
971
972
0
    return( -1 );
973
0
  }
974
0
  return( 1 );
975
0
}
976
977
/* Sets the value data flags
978
 * Returns 1 if successful or -1 on error
979
 */
980
int libfvalue_value_set_data_flags(
981
     libfvalue_value_t *value,
982
     uint32_t data_flags,
983
     libcerror_error_t **error )
984
0
{
985
0
  libfvalue_internal_value_t *internal_value = NULL;
986
0
  static char *function                      = "libfvalue_value_set_data_flags";
987
988
0
  if( value == NULL )
989
0
  {
990
0
    libcerror_error_set(
991
0
     error,
992
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
993
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
994
0
     "%s: invalid value.",
995
0
     function );
996
997
0
    return( -1 );
998
0
  }
999
0
  internal_value = (libfvalue_internal_value_t *) value;
1000
1001
0
  if( libfvalue_data_handle_set_data_flags(
1002
0
       internal_value->data_handle,
1003
0
       data_flags,
1004
0
       error ) != 1 )
1005
0
  {
1006
0
    libcerror_error_set(
1007
0
     error,
1008
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1009
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1010
0
     "%s: unable to set data flags in data handle.",
1011
0
     function );
1012
1013
0
    return( -1 );
1014
0
  }
1015
0
  return( 1 );
1016
0
}
1017
1018
/* Determines if the value has data
1019
 * Returns 1 if the value has data, 0 if not or -1 on error
1020
 */
1021
int libfvalue_value_has_data(
1022
     libfvalue_value_t *value,
1023
     libcerror_error_t **error )
1024
0
{
1025
0
  libfvalue_internal_value_t *internal_value = NULL;
1026
0
  uint8_t *data                              = NULL;
1027
0
  static char *function                      = "libfvalue_value_has_data";
1028
0
  size_t data_size                           = 0;
1029
0
  int encoding                               = 0;
1030
1031
0
  if( value == NULL )
1032
0
  {
1033
0
    libcerror_error_set(
1034
0
     error,
1035
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1036
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1037
0
     "%s: invalid value.",
1038
0
     function );
1039
1040
0
    return( -1 );
1041
0
  }
1042
0
  internal_value = (libfvalue_internal_value_t *) value;
1043
1044
0
  if( libfvalue_data_handle_get_data(
1045
0
       internal_value->data_handle,
1046
0
       &data,
1047
0
       &data_size,
1048
0
       &encoding,
1049
0
       error ) != 1 )
1050
0
  {
1051
0
    libcerror_error_set(
1052
0
     error,
1053
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1054
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1055
0
     "%s: unable to retrieve data from data handle.",
1056
0
     function );
1057
1058
0
    return( -1 );
1059
0
  }
1060
0
  if( data == NULL )
1061
0
  {
1062
0
    return( 0 );
1063
0
  }
1064
0
  return( 1 );
1065
0
}
1066
1067
/* Initializes the data
1068
 * Returns 1 if successful or -1 on error
1069
 */
1070
int libfvalue_value_initialize_data(
1071
     libfvalue_value_t *value,
1072
     size_t data_size,
1073
     libcerror_error_t **error )
1074
0
{
1075
0
  libfvalue_internal_value_t *internal_value = NULL;
1076
0
  uint8_t *data                              = NULL;
1077
0
  static char *function                      = "libfvalue_value_initialize_data";
1078
0
  int result                                 = 0;
1079
1080
0
  if( value == NULL )
1081
0
  {
1082
0
    libcerror_error_set(
1083
0
     error,
1084
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1085
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1086
0
     "%s: invalid value.",
1087
0
     function );
1088
1089
0
    return( -1 );
1090
0
  }
1091
0
  internal_value = (libfvalue_internal_value_t *) value;
1092
1093
0
  if( ( data_size == 0 )
1094
0
   || ( data_size > (size_t) SSIZE_MAX ) )
1095
0
  {
1096
0
    libcerror_error_set(
1097
0
     error,
1098
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1099
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1100
0
     "%s: invalid data size value out of bounds.",
1101
0
     function );
1102
1103
0
    return( -1 );
1104
0
  }
1105
0
  result = libfvalue_value_has_data(
1106
0
      value,
1107
0
      error );
1108
1109
0
  if( result == -1 )
1110
0
  {
1111
0
    libcerror_error_set(
1112
0
     error,
1113
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1114
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1115
0
     "%s: unable to determine if value has data.",
1116
0
     function );
1117
1118
0
    return( -1 );
1119
0
  }
1120
0
  else if( result != 0 )
1121
0
  {
1122
0
    libcerror_error_set(
1123
0
     error,
1124
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1125
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1126
0
     "%s: invalid value data already set.",
1127
0
     function );
1128
1129
0
    return( -1 );
1130
0
  }
1131
0
  data = (uint8_t *) memory_allocate(
1132
0
                      sizeof( uint8_t ) * data_size );
1133
1134
0
  if( data == NULL )
1135
0
  {
1136
0
    libcerror_error_set(
1137
0
     error,
1138
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1139
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1140
0
     "%s: unable to create data.",
1141
0
     function );
1142
1143
0
    goto on_error;
1144
0
  }
1145
0
  if( libfvalue_data_handle_set_data(
1146
0
       internal_value->data_handle,
1147
0
       data,
1148
0
       data_size,
1149
0
       LIBFVALUE_ENDIAN_NATIVE,
1150
0
       LIBFVALUE_VALUE_DATA_FLAG_MANAGED | LIBFVALUE_VALUE_DATA_FLAG_CLONE_BY_REFERENCE,
1151
0
       error ) != 1 )
1152
0
  {
1153
0
    libcerror_error_set(
1154
0
     error,
1155
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1156
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1157
0
     "%s: unable to set data in data handle.",
1158
0
     function );
1159
1160
0
    goto on_error;
1161
0
  }
1162
#if defined( __clang_analyzer__ )
1163
  __builtin_assume( ( (libfvalue_internal_data_handle_t *) internal_value->data_handle )->data == data );
1164
#endif
1165
0
  return( 1 );
1166
1167
0
on_error:
1168
0
  if( data != NULL )
1169
0
  {
1170
0
    memory_free(
1171
0
     data );
1172
0
  }
1173
0
  return( -1 );
1174
0
}
1175
1176
/* Retrieves the data size
1177
 * Returns 1 if successful or -1 on error
1178
 */
1179
int libfvalue_value_get_data_size(
1180
     libfvalue_value_t *value,
1181
     size_t *data_size,
1182
     libcerror_error_t **error )
1183
0
{
1184
0
  libfvalue_internal_value_t *internal_value = NULL;
1185
0
  uint8_t *data                              = NULL;
1186
0
  static char *function                      = "libfvalue_value_get_data_size";
1187
0
  int encoding                               = 0;
1188
1189
0
  if( value == NULL )
1190
0
  {
1191
0
    libcerror_error_set(
1192
0
     error,
1193
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1194
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1195
0
     "%s: invalid value.",
1196
0
     function );
1197
1198
0
    return( -1 );
1199
0
  }
1200
0
  internal_value = (libfvalue_internal_value_t *) value;
1201
1202
0
  if( libfvalue_data_handle_get_data(
1203
0
       internal_value->data_handle,
1204
0
       &data,
1205
0
       data_size,
1206
0
       &encoding,
1207
0
       error ) != 1 )
1208
0
  {
1209
0
    libcerror_error_set(
1210
0
     error,
1211
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1212
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1213
0
     "%s: unable to retrieve data from data handle.",
1214
0
     function );
1215
1216
0
    return( -1 );
1217
0
  }
1218
0
  if( data == NULL )
1219
0
  {
1220
0
    if( data_size == NULL )
1221
0
    {
1222
0
      libcerror_error_set(
1223
0
       error,
1224
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1225
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1226
0
       "%s: invalid data size.",
1227
0
       function );
1228
1229
0
      return( -1 );
1230
0
    }
1231
0
    *data_size = 0;
1232
0
  }
1233
0
  return( 1 );
1234
0
}
1235
1236
/* Retrieves the data
1237
 * Returns 1 if successful or -1 on error
1238
 */
1239
int libfvalue_value_get_data(
1240
     libfvalue_value_t *value,
1241
     uint8_t **data,
1242
     size_t *data_size,
1243
     int *encoding,
1244
     libcerror_error_t **error )
1245
0
{
1246
0
  libfvalue_internal_value_t *internal_value = NULL;
1247
0
  static char *function                      = "libfvalue_value_get_data";
1248
1249
0
  if( value == NULL )
1250
0
  {
1251
0
    libcerror_error_set(
1252
0
     error,
1253
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1254
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1255
0
     "%s: invalid value.",
1256
0
     function );
1257
1258
0
    return( -1 );
1259
0
  }
1260
0
  internal_value = (libfvalue_internal_value_t *) value;
1261
1262
0
  if( libfvalue_data_handle_get_data(
1263
0
       internal_value->data_handle,
1264
0
       data,
1265
0
       data_size,
1266
0
       encoding,
1267
0
       error ) != 1 )
1268
0
  {
1269
0
    libcerror_error_set(
1270
0
     error,
1271
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1272
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1273
0
     "%s: unable to retrieve data from data handle.",
1274
0
     function );
1275
1276
0
    return( -1 );
1277
0
  }
1278
0
  return( 1 );
1279
0
}
1280
1281
/* Sets the data
1282
 * Returns 1 if successful or -1 on error
1283
 */
1284
int libfvalue_value_set_data(
1285
     libfvalue_value_t *value,
1286
     const uint8_t *data,
1287
     size_t data_size,
1288
     int encoding,
1289
     uint8_t flags,
1290
     libcerror_error_t **error )
1291
6.91k
{
1292
6.91k
  libfvalue_internal_value_t *internal_value = NULL;
1293
6.91k
  static char *function                      = "libfvalue_value_set_data";
1294
1295
6.91k
  if( value == NULL )
1296
0
  {
1297
0
    libcerror_error_set(
1298
0
     error,
1299
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1300
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1301
0
     "%s: invalid value.",
1302
0
     function );
1303
1304
0
    return( -1 );
1305
0
  }
1306
6.91k
  internal_value = (libfvalue_internal_value_t *) value;
1307
1308
6.91k
  if( libfvalue_data_handle_set_data(
1309
6.91k
       internal_value->data_handle,
1310
6.91k
       data,
1311
6.91k
       data_size,
1312
6.91k
       encoding,
1313
6.91k
       flags,
1314
6.91k
       error ) != 1 )
1315
0
  {
1316
0
    libcerror_error_set(
1317
0
     error,
1318
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1319
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1320
0
     "%s: unable to set data in data handle.",
1321
0
     function );
1322
1323
0
    return( -1 );
1324
0
  }
1325
6.91k
  return( 1 );
1326
6.91k
}
1327
1328
/* Copies the data
1329
 * Returns 1 if successful or -1 on error
1330
 */
1331
int libfvalue_value_copy_data(
1332
     libfvalue_value_t *value,
1333
     uint8_t *data,
1334
     size_t data_size,
1335
     libcerror_error_t **error )
1336
0
{
1337
0
  libfvalue_internal_value_t *internal_value = NULL;
1338
0
  uint8_t *data_handle_data                  = NULL;
1339
0
  static char *function                      = "libfvalue_value_copy_data";
1340
0
  size_t data_handle_data_size               = 0;
1341
0
  int encoding                               = 0;
1342
1343
0
  if( value == NULL )
1344
0
  {
1345
0
    libcerror_error_set(
1346
0
     error,
1347
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1348
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1349
0
     "%s: invalid value.",
1350
0
     function );
1351
1352
0
    return( -1 );
1353
0
  }
1354
0
  internal_value = (libfvalue_internal_value_t *) value;
1355
1356
0
  if( data == NULL )
1357
0
  {
1358
0
    libcerror_error_set(
1359
0
     error,
1360
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1361
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1362
0
     "%s: invalid data.",
1363
0
     function );
1364
1365
0
    return( -1 );
1366
0
  }
1367
0
  if( data_size > (size_t) SSIZE_MAX )
1368
0
  {
1369
0
    libcerror_error_set(
1370
0
     error,
1371
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1372
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1373
0
     "%s: invalid data size value exceeds maximum.",
1374
0
     function );
1375
1376
0
    return( -1 );
1377
0
  }
1378
0
  if( libfvalue_data_handle_get_data(
1379
0
       internal_value->data_handle,
1380
0
       &data_handle_data,
1381
0
       &data_handle_data_size,
1382
0
       &encoding,
1383
0
       error ) != 1 )
1384
0
  {
1385
0
    libcerror_error_set(
1386
0
     error,
1387
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1388
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1389
0
     "%s: unable to retrieve data from data handle.",
1390
0
     function );
1391
1392
0
    return( -1 );
1393
0
  }
1394
0
  if( ( data_handle_data == NULL )
1395
0
   || ( data_handle_data_size == 0 ) )
1396
0
  {
1397
0
    libcerror_error_set(
1398
0
     error,
1399
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1400
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1401
0
     "%s: missing data in data handle.",
1402
0
     function );
1403
1404
0
    return( -1 );
1405
0
  }
1406
0
  if( data_handle_data_size > data_size )
1407
0
  {
1408
0
    libcerror_error_set(
1409
0
     error,
1410
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1411
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1412
0
     "%s: invalid data size value too small.",
1413
0
     function );
1414
1415
0
    return( -1 );
1416
0
  }
1417
0
  if( memory_copy(
1418
0
       data,
1419
0
       data_handle_data,
1420
0
       data_handle_data_size ) == NULL )
1421
0
  {
1422
0
    libcerror_error_set(
1423
0
     error,
1424
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1425
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1426
0
     "%s: unable to copy data.",
1427
0
     function );
1428
1429
0
    return( -1 );
1430
0
  }
1431
0
  return( 1 );
1432
0
}
1433
1434
/* Retrieves the format flags
1435
 * Returns 1 if successful or -1 on error
1436
 */
1437
int libfvalue_value_get_format_flags(
1438
     libfvalue_value_t *value,
1439
     uint32_t *format_flags,
1440
     libcerror_error_t **error )
1441
0
{
1442
0
  libfvalue_internal_value_t *internal_value = NULL;
1443
0
  static char *function                      = "libfvalue_value_get_format_flags";
1444
1445
0
  if( value == NULL )
1446
0
  {
1447
0
    libcerror_error_set(
1448
0
     error,
1449
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1450
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1451
0
     "%s: invalid value.",
1452
0
     function );
1453
1454
0
    return( -1 );
1455
0
  }
1456
0
  internal_value = (libfvalue_internal_value_t *) value;
1457
1458
0
  if( format_flags == NULL )
1459
0
  {
1460
0
    libcerror_error_set(
1461
0
     error,
1462
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1463
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1464
0
     "%s: invalid format flags.",
1465
0
     function );
1466
1467
0
    return( -1 );
1468
0
  }
1469
0
  *format_flags = internal_value->format_flags;
1470
1471
0
  return( 1 );
1472
0
}
1473
1474
/* Sets the format flags
1475
 * Returns 1 if successful or -1 on error
1476
 */
1477
int libfvalue_value_set_format_flags(
1478
     libfvalue_value_t *value,
1479
     uint32_t format_flags,
1480
     libcerror_error_t **error )
1481
0
{
1482
0
  libfvalue_internal_value_t *internal_value = NULL;
1483
0
  static char *function                      = "libfvalue_value_set_format_flags";
1484
1485
0
  if( value == NULL )
1486
0
  {
1487
0
    libcerror_error_set(
1488
0
     error,
1489
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1490
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1491
0
     "%s: invalid value.",
1492
0
     function );
1493
1494
0
    return( -1 );
1495
0
  }
1496
0
  internal_value = (libfvalue_internal_value_t *) value;
1497
1498
0
  internal_value->format_flags = format_flags;
1499
1500
0
  return( 1 );
1501
0
}
1502
1503
/* Value instance functions
1504
 */
1505
1506
/* Retrieves the value instance
1507
 * The value instance is created if it does not exist
1508
 * Returns 1 if successful or -1 on error
1509
 */
1510
int libfvalue_value_get_value_instance_by_index(
1511
     libfvalue_value_t *value,
1512
     int value_entry_index,
1513
     intptr_t **value_instance,
1514
     libcerror_error_t **error )
1515
0
{
1516
0
  libfvalue_internal_value_t *internal_value = NULL;
1517
0
  uint8_t *value_entry_data                  = NULL;
1518
0
  static char *function                      = "libfvalue_value_get_value_instance_by_index";
1519
0
  size_t value_entry_data_size               = 0;
1520
0
  int encoding                               = 0;
1521
0
  int result                                 = 0;
1522
1523
0
  if( value == NULL )
1524
0
  {
1525
0
    libcerror_error_set(
1526
0
     error,
1527
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1528
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1529
0
     "%s: invalid value.",
1530
0
     function );
1531
1532
0
    return( -1 );
1533
0
  }
1534
0
  internal_value = (libfvalue_internal_value_t *) value;
1535
1536
0
  if( internal_value->initialize_instance == NULL )
1537
0
  {
1538
0
    libcerror_error_set(
1539
0
     error,
1540
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1541
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1542
0
     "%s: invalid value - missing initialize instance function.",
1543
0
     function );
1544
1545
0
    return( -1 );
1546
0
  }
1547
0
  if( internal_value->value_instances != NULL )
1548
0
  {
1549
0
    if( internal_value->free_instance == NULL )
1550
0
    {
1551
0
      libcerror_error_set(
1552
0
       error,
1553
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1554
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1555
0
       "%s: invalid value - missing free instance function.",
1556
0
       function );
1557
1558
0
      return( -1 );
1559
0
    }
1560
0
    if( internal_value->copy_from_byte_stream == NULL )
1561
0
    {
1562
0
      libcerror_error_set(
1563
0
       error,
1564
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1565
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1566
0
       "%s: invalid value - missing free copy from byte stream function.",
1567
0
       function );
1568
1569
0
      return( -1 );
1570
0
    }
1571
0
  }
1572
0
  if( value_instance == NULL )
1573
0
  {
1574
0
    libcerror_error_set(
1575
0
     error,
1576
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1577
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1578
0
     "%s: invalid value instance.",
1579
0
     function );
1580
1581
0
    return( -1 );
1582
0
  }
1583
0
  if( *value_instance != NULL )
1584
0
  {
1585
0
    libcerror_error_set(
1586
0
     error,
1587
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1588
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1589
0
     "%s: invalid value instance value already set.",
1590
0
     function );
1591
1592
0
    return( -1 );
1593
0
  }
1594
0
  if( libcdata_array_get_entry_by_index(
1595
0
       internal_value->value_instances,
1596
0
       value_entry_index,
1597
0
       value_instance,
1598
0
       error ) != 1 )
1599
0
  {
1600
0
    libcerror_error_set(
1601
0
     error,
1602
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1603
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1604
0
     "%s: unable to retrieve entry: %d from values instances array.",
1605
0
     function,
1606
0
     value_entry_index );
1607
1608
0
    goto on_error;
1609
0
  }
1610
0
  if( *value_instance == NULL )
1611
0
  {
1612
0
    result = libfvalue_value_get_entry_data(
1613
0
              value,
1614
0
              value_entry_index,
1615
0
              &value_entry_data,
1616
0
              &value_entry_data_size,
1617
0
              &encoding,
1618
0
              error );
1619
1620
0
    if( result == -1 )
1621
0
    {
1622
0
      libcerror_error_set(
1623
0
       error,
1624
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1625
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1626
0
       "%s: unable to retrieve entry data: %d.",
1627
0
       function,
1628
0
       value_entry_index );
1629
1630
0
      goto on_error;
1631
0
    }
1632
0
    else if( result != 0 )
1633
0
    {
1634
0
      if( internal_value->initialize_instance(
1635
0
           value_instance,
1636
0
           error ) != 1 )
1637
0
      {
1638
0
        libcerror_error_set(
1639
0
         error,
1640
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
1641
0
         LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1642
0
         "%s: unable to create value instance.",
1643
0
         function );
1644
1645
0
        goto on_error;
1646
0
      }
1647
0
      if( internal_value->copy_from_byte_stream(
1648
0
           *value_instance,
1649
0
           value_entry_data,
1650
0
           value_entry_data_size,
1651
0
           encoding,
1652
0
           error ) != 1 )
1653
0
      {
1654
0
        libcerror_error_set(
1655
0
         error,
1656
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
1657
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1658
0
         "%s: unable to copy value instance from byte stream.",
1659
0
         function );
1660
1661
0
        goto on_error;
1662
0
      }
1663
0
    }
1664
0
    else
1665
0
    {
1666
0
      *value_instance = NULL;
1667
0
    }
1668
0
    if( libcdata_array_set_entry_by_index(
1669
0
         internal_value->value_instances,
1670
0
         value_entry_index,
1671
0
         *value_instance,
1672
0
         error ) != 1 )
1673
0
    {
1674
0
      libcerror_error_set(
1675
0
       error,
1676
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1677
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1678
0
       "%s: unable to set entry: %d in values instances array.",
1679
0
       function,
1680
0
       value_entry_index );
1681
1682
0
      goto on_error;
1683
0
    }
1684
0
  }
1685
0
  return( 1 );
1686
1687
0
on_error:
1688
0
  if( *value_instance != NULL )
1689
0
  {
1690
0
    internal_value->free_instance(
1691
0
     value_instance,
1692
0
     NULL );
1693
0
  }
1694
0
  return( -1 );
1695
0
}
1696
1697
/* Value entry functions
1698
 */
1699
1700
/* Retrieves the number of values entries
1701
 * Returns 1 if successful or -1 on error
1702
 */
1703
int libfvalue_value_get_number_of_value_entries(
1704
     libfvalue_value_t *value,
1705
     int *number_of_value_entries,
1706
     libcerror_error_t **error )
1707
0
{
1708
0
  libfvalue_internal_value_t *internal_value = NULL;
1709
0
  static char *function                      = "libfvalue_value_get_number_of_value_entries";
1710
0
  int safe_number_of_value_entries           = 0;
1711
0
  int result                                 = 0;
1712
1713
0
  if( value == NULL )
1714
0
  {
1715
0
    libcerror_error_set(
1716
0
     error,
1717
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1718
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1719
0
     "%s: invalid value.",
1720
0
     function );
1721
1722
0
    return( -1 );
1723
0
  }
1724
0
  internal_value = (libfvalue_internal_value_t *) value;
1725
1726
0
  if( number_of_value_entries == NULL )
1727
0
  {
1728
0
    libcerror_error_set(
1729
0
     error,
1730
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1731
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1732
0
     "%s: invalid number of value entries.",
1733
0
     function );
1734
1735
0
    return( -1 );
1736
0
  }
1737
0
  result = libfvalue_value_has_data(
1738
0
      value,
1739
0
      error );
1740
1741
0
  if( result == -1 )
1742
0
  {
1743
0
    libcerror_error_set(
1744
0
     error,
1745
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1746
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1747
0
     "%s: unable to determine if value has data.",
1748
0
     function );
1749
1750
0
    return( -1 );
1751
0
  }
1752
0
  else if( result != 0 )
1753
0
  {
1754
0
    if( libfvalue_data_handle_get_number_of_value_entries(
1755
0
         internal_value->data_handle,
1756
0
         &safe_number_of_value_entries,
1757
0
         error ) != 1 )
1758
0
    {
1759
0
      libcerror_error_set(
1760
0
       error,
1761
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1762
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1763
0
       "%s: unable to retrieve number of value entries from data handle.",
1764
0
       function );
1765
1766
0
      return( -1 );
1767
0
    }
1768
0
  }
1769
0
  else if( internal_value->value_instances != NULL )
1770
0
  {
1771
0
    if( libcdata_array_get_number_of_entries(
1772
0
         internal_value->value_instances,
1773
0
         &safe_number_of_value_entries,
1774
0
         error ) != 1 )
1775
0
    {
1776
0
      libcerror_error_set(
1777
0
       error,
1778
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1779
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1780
0
       "%s: unable to retrieve number of entries from values instances array.",
1781
0
       function );
1782
1783
0
      return( -1 );
1784
0
    }
1785
0
  }
1786
0
  if( safe_number_of_value_entries < 0 )
1787
0
  {
1788
0
    libcerror_error_set(
1789
0
     error,
1790
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1791
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
1792
0
     "%s: invalid number of value entries value out of bounds.",
1793
0
     function );
1794
1795
0
    return( -1 );
1796
0
  }
1797
0
  *number_of_value_entries = safe_number_of_value_entries;
1798
1799
0
  return( 1 );
1800
0
}
1801
1802
/* Retrieves the entry
1803
 * Returns 1 if successful, 0 if the value has no data or -1 on error
1804
 */
1805
int libfvalue_value_get_entry(
1806
     libfvalue_value_t *value,
1807
     int value_entry_index,
1808
     size_t *entry_data_offset,
1809
     size_t *entry_data_size,
1810
     libcerror_error_t **error )
1811
0
{
1812
0
  libfvalue_internal_value_t *internal_value = NULL;
1813
0
  static char *function                      = "libfvalue_value_get_entry";
1814
0
  int result                                 = 0;
1815
1816
0
  if( value == NULL )
1817
0
  {
1818
0
    libcerror_error_set(
1819
0
     error,
1820
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1821
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1822
0
     "%s: invalid value.",
1823
0
     function );
1824
1825
0
    return( -1 );
1826
0
  }
1827
0
  internal_value = (libfvalue_internal_value_t *) value;
1828
1829
0
  if( entry_data_offset == NULL )
1830
0
  {
1831
0
    libcerror_error_set(
1832
0
     error,
1833
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1834
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1835
0
     "%s: invalid entry data offset.",
1836
0
     function );
1837
1838
0
    return( -1 );
1839
0
  }
1840
0
  if( entry_data_size == NULL )
1841
0
  {
1842
0
    libcerror_error_set(
1843
0
     error,
1844
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1845
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1846
0
     "%s: invalid entry data size.",
1847
0
     function );
1848
1849
0
    return( -1 );
1850
0
  }
1851
0
  result = libfvalue_value_has_data(
1852
0
            value,
1853
0
            error );
1854
1855
0
  if( result == -1 )
1856
0
  {
1857
0
    libcerror_error_set(
1858
0
     error,
1859
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1860
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1861
0
     "%s: unable to determine if value has data.",
1862
0
     function );
1863
1864
0
    return( -1 );
1865
0
  }
1866
0
  else if( result != 0 )
1867
0
  {
1868
0
    if( libfvalue_data_handle_get_value_entry(
1869
0
         internal_value->data_handle,
1870
0
         value_entry_index,
1871
0
         entry_data_offset,
1872
0
         entry_data_size,
1873
0
         error ) != 1 )
1874
0
    {
1875
0
      libcerror_error_set(
1876
0
       error,
1877
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1878
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1879
0
       "%s: unable to retrieve entry: %d from data handle.",
1880
0
       function,
1881
0
       value_entry_index );
1882
1883
0
      return( -1 );
1884
0
    }
1885
0
    if( *entry_data_size == 0 )
1886
0
    {
1887
0
      result = 0;
1888
0
    }
1889
0
  }
1890
0
  if( result == 0 )
1891
0
  {
1892
0
    *entry_data_offset = 0;
1893
0
    *entry_data_size   = 0;
1894
0
  }
1895
0
  return( result );
1896
0
}
1897
1898
/* Sets the entry
1899
 * Returns 1 if successful or -1 on error
1900
 */
1901
int libfvalue_value_set_entry(
1902
     libfvalue_value_t *value,
1903
     int value_entry_index,
1904
     size_t entry_data_offset,
1905
     size_t entry_data_size,
1906
     libcerror_error_t **error )
1907
0
{
1908
0
  libfvalue_internal_value_t *internal_value = NULL;
1909
0
  intptr_t *value_instance                   = NULL;
1910
0
  static char *function                      = "libfvalue_value_set_entry";
1911
1912
0
  if( value == NULL )
1913
0
  {
1914
0
    libcerror_error_set(
1915
0
     error,
1916
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1917
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1918
0
     "%s: invalid value.",
1919
0
     function );
1920
1921
0
    return( -1 );
1922
0
  }
1923
0
  internal_value = (libfvalue_internal_value_t *) value;
1924
1925
0
  if( internal_value->free_instance == NULL )
1926
0
  {
1927
0
    libcerror_error_set(
1928
0
     error,
1929
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1930
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1931
0
     "%s: invalid value - missing free instance function.",
1932
0
     function );
1933
1934
0
    return( -1 );
1935
0
  }
1936
0
  if( libcdata_array_get_entry_by_index(
1937
0
       internal_value->value_instances,
1938
0
       value_entry_index,
1939
0
       &value_instance,
1940
0
       error ) != 1 )
1941
0
  {
1942
0
    libcerror_error_set(
1943
0
     error,
1944
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1945
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1946
0
     "%s: unable to retrieve entry: %d from values instances array.",
1947
0
     function,
1948
0
     value_entry_index );
1949
1950
0
    return( -1 );
1951
0
  }
1952
0
  if( value_instance != NULL )
1953
0
  {
1954
0
    if( libcdata_array_set_entry_by_index(
1955
0
         internal_value->value_instances,
1956
0
         value_entry_index,
1957
0
         NULL,
1958
0
         error ) != 1 )
1959
0
    {
1960
0
      libcerror_error_set(
1961
0
       error,
1962
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1963
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1964
0
       "%s: unable to set entry: %d in values instances array.",
1965
0
       function,
1966
0
       value_entry_index );
1967
1968
0
      return( -1 );
1969
0
    }
1970
0
    if( internal_value->free_instance(
1971
0
         &value_instance,
1972
0
         error ) != 1 )
1973
0
    {
1974
0
      libcerror_error_set(
1975
0
       error,
1976
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1977
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1978
0
       "%s: unable to free value instance: %d.",
1979
0
       function,
1980
0
       value_entry_index );
1981
1982
0
      return( -1 );
1983
0
    }
1984
0
  }
1985
0
  if( libfvalue_data_handle_set_value_entry(
1986
0
       internal_value->data_handle,
1987
0
       value_entry_index,
1988
0
       entry_data_offset,
1989
0
       entry_data_size,
1990
0
       error ) != 1 )
1991
0
  {
1992
0
    libcerror_error_set(
1993
0
     error,
1994
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1995
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1996
0
     "%s: unable to set entry: %d in data handle.",
1997
0
     function,
1998
0
     value_entry_index );
1999
2000
0
    return( -1 );
2001
0
  }
2002
0
  return( 1 );
2003
0
}
2004
2005
/* Appends the entry
2006
 * Returns 1 if successful or -1 on error
2007
 */
2008
int libfvalue_value_append_entry(
2009
     libfvalue_value_t *value,
2010
     int *value_entry_index,
2011
     size_t entry_data_offset,
2012
     size_t entry_data_size,
2013
     libcerror_error_t **error )
2014
0
{
2015
0
  libfvalue_internal_value_t *internal_value = NULL;
2016
0
  intptr_t *value_instance                   = NULL;
2017
0
  static char *function                      = "libfvalue_value_append_entry";
2018
0
  int entry_index                            = 0;
2019
0
  int number_of_value_entries                = 0;
2020
2021
0
  if( value == NULL )
2022
0
  {
2023
0
    libcerror_error_set(
2024
0
     error,
2025
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2026
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2027
0
     "%s: invalid value.",
2028
0
     function );
2029
2030
0
    return( -1 );
2031
0
  }
2032
0
  internal_value = (libfvalue_internal_value_t *) value;
2033
2034
0
  if( internal_value->free_instance == NULL )
2035
0
  {
2036
0
    libcerror_error_set(
2037
0
     error,
2038
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2039
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2040
0
     "%s: invalid value - missing free instance function.",
2041
0
     function );
2042
2043
0
    return( -1 );
2044
0
  }
2045
0
  if( value_entry_index == NULL )
2046
0
  {
2047
0
    libcerror_error_set(
2048
0
     error,
2049
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2050
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2051
0
     "%s: invalid value entry index.",
2052
0
     function );
2053
2054
0
    return( -1 );
2055
0
  }
2056
0
  if( libfvalue_data_handle_get_number_of_value_entries(
2057
0
       internal_value->data_handle,
2058
0
       &number_of_value_entries,
2059
0
       error ) != 1 )
2060
0
  {
2061
0
    libcerror_error_set(
2062
0
     error,
2063
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2064
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2065
0
     "%s: unable to retrieve number of value entries from data handle.",
2066
0
     function );
2067
2068
0
    return( -1 );
2069
0
  }
2070
  /* Since the data handle can reallocate the buffer used to store the data
2071
   * and the value instances reference this data make sure that no stale
2072
   * value instances are kept around.
2073
   */
2074
0
  for( entry_index = 0;
2075
0
       entry_index < number_of_value_entries;
2076
0
       entry_index += 1 )
2077
0
  {
2078
0
    if( libcdata_array_get_entry_by_index(
2079
0
         internal_value->value_instances,
2080
0
         entry_index,
2081
0
         &value_instance,
2082
0
         error ) != 1 )
2083
0
    {
2084
0
      libcerror_error_set(
2085
0
       error,
2086
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2087
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2088
0
       "%s: unable to retrieve entry: %d from values instances array.",
2089
0
       function,
2090
0
       entry_index );
2091
2092
0
      return( -1 );
2093
0
    }
2094
0
    if( value_instance != NULL )
2095
0
    {
2096
0
      if( libcdata_array_set_entry_by_index(
2097
0
           internal_value->value_instances,
2098
0
           entry_index,
2099
0
           NULL,
2100
0
           error ) != 1 )
2101
0
      {
2102
0
        libcerror_error_set(
2103
0
         error,
2104
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2105
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2106
0
         "%s: unable to set entry: %d in values instances array.",
2107
0
         function,
2108
0
         entry_index );
2109
2110
0
        return( -1 );
2111
0
      }
2112
0
      if( internal_value->free_instance(
2113
0
           &value_instance,
2114
0
           error ) != 1 )
2115
0
      {
2116
0
        libcerror_error_set(
2117
0
         error,
2118
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2119
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
2120
0
         "%s: unable to free value instance: %d.",
2121
0
         function,
2122
0
         entry_index );
2123
2124
0
        return( -1 );
2125
0
      }
2126
0
    }
2127
0
  }
2128
0
  if( libcdata_array_resize(
2129
0
       internal_value->value_instances,
2130
0
       number_of_value_entries + 1,
2131
0
       internal_value->free_instance,
2132
0
       error ) != 1 )
2133
0
  {
2134
0
    libcerror_error_set(
2135
0
     error,
2136
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2137
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2138
0
     "%s: unable to resize value instances array.",
2139
0
     function );
2140
2141
0
    return( -1 );
2142
0
  }
2143
0
  if( libfvalue_data_handle_append_value_entry(
2144
0
       internal_value->data_handle,
2145
0
       value_entry_index,
2146
0
       entry_data_offset,
2147
0
       entry_data_size,
2148
0
       error ) != 1 )
2149
0
  {
2150
0
    libcerror_error_set(
2151
0
     error,
2152
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2153
0
     LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2154
0
     "%s: unable to append entry to data handle.",
2155
0
     function );
2156
2157
0
    return( -1 );
2158
0
  }
2159
0
  return( 1 );
2160
0
}
2161
2162
/* Retrieves entry data
2163
 * Returns 1 if successful, 0 if the value has no data or -1 on error
2164
 */
2165
int libfvalue_value_get_entry_data(
2166
     libfvalue_value_t *value,
2167
     int value_entry_index,
2168
     uint8_t **entry_data,
2169
     size_t *entry_data_size,
2170
     int *encoding,
2171
     libcerror_error_t **error )
2172
0
{
2173
0
  libfvalue_internal_value_t *internal_value = NULL;
2174
0
  static char *function                      = "libfvalue_value_get_entry_data";
2175
0
  int result                                 = 0;
2176
2177
0
  if( value == NULL )
2178
0
  {
2179
0
    libcerror_error_set(
2180
0
     error,
2181
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2182
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2183
0
     "%s: invalid value.",
2184
0
     function );
2185
2186
0
    return( -1 );
2187
0
  }
2188
0
  internal_value = (libfvalue_internal_value_t *) value;
2189
2190
0
  if( entry_data == NULL )
2191
0
  {
2192
0
    libcerror_error_set(
2193
0
     error,
2194
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2195
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2196
0
     "%s: invalid entry data.",
2197
0
     function );
2198
2199
0
    return( -1 );
2200
0
  }
2201
0
  if( entry_data_size == NULL )
2202
0
  {
2203
0
    libcerror_error_set(
2204
0
     error,
2205
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2206
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2207
0
     "%s: invalid entry data size.",
2208
0
     function );
2209
2210
0
    return( -1 );
2211
0
  }
2212
0
  if( encoding == NULL )
2213
0
  {
2214
0
    libcerror_error_set(
2215
0
     error,
2216
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2217
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2218
0
     "%s: invalid encoding.",
2219
0
     function );
2220
2221
0
    return( -1 );
2222
0
  }
2223
0
  result = libfvalue_value_has_data(
2224
0
            value,
2225
0
            error );
2226
2227
0
  if( result == -1 )
2228
0
  {
2229
0
    libcerror_error_set(
2230
0
     error,
2231
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2232
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2233
0
     "%s: unable to determine if value has data.",
2234
0
     function );
2235
2236
0
    return( -1 );
2237
0
  }
2238
0
  else if( result != 0 )
2239
0
  {
2240
0
    if( libfvalue_data_handle_get_value_entry_data(
2241
0
         internal_value->data_handle,
2242
0
         value_entry_index,
2243
0
         entry_data,
2244
0
         entry_data_size,
2245
0
         encoding,
2246
0
         error ) != 1 )
2247
0
    {
2248
0
      libcerror_error_set(
2249
0
       error,
2250
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2251
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2252
0
       "%s: unable to retrieve entry: %d data from data handle.",
2253
0
       function,
2254
0
       value_entry_index );
2255
2256
0
      return( -1 );
2257
0
    }
2258
0
    if( ( *entry_data == NULL )
2259
0
     || ( *entry_data_size == 0 ) )
2260
0
    {
2261
0
      result = 0;
2262
0
    }
2263
0
  }
2264
0
  if( result == 0 )
2265
0
  {
2266
0
    *entry_data      = NULL;
2267
0
    *entry_data_size = 0;
2268
0
  }
2269
0
  return( result );
2270
0
}
2271
2272
/* Sets entry data
2273
 * Returns 1 if successful or -1 on error
2274
 */
2275
int libfvalue_value_set_entry_data(
2276
     libfvalue_value_t *value,
2277
     int value_entry_index,
2278
     const uint8_t *entry_data,
2279
     size_t entry_data_size,
2280
     int encoding,
2281
     libcerror_error_t **error )
2282
0
{
2283
0
  libfvalue_internal_value_t *internal_value = NULL;
2284
0
  intptr_t *value_instance                   = NULL;
2285
0
  static char *function                      = "libfvalue_value_set_entry_data";
2286
2287
0
  if( value == NULL )
2288
0
  {
2289
0
    libcerror_error_set(
2290
0
     error,
2291
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2292
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2293
0
     "%s: invalid value.",
2294
0
     function );
2295
2296
0
    return( -1 );
2297
0
  }
2298
0
  internal_value = (libfvalue_internal_value_t *) value;
2299
2300
0
  if( internal_value->free_instance == NULL )
2301
0
  {
2302
0
    libcerror_error_set(
2303
0
     error,
2304
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2305
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2306
0
     "%s: invalid value - missing free instance function.",
2307
0
     function );
2308
2309
0
    return( -1 );
2310
0
  }
2311
0
  if( libcdata_array_get_entry_by_index(
2312
0
       internal_value->value_instances,
2313
0
       value_entry_index,
2314
0
       &value_instance,
2315
0
       error ) != 1 )
2316
0
  {
2317
0
    libcerror_error_set(
2318
0
     error,
2319
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2320
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2321
0
     "%s: unable to retrieve entry: %d from values instances array.",
2322
0
     function,
2323
0
     value_entry_index );
2324
2325
0
    return( -1 );
2326
0
  }
2327
0
  if( value_instance != NULL )
2328
0
  {
2329
0
    if( libcdata_array_set_entry_by_index(
2330
0
         internal_value->value_instances,
2331
0
         value_entry_index,
2332
0
         NULL,
2333
0
         error ) != 1 )
2334
0
    {
2335
0
      libcerror_error_set(
2336
0
       error,
2337
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2338
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2339
0
       "%s: unable to set entry: %d data in values instances array.",
2340
0
       function,
2341
0
       value_entry_index );
2342
2343
0
      return( -1 );
2344
0
    }
2345
0
    if( internal_value->free_instance(
2346
0
         &value_instance,
2347
0
         error ) != 1 )
2348
0
    {
2349
0
      libcerror_error_set(
2350
0
       error,
2351
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2352
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
2353
0
       "%s: unable to free value instance: %d.",
2354
0
       function,
2355
0
       value_entry_index );
2356
2357
0
      return( -1 );
2358
0
    }
2359
0
  }
2360
0
  if( libfvalue_data_handle_set_value_entry_data(
2361
0
       internal_value->data_handle,
2362
0
       value_entry_index,
2363
0
       entry_data,
2364
0
       entry_data_size,
2365
0
       encoding,
2366
0
       error ) != 1 )
2367
0
  {
2368
0
    libcerror_error_set(
2369
0
     error,
2370
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2371
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2372
0
     "%s: unable to set entry: %d in data handle.",
2373
0
     function,
2374
0
     value_entry_index );
2375
2376
0
    return( -1 );
2377
0
  }
2378
0
  return( 1 );
2379
0
}
2380
2381
/* Appends entry data
2382
 * Returns 1 if successful or -1 on error
2383
 */
2384
int libfvalue_value_append_entry_data(
2385
     libfvalue_value_t *value,
2386
     int *value_entry_index,
2387
     const uint8_t *entry_data,
2388
     size_t entry_data_size,
2389
     int encoding,
2390
     libcerror_error_t **error )
2391
0
{
2392
0
  libfvalue_internal_value_t *internal_value = NULL;
2393
0
  intptr_t *value_instance                   = NULL;
2394
0
  static char *function                      = "libfvalue_value_append_entry_data";
2395
0
  int number_of_value_entries                = 0;
2396
2397
0
  if( value == NULL )
2398
0
  {
2399
0
    libcerror_error_set(
2400
0
     error,
2401
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2402
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2403
0
     "%s: invalid value.",
2404
0
     function );
2405
2406
0
    return( -1 );
2407
0
  }
2408
0
  internal_value = (libfvalue_internal_value_t *) value;
2409
2410
0
  if( internal_value->free_instance == NULL )
2411
0
  {
2412
0
    libcerror_error_set(
2413
0
     error,
2414
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2415
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2416
0
     "%s: invalid value - missing free instance function.",
2417
0
     function );
2418
2419
0
    return( -1 );
2420
0
  }
2421
0
  if( value_entry_index == NULL )
2422
0
  {
2423
0
    libcerror_error_set(
2424
0
     error,
2425
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2426
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2427
0
     "%s: invalid value entry index.",
2428
0
     function );
2429
2430
0
    return( -1 );
2431
0
  }
2432
0
  if( libfvalue_data_handle_get_number_of_value_entries(
2433
0
       internal_value->data_handle,
2434
0
       &number_of_value_entries,
2435
0
       error ) != 1 )
2436
0
  {
2437
0
    libcerror_error_set(
2438
0
     error,
2439
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2440
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2441
0
     "%s: unable to retrieve number of value entries from data handle.",
2442
0
     function );
2443
2444
0
    return( -1 );
2445
0
  }
2446
  /* Since the data handle can reallocate the buffer used to store the data
2447
   * and the value instances reference this data make sure that no stale
2448
   * value instances are kept around.
2449
   */
2450
0
  for( *value_entry_index = 0;
2451
0
       *value_entry_index < number_of_value_entries;
2452
0
       *value_entry_index += 1 )
2453
0
  {
2454
0
    if( libcdata_array_get_entry_by_index(
2455
0
         internal_value->value_instances,
2456
0
         *value_entry_index,
2457
0
         &value_instance,
2458
0
         error ) != 1 )
2459
0
    {
2460
0
      libcerror_error_set(
2461
0
       error,
2462
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2463
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2464
0
       "%s: unable to retrieve entry: %d from values instances array.",
2465
0
       function,
2466
0
       *value_entry_index );
2467
2468
0
      return( -1 );
2469
0
    }
2470
0
    if( value_instance != NULL )
2471
0
    {
2472
0
      if( libcdata_array_set_entry_by_index(
2473
0
           internal_value->value_instances,
2474
0
           *value_entry_index,
2475
0
           NULL,
2476
0
           error ) != 1 )
2477
0
      {
2478
0
        libcerror_error_set(
2479
0
         error,
2480
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2481
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2482
0
         "%s: unable to set entry: %d in values instances array.",
2483
0
         function,
2484
0
         *value_entry_index );
2485
2486
0
        return( -1 );
2487
0
      }
2488
0
      if( internal_value->free_instance(
2489
0
           &value_instance,
2490
0
           error ) != 1 )
2491
0
      {
2492
0
        libcerror_error_set(
2493
0
         error,
2494
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2495
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
2496
0
         "%s: unable to free value instance: %d.",
2497
0
         function,
2498
0
         *value_entry_index );
2499
2500
0
        return( -1 );
2501
0
      }
2502
0
    }
2503
0
  }
2504
0
  if( libcdata_array_resize(
2505
0
       internal_value->value_instances,
2506
0
       number_of_value_entries + 1,
2507
0
       internal_value->free_instance,
2508
0
       error ) != 1 )
2509
0
  {
2510
0
    libcerror_error_set(
2511
0
     error,
2512
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2513
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2514
0
     "%s: unable to resize value instances array.",
2515
0
     function );
2516
2517
0
    return( -1 );
2518
0
  }
2519
0
  if( libfvalue_data_handle_append_value_entry_data(
2520
0
       internal_value->data_handle,
2521
0
       value_entry_index,
2522
0
       entry_data,
2523
0
       entry_data_size,
2524
0
       encoding,
2525
0
       error ) != 1 )
2526
0
  {
2527
0
    libcerror_error_set(
2528
0
     error,
2529
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2530
0
     LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2531
0
     "%s: unable to append entry to data handle.",
2532
0
     function );
2533
2534
0
    return( -1 );
2535
0
  }
2536
0
  return( 1 );
2537
0
}
2538
2539
/* Copies entry data
2540
 * Returns 1 if successful, 0 if the value has no data or -1 on error
2541
 */
2542
int libfvalue_value_copy_entry_data(
2543
     libfvalue_value_t *value,
2544
     int value_entry_index,
2545
     uint8_t *entry_data,
2546
     size_t entry_data_size,
2547
     int *encoding,
2548
     libcerror_error_t **error )
2549
0
{
2550
0
  libfvalue_internal_value_t *internal_value = NULL;
2551
0
  uint8_t *value_entry_data                  = NULL;
2552
0
  static char *function                      = "libfvalue_value_copy_entry_data";
2553
0
  size_t value_entry_data_size               = 0;
2554
0
  int result                                 = 0;
2555
2556
0
  if( value == NULL )
2557
0
  {
2558
0
    libcerror_error_set(
2559
0
     error,
2560
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2561
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2562
0
     "%s: invalid value.",
2563
0
     function );
2564
2565
0
    return( -1 );
2566
0
  }
2567
0
  internal_value = (libfvalue_internal_value_t *) value;
2568
2569
0
  if( entry_data == NULL )
2570
0
  {
2571
0
    libcerror_error_set(
2572
0
     error,
2573
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2574
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2575
0
     "%s: invalid entry data.",
2576
0
     function );
2577
2578
0
    return( -1 );
2579
0
  }
2580
0
  if( entry_data_size > (size_t) SSIZE_MAX )
2581
0
  {
2582
0
    libcerror_error_set(
2583
0
     error,
2584
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2585
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
2586
0
     "%s: invalid entry data size value exceeds maximum.",
2587
0
     function );
2588
2589
0
    return( -1 );
2590
0
  }
2591
0
  result = libfvalue_value_has_data(
2592
0
            value,
2593
0
            error );
2594
2595
0
  if( result == -1 )
2596
0
  {
2597
0
    libcerror_error_set(
2598
0
     error,
2599
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2600
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2601
0
     "%s: unable to determine if value has data.",
2602
0
     function );
2603
2604
0
    return( -1 );
2605
0
  }
2606
0
  else if( result != 0 )
2607
0
  {
2608
0
    if( libfvalue_data_handle_get_value_entry_data(
2609
0
         internal_value->data_handle,
2610
0
         value_entry_index,
2611
0
         &value_entry_data,
2612
0
         &value_entry_data_size,
2613
0
         encoding,
2614
0
         error ) != 1 )
2615
0
    {
2616
0
      libcerror_error_set(
2617
0
       error,
2618
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2619
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2620
0
       "%s: unable to retrieve entry: %d data from data handle.",
2621
0
       function,
2622
0
       value_entry_index );
2623
2624
0
      return( -1 );
2625
0
    }
2626
0
    if( ( value_entry_data == NULL )
2627
0
     || ( value_entry_data_size == 0 ) )
2628
0
    {
2629
0
      result = 0;
2630
0
    }
2631
0
  }
2632
0
  if( result != 0 )
2633
0
  {
2634
0
    if( entry_data_size < value_entry_data_size )
2635
0
    {
2636
0
      libcerror_error_set(
2637
0
       error,
2638
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2639
0
       LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2640
0
       "%s: invalid entry: %d data size value out of bounds.",
2641
0
       function,
2642
0
       value_entry_index );
2643
2644
0
      return( -1 );
2645
0
    }
2646
0
    if( memory_copy(
2647
0
         entry_data,
2648
0
         value_entry_data,
2649
0
         value_entry_data_size ) == NULL )
2650
0
    {
2651
0
      libcerror_error_set(
2652
0
       error,
2653
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
2654
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
2655
0
       "%s: unable to copy entry: %d data.",
2656
0
       function,
2657
0
       value_entry_index );
2658
2659
0
      return( -1 );
2660
0
    }
2661
0
  }
2662
0
  return( result );
2663
0
}
2664
2665
/* Boolean value functions
2666
 */
2667
2668
/* Copies the value data from a boolean value
2669
 * Returns 1 if successful, 0 if value could not be set or -1 on error
2670
 */
2671
int libfvalue_value_copy_from_boolean(
2672
     libfvalue_value_t *value,
2673
     int value_entry_index,
2674
     uint8_t value_boolean,
2675
     libcerror_error_t **error )
2676
0
{
2677
0
  libfvalue_internal_value_t *internal_value = NULL;
2678
0
  intptr_t *value_instance                   = NULL;
2679
0
  static char *function                      = "libfvalue_value_copy_from_boolean";
2680
0
  int result                                 = 0;
2681
2682
0
  if( value == NULL )
2683
0
  {
2684
0
    libcerror_error_set(
2685
0
     error,
2686
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2687
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2688
0
     "%s: invalid value.",
2689
0
     function );
2690
2691
0
    return( -1 );
2692
0
  }
2693
0
  internal_value = (libfvalue_internal_value_t *) value;
2694
2695
0
  if( internal_value->copy_from_integer != NULL )
2696
0
  {
2697
0
    if( libfvalue_value_get_value_instance_by_index(
2698
0
         value,
2699
0
         value_entry_index,
2700
0
         &value_instance,
2701
0
         error ) != 1 )
2702
0
    {
2703
0
      libcerror_error_set(
2704
0
       error,
2705
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2706
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2707
0
       "%s: unable to retrieve value instance: %d.",
2708
0
       function,
2709
0
       value_entry_index );
2710
2711
0
      return( -1 );
2712
0
    }
2713
0
    if( value_instance != NULL )
2714
0
    {
2715
0
      if( internal_value->copy_from_integer(
2716
0
           value_instance,
2717
0
           (uint64_t) value_boolean,
2718
0
           1,
2719
0
           error ) != 1 )
2720
0
      {
2721
0
        libcerror_error_set(
2722
0
         error,
2723
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2724
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2725
0
         "%s: unable to copy instance from boolean.",
2726
0
         function );
2727
2728
0
        return( -1 );
2729
0
      }
2730
0
      result = 1;
2731
0
    }
2732
0
  }
2733
0
  return( result );
2734
0
}
2735
2736
/* Copies the value data to a boolean value
2737
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
2738
 */
2739
int libfvalue_value_copy_to_boolean(
2740
     libfvalue_value_t *value,
2741
     int value_entry_index,
2742
     uint8_t *value_boolean,
2743
     libcerror_error_t **error )
2744
0
{
2745
0
  libfvalue_internal_value_t *internal_value = NULL;
2746
0
  intptr_t *value_instance                   = NULL;
2747
0
  static char *function                      = "libfvalue_value_copy_to_boolean";
2748
0
  size_t integer_value_size                  = 0;
2749
0
  uint64_t integer_value                     = 0;
2750
0
  int result                                 = 0;
2751
2752
0
  if( value == NULL )
2753
0
  {
2754
0
    libcerror_error_set(
2755
0
     error,
2756
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2757
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2758
0
     "%s: invalid value.",
2759
0
     function );
2760
2761
0
    return( -1 );
2762
0
  }
2763
0
  internal_value = (libfvalue_internal_value_t *) value;
2764
2765
0
  if( value_boolean == NULL )
2766
0
  {
2767
0
    libcerror_error_set(
2768
0
     error,
2769
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2770
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2771
0
     "%s: missing value boolean.",
2772
0
     function );
2773
2774
0
    return( -1 );
2775
0
  }
2776
0
  if( internal_value->copy_to_integer != NULL )
2777
0
  {
2778
0
    if( libfvalue_value_get_value_instance_by_index(
2779
0
         value,
2780
0
         value_entry_index,
2781
0
         &value_instance,
2782
0
         error ) != 1 )
2783
0
    {
2784
0
      libcerror_error_set(
2785
0
       error,
2786
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2787
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2788
0
       "%s: unable to retrieve value instance: %d.",
2789
0
       function,
2790
0
       value_entry_index );
2791
2792
0
      return( -1 );
2793
0
    }
2794
0
    if( value_instance != NULL )
2795
0
    {
2796
0
      if( internal_value->copy_to_integer(
2797
0
           value_instance,
2798
0
           &integer_value,
2799
0
           &integer_value_size,
2800
0
           error ) != 1 )
2801
0
      {
2802
0
        libcerror_error_set(
2803
0
         error,
2804
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2805
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2806
0
         "%s: unable to copy instance to boolean.",
2807
0
         function );
2808
2809
0
        return( -1 );
2810
0
      }
2811
0
      if( integer_value != 0 )
2812
0
      {
2813
0
        *value_boolean = 1;
2814
0
      }
2815
0
      else
2816
0
      {
2817
0
        *value_boolean = 0;
2818
0
      }
2819
0
      result = 1;
2820
0
    }
2821
0
  }
2822
0
  return( result );
2823
0
}
2824
2825
/* Integer value functions
2826
 */
2827
2828
/* Copies the value data from an 8-bit value
2829
 * Returns 1 if successful, 0 if value could not be set or -1 on error
2830
 */
2831
int libfvalue_value_copy_from_8bit(
2832
     libfvalue_value_t *value,
2833
     int value_entry_index,
2834
     uint8_t value_8bit,
2835
     libcerror_error_t **error )
2836
0
{
2837
0
  libfvalue_internal_value_t *internal_value = NULL;
2838
0
  intptr_t *value_instance                   = NULL;
2839
0
  static char *function                      = "libfvalue_value_copy_from_8bit";
2840
0
  int result                                 = 0;
2841
2842
0
  if( value == NULL )
2843
0
  {
2844
0
    libcerror_error_set(
2845
0
     error,
2846
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2847
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2848
0
     "%s: invalid value.",
2849
0
     function );
2850
2851
0
    return( -1 );
2852
0
  }
2853
0
  internal_value = (libfvalue_internal_value_t *) value;
2854
2855
0
  if( internal_value->copy_from_integer != NULL )
2856
0
  {
2857
0
    if( libfvalue_value_get_value_instance_by_index(
2858
0
         value,
2859
0
         value_entry_index,
2860
0
         &value_instance,
2861
0
         error ) != 1 )
2862
0
    {
2863
0
      libcerror_error_set(
2864
0
       error,
2865
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2866
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2867
0
       "%s: unable to retrieve value instance: %d.",
2868
0
       function,
2869
0
       value_entry_index );
2870
2871
0
      return( -1 );
2872
0
    }
2873
0
    if( value_instance != NULL )
2874
0
    {
2875
0
      if( internal_value->copy_from_integer(
2876
0
           value_instance,
2877
0
           (uint64_t) value_8bit,
2878
0
           8,
2879
0
           error ) != 1 )
2880
0
      {
2881
0
        libcerror_error_set(
2882
0
         error,
2883
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2884
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2885
0
         "%s: unable to copy instance from 8-bit integer.",
2886
0
         function );
2887
2888
0
        return( -1 );
2889
0
      }
2890
0
      result = 1;
2891
0
    }
2892
0
  }
2893
0
  return( result );
2894
0
}
2895
2896
/* Copies the value data to an 8-bit value
2897
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
2898
 */
2899
int libfvalue_value_copy_to_8bit(
2900
     libfvalue_value_t *value,
2901
     int value_entry_index,
2902
     uint8_t *value_8bit,
2903
     libcerror_error_t **error )
2904
0
{
2905
0
  libfvalue_internal_value_t *internal_value = NULL;
2906
0
  intptr_t *value_instance                   = NULL;
2907
0
  static char *function                      = "libfvalue_value_copy_to_8bit";
2908
0
  size_t integer_value_size                  = 0;
2909
0
  uint64_t integer_value                     = 0;
2910
0
  int result                                 = 0;
2911
2912
0
  if( value == NULL )
2913
0
  {
2914
0
    libcerror_error_set(
2915
0
     error,
2916
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2917
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2918
0
     "%s: invalid value.",
2919
0
     function );
2920
2921
0
    return( -1 );
2922
0
  }
2923
0
  internal_value = (libfvalue_internal_value_t *) value;
2924
2925
0
  if( value_8bit == NULL )
2926
0
  {
2927
0
    libcerror_error_set(
2928
0
     error,
2929
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2930
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2931
0
     "%s: missing value 8-bit.",
2932
0
     function );
2933
2934
0
    return( -1 );
2935
0
  }
2936
0
  if( internal_value->copy_to_integer != NULL )
2937
0
  {
2938
0
    if( libfvalue_value_get_value_instance_by_index(
2939
0
         value,
2940
0
         value_entry_index,
2941
0
         &value_instance,
2942
0
         error ) != 1 )
2943
0
    {
2944
0
      libcerror_error_set(
2945
0
       error,
2946
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2947
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2948
0
       "%s: unable to retrieve value instance: %d.",
2949
0
       function,
2950
0
       value_entry_index );
2951
2952
0
      return( -1 );
2953
0
    }
2954
0
    if( value_instance != NULL )
2955
0
    {
2956
0
      if( internal_value->copy_to_integer(
2957
0
           value_instance,
2958
0
           &integer_value,
2959
0
           &integer_value_size,
2960
0
           error ) != 1 )
2961
0
      {
2962
0
        libcerror_error_set(
2963
0
         error,
2964
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2965
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2966
0
         "%s: unable to copy instance to integer value.",
2967
0
         function );
2968
2969
0
        return( -1 );
2970
0
      }
2971
0
      if( integer_value > (uint64_t) UINT8_MAX )
2972
0
      {
2973
0
        libcerror_error_set(
2974
0
         error,
2975
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
2976
0
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
2977
0
         "%s: integer value out of bounds.",
2978
0
         function );
2979
2980
0
        return( -1 );
2981
0
      }
2982
0
      *value_8bit = (uint8_t) integer_value;
2983
2984
0
      result = 1;
2985
0
    }
2986
0
  }
2987
0
  return( result );
2988
0
}
2989
2990
/* Copies the value data from a 16-bit value
2991
 * Returns 1 if successful, 0 if value could not be set or -1 on error
2992
 */
2993
int libfvalue_value_copy_from_16bit(
2994
     libfvalue_value_t *value,
2995
     int value_entry_index,
2996
     uint16_t value_16bit,
2997
     libcerror_error_t **error )
2998
0
{
2999
0
  libfvalue_internal_value_t *internal_value = NULL;
3000
0
  intptr_t *value_instance                   = NULL;
3001
0
  static char *function                      = "libfvalue_value_copy_from_16bit";
3002
0
  int result                                 = 0;
3003
3004
0
  if( value == NULL )
3005
0
  {
3006
0
    libcerror_error_set(
3007
0
     error,
3008
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3009
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3010
0
     "%s: invalid value.",
3011
0
     function );
3012
3013
0
    return( -1 );
3014
0
  }
3015
0
  internal_value = (libfvalue_internal_value_t *) value;
3016
3017
0
  if( internal_value->copy_from_integer != NULL )
3018
0
  {
3019
0
    if( libfvalue_value_get_value_instance_by_index(
3020
0
         value,
3021
0
         value_entry_index,
3022
0
         &value_instance,
3023
0
         error ) != 1 )
3024
0
    {
3025
0
      libcerror_error_set(
3026
0
       error,
3027
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3028
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3029
0
       "%s: unable to retrieve value instance: %d.",
3030
0
       function,
3031
0
       value_entry_index );
3032
3033
0
      return( -1 );
3034
0
    }
3035
0
    if( value_instance != NULL )
3036
0
    {
3037
0
      if( internal_value->copy_from_integer(
3038
0
           value_instance,
3039
0
           (uint64_t) value_16bit,
3040
0
           16,
3041
0
           error ) != 1 )
3042
0
      {
3043
0
        libcerror_error_set(
3044
0
         error,
3045
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3046
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3047
0
         "%s: unable to copy instance from 16-bit integer.",
3048
0
         function );
3049
3050
0
        return( -1 );
3051
0
      }
3052
0
      result = 1;
3053
0
    }
3054
0
  }
3055
0
  return( result );
3056
0
}
3057
3058
/* Copies the value data to a 16-bit value
3059
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3060
 */
3061
int libfvalue_value_copy_to_16bit(
3062
     libfvalue_value_t *value,
3063
     int value_entry_index,
3064
     uint16_t *value_16bit,
3065
     libcerror_error_t **error )
3066
0
{
3067
0
  libfvalue_internal_value_t *internal_value = NULL;
3068
0
  intptr_t *value_instance                   = NULL;
3069
0
  static char *function                      = "libfvalue_value_copy_to_16bit";
3070
0
  size_t integer_value_size                  = 0;
3071
0
  uint64_t integer_value                     = 0;
3072
0
  int result                                 = 0;
3073
3074
0
  if( value == NULL )
3075
0
  {
3076
0
    libcerror_error_set(
3077
0
     error,
3078
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3079
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3080
0
     "%s: invalid value.",
3081
0
     function );
3082
3083
0
    return( -1 );
3084
0
  }
3085
0
  internal_value = (libfvalue_internal_value_t *) value;
3086
3087
0
  if( value_16bit == NULL )
3088
0
  {
3089
0
    libcerror_error_set(
3090
0
     error,
3091
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3092
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3093
0
     "%s: missing value 16-bit.",
3094
0
     function );
3095
3096
0
    return( -1 );
3097
0
  }
3098
0
  if( internal_value->copy_to_integer != NULL )
3099
0
  {
3100
0
    if( libfvalue_value_get_value_instance_by_index(
3101
0
         value,
3102
0
         value_entry_index,
3103
0
         &value_instance,
3104
0
         error ) != 1 )
3105
0
    {
3106
0
      libcerror_error_set(
3107
0
       error,
3108
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3109
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3110
0
       "%s: unable to retrieve value instance: %d.",
3111
0
       function,
3112
0
       value_entry_index );
3113
3114
0
      return( -1 );
3115
0
    }
3116
0
    if( value_instance != NULL )
3117
0
    {
3118
0
      if( internal_value->copy_to_integer(
3119
0
           value_instance,
3120
0
           &integer_value,
3121
0
           &integer_value_size,
3122
0
           error ) != 1 )
3123
0
      {
3124
0
        libcerror_error_set(
3125
0
         error,
3126
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3127
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3128
0
         "%s: unable to copy instance to integer value.",
3129
0
         function );
3130
3131
0
        return( -1 );
3132
0
      }
3133
0
      if( integer_value > (uint64_t) UINT16_MAX )
3134
0
      {
3135
0
        libcerror_error_set(
3136
0
         error,
3137
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3138
0
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
3139
0
         "%s: integer value out of bounds.",
3140
0
         function );
3141
3142
0
        return( -1 );
3143
0
      }
3144
0
      *value_16bit = (uint16_t) integer_value;
3145
3146
0
      result = 1;
3147
0
    }
3148
0
  }
3149
0
  return( result );
3150
0
}
3151
3152
/* Copies the value data from a 32-bit value
3153
 * Returns 1 if successful, 0 if value could not be set or -1 on error
3154
 */
3155
int libfvalue_value_copy_from_32bit(
3156
     libfvalue_value_t *value,
3157
     int value_entry_index,
3158
     uint32_t value_32bit,
3159
     libcerror_error_t **error )
3160
0
{
3161
0
  libfvalue_internal_value_t *internal_value = NULL;
3162
0
  intptr_t *value_instance                   = NULL;
3163
0
  static char *function                      = "libfvalue_value_copy_from_32bit";
3164
0
  int result                                 = 0;
3165
3166
0
  if( value == NULL )
3167
0
  {
3168
0
    libcerror_error_set(
3169
0
     error,
3170
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3171
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3172
0
     "%s: invalid value.",
3173
0
     function );
3174
3175
0
    return( -1 );
3176
0
  }
3177
0
  internal_value = (libfvalue_internal_value_t *) value;
3178
3179
0
  if( internal_value->copy_from_integer != NULL )
3180
0
  {
3181
0
    if( libfvalue_value_get_value_instance_by_index(
3182
0
         value,
3183
0
         value_entry_index,
3184
0
         &value_instance,
3185
0
         error ) != 1 )
3186
0
    {
3187
0
      libcerror_error_set(
3188
0
       error,
3189
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3190
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3191
0
       "%s: unable to retrieve value instance: %d.",
3192
0
       function,
3193
0
       value_entry_index );
3194
3195
0
      return( -1 );
3196
0
    }
3197
0
    if( value_instance != NULL )
3198
0
    {
3199
0
      if( internal_value->copy_from_integer(
3200
0
           value_instance,
3201
0
           (uint64_t) value_32bit,
3202
0
           32,
3203
0
           error ) != 1 )
3204
0
      {
3205
0
        libcerror_error_set(
3206
0
         error,
3207
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3208
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3209
0
         "%s: unable to copy instance from 32-bit integer.",
3210
0
         function );
3211
3212
0
        return( -1 );
3213
0
      }
3214
0
      result = 1;
3215
0
    }
3216
0
  }
3217
0
  return( result );
3218
0
}
3219
3220
/* Copies the value data to a 32-bit value
3221
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3222
 */
3223
int libfvalue_value_copy_to_32bit(
3224
     libfvalue_value_t *value,
3225
     int value_entry_index,
3226
     uint32_t *value_32bit,
3227
     libcerror_error_t **error )
3228
0
{
3229
0
  libfvalue_internal_value_t *internal_value = NULL;
3230
0
  intptr_t *value_instance                   = NULL;
3231
0
  static char *function                      = "libfvalue_value_copy_to_32bit";
3232
0
  size_t integer_value_size                  = 0;
3233
0
  uint64_t integer_value                     = 0;
3234
0
  int result                                 = 0;
3235
3236
0
  if( value == NULL )
3237
0
  {
3238
0
    libcerror_error_set(
3239
0
     error,
3240
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3241
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3242
0
     "%s: invalid value.",
3243
0
     function );
3244
3245
0
    return( -1 );
3246
0
  }
3247
0
  internal_value = (libfvalue_internal_value_t *) value;
3248
3249
0
  if( value_32bit == NULL )
3250
0
  {
3251
0
    libcerror_error_set(
3252
0
     error,
3253
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3254
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3255
0
     "%s: missing value 32-bit.",
3256
0
     function );
3257
3258
0
    return( -1 );
3259
0
  }
3260
0
  if( internal_value->copy_to_integer != NULL )
3261
0
  {
3262
0
    if( libfvalue_value_get_value_instance_by_index(
3263
0
         value,
3264
0
         value_entry_index,
3265
0
         &value_instance,
3266
0
         error ) != 1 )
3267
0
    {
3268
0
      libcerror_error_set(
3269
0
       error,
3270
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3271
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3272
0
       "%s: unable to retrieve value instance: %d.",
3273
0
       function,
3274
0
       value_entry_index );
3275
3276
0
      return( -1 );
3277
0
    }
3278
0
    if( value_instance != NULL )
3279
0
    {
3280
0
      if( internal_value->copy_to_integer(
3281
0
           value_instance,
3282
0
           &integer_value,
3283
0
           &integer_value_size,
3284
0
           error ) != 1 )
3285
0
      {
3286
0
        libcerror_error_set(
3287
0
         error,
3288
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3289
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3290
0
         "%s: unable to copy instance to integer value.",
3291
0
         function );
3292
3293
0
        return( -1 );
3294
0
      }
3295
0
      if( integer_value > (uint64_t) UINT32_MAX )
3296
0
      {
3297
0
        libcerror_error_set(
3298
0
         error,
3299
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3300
0
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
3301
0
         "%s: integer value out of bounds.",
3302
0
         function );
3303
3304
0
        return( -1 );
3305
0
      }
3306
0
      *value_32bit = (uint32_t) integer_value;
3307
3308
0
      result = 1;
3309
0
    }
3310
0
  }
3311
0
  return( result );
3312
0
}
3313
3314
/* Copies the value data from a 64-bit value
3315
 * Returns 1 if successful, 0 if value could not be set or -1 on error
3316
 */
3317
int libfvalue_value_copy_from_64bit(
3318
     libfvalue_value_t *value,
3319
     int value_entry_index,
3320
     uint64_t value_64bit,
3321
     libcerror_error_t **error )
3322
0
{
3323
0
  libfvalue_internal_value_t *internal_value = NULL;
3324
0
  intptr_t *value_instance                   = NULL;
3325
0
  static char *function                      = "libfvalue_value_copy_from_64bit";
3326
0
  int result                                 = 0;
3327
3328
0
  if( value == NULL )
3329
0
  {
3330
0
    libcerror_error_set(
3331
0
     error,
3332
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3333
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3334
0
     "%s: invalid value.",
3335
0
     function );
3336
3337
0
    return( -1 );
3338
0
  }
3339
0
  internal_value = (libfvalue_internal_value_t *) value;
3340
3341
0
  if( internal_value->copy_from_integer != NULL )
3342
0
  {
3343
0
    if( libfvalue_value_get_value_instance_by_index(
3344
0
         value,
3345
0
         value_entry_index,
3346
0
         &value_instance,
3347
0
         error ) != 1 )
3348
0
    {
3349
0
      libcerror_error_set(
3350
0
       error,
3351
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3352
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3353
0
       "%s: unable to retrieve value instance: %d.",
3354
0
       function,
3355
0
       value_entry_index );
3356
3357
0
      return( -1 );
3358
0
    }
3359
0
    if( value_instance != NULL )
3360
0
    {
3361
0
      if( internal_value->copy_from_integer(
3362
0
           value_instance,
3363
0
           (uint64_t) value_64bit,
3364
0
           64,
3365
0
           error ) != 1 )
3366
0
      {
3367
0
        libcerror_error_set(
3368
0
         error,
3369
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3370
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3371
0
         "%s: unable to copy instance from 64-bit integer.",
3372
0
         function );
3373
3374
0
        return( -1 );
3375
0
      }
3376
0
      result = 1;
3377
0
    }
3378
0
  }
3379
0
  return( result );
3380
0
}
3381
3382
/* Copies the value data to a 64-bit value
3383
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3384
 */
3385
int libfvalue_value_copy_to_64bit(
3386
     libfvalue_value_t *value,
3387
     int value_entry_index,
3388
     uint64_t *value_64bit,
3389
     libcerror_error_t **error )
3390
0
{
3391
0
  libfvalue_internal_value_t *internal_value = NULL;
3392
0
  intptr_t *value_instance                   = NULL;
3393
0
  static char *function                      = "libfvalue_value_copy_to_64bit";
3394
0
  size_t integer_value_size                  = 0;
3395
0
  uint64_t integer_value                     = 0;
3396
0
  int result                                 = 0;
3397
3398
0
  if( value == NULL )
3399
0
  {
3400
0
    libcerror_error_set(
3401
0
     error,
3402
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3403
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3404
0
     "%s: invalid value.",
3405
0
     function );
3406
3407
0
    return( -1 );
3408
0
  }
3409
0
  internal_value = (libfvalue_internal_value_t *) value;
3410
3411
0
  if( value_64bit == NULL )
3412
0
  {
3413
0
    libcerror_error_set(
3414
0
     error,
3415
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3416
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3417
0
     "%s: missing value 64-bit.",
3418
0
     function );
3419
3420
0
    return( -1 );
3421
0
  }
3422
0
  if( internal_value->copy_to_integer != NULL )
3423
0
  {
3424
0
    if( libfvalue_value_get_value_instance_by_index(
3425
0
         value,
3426
0
         value_entry_index,
3427
0
         &value_instance,
3428
0
         error ) != 1 )
3429
0
    {
3430
0
      libcerror_error_set(
3431
0
       error,
3432
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3433
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3434
0
       "%s: unable to retrieve value instance: %d.",
3435
0
       function,
3436
0
       value_entry_index );
3437
3438
0
      return( -1 );
3439
0
    }
3440
0
    if( value_instance != NULL )
3441
0
    {
3442
0
      if( internal_value->copy_to_integer(
3443
0
           value_instance,
3444
0
           &integer_value,
3445
0
           &integer_value_size,
3446
0
           error ) != 1 )
3447
0
      {
3448
0
        libcerror_error_set(
3449
0
         error,
3450
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3451
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3452
0
         "%s: unable to copy instance to integer value.",
3453
0
         function );
3454
3455
0
        return( -1 );
3456
0
      }
3457
0
      *value_64bit = (uint64_t) integer_value;
3458
3459
0
      result = 1;
3460
0
    }
3461
0
  }
3462
0
  return( result );
3463
0
}
3464
3465
/* Floating point value functions
3466
 */
3467
3468
/* Copies the value data from a float value
3469
 * Returns 1 if successful, 0 if value could not be set or -1 on error
3470
 */
3471
int libfvalue_value_copy_from_float(
3472
     libfvalue_value_t *value,
3473
     int value_entry_index,
3474
     float value_float,
3475
     libcerror_error_t **error )
3476
0
{
3477
0
  libfvalue_internal_value_t *internal_value = NULL;
3478
0
  intptr_t *value_instance                   = NULL;
3479
0
  static char *function                      = "libfvalue_value_copy_from_float";
3480
0
  int result                                 = 0;
3481
3482
0
  if( value == NULL )
3483
0
  {
3484
0
    libcerror_error_set(
3485
0
     error,
3486
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3487
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3488
0
     "%s: invalid value.",
3489
0
     function );
3490
3491
0
    return( -1 );
3492
0
  }
3493
0
  internal_value = (libfvalue_internal_value_t *) value;
3494
3495
0
  if( internal_value->copy_from_floating_point != NULL )
3496
0
  {
3497
0
    if( libfvalue_value_get_value_instance_by_index(
3498
0
         value,
3499
0
         value_entry_index,
3500
0
         &value_instance,
3501
0
         error ) != 1 )
3502
0
    {
3503
0
      libcerror_error_set(
3504
0
       error,
3505
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3506
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3507
0
       "%s: unable to retrieve value instance: %d.",
3508
0
       function,
3509
0
       value_entry_index );
3510
3511
0
      return( -1 );
3512
0
    }
3513
0
    if( value_instance != NULL )
3514
0
    {
3515
0
      if( internal_value->copy_from_floating_point(
3516
0
           value_instance,
3517
0
           (double) value_float,
3518
0
           32,
3519
0
           error ) != 1 )
3520
0
      {
3521
0
        libcerror_error_set(
3522
0
         error,
3523
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3524
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3525
0
         "%s: unable to copy instance from 32-bit floating point.",
3526
0
         function );
3527
3528
0
        return( -1 );
3529
0
      }
3530
0
      result = 1;
3531
0
    }
3532
0
  }
3533
0
  return( result );
3534
0
}
3535
3536
/* Copies the value data to a float value
3537
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3538
 */
3539
int libfvalue_value_copy_to_float(
3540
     libfvalue_value_t *value,
3541
     int value_entry_index,
3542
     float *value_float,
3543
     libcerror_error_t **error )
3544
0
{
3545
0
  libfvalue_internal_value_t *internal_value = NULL;
3546
0
  intptr_t *value_instance                   = NULL;
3547
0
  static char *function                      = "libfvalue_value_copy_to_float";
3548
0
  size_t floating_point_value_size           = 0;
3549
0
  double floating_point_value                = 0.0;
3550
0
  int result                                 = 0;
3551
3552
0
  if( value == NULL )
3553
0
  {
3554
0
    libcerror_error_set(
3555
0
     error,
3556
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3557
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3558
0
     "%s: invalid value.",
3559
0
     function );
3560
3561
0
    return( -1 );
3562
0
  }
3563
0
  internal_value = (libfvalue_internal_value_t *) value;
3564
3565
0
  if( value_float == NULL )
3566
0
  {
3567
0
    libcerror_error_set(
3568
0
     error,
3569
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3570
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3571
0
     "%s: invalid value float.",
3572
0
     function );
3573
3574
0
    return( -1 );
3575
0
  }
3576
0
  if( internal_value->copy_to_floating_point != NULL )
3577
0
  {
3578
0
    if( libfvalue_value_get_value_instance_by_index(
3579
0
         value,
3580
0
         value_entry_index,
3581
0
         &value_instance,
3582
0
         error ) != 1 )
3583
0
    {
3584
0
      libcerror_error_set(
3585
0
       error,
3586
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3587
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3588
0
       "%s: unable to retrieve value instance: %d.",
3589
0
       function,
3590
0
       value_entry_index );
3591
3592
0
      return( -1 );
3593
0
    }
3594
0
    if( value_instance != NULL )
3595
0
    {
3596
0
      if( internal_value->copy_to_floating_point(
3597
0
           value_instance,
3598
0
           &floating_point_value,
3599
0
           &floating_point_value_size,
3600
0
           error ) != 1 )
3601
0
      {
3602
0
        libcerror_error_set(
3603
0
         error,
3604
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3605
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3606
0
         "%s: unable to copy instance to floating point value.",
3607
0
         function );
3608
3609
0
        return( -1 );
3610
0
      }
3611
0
      *value_float = (float) floating_point_value;
3612
3613
0
      result = 1;
3614
0
    }
3615
0
  }
3616
0
  return( result );
3617
0
}
3618
3619
/* Copies the value data from a double value
3620
 * Returns 1 if successful, 0 if value could not be set or -1 on error
3621
 */
3622
int libfvalue_value_copy_from_double(
3623
     libfvalue_value_t *value,
3624
     int value_entry_index,
3625
     double value_double,
3626
     libcerror_error_t **error )
3627
0
{
3628
0
  libfvalue_internal_value_t *internal_value = NULL;
3629
0
  intptr_t *value_instance                   = NULL;
3630
0
  static char *function                      = "libfvalue_value_copy_from_double";
3631
0
  int result                                 = 0;
3632
3633
0
  if( value == NULL )
3634
0
  {
3635
0
    libcerror_error_set(
3636
0
     error,
3637
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3638
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3639
0
     "%s: invalid value.",
3640
0
     function );
3641
3642
0
    return( -1 );
3643
0
  }
3644
0
  internal_value = (libfvalue_internal_value_t *) value;
3645
3646
0
  if( internal_value->copy_from_floating_point != NULL )
3647
0
  {
3648
0
    if( libfvalue_value_get_value_instance_by_index(
3649
0
         value,
3650
0
         value_entry_index,
3651
0
         &value_instance,
3652
0
         error ) != 1 )
3653
0
    {
3654
0
      libcerror_error_set(
3655
0
       error,
3656
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3657
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3658
0
       "%s: unable to retrieve value instance: %d.",
3659
0
       function,
3660
0
       value_entry_index );
3661
3662
0
      return( -1 );
3663
0
    }
3664
0
    if( value_instance != NULL )
3665
0
    {
3666
0
      if( internal_value->copy_from_floating_point(
3667
0
           value_instance,
3668
0
           (double) value_double,
3669
0
           64,
3670
0
           error ) != 1 )
3671
0
      {
3672
0
        libcerror_error_set(
3673
0
         error,
3674
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3675
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3676
0
         "%s: unable to copy instance from 32-bit floating point.",
3677
0
         function );
3678
3679
0
        return( -1 );
3680
0
      }
3681
0
      result = 1;
3682
0
    }
3683
0
  }
3684
0
  return( result );
3685
0
}
3686
3687
/* Copies the value data to a double value
3688
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3689
 */
3690
int libfvalue_value_copy_to_double(
3691
     libfvalue_value_t *value,
3692
     int value_entry_index,
3693
     double *value_double,
3694
     libcerror_error_t **error )
3695
0
{
3696
0
  libfvalue_internal_value_t *internal_value = NULL;
3697
0
  intptr_t *value_instance                   = NULL;
3698
0
  static char *function                      = "libfvalue_value_copy_to_double";
3699
0
  size_t floating_point_value_size           = 0;
3700
0
  double floating_point_value                = 0.0;
3701
0
  int result                                 = 0;
3702
3703
0
  if( value == NULL )
3704
0
  {
3705
0
    libcerror_error_set(
3706
0
     error,
3707
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3708
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3709
0
     "%s: invalid value.",
3710
0
     function );
3711
3712
0
    return( -1 );
3713
0
  }
3714
0
  internal_value = (libfvalue_internal_value_t *) value;
3715
3716
0
  if( value_double == NULL )
3717
0
  {
3718
0
    libcerror_error_set(
3719
0
     error,
3720
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3721
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3722
0
     "%s: invalid value double.",
3723
0
     function );
3724
3725
0
    return( -1 );
3726
0
  }
3727
0
  if( internal_value->copy_to_floating_point != NULL )
3728
0
  {
3729
0
    if( libfvalue_value_get_value_instance_by_index(
3730
0
         value,
3731
0
         value_entry_index,
3732
0
         &value_instance,
3733
0
         error ) != 1 )
3734
0
    {
3735
0
      libcerror_error_set(
3736
0
       error,
3737
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3738
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3739
0
       "%s: unable to retrieve value instance: %d.",
3740
0
       function,
3741
0
       value_entry_index );
3742
3743
0
      return( -1 );
3744
0
    }
3745
0
    if( value_instance != NULL )
3746
0
    {
3747
0
      if( internal_value->copy_to_floating_point(
3748
0
           value_instance,
3749
0
           &floating_point_value,
3750
0
           &floating_point_value_size,
3751
0
           error ) != 1 )
3752
0
      {
3753
0
        libcerror_error_set(
3754
0
         error,
3755
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3756
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3757
0
         "%s: unable to copy instance to floating point value.",
3758
0
         function );
3759
3760
0
        return( -1 );
3761
0
      }
3762
0
      *value_double = (double) floating_point_value;
3763
3764
0
      result = 1;
3765
0
    }
3766
0
  }
3767
0
  return( result );
3768
0
}
3769
3770
/* String value functions
3771
 */
3772
3773
/* Copies the value data from an UTF-8 encoded string
3774
 * Returns 1 if successful, 0 if value could not be set or -1 on error
3775
 */
3776
int libfvalue_value_copy_from_utf8_string(
3777
     libfvalue_value_t *value,
3778
     int value_entry_index,
3779
     const uint8_t *utf8_string,
3780
     size_t utf8_string_length,
3781
     libcerror_error_t **error )
3782
0
{
3783
0
  libfvalue_internal_value_t *internal_value = NULL;
3784
0
  intptr_t *value_instance                   = NULL;
3785
0
  static char *function                      = "libfvalue_value_copy_from_utf8_string";
3786
0
  size_t utf8_string_index                   = 0;
3787
0
  int result                                 = 0;
3788
3789
0
  if( value == NULL )
3790
0
  {
3791
0
    libcerror_error_set(
3792
0
     error,
3793
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3794
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3795
0
     "%s: invalid value.",
3796
0
     function );
3797
3798
0
    return( -1 );
3799
0
  }
3800
0
  internal_value = (libfvalue_internal_value_t *) value;
3801
3802
0
  if( internal_value->initialize_instance == NULL )
3803
0
  {
3804
0
    libcerror_error_set(
3805
0
     error,
3806
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3807
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3808
0
     "%s: invalid value - missing initialize instance function.",
3809
0
     function );
3810
3811
0
    return( -1 );
3812
0
  }
3813
0
  if( internal_value->free_instance == NULL )
3814
0
  {
3815
0
    libcerror_error_set(
3816
0
     error,
3817
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3818
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3819
0
     "%s: invalid value - missing free instance function.",
3820
0
     function );
3821
3822
0
    return( -1 );
3823
0
  }
3824
0
  if( internal_value->copy_from_utf8_string_with_index != NULL )
3825
0
  {
3826
0
    if( libfvalue_value_get_value_instance_by_index(
3827
0
         value,
3828
0
         value_entry_index,
3829
0
         &value_instance,
3830
0
         error ) != 1 )
3831
0
    {
3832
0
      libcerror_error_set(
3833
0
       error,
3834
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3835
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3836
0
       "%s: unable to retrieve value instance: %d.",
3837
0
       function,
3838
0
       value_entry_index );
3839
3840
0
      return( -1 );
3841
0
    }
3842
0
    if( value_instance == NULL )
3843
0
    {
3844
0
      if( internal_value->initialize_instance(
3845
0
           &value_instance,
3846
0
           error ) != 1 )
3847
0
      {
3848
0
        libcerror_error_set(
3849
0
         error,
3850
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3851
0
         LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
3852
0
         "%s: unable to create value instance.",
3853
0
         function );
3854
3855
0
        return( -1 );
3856
0
      }
3857
0
      if( libcdata_array_set_entry_by_index(
3858
0
           internal_value->value_instances,
3859
0
           value_entry_index,
3860
0
           value_instance,
3861
0
           error ) != 1 )
3862
0
      {
3863
0
        libcerror_error_set(
3864
0
         error,
3865
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3866
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3867
0
         "%s: unable to set entry: %d in values instances array.",
3868
0
         function,
3869
0
         value_entry_index );
3870
3871
0
        internal_value->free_instance(
3872
0
         &value_instance,
3873
0
         NULL );
3874
3875
0
        return( -1 );
3876
0
      }
3877
0
    }
3878
0
    if( internal_value->copy_from_utf8_string_with_index(
3879
0
         value_instance,
3880
0
         utf8_string,
3881
0
         utf8_string_length,
3882
0
         &utf8_string_index,
3883
0
         internal_value->format_flags,
3884
0
         error ) != 1 )
3885
0
    {
3886
0
      libcerror_error_set(
3887
0
       error,
3888
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3889
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3890
0
       "%s: unable to copy instance from UTF-8 string.",
3891
0
       function );
3892
3893
0
      return( -1 );
3894
0
    }
3895
0
    result = 1;
3896
0
  }
3897
0
  return( result );
3898
0
}
3899
3900
/* Retrieves the size of an UTF-8 encoded string of the value data
3901
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3902
 */
3903
int libfvalue_value_get_utf8_string_size(
3904
     libfvalue_value_t *value,
3905
     int value_entry_index,
3906
     size_t *utf8_string_size,
3907
     libcerror_error_t **error )
3908
0
{
3909
0
  libfvalue_internal_value_t *internal_value = NULL;
3910
0
  intptr_t *value_instance                   = NULL;
3911
0
  static char *function                      = "libfvalue_value_get_utf8_string_size";
3912
0
  int result                                 = 0;
3913
3914
0
  if( value == NULL )
3915
0
  {
3916
0
    libcerror_error_set(
3917
0
     error,
3918
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3919
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3920
0
     "%s: invalid value.",
3921
0
     function );
3922
3923
0
    return( -1 );
3924
0
  }
3925
0
  internal_value = (libfvalue_internal_value_t *) value;
3926
3927
0
  if( internal_value->get_utf8_string_size != NULL )
3928
0
  {
3929
0
    if( libfvalue_value_get_value_instance_by_index(
3930
0
         value,
3931
0
         value_entry_index,
3932
0
         &value_instance,
3933
0
         error ) != 1 )
3934
0
    {
3935
0
      libcerror_error_set(
3936
0
       error,
3937
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3938
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3939
0
       "%s: unable to retrieve value instance: %d.",
3940
0
       function,
3941
0
       value_entry_index );
3942
3943
0
      return( -1 );
3944
0
    }
3945
0
    if( value_instance != NULL )
3946
0
    {
3947
0
      if( internal_value->get_utf8_string_size(
3948
0
           value_instance,
3949
0
           utf8_string_size,
3950
0
           internal_value->format_flags,
3951
0
           error ) != 1 )
3952
0
      {
3953
0
        libcerror_error_set(
3954
0
         error,
3955
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
3956
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3957
0
         "%s: unable to determine size UTF-8 string of instance.",
3958
0
         function );
3959
3960
0
        return( -1 );
3961
0
      }
3962
0
      result = 1;
3963
0
    }
3964
0
  }
3965
0
  return( result );
3966
0
}
3967
3968
/* Copies the value data to an UTF-8 encoded string
3969
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
3970
 */
3971
int libfvalue_value_copy_to_utf8_string(
3972
     libfvalue_value_t *value,
3973
     int value_entry_index,
3974
     uint8_t *utf8_string,
3975
     size_t utf8_string_size,
3976
     libcerror_error_t **error )
3977
0
{
3978
0
  static char *function    = "libfvalue_value_copy_to_utf8_string";
3979
0
  size_t utf8_string_index = 0;
3980
0
  int result               = 0;
3981
3982
0
  result = libfvalue_value_copy_to_utf8_string_with_index(
3983
0
            value,
3984
0
            value_entry_index,
3985
0
            utf8_string,
3986
0
            utf8_string_size,
3987
0
            &utf8_string_index,
3988
0
            error );
3989
3990
0
  if( result == -1 )
3991
0
  {
3992
0
    libcerror_error_set(
3993
0
     error,
3994
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3995
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3996
0
     "%s: unable to copy value: %d to UTF-8 string.",
3997
0
     function,
3998
0
     value_entry_index );
3999
4000
0
    return( -1 );
4001
0
  }
4002
0
  return( result );
4003
0
}
4004
4005
/* Copies the value data to an UTF-8 encoded string
4006
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4007
 */
4008
int libfvalue_value_copy_to_utf8_string_with_index(
4009
     libfvalue_value_t *value,
4010
     int value_entry_index,
4011
     uint8_t *utf8_string,
4012
     size_t utf8_string_size,
4013
     size_t *utf8_string_index,
4014
     libcerror_error_t **error )
4015
0
{
4016
0
  libfvalue_internal_value_t *internal_value = NULL;
4017
0
  intptr_t *value_instance                   = NULL;
4018
0
  static char *function                      = "libfvalue_value_copy_to_utf8_string_with_index";
4019
0
  int result                                 = 0;
4020
4021
0
  if( value == NULL )
4022
0
  {
4023
0
    libcerror_error_set(
4024
0
     error,
4025
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4026
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4027
0
     "%s: invalid value.",
4028
0
     function );
4029
4030
0
    return( -1 );
4031
0
  }
4032
0
  internal_value = (libfvalue_internal_value_t *) value;
4033
4034
0
  if( internal_value->copy_to_utf8_string_with_index != NULL )
4035
0
  {
4036
0
    if( libfvalue_value_get_value_instance_by_index(
4037
0
         value,
4038
0
         value_entry_index,
4039
0
         &value_instance,
4040
0
         error ) != 1 )
4041
0
    {
4042
0
      libcerror_error_set(
4043
0
       error,
4044
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4045
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4046
0
       "%s: unable to retrieve value instance: %d.",
4047
0
       function,
4048
0
       value_entry_index );
4049
4050
0
      return( -1 );
4051
0
    }
4052
0
    if( value_instance != NULL )
4053
0
    {
4054
0
      if( internal_value->copy_to_utf8_string_with_index(
4055
0
           value_instance,
4056
0
           utf8_string,
4057
0
           utf8_string_size,
4058
0
           utf8_string_index,
4059
0
           internal_value->format_flags,
4060
0
           error ) != 1 )
4061
0
      {
4062
0
        libcerror_error_set(
4063
0
         error,
4064
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4065
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4066
0
         "%s: unable to copy instance to UTF-8 string.",
4067
0
         function );
4068
4069
0
        return( -1 );
4070
0
      }
4071
0
      result = 1;
4072
0
    }
4073
0
  }
4074
0
  return( result );
4075
0
}
4076
4077
/* Copies the value data from an UTF-16 encoded string
4078
 * Returns 1 if successful, 0 if value could not be set or -1 on error
4079
 */
4080
int libfvalue_value_copy_from_utf16_string(
4081
     libfvalue_value_t *value,
4082
     int value_entry_index,
4083
     const uint16_t *utf16_string,
4084
     size_t utf16_string_length,
4085
     libcerror_error_t **error )
4086
0
{
4087
0
  libfvalue_internal_value_t *internal_value = NULL;
4088
0
  intptr_t *value_instance                   = NULL;
4089
0
  static char *function                      = "libfvalue_value_copy_from_utf16_string";
4090
0
  size_t utf16_string_index                  = 0;
4091
0
  int result                                 = 0;
4092
4093
0
  if( value == NULL )
4094
0
  {
4095
0
    libcerror_error_set(
4096
0
     error,
4097
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4098
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4099
0
     "%s: invalid value.",
4100
0
     function );
4101
4102
0
    return( -1 );
4103
0
  }
4104
0
  internal_value = (libfvalue_internal_value_t *) value;
4105
4106
0
  if( internal_value->initialize_instance == NULL )
4107
0
  {
4108
0
    libcerror_error_set(
4109
0
     error,
4110
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4111
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4112
0
     "%s: invalid value - missing initialize instance function.",
4113
0
     function );
4114
4115
0
    return( -1 );
4116
0
  }
4117
0
  if( internal_value->free_instance == NULL )
4118
0
  {
4119
0
    libcerror_error_set(
4120
0
     error,
4121
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4122
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4123
0
     "%s: invalid value - missing free instance function.",
4124
0
     function );
4125
4126
0
    return( -1 );
4127
0
  }
4128
0
  if( internal_value->copy_from_utf16_string_with_index != NULL )
4129
0
  {
4130
0
    if( libfvalue_value_get_value_instance_by_index(
4131
0
         value,
4132
0
         value_entry_index,
4133
0
         &value_instance,
4134
0
         error ) != 1 )
4135
0
    {
4136
0
      libcerror_error_set(
4137
0
       error,
4138
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4139
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4140
0
       "%s: unable to retrieve value instance: %d.",
4141
0
       function,
4142
0
       value_entry_index );
4143
4144
0
      return( -1 );
4145
0
    }
4146
0
    if( value_instance == NULL )
4147
0
    {
4148
0
      if( internal_value->initialize_instance(
4149
0
           &value_instance,
4150
0
           error ) != 1 )
4151
0
      {
4152
0
        libcerror_error_set(
4153
0
         error,
4154
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4155
0
         LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
4156
0
         "%s: unable to create value instance.",
4157
0
         function );
4158
4159
0
        return( -1 );
4160
0
      }
4161
0
      if( libcdata_array_set_entry_by_index(
4162
0
           internal_value->value_instances,
4163
0
           value_entry_index,
4164
0
           value_instance,
4165
0
           error ) != 1 )
4166
0
      {
4167
0
        libcerror_error_set(
4168
0
         error,
4169
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4170
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4171
0
         "%s: unable to set entry: %d in values instances array.",
4172
0
         function,
4173
0
         value_entry_index );
4174
4175
0
        internal_value->free_instance(
4176
0
         &value_instance,
4177
0
         NULL );
4178
4179
0
        return( -1 );
4180
0
      }
4181
0
    }
4182
0
    if( internal_value->copy_from_utf16_string_with_index(
4183
0
         value_instance,
4184
0
         utf16_string,
4185
0
         utf16_string_length,
4186
0
         &utf16_string_index,
4187
0
         internal_value->format_flags,
4188
0
         error ) != 1 )
4189
0
    {
4190
0
      libcerror_error_set(
4191
0
       error,
4192
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4193
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4194
0
       "%s: unable to copy instance from UTF-16 string.",
4195
0
       function );
4196
4197
0
      return( -1 );
4198
0
    }
4199
0
    result = 1;
4200
0
  }
4201
0
  return( result );
4202
0
}
4203
4204
/* Retrieves the size of an UTF-16 encoded string of the value data
4205
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4206
 */
4207
int libfvalue_value_get_utf16_string_size(
4208
     libfvalue_value_t *value,
4209
     int value_entry_index,
4210
     size_t *utf16_string_size,
4211
     libcerror_error_t **error )
4212
0
{
4213
0
  libfvalue_internal_value_t *internal_value = NULL;
4214
0
  intptr_t *value_instance                   = NULL;
4215
0
  static char *function                      = "libfvalue_value_get_utf16_string_size";
4216
0
  int result                                 = 0;
4217
4218
0
  if( value == NULL )
4219
0
  {
4220
0
    libcerror_error_set(
4221
0
     error,
4222
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4223
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4224
0
     "%s: invalid value.",
4225
0
     function );
4226
4227
0
    return( -1 );
4228
0
  }
4229
0
  internal_value = (libfvalue_internal_value_t *) value;
4230
4231
0
  if( internal_value->get_utf16_string_size != NULL )
4232
0
  {
4233
0
    if( libfvalue_value_get_value_instance_by_index(
4234
0
         value,
4235
0
         value_entry_index,
4236
0
         &value_instance,
4237
0
         error ) != 1 )
4238
0
    {
4239
0
      libcerror_error_set(
4240
0
       error,
4241
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4242
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4243
0
       "%s: unable to retrieve value instance: %d.",
4244
0
       function,
4245
0
       value_entry_index );
4246
4247
0
      return( -1 );
4248
0
    }
4249
0
    if( value_instance != NULL )
4250
0
    {
4251
0
      if( internal_value->get_utf16_string_size(
4252
0
           value_instance,
4253
0
           utf16_string_size,
4254
0
           internal_value->format_flags,
4255
0
           error ) != 1 )
4256
0
      {
4257
0
        libcerror_error_set(
4258
0
         error,
4259
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4260
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4261
0
         "%s: unable to determine size UTF-16 string of instance.",
4262
0
         function );
4263
4264
0
        return( -1 );
4265
0
      }
4266
0
      result = 1;
4267
0
    }
4268
0
  }
4269
0
  return( result );
4270
0
}
4271
4272
/* Copies the value data to an UTF-16 encoded string
4273
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4274
 */
4275
int libfvalue_value_copy_to_utf16_string(
4276
     libfvalue_value_t *value,
4277
     int value_entry_index,
4278
     uint16_t *utf16_string,
4279
     size_t utf16_string_size,
4280
     libcerror_error_t **error )
4281
0
{
4282
0
  static char *function     = "libfvalue_value_copy_to_utf16_string";
4283
0
  size_t utf16_string_index = 0;
4284
0
  int result                = 0;
4285
4286
0
  result = libfvalue_value_copy_to_utf16_string_with_index(
4287
0
            value,
4288
0
            value_entry_index,
4289
0
            utf16_string,
4290
0
            utf16_string_size,
4291
0
            &utf16_string_index,
4292
0
            error );
4293
4294
0
  if( result == -1 )
4295
0
  {
4296
0
    libcerror_error_set(
4297
0
     error,
4298
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4299
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4300
0
     "%s: unable to copy value: %d to UTF-16 string.",
4301
0
     function,
4302
0
     value_entry_index );
4303
4304
0
    return( -1 );
4305
0
  }
4306
0
  return( result );
4307
0
}
4308
4309
/* Copies the value data to an UTF-16 encoded string
4310
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4311
 */
4312
int libfvalue_value_copy_to_utf16_string_with_index(
4313
     libfvalue_value_t *value,
4314
     int value_entry_index,
4315
     uint16_t *utf16_string,
4316
     size_t utf16_string_size,
4317
     size_t *utf16_string_index,
4318
     libcerror_error_t **error )
4319
0
{
4320
0
  libfvalue_internal_value_t *internal_value = NULL;
4321
0
  intptr_t *value_instance                   = NULL;
4322
0
  static char *function                      = "libfvalue_value_copy_to_utf16_string_with_index";
4323
0
  int result                                 = 0;
4324
4325
0
  if( value == NULL )
4326
0
  {
4327
0
    libcerror_error_set(
4328
0
     error,
4329
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4330
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4331
0
     "%s: invalid value.",
4332
0
     function );
4333
4334
0
    return( -1 );
4335
0
  }
4336
0
  internal_value = (libfvalue_internal_value_t *) value;
4337
4338
0
  if( internal_value->copy_to_utf16_string_with_index != NULL )
4339
0
  {
4340
0
    if( libfvalue_value_get_value_instance_by_index(
4341
0
         value,
4342
0
         value_entry_index,
4343
0
         &value_instance,
4344
0
         error ) != 1 )
4345
0
    {
4346
0
      libcerror_error_set(
4347
0
       error,
4348
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4349
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4350
0
       "%s: unable to retrieve value instance: %d.",
4351
0
       function,
4352
0
       value_entry_index );
4353
4354
0
      return( -1 );
4355
0
    }
4356
0
    if( value_instance != NULL )
4357
0
    {
4358
0
      if( internal_value->copy_to_utf16_string_with_index(
4359
0
           value_instance,
4360
0
           utf16_string,
4361
0
           utf16_string_size,
4362
0
           utf16_string_index,
4363
0
           internal_value->format_flags,
4364
0
           error ) != 1 )
4365
0
      {
4366
0
        libcerror_error_set(
4367
0
         error,
4368
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4369
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4370
0
         "%s: unable to copy instance to UTF-16 string.",
4371
0
         function );
4372
4373
0
        return( -1 );
4374
0
      }
4375
0
      result = 1;
4376
0
    }
4377
0
  }
4378
0
  return( result );
4379
0
}
4380
4381
/* Copies the value data from an UTF-32 encoded string
4382
 * Returns 1 if successful, 0 if value could not be set or -1 on error
4383
 */
4384
int libfvalue_value_copy_from_utf32_string(
4385
     libfvalue_value_t *value,
4386
     int value_entry_index,
4387
     const uint32_t *utf32_string,
4388
     size_t utf32_string_length,
4389
     libcerror_error_t **error )
4390
0
{
4391
0
  libfvalue_internal_value_t *internal_value = NULL;
4392
0
  intptr_t *value_instance                   = NULL;
4393
0
  static char *function                      = "libfvalue_value_copy_from_utf32_string";
4394
0
  size_t utf32_string_index                  = 0;
4395
0
  int result                                 = 0;
4396
4397
0
  if( value == NULL )
4398
0
  {
4399
0
    libcerror_error_set(
4400
0
     error,
4401
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4402
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4403
0
     "%s: invalid value.",
4404
0
     function );
4405
4406
0
    return( -1 );
4407
0
  }
4408
0
  internal_value = (libfvalue_internal_value_t *) value;
4409
4410
0
  if( internal_value->initialize_instance == NULL )
4411
0
  {
4412
0
    libcerror_error_set(
4413
0
     error,
4414
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4415
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4416
0
     "%s: invalid value - missing initialize instance function.",
4417
0
     function );
4418
4419
0
    return( -1 );
4420
0
  }
4421
0
  if( internal_value->free_instance == NULL )
4422
0
  {
4423
0
    libcerror_error_set(
4424
0
     error,
4425
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4426
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4427
0
     "%s: invalid value - missing free instance function.",
4428
0
     function );
4429
4430
0
    return( -1 );
4431
0
  }
4432
0
  internal_value = (libfvalue_internal_value_t *) value;
4433
4434
0
  if( internal_value->copy_from_utf32_string_with_index != NULL )
4435
0
  {
4436
0
    if( libfvalue_value_get_value_instance_by_index(
4437
0
         value,
4438
0
         value_entry_index,
4439
0
         &value_instance,
4440
0
         error ) != 1 )
4441
0
    {
4442
0
      libcerror_error_set(
4443
0
       error,
4444
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4445
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4446
0
       "%s: unable to retrieve value instance: %d.",
4447
0
       function,
4448
0
       value_entry_index );
4449
4450
0
      return( -1 );
4451
0
    }
4452
0
    if( value_instance == NULL )
4453
0
    {
4454
0
      if( internal_value->initialize_instance(
4455
0
           &value_instance,
4456
0
           error ) != 1 )
4457
0
      {
4458
0
        libcerror_error_set(
4459
0
         error,
4460
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4461
0
         LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
4462
0
         "%s: unable to create value instance.",
4463
0
         function );
4464
4465
0
        return( -1 );
4466
0
      }
4467
0
      if( libcdata_array_set_entry_by_index(
4468
0
           internal_value->value_instances,
4469
0
           value_entry_index,
4470
0
           value_instance,
4471
0
           error ) != 1 )
4472
0
      {
4473
0
        libcerror_error_set(
4474
0
         error,
4475
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4476
0
         LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4477
0
         "%s: unable to set entry: %d in values instances array.",
4478
0
         function,
4479
0
         value_entry_index );
4480
4481
0
        internal_value->free_instance(
4482
0
         &value_instance,
4483
0
         NULL );
4484
4485
0
        return( -1 );
4486
0
      }
4487
0
    }
4488
0
    if( internal_value->copy_from_utf32_string_with_index(
4489
0
         value_instance,
4490
0
         utf32_string,
4491
0
         utf32_string_length,
4492
0
         &utf32_string_index,
4493
0
         internal_value->format_flags,
4494
0
         error ) != 1 )
4495
0
    {
4496
0
      libcerror_error_set(
4497
0
       error,
4498
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4499
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4500
0
       "%s: unable to copy instance from UTF-32 string.",
4501
0
       function );
4502
4503
0
      return( -1 );
4504
0
    }
4505
0
    result = 1;
4506
0
  }
4507
0
  return( result );
4508
0
}
4509
4510
/* Retrieves the size of an UTF-32 encoded string of the value data
4511
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4512
 */
4513
int libfvalue_value_get_utf32_string_size(
4514
     libfvalue_value_t *value,
4515
     int value_entry_index,
4516
     size_t *utf32_string_size,
4517
     libcerror_error_t **error )
4518
0
{
4519
0
  libfvalue_internal_value_t *internal_value = NULL;
4520
0
  intptr_t *value_instance                   = NULL;
4521
0
  static char *function                      = "libfvalue_value_get_utf32_string_size";
4522
0
  int result                                 = 0;
4523
4524
0
  if( value == NULL )
4525
0
  {
4526
0
    libcerror_error_set(
4527
0
     error,
4528
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4529
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4530
0
     "%s: invalid value.",
4531
0
     function );
4532
4533
0
    return( -1 );
4534
0
  }
4535
0
  internal_value = (libfvalue_internal_value_t *) value;
4536
4537
0
  if( internal_value->get_utf32_string_size != NULL )
4538
0
  {
4539
0
    if( libfvalue_value_get_value_instance_by_index(
4540
0
         value,
4541
0
         value_entry_index,
4542
0
         &value_instance,
4543
0
         error ) != 1 )
4544
0
    {
4545
0
      libcerror_error_set(
4546
0
       error,
4547
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4548
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4549
0
       "%s: unable to retrieve value instance: %d.",
4550
0
       function,
4551
0
       value_entry_index );
4552
4553
0
      return( -1 );
4554
0
    }
4555
0
    if( value_instance != NULL )
4556
0
    {
4557
0
      if( internal_value->get_utf32_string_size(
4558
0
           value_instance,
4559
0
           utf32_string_size,
4560
0
           internal_value->format_flags,
4561
0
           error ) != 1 )
4562
0
      {
4563
0
        libcerror_error_set(
4564
0
         error,
4565
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4566
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4567
0
         "%s: unable to determine size UTF-32 string of instance.",
4568
0
         function );
4569
4570
0
        return( -1 );
4571
0
      }
4572
0
      result = 1;
4573
0
    }
4574
0
  }
4575
0
  return( result );
4576
0
}
4577
4578
/* Copies the value data to an UTF-32 encoded string
4579
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4580
 */
4581
int libfvalue_value_copy_to_utf32_string(
4582
     libfvalue_value_t *value,
4583
     int value_entry_index,
4584
     uint32_t *utf32_string,
4585
     size_t utf32_string_size,
4586
     libcerror_error_t **error )
4587
0
{
4588
0
  static char *function     = "libfvalue_value_copy_to_utf32_string";
4589
0
  size_t utf32_string_index = 0;
4590
0
  int result                = 0;
4591
4592
0
  result = libfvalue_value_copy_to_utf32_string_with_index(
4593
0
            value,
4594
0
            value_entry_index,
4595
0
            utf32_string,
4596
0
            utf32_string_size,
4597
0
            &utf32_string_index,
4598
0
            error );
4599
4600
0
  if( result == -1 )
4601
0
  {
4602
0
    libcerror_error_set(
4603
0
     error,
4604
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4605
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4606
0
     "%s: unable to copy value: %d to UTF-32 string.",
4607
0
     function,
4608
0
     value_entry_index );
4609
4610
0
    return( -1 );
4611
0
  }
4612
0
  return( result );
4613
0
}
4614
4615
/* Copies the value data to an UTF-32 encoded string
4616
 * Returns 1 if successful, 0 if size value not be retrieved or -1 on error
4617
 */
4618
int libfvalue_value_copy_to_utf32_string_with_index(
4619
     libfvalue_value_t *value,
4620
     int value_entry_index,
4621
     uint32_t *utf32_string,
4622
     size_t utf32_string_size,
4623
     size_t *utf32_string_index,
4624
     libcerror_error_t **error )
4625
0
{
4626
0
  libfvalue_internal_value_t *internal_value = NULL;
4627
0
  intptr_t *value_instance                   = NULL;
4628
0
  static char *function                      = "libfvalue_value_copy_to_utf32_string_with_index";
4629
0
  int result                                 = 0;
4630
4631
0
  if( value == NULL )
4632
0
  {
4633
0
    libcerror_error_set(
4634
0
     error,
4635
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4636
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4637
0
     "%s: invalid value.",
4638
0
     function );
4639
4640
0
    return( -1 );
4641
0
  }
4642
0
  internal_value = (libfvalue_internal_value_t *) value;
4643
4644
0
  if( internal_value->copy_to_utf32_string_with_index != NULL )
4645
0
  {
4646
0
    if( libfvalue_value_get_value_instance_by_index(
4647
0
         value,
4648
0
         value_entry_index,
4649
0
         &value_instance,
4650
0
         error ) != 1 )
4651
0
    {
4652
0
      libcerror_error_set(
4653
0
       error,
4654
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4655
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4656
0
       "%s: unable to retrieve value instance: %d.",
4657
0
       function,
4658
0
       value_entry_index );
4659
4660
0
      return( -1 );
4661
0
    }
4662
0
    if( value_instance != NULL )
4663
0
    {
4664
0
      if( internal_value->copy_to_utf32_string_with_index(
4665
0
           value_instance,
4666
0
           utf32_string,
4667
0
           utf32_string_size,
4668
0
           utf32_string_index,
4669
0
           internal_value->format_flags,
4670
0
           error ) != 1 )
4671
0
      {
4672
0
        libcerror_error_set(
4673
0
         error,
4674
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4675
0
         LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4676
0
         "%s: unable to copy instance to UTF-32 string.",
4677
0
         function );
4678
4679
0
        return( -1 );
4680
0
      }
4681
0
      result = 1;
4682
0
    }
4683
0
  }
4684
0
  return( result );
4685
0
}
4686
4687
/* Marshalling functions
4688
 */
4689
4690
#ifdef TODO
4691
4692
/* Reads the value data from a file stream
4693
 * Returns the number of bytes read or -1 on error
4694
 */
4695
ssize_t libfvalue_value_read_from_file_stream(
4696
         libfvalue_value_t *value,
4697
         FILE *file_stream,
4698
         libcerror_error_t **error )
4699
{
4700
  libfvalue_internal_value_t *internal_value = NULL;
4701
  static char *function                      = "libfvalue_value_read_from_file_stream";
4702
4703
  if( value == NULL )
4704
  {
4705
    libcerror_error_set(
4706
     error,
4707
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4708
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4709
     "%s: invalid value.",
4710
     function );
4711
4712
    return( -1 );
4713
  }
4714
  internal_value = (libfvalue_internal_value_t *) value;
4715
4716
  if( internal_value->copy_from_utf8_string_with_index == NULL )
4717
  {
4718
    libcerror_error_set(
4719
     error,
4720
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4721
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4722
     "%s: invalid value - missing copy from UTF-8 string function.",
4723
     function );
4724
4725
    return( -1 );
4726
  }
4727
  if( file_stream == NULL )
4728
  {
4729
    libcerror_error_set(
4730
     error,
4731
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4732
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4733
     "%s: invalid file stream.",
4734
     function );
4735
4736
    return( -1 );
4737
  }
4738
/* TODO implement function */
4739
  return( -1 );
4740
}
4741
4742
#endif /* TODO */
4743
4744
/* Writes the value data to a file stream
4745
 * Returns the number of bytes written or -1 on error
4746
 */
4747
ssize_t libfvalue_value_write_to_file_stream(
4748
         libfvalue_value_t *value,
4749
         FILE *file_stream,
4750
         libcerror_error_t **error )
4751
0
{
4752
0
  libfvalue_internal_value_t *internal_value = NULL;
4753
0
  intptr_t *value_instance                   = NULL;
4754
0
  uint8_t *value_string                      = NULL;
4755
0
  static char *function                      = "libfvalue_value_write_to_file_stream";
4756
0
  size_t value_string_index                  = 0;
4757
0
  size_t value_string_size                   = 0;
4758
0
  ssize_t write_count                        = 0;
4759
0
  int print_count                            = 0;
4760
0
  int number_of_value_entries                = 0;
4761
0
  int value_entry_index                      = 0;
4762
4763
0
  if( value == NULL )
4764
0
  {
4765
0
    libcerror_error_set(
4766
0
     error,
4767
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4768
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4769
0
     "%s: invalid value.",
4770
0
     function );
4771
4772
0
    return( -1 );
4773
0
  }
4774
0
  internal_value = (libfvalue_internal_value_t *) value;
4775
4776
0
  if( internal_value->type_string == NULL )
4777
0
  {
4778
0
    libcerror_error_set(
4779
0
     error,
4780
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4781
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4782
0
     "%s: invalid value - missing type string.",
4783
0
     function );
4784
4785
0
    return( -1 );
4786
0
  }
4787
0
  if( ( internal_value->identifier == NULL )
4788
0
   || ( internal_value->identifier[ 0 ] == 0 ) )
4789
0
  {
4790
0
    libcerror_error_set(
4791
0
     error,
4792
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4793
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4794
0
     "%s: invalid value - missing identifier.",
4795
0
     function );
4796
4797
0
    return( -1 );
4798
0
  }
4799
0
  if( internal_value->get_utf8_string_size == NULL )
4800
0
  {
4801
0
    libcerror_error_set(
4802
0
     error,
4803
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4804
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4805
0
     "%s: invalid value - missing get UTF-8 string size function.",
4806
0
     function );
4807
4808
0
    return( -1 );
4809
0
  }
4810
0
  if( internal_value->copy_to_utf8_string_with_index == NULL )
4811
0
  {
4812
0
    libcerror_error_set(
4813
0
     error,
4814
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4815
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4816
0
     "%s: invalid value - missing copy to UTF-8 string function.",
4817
0
     function );
4818
4819
0
    return( -1 );
4820
0
  }
4821
0
  if( file_stream == NULL )
4822
0
  {
4823
0
    libcerror_error_set(
4824
0
     error,
4825
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4826
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4827
0
     "%s: invalid file stream.",
4828
0
     function );
4829
4830
0
    return( -1 );
4831
0
  }
4832
0
  if( libfvalue_value_get_number_of_value_entries(
4833
0
       value,
4834
0
       &number_of_value_entries,
4835
0
       error ) != 1 )
4836
0
  {
4837
0
    libcerror_error_set(
4838
0
     error,
4839
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
4840
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4841
0
     "%s: unable to retrieve number of value entries.",
4842
0
     function );
4843
4844
0
    goto on_error;
4845
0
  }
4846
0
  for( value_entry_index = 0;
4847
0
       value_entry_index < number_of_value_entries;
4848
0
       value_entry_index++ )
4849
0
  {
4850
0
    if( libfvalue_value_get_value_instance_by_index(
4851
0
         value,
4852
0
         value_entry_index,
4853
0
         &value_instance,
4854
0
         error ) != 1 )
4855
0
    {
4856
0
      libcerror_error_set(
4857
0
       error,
4858
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
4859
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4860
0
       "%s: unable to retrieve value instance: %d.",
4861
0
       function,
4862
0
       value_entry_index );
4863
4864
0
      goto on_error;
4865
0
    }
4866
0
    print_count = fprintf(
4867
0
             file_stream,
4868
0
             "<%s type=\"%s\">",
4869
0
             (char *) internal_value->identifier,
4870
0
             internal_value->type_string );
4871
4872
0
    if( print_count < 0 )
4873
0
    {
4874
0
      libcerror_error_set(
4875
0
       error,
4876
0
       LIBCERROR_ERROR_DOMAIN_IO,
4877
0
       LIBCERROR_IO_ERROR_WRITE_FAILED,
4878
0
       "%s: unable to write to file stream.",
4879
0
       function );
4880
4881
0
      goto on_error;
4882
0
    }
4883
0
    write_count += print_count;
4884
4885
0
    if( number_of_value_entries > 1 )
4886
0
    {
4887
0
      print_count = fprintf(
4888
0
               file_stream,
4889
0
               "<value_entry>" );
4890
4891
0
      if( print_count < 0 )
4892
0
      {
4893
0
        libcerror_error_set(
4894
0
         error,
4895
0
         LIBCERROR_ERROR_DOMAIN_IO,
4896
0
         LIBCERROR_IO_ERROR_WRITE_FAILED,
4897
0
         "%s: unable to write to file stream.",
4898
0
         function );
4899
4900
0
        goto on_error;
4901
0
      }
4902
0
      write_count += print_count;
4903
0
    }
4904
0
    if( value_instance != NULL )
4905
0
    {
4906
0
      if( internal_value->get_utf8_string_size(
4907
0
           value_instance,
4908
0
           &value_string_size,
4909
0
           internal_value->format_flags,
4910
0
           error ) != 1 )
4911
0
      {
4912
0
        libcerror_error_set(
4913
0
         error,
4914
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
4915
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4916
0
         "%s: unable to determine size UTF-8 string of instance.",
4917
0
         function );
4918
4919
0
        goto on_error;
4920
0
      }
4921
0
      if( value_string_size > 0 )
4922
0
      {
4923
0
        value_string = (uint8_t *) memory_allocate(
4924
0
                  sizeof( uint8_t ) * value_string_size );
4925
4926
0
        if( value_string == NULL )
4927
0
        {
4928
0
          libcerror_error_set(
4929
0
           error,
4930
0
           LIBCERROR_ERROR_DOMAIN_MEMORY,
4931
0
           LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
4932
0
           "%s: unable to value string.",
4933
0
           function );
4934
4935
0
          goto on_error;
4936
0
        }
4937
0
        if( internal_value->copy_to_utf8_string_with_index(
4938
0
             value_instance,
4939
0
             value_string,
4940
0
             value_string_size,
4941
0
             &value_string_index,
4942
0
             internal_value->format_flags,
4943
0
             error ) != 1 )
4944
0
        {
4945
0
          libcerror_error_set(
4946
0
           error,
4947
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
4948
0
           LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4949
0
           "%s: unable to copy instance to UTF-8 string.",
4950
0
           function );
4951
4952
0
          goto on_error;
4953
0
        }
4954
0
        print_count = fprintf(
4955
0
                 file_stream,
4956
0
                 "%s",
4957
0
                 value_string );
4958
4959
0
        if( print_count < 0 )
4960
0
        {
4961
0
          libcerror_error_set(
4962
0
           error,
4963
0
           LIBCERROR_ERROR_DOMAIN_IO,
4964
0
           LIBCERROR_IO_ERROR_WRITE_FAILED,
4965
0
           "%s: unable to write to file stream.",
4966
0
           function );
4967
4968
0
          goto on_error;
4969
0
        }
4970
0
        write_count += print_count;
4971
4972
0
        memory_free(
4973
0
         value_string );
4974
4975
0
        value_string = NULL;
4976
0
      }
4977
0
    }
4978
0
    if( number_of_value_entries > 1 )
4979
0
    {
4980
0
      print_count = fprintf(
4981
0
               file_stream,
4982
0
               "</value_entry>" );
4983
4984
0
      if( print_count < 0 )
4985
0
      {
4986
0
        libcerror_error_set(
4987
0
         error,
4988
0
         LIBCERROR_ERROR_DOMAIN_IO,
4989
0
         LIBCERROR_IO_ERROR_WRITE_FAILED,
4990
0
         "%s: unable to write to file stream.",
4991
0
         function );
4992
4993
0
        goto on_error;
4994
0
      }
4995
0
      write_count += print_count;
4996
0
    }
4997
0
    print_count = fprintf(
4998
0
             file_stream,
4999
0
             "</%s>",
5000
0
             (char *) internal_value->identifier );
5001
5002
0
    if( print_count < 0 )
5003
0
    {
5004
0
      libcerror_error_set(
5005
0
       error,
5006
0
       LIBCERROR_ERROR_DOMAIN_IO,
5007
0
       LIBCERROR_IO_ERROR_WRITE_FAILED,
5008
0
       "%s: unable to write to file stream.",
5009
0
       function );
5010
5011
0
      goto on_error;
5012
0
    }
5013
0
    write_count += print_count;
5014
0
  }
5015
0
  return( write_count );
5016
5017
0
on_error:
5018
0
  if( value_string != NULL )
5019
0
  {
5020
0
    memory_free(
5021
0
     value_string );
5022
0
  }
5023
0
  return( -1 );
5024
0
}
5025
5026
/* Prints the value
5027
 * Returns 1 if successful or -1 on error
5028
 */
5029
int libfvalue_value_print(
5030
     libfvalue_value_t *value,
5031
     int value_entry_index,
5032
     uint8_t flags,
5033
     libcerror_error_t **error )
5034
0
{
5035
0
  libfvalue_internal_value_t *internal_value = NULL;
5036
0
  system_character_t *value_string           = NULL;
5037
0
  intptr_t *value_instance                   = NULL;
5038
0
  static char *function                      = "libfvalue_value_print";
5039
0
  size_t value_string_index                  = 0;
5040
0
  size_t value_string_size                   = 0;
5041
0
  int result                                 = 0;
5042
5043
0
  if( value == NULL )
5044
0
  {
5045
0
    libcerror_error_set(
5046
0
     error,
5047
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5048
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5049
0
     "%s: invalid value.",
5050
0
     function );
5051
5052
0
    return( -1 );
5053
0
  }
5054
0
  internal_value = (libfvalue_internal_value_t *) value;
5055
5056
0
  if( internal_value->type_description == NULL )
5057
0
  {
5058
0
    libcerror_error_set(
5059
0
     error,
5060
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
5061
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
5062
0
     "%s: invalid value - missing type description.",
5063
0
     function );
5064
5065
0
    return( -1 );
5066
0
  }
5067
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
5068
  if( internal_value->get_utf16_string_size == NULL )
5069
#else
5070
0
  if( internal_value->get_utf8_string_size == NULL )
5071
0
#endif
5072
0
  {
5073
0
    libcerror_error_set(
5074
0
     error,
5075
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
5076
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
5077
0
     "%s: invalid value - missing get string size function.",
5078
0
     function );
5079
5080
0
    return( -1 );
5081
0
  }
5082
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
5083
  if( internal_value->copy_to_utf16_string_with_index == NULL )
5084
#else
5085
0
  if( internal_value->copy_to_utf8_string_with_index == NULL )
5086
0
#endif
5087
0
  {
5088
0
    libcerror_error_set(
5089
0
     error,
5090
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
5091
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
5092
0
     "%s: invalid value - missing copy to string function.",
5093
0
     function );
5094
5095
0
    return( -1 );
5096
0
  }
5097
0
  if( ( flags & ~( LIBFVALUE_PRINT_FLAG_WITH_TYPE_DESCRIPTION ) ) != 0 )
5098
0
  {
5099
0
    libcerror_error_set(
5100
0
     error,
5101
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
5102
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
5103
0
     "%s: unsupported flags: 0x%02" PRIx8 ".",
5104
0
     function,
5105
0
     flags );
5106
5107
0
    return( -1 );
5108
0
  }
5109
0
  if( ( flags & LIBFVALUE_PRINT_FLAG_WITH_TYPE_DESCRIPTION ) != 0 )
5110
0
  {
5111
0
    libcnotify_printf(
5112
0
     "%s\t: ",
5113
0
    internal_value->type_description );
5114
0
  }
5115
0
  result = libfvalue_value_has_data(
5116
0
            value,
5117
0
            error );
5118
5119
0
  if( result == -1 )
5120
0
  {
5121
0
    libcerror_error_set(
5122
0
     error,
5123
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
5124
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5125
0
     "%s: unable to determine if value has data.",
5126
0
     function );
5127
5128
0
    goto on_error;
5129
0
  }
5130
0
  else if( result != 0 )
5131
0
  {
5132
0
    if( libfvalue_value_get_value_instance_by_index(
5133
0
         value,
5134
0
         value_entry_index,
5135
0
         &value_instance,
5136
0
         error ) != 1 )
5137
0
    {
5138
0
      libcerror_error_set(
5139
0
       error,
5140
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
5141
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5142
0
       "%s: unable to retrieve value instance: %d.",
5143
0
       function,
5144
0
       value_entry_index );
5145
5146
0
      goto on_error;
5147
0
    }
5148
0
    if( value_instance != NULL )
5149
0
    {
5150
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
5151
      result = internal_value->get_utf16_string_size(
5152
          value_instance,
5153
          &value_string_size,
5154
          internal_value->format_flags,
5155
          error );
5156
#else
5157
0
      result = internal_value->get_utf8_string_size(
5158
0
          value_instance,
5159
0
          &value_string_size,
5160
0
          internal_value->format_flags,
5161
0
          error );
5162
0
#endif
5163
0
      if( result != 1 )
5164
0
      {
5165
0
        libcerror_error_set(
5166
0
         error,
5167
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
5168
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5169
0
         "%s: unable to determine size value string of instance.",
5170
0
         function );
5171
5172
0
        goto on_error;
5173
0
      }
5174
0
      if( value_string_size > 0 )
5175
0
      {
5176
0
        value_string = system_string_allocate(
5177
0
                        value_string_size );
5178
5179
0
        if( value_string == NULL )
5180
0
        {
5181
0
          libcerror_error_set(
5182
0
           error,
5183
0
           LIBCERROR_ERROR_DOMAIN_MEMORY,
5184
0
           LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
5185
0
           "%s: unable to value string.",
5186
0
           function );
5187
5188
0
          goto on_error;
5189
0
        }
5190
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
5191
        result = internal_value->copy_to_utf16_string_with_index(
5192
            value_instance,
5193
            (uint16_t *) value_string,
5194
            value_string_size,
5195
            &value_string_index,
5196
            internal_value->format_flags,
5197
            error );
5198
#else
5199
0
        result = internal_value->copy_to_utf8_string_with_index(
5200
0
            value_instance,
5201
0
            (uint8_t *) value_string,
5202
0
            value_string_size,
5203
0
            &value_string_index,
5204
0
            internal_value->format_flags,
5205
0
            error );
5206
0
#endif
5207
0
        if( result != 1 )
5208
0
        {
5209
0
          libcerror_error_set(
5210
0
           error,
5211
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
5212
0
           LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
5213
0
           "%s: unable to copy instance to value string.",
5214
0
           function );
5215
5216
0
          goto on_error;
5217
0
        }
5218
0
        libcnotify_printf(
5219
0
         "%" PRIs_SYSTEM "",
5220
0
         value_string );
5221
5222
0
        memory_free(
5223
0
         value_string );
5224
5225
0
        value_string = NULL;
5226
0
      }
5227
0
    }
5228
0
  }
5229
0
  if( ( flags & LIBFVALUE_PRINT_FLAG_WITH_TYPE_DESCRIPTION ) != 0 )
5230
0
  {
5231
0
    libcnotify_printf(
5232
0
     "\n\n" );
5233
0
  }
5234
0
  return( 1 );
5235
5236
0
on_error:
5237
0
  if( value_string != NULL )
5238
0
  {
5239
0
    memory_free(
5240
0
     value_string );
5241
0
  }
5242
0
  return( -1 );
5243
0
}
5244