Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwps/libfwps/libfwps_record.c
Line
Count
Source
1
/*
2
 * Windows Serialized Property Record functions
3
 *
4
 * Copyright (C) 2013-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 <byte_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 "libfwps_debug.h"
31
#include "libfwps_definitions.h"
32
#include "libfwps_libcerror.h"
33
#include "libfwps_libcnotify.h"
34
#include "libfwps_libuna.h"
35
#include "libfwps_record.h"
36
#include "libfwps_types.h"
37
38
/* Creates a record
39
 * Make sure the record value is referencing, is set to NULL
40
 * Returns 1 if successful or -1 on error
41
 */
42
int libfwps_record_initialize(
43
     libfwps_record_t **record,
44
     uint8_t record_type,
45
     libcerror_error_t **error )
46
553k
{
47
553k
  libfwps_internal_record_t *internal_record = NULL;
48
553k
  static char *function                      = "libfwps_record_initialize";
49
50
553k
  if( record == NULL )
51
0
  {
52
0
    libcerror_error_set(
53
0
     error,
54
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
55
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
56
0
     "%s: invalid record.",
57
0
     function );
58
59
0
    return( -1 );
60
0
  }
61
553k
  if( *record != NULL )
62
0
  {
63
0
    libcerror_error_set(
64
0
     error,
65
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
66
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
67
0
     "%s: invalid record value already set.",
68
0
     function );
69
70
0
    return( -1 );
71
0
  }
72
553k
  if( ( record_type != LIBFWPS_RECORD_TYPE_NAMED )
73
550k
   && ( record_type != LIBFWPS_RECORD_TYPE_NUMERIC ) )
74
0
  {
75
0
    libcerror_error_set(
76
0
     error,
77
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
78
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
79
0
     "%s: unsupported record type.",
80
0
     function );
81
82
0
    return( -1 );
83
0
  }
84
553k
  internal_record = memory_allocate_structure(
85
553k
                     libfwps_internal_record_t );
86
87
553k
  if( internal_record == NULL )
88
0
  {
89
0
    libcerror_error_set(
90
0
     error,
91
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
92
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
93
0
     "%s: unable to create record.",
94
0
     function );
95
96
0
    goto on_error;
97
0
  }
98
553k
  if( memory_set(
99
553k
       internal_record,
100
553k
       0,
101
553k
       sizeof( libfwps_internal_record_t ) ) == NULL )
102
0
  {
103
0
    libcerror_error_set(
104
0
     error,
105
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
106
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
107
0
     "%s: unable to clear record.",
108
0
     function );
109
110
0
    goto on_error;
111
0
  }
112
553k
  internal_record->type = record_type;
113
114
553k
  *record = (libfwps_record_t *) internal_record;
115
116
553k
  return( 1 );
117
118
0
on_error:
119
0
  if( internal_record != NULL )
120
0
  {
121
0
    memory_free(
122
0
     internal_record );
123
0
  }
124
0
  return( -1 );
125
553k
}
126
127
/* Frees a record
128
 * Returns 1 if successful or -1 on error
129
 */
130
int libfwps_record_free(
131
     libfwps_record_t **record,
132
     libcerror_error_t **error )
133
541k
{
134
541k
  static char *function = "libfwps_record_free";
135
136
541k
  if( record == NULL )
137
0
  {
138
0
    libcerror_error_set(
139
0
     error,
140
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
141
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
142
0
     "%s: invalid record.",
143
0
     function );
144
145
0
    return( -1 );
146
0
  }
147
541k
  if( *record != NULL )
148
541k
  {
149
541k
    *record = NULL;
150
541k
  }
151
541k
  return( 1 );
152
541k
}
153
154
/* Frees a record
155
 * Returns 1 if successful or -1 on error
156
 */
157
int libfwps_internal_record_free(
158
     libfwps_internal_record_t **internal_record,
159
     libcerror_error_t **error )
160
553k
{
161
553k
  static char *function = "libfwps_internal_record_free";
162
163
553k
  if( internal_record == NULL )
164
0
  {
165
0
    libcerror_error_set(
166
0
     error,
167
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
168
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
169
0
     "%s: invalid internal record.",
170
0
     function );
171
172
0
    return( -1 );
173
0
  }
174
553k
  if( *internal_record != NULL )
175
553k
  {
176
553k
    if( ( *internal_record )->entry_name != NULL )
177
373
    {
178
373
      memory_free(
179
373
       ( *internal_record )->entry_name );
180
373
    }
181
553k
    if( ( *internal_record )->value_name != NULL )
182
401
    {
183
401
      memory_free(
184
401
       ( *internal_record )->value_name );
185
401
    }
186
553k
    if( ( *internal_record )->value_data != NULL )
187
10.0k
    {
188
10.0k
      memory_free(
189
10.0k
       ( *internal_record )->value_data );
190
10.0k
    }
191
553k
    memory_free(
192
553k
     *internal_record );
193
194
553k
    *internal_record = NULL;
195
553k
  }
196
553k
  return( 1 );
197
553k
}
198
199
/* Copies a record from a byte stream
200
 * Returns 1 if successful or -1 on error
201
 */
202
int libfwps_record_copy_from_byte_stream(
203
     libfwps_record_t *record,
204
     const uint8_t *byte_stream,
205
     size_t byte_stream_size,
206
     int ascii_codepage,
207
     libcerror_error_t **error )
208
553k
{
209
553k
  libfwps_internal_record_t *internal_record = NULL;
210
553k
  static char *function                      = "libfwps_record_copy_from_byte_stream";
211
553k
  size_t byte_stream_offset                  = 0;
212
553k
  uint32_t name_size                         = 0;
213
553k
  uint32_t number_of_values                  = 0;
214
553k
  uint32_t value_index                       = 0;
215
553k
  uint32_t vector_value_data_size            = 0;
216
553k
  uint16_t value_16bit                       = 0;
217
553k
  int has_variable_data_size                 = 0;
218
219
#if defined( HAVE_DEBUG_OUTPUT )
220
  system_character_t *value_string           = NULL;
221
#endif
222
223
553k
  if( record == NULL )
224
0
  {
225
0
    libcerror_error_set(
226
0
     error,
227
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
228
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
229
0
     "%s: invalid record.",
230
0
     function );
231
232
0
    return( -1 );
233
0
  }
234
553k
  internal_record = (libfwps_internal_record_t *) record;
235
236
553k
  if( internal_record->entry_name != NULL )
237
0
  {
238
0
    libcerror_error_set(
239
0
     error,
240
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
241
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
242
0
     "%s: invalid record - entry name already set.",
243
0
     function );
244
245
0
    return( -1 );
246
0
  }
247
553k
  if( internal_record->value_name != NULL )
248
0
  {
249
0
    libcerror_error_set(
250
0
     error,
251
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
252
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
253
0
     "%s: invalid record - value name already set.",
254
0
     function );
255
256
0
    return( -1 );
257
0
  }
258
553k
  if( internal_record->value_data != NULL )
259
0
  {
260
0
    libcerror_error_set(
261
0
     error,
262
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
263
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
264
0
     "%s: invalid record - value data already set.",
265
0
     function );
266
267
0
    return( -1 );
268
0
  }
269
553k
  if( byte_stream == NULL )
270
0
  {
271
0
    libcerror_error_set(
272
0
     error,
273
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
274
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
275
0
     "%s: invalid byte stream.",
276
0
     function );
277
278
0
    return( -1 );
279
0
  }
280
553k
  if( ( byte_stream_size < 13 )
281
553k
   || ( byte_stream_size > (size_t) SSIZE_MAX ) )
282
85
  {
283
85
    libcerror_error_set(
284
85
     error,
285
85
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
286
85
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
287
85
     "%s: invalid byte stream size value out of bounds.",
288
85
     function );
289
290
85
    return( -1 );
291
85
  }
292
553k
  byte_stream_copy_to_uint32_little_endian(
293
553k
   byte_stream,
294
553k
   internal_record->size );
295
296
553k
  if( ( internal_record->size < 13 )
297
553k
   || ( (size_t) internal_record->size > byte_stream_size ) )
298
57
  {
299
57
    libcerror_error_set(
300
57
     error,
301
57
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
302
57
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
303
57
     "%s: invalid record - size value out of bounds.",
304
57
     function );
305
306
57
    goto on_error;
307
57
  }
308
#if defined( HAVE_DEBUG_OUTPUT )
309
  if( libcnotify_verbose != 0 )
310
  {
311
    libcnotify_printf(
312
     "%s: record data:\n",
313
     function );
314
    libcnotify_print_data(
315
     byte_stream,
316
     internal_record->size,
317
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
318
  }
319
#endif
320
553k
  if( internal_record->type == LIBFWPS_RECORD_TYPE_NAMED )
321
3.29k
  {
322
3.29k
    byte_stream_copy_to_uint32_little_endian(
323
3.29k
     &( byte_stream[ byte_stream_offset + 4 ] ),
324
3.29k
     name_size );
325
3.29k
  }
326
550k
  else if( internal_record->type == LIBFWPS_RECORD_TYPE_NUMERIC )
327
550k
  {
328
550k
    byte_stream_copy_to_uint32_little_endian(
329
550k
     &( byte_stream[ byte_stream_offset + 4 ] ),
330
550k
     internal_record->entry_type );
331
550k
  }
332
#if defined( HAVE_DEBUG_OUTPUT )
333
  if( libcnotify_verbose != 0 )
334
  {
335
    libcnotify_printf(
336
     "%s: size\t\t\t\t: %" PRIu32 "\n",
337
     function,
338
     internal_record->size );
339
340
    if( internal_record->type == LIBFWPS_RECORD_TYPE_NAMED )
341
    {
342
      libcnotify_printf(
343
       "%s: name size\t\t\t\t: %" PRIu32 "\n",
344
       function,
345
       name_size );
346
    }
347
    else
348
    {
349
      libcnotify_printf(
350
       "%s: entry type\t\t\t: %" PRIu32 "\n",
351
       function,
352
       internal_record->entry_type );
353
    }
354
    libcnotify_printf(
355
     "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n",
356
     function,
357
     byte_stream[ byte_stream_offset + 8 ] );
358
  }
359
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
360
361
553k
  byte_stream_offset += 9;
362
363
553k
  if( internal_record->type == LIBFWPS_RECORD_TYPE_NAMED )
364
3.29k
  {
365
3.29k
    if( ( name_size > byte_stream_size )
366
3.19k
     || ( byte_stream_offset > ( byte_stream_size - name_size ) ) )
367
109
    {
368
109
      libcerror_error_set(
369
109
       error,
370
109
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
371
109
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
372
109
       "%s: invalid name size value out of bounds.",
373
109
       function );
374
375
109
      goto on_error;
376
109
    }
377
3.18k
    if( name_size > 0 )
378
595
    {
379
595
      if( name_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
380
0
      {
381
0
        libcerror_error_set(
382
0
         error,
383
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
384
0
         LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
385
0
         "%s: invalid name size value exceeds maximum.",
386
0
         function );
387
388
0
        goto on_error;
389
0
      }
390
595
      internal_record->entry_name = (uint8_t *) memory_allocate(
391
595
                                                 sizeof( uint8_t ) * name_size );
392
393
595
      if( internal_record->entry_name == NULL )
394
0
      {
395
0
        libcerror_error_set(
396
0
         error,
397
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
398
0
         LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
399
0
         "%s: unable to create entry name.",
400
0
         function );
401
402
0
        goto on_error;
403
0
      }
404
595
      if( memory_copy(
405
595
           internal_record->entry_name,
406
595
           &( byte_stream[ byte_stream_offset ] ),
407
595
           name_size ) == NULL )
408
0
      {
409
0
        libcerror_error_set(
410
0
         error,
411
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
412
0
         LIBCERROR_MEMORY_ERROR_COPY_FAILED,
413
0
         "%s: unable to copy entry name data.",
414
0
         function );
415
416
0
        goto on_error;
417
0
      }
418
595
      internal_record->entry_name_size = name_size;
419
420
#if defined( HAVE_DEBUG_OUTPUT )
421
      if( libcnotify_verbose != 0 )
422
      {
423
        if( libfwps_debug_print_utf16_string_value(
424
             function,
425
             "entry name\t\t\t",
426
             internal_record->entry_name,
427
             internal_record->entry_name_size,
428
             LIBUNA_ENDIAN_LITTLE,
429
             error ) != 1 )
430
        {
431
          libcerror_error_set(
432
           error,
433
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
434
           LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
435
           "%s: unable to print UTF-16 string value.",
436
           function );
437
438
          goto on_error;
439
        }
440
      }
441
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
442
443
595
      byte_stream_offset += name_size;
444
595
    }
445
3.18k
  }
446
553k
  if( byte_stream_offset > ( byte_stream_size - 4 ) )
447
30
  {
448
30
    libcerror_error_set(
449
30
     error,
450
30
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
451
30
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
452
30
     "%s: invalid byte stream size value too small.",
453
30
     function );
454
455
30
    goto on_error;
456
30
  }
457
553k
  byte_stream_copy_to_uint32_little_endian(
458
553k
   &( byte_stream[ byte_stream_offset ] ),
459
553k
   internal_record->value_type );
460
461
553k
  byte_stream_offset += 4;
462
463
#if defined( HAVE_DEBUG_OUTPUT )
464
  if( libcnotify_verbose != 0 )
465
  {
466
    libcnotify_printf(
467
     "%s: value type\t\t\t: 0x%04" PRIx32 "\n",
468
     function,
469
     internal_record->value_type );
470
  }
471
#endif
472
  /* TODO add support for VT_ARRAY and VT_BYREF
473
   */
474
553k
  switch( internal_record->value_type & 0xffffefffUL )
475
553k
  {
476
532k
    case LIBFWPS_VALUE_TYPE_NULL:
477
532k
      internal_record->value_data_size = 0;
478
532k
      break;
479
480
1.38k
    case LIBFWPS_VALUE_TYPE_BOOLEAN:
481
2.11k
    case LIBFWPS_VALUE_TYPE_INTEGER_8BIT_SIGNED:
482
2.84k
    case LIBFWPS_VALUE_TYPE_INTEGER_8BIT_UNSIGNED:
483
2.84k
      internal_record->value_data_size = 1;
484
2.84k
      break;
485
486
1.23k
    case LIBFWPS_VALUE_TYPE_INTEGER_16BIT_SIGNED:
487
1.83k
    case LIBFWPS_VALUE_TYPE_INTEGER_16BIT_UNSIGNED:
488
1.83k
      internal_record->value_data_size = 2;
489
1.83k
      break;
490
491
343
    case LIBFWPS_VALUE_TYPE_ERROR:
492
1.39k
    case LIBFWPS_VALUE_TYPE_FLOAT_32BIT:
493
2.92k
    case LIBFWPS_VALUE_TYPE_INTEGER_32BIT_SIGNED:
494
3.33k
    case LIBFWPS_VALUE_TYPE_INTEGER_32BIT_UNSIGNED:
495
3.82k
    case LIBFWPS_VALUE_TYPE_INTEGER_SIGNED:
496
4.22k
    case LIBFWPS_VALUE_TYPE_INTEGER_UNSIGNED:
497
4.22k
      internal_record->value_data_size = 4;
498
4.22k
      break;
499
500
348
    case LIBFWPS_VALUE_TYPE_APPLICATION_TIME:
501
1.45k
    case LIBFWPS_VALUE_TYPE_CURRENCY:
502
1.73k
    case LIBFWPS_VALUE_TYPE_DOUBLE_64BIT:
503
2.16k
    case LIBFWPS_VALUE_TYPE_FILETIME:
504
2.57k
    case LIBFWPS_VALUE_TYPE_INTEGER_64BIT_SIGNED:
505
3.26k
    case LIBFWPS_VALUE_TYPE_INTEGER_64BIT_UNSIGNED:
506
3.26k
      internal_record->value_data_size = 8;
507
3.26k
      break;
508
509
420
    case LIBFWPS_VALUE_TYPE_FIXED_POINT_128BIT:
510
1.08k
    case LIBFWPS_VALUE_TYPE_GUID:
511
1.08k
      internal_record->value_data_size = 16;
512
1.08k
      break;
513
514
596
    case LIBFWPS_VALUE_TYPE_BINARY_DATA:
515
1.54k
    case LIBFWPS_VALUE_TYPE_BINARY_STRING:
516
3.51k
    case LIBFWPS_VALUE_TYPE_STREAM:
517
5.72k
    case LIBFWPS_VALUE_TYPE_STRING_ASCII:
518
7.23k
    case LIBFWPS_VALUE_TYPE_STRING_UNICODE:
519
7.23k
      has_variable_data_size = 1;
520
7.23k
      break;
521
522
242
    default:
523
242
      libcerror_error_set(
524
242
       error,
525
242
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
526
242
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
527
242
       "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
528
242
       function,
529
242
       internal_record->value_type );
530
531
242
      goto on_error;
532
553k
  }
533
553k
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STREAM )
534
1.32k
  {
535
1.32k
    if( byte_stream_offset > ( byte_stream_size - 4 ) )
536
17
    {
537
17
      libcerror_error_set(
538
17
       error,
539
17
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
540
17
       LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
541
17
       "%s: invalid byte stream size value too small.",
542
17
       function );
543
544
17
      goto on_error;
545
17
    }
546
1.30k
    byte_stream_copy_to_uint32_little_endian(
547
1.30k
     &( byte_stream[ byte_stream_offset ] ),
548
1.30k
     name_size );
549
550
1.30k
    byte_stream_offset += 4;
551
552
1.30k
    if( ( name_size > byte_stream_size )
553
1.20k
     || ( byte_stream_offset > ( byte_stream_size - name_size ) ) )
554
163
    {
555
163
      libcerror_error_set(
556
163
       error,
557
163
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
558
163
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
559
163
       "%s: invalid name size value out of bounds.",
560
163
       function );
561
562
163
      goto on_error;
563
163
    }
564
1.14k
    if( name_size > 0 )
565
527
    {
566
527
      if( name_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
567
0
      {
568
0
        libcerror_error_set(
569
0
         error,
570
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
571
0
         LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
572
0
         "%s: invalid name size value exceeds maximum.",
573
0
         function );
574
575
0
        goto on_error;
576
0
      }
577
527
      internal_record->value_name = (uint8_t *) memory_allocate(
578
527
                                                 sizeof( uint8_t ) * name_size );
579
580
527
      if( internal_record->value_name == NULL )
581
0
      {
582
0
        libcerror_error_set(
583
0
         error,
584
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
585
0
         LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
586
0
         "%s: unable to create value name.",
587
0
         function );
588
589
0
        goto on_error;
590
0
      }
591
527
      if( memory_copy(
592
527
           internal_record->value_name,
593
527
           &( byte_stream[ byte_stream_offset ] ),
594
527
           name_size ) == NULL )
595
0
      {
596
0
        libcerror_error_set(
597
0
         error,
598
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
599
0
         LIBCERROR_MEMORY_ERROR_COPY_FAILED,
600
0
         "%s: unable to copy value name data.",
601
0
         function );
602
603
0
        goto on_error;
604
0
      }
605
527
      internal_record->value_name_size = name_size;
606
607
#if defined( HAVE_DEBUG_OUTPUT )
608
      if( libcnotify_verbose != 0 )
609
      {
610
        if( libfwps_debug_print_utf16_string_value(
611
             function,
612
             "value name\t\t\t",
613
             internal_record->value_name,
614
             internal_record->value_name_size,
615
             LIBUNA_ENDIAN_LITTLE,
616
             error ) != 1 )
617
        {
618
          libcerror_error_set(
619
           error,
620
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
621
           LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
622
           "%s: unable to print UTF-16 string value.",
623
           function );
624
625
          goto on_error;
626
        }
627
      }
628
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
629
630
527
      byte_stream_offset += name_size;
631
527
    }
632
633
1.14k
    if( byte_stream_offset > ( byte_stream_size - 2 ) )
634
31
    {
635
31
      libcerror_error_set(
636
31
       error,
637
31
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
638
31
       LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
639
31
       "%s: invalid byte stream size value too small.",
640
31
       function );
641
642
31
      goto on_error;
643
31
    }
644
#if defined( HAVE_DEBUG_OUTPUT )
645
    if( libcnotify_verbose != 0 )
646
    {
647
      byte_stream_copy_to_uint16_little_endian(
648
       &( byte_stream[ byte_stream_offset ] ),
649
       value_16bit );
650
      libcnotify_printf(
651
       "%s: unknown1\t\t\t\t: 0x%04" PRIx16 "\n",
652
       function,
653
       value_16bit );
654
    }
655
#endif
656
1.11k
    byte_stream_offset += 2;
657
1.11k
  }
658
552k
  if( ( internal_record->value_type & 0x0000f000UL ) == 0x00001000UL )
659
6.96k
  {
660
6.96k
    if( byte_stream_offset > ( byte_stream_size - 4 ) )
661
35
    {
662
35
      libcerror_error_set(
663
35
       error,
664
35
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
665
35
       LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
666
35
       "%s: invalid byte stream size value too small.",
667
35
       function );
668
669
35
      goto on_error;
670
35
    }
671
6.92k
    byte_stream_copy_to_uint32_little_endian(
672
6.92k
     &( byte_stream[ byte_stream_offset ] ),
673
6.92k
     number_of_values );
674
675
#if defined( HAVE_DEBUG_OUTPUT )
676
    if( libcnotify_verbose != 0 )
677
    {
678
      if( has_variable_data_size == 0 )
679
      {
680
        libcnotify_printf(
681
         "%s: value data size\t\t\t: %" PRIzu "\n",
682
         function,
683
         internal_record->value_data_size );
684
      }
685
      libcnotify_printf(
686
       "%s: number of values\t\t\t: %" PRIu32 "\n",
687
       function,
688
       number_of_values );
689
    }
690
#endif
691
6.92k
    byte_stream_offset += 4;
692
693
6.92k
    if( has_variable_data_size == 0 )
694
4.79k
    {
695
4.79k
      if( ( internal_record->value_data_size > 0 )
696
4.39k
       && ( number_of_values > ( (size_t) SSIZE_MAX / internal_record->value_data_size ) ) )
697
0
      {
698
0
        libcerror_error_set(
699
0
         error,
700
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
701
0
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
702
0
         "%s: invalid number of values value out of bounds.",
703
0
         function );
704
705
0
        goto on_error;
706
0
      }
707
4.79k
      internal_record->value_data_size *= number_of_values;
708
709
4.79k
      if( ( internal_record->value_data_size > byte_stream_size )
710
4.54k
       || ( byte_stream_offset > ( byte_stream_size - internal_record->value_data_size ) ) )
711
291
      {
712
291
        libcerror_error_set(
713
291
         error,
714
291
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
715
291
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
716
291
         "%s: invalid vector values data size value out of bounds.",
717
291
         function );
718
719
291
        goto on_error;
720
291
      }
721
#if defined( HAVE_DEBUG_OUTPUT )
722
      if( libcnotify_verbose != 0 )
723
      {
724
        libcnotify_printf(
725
         "%s: vector values data:\n",
726
         function );
727
        libcnotify_print_data(
728
         &( byte_stream[ byte_stream_offset ] ),
729
         internal_record->value_data_size,
730
         LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
731
      }
732
#endif
733
#if defined( HAVE_DEBUG_OUTPUT )
734
      byte_stream_offset += internal_record->value_data_size;
735
#endif
736
4.79k
    }
737
2.13k
    else
738
2.13k
    {
739
2.13k
      if( ( number_of_values > ( ( byte_stream_size - byte_stream_offset ) / 4 ) )
740
2.03k
       || ( number_of_values == 0xffffffffUL ) )
741
97
      {
742
97
        libcerror_error_set(
743
97
         error,
744
97
         LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
745
97
         LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
746
97
         "%s: invalid number of values value out of bounds.",
747
97
         function );
748
749
97
        goto on_error;
750
97
      }
751
2.03k
      for( value_index = 0;
752
138k
           value_index < number_of_values;
753
136k
           value_index++ )
754
136k
      {
755
136k
        if( byte_stream_offset > ( byte_stream_size - 4 ) )
756
57
        {
757
57
          libcerror_error_set(
758
57
           error,
759
57
           LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
760
57
           LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
761
57
           "%s: invalid byte stream size value too small.",
762
57
           function );
763
764
57
          goto on_error;
765
57
        }
766
136k
        byte_stream_copy_to_uint32_little_endian(
767
136k
         &( byte_stream[ byte_stream_offset ] ),
768
136k
         vector_value_data_size );
769
770
#if defined( HAVE_DEBUG_OUTPUT )
771
        if( libcnotify_verbose != 0 )
772
        {
773
          libcnotify_printf(
774
           "%s: vector value: %" PRIu32 " data size\t\t: %" PRIu32 "\n",
775
           function,
776
           value_index,
777
           vector_value_data_size );
778
        }
779
#endif
780
136k
        byte_stream_offset += 4;
781
782
136k
        if( ( internal_record->value_type & 0x00000fffUL ) == LIBFWPS_VALUE_TYPE_STRING_UNICODE )
783
10.0k
        {
784
10.0k
          if( vector_value_data_size > ( (uint32_t) UINT32_MAX / 2 ) )
785
86
          {
786
86
            libcerror_error_set(
787
86
             error,
788
86
             LIBCERROR_ERROR_DOMAIN_RUNTIME,
789
86
             LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
790
86
             "%s: invalid vector value: %" PRIu32 " data size value out of bounds.",
791
86
             function,
792
86
             value_index );
793
794
86
            goto on_error;
795
86
          }
796
10.0k
          vector_value_data_size *= 2;
797
10.0k
        }
798
136k
        if( ( vector_value_data_size > byte_stream_size )
799
136k
         || ( byte_stream_offset > ( byte_stream_size - vector_value_data_size ) )
800
136k
         || ( internal_record->value_data_size > ( (size_t) SSIZE_MAX - 4 ) )
801
136k
         || ( vector_value_data_size > ( (size_t) SSIZE_MAX - 4 - internal_record->value_data_size ) ) )
802
352
        {
803
352
          libcerror_error_set(
804
352
           error,
805
352
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
806
352
           LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
807
352
           "%s: invalid vector value: %" PRIu32 " data size value out of bounds.",
808
352
           function,
809
352
           value_index );
810
811
352
          goto on_error;
812
352
        }
813
#if defined( HAVE_DEBUG_OUTPUT )
814
        if( libcnotify_verbose != 0 )
815
        {
816
          libcnotify_printf(
817
           "%s: vector value: %" PRIu32 " data:\n",
818
           function,
819
           value_index );
820
          libcnotify_print_data(
821
           &( byte_stream[ byte_stream_offset ] ),
822
           vector_value_data_size,
823
           LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
824
        }
825
#endif
826
136k
        byte_stream_offset += vector_value_data_size;
827
828
136k
        internal_record->value_data_size += 4 + vector_value_data_size;
829
830
136k
        if( byte_stream_offset <= ( byte_stream_size - 2 ) )
831
135k
        {
832
135k
          byte_stream_copy_to_uint16_little_endian(
833
135k
           &( byte_stream[ byte_stream_offset ] ),
834
135k
           value_16bit );
835
836
135k
          if( value_16bit == 0 )
837
134k
          {
838
#if defined( HAVE_DEBUG_OUTPUT )
839
            if( libcnotify_verbose != 0 )
840
            {
841
              libcnotify_printf(
842
               "%s: alignment padding data:\n",
843
               function );
844
              libcnotify_print_data(
845
               &( byte_stream[ byte_stream_offset ] ),
846
               2,
847
               0 );
848
            }
849
#endif
850
134k
            byte_stream_offset += 2;
851
852
134k
            internal_record->value_data_size += 2;
853
134k
          }
854
135k
        }
855
136k
      }
856
2.03k
    }
857
6.92k
  }
858
546k
  else
859
546k
  {
860
546k
    if( has_variable_data_size != 0 )
861
4.87k
    {
862
4.87k
      if( byte_stream_offset > ( byte_stream_size - 4 ) )
863
70
      {
864
70
        libcerror_error_set(
865
70
         error,
866
70
         LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
867
70
         LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
868
70
         "%s: invalid byte stream size value too small.",
869
70
         function );
870
871
70
        goto on_error;
872
70
      }
873
4.80k
      byte_stream_copy_to_uint32_little_endian(
874
4.80k
       &( byte_stream[ byte_stream_offset ] ),
875
4.80k
       internal_record->value_data_size );
876
877
4.80k
      byte_stream_offset += 4;
878
879
4.80k
      if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_UNICODE )
880
735
      {
881
735
        if( internal_record->value_data_size > ( (size_t) SSIZE_MAX / 2 ) )
882
0
        {
883
0
          libcerror_error_set(
884
0
           error,
885
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
886
0
           LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
887
0
           "%s: invalid value data size value out of bounds.",
888
0
           function );
889
890
0
          goto on_error;
891
0
        }
892
735
        internal_record->value_data_size *= 2;
893
735
      }
894
4.80k
    }
895
#if defined( HAVE_DEBUG_OUTPUT )
896
    if( libcnotify_verbose != 0 )
897
    {
898
      libcnotify_printf(
899
       "%s: value data size\t\t\t: %" PRIzu "\n",
900
       function,
901
       internal_record->value_data_size );
902
    }
903
#endif
904
545k
    if( internal_record->value_data_size > 0 )
905
10.5k
    {
906
10.5k
      if( ( internal_record->value_data_size > byte_stream_size )
907
10.2k
       || ( byte_stream_offset > ( byte_stream_size - internal_record->value_data_size ) ) )
908
468
      {
909
468
        libcerror_error_set(
910
468
         error,
911
468
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
912
468
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
913
468
         "%s: invalid value data size value out of bounds.",
914
468
         function );
915
916
468
        goto on_error;
917
468
      }
918
#if defined( HAVE_DEBUG_OUTPUT )
919
      if( libcnotify_verbose != 0 )
920
      {
921
        libcnotify_printf(
922
         "%s: value data:\n",
923
         function );
924
        libcnotify_print_data(
925
         &( byte_stream[ byte_stream_offset ] ),
926
         internal_record->value_data_size,
927
         LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
928
      }
929
#endif
930
10.0k
      if( internal_record->value_data_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
931
0
      {
932
0
        libcerror_error_set(
933
0
         error,
934
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
935
0
         LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
936
0
         "%s: invalid value data size value exceeds maximum.",
937
0
         function );
938
939
0
        goto on_error;
940
0
      }
941
10.0k
      internal_record->value_data = (uint8_t *) memory_allocate(
942
10.0k
                                                 sizeof( uint8_t ) * internal_record->value_data_size );
943
944
10.0k
      if( internal_record->value_data == NULL )
945
0
      {
946
0
        libcerror_error_set(
947
0
         error,
948
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
949
0
         LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
950
0
         "%s: unable to create value data.",
951
0
         function );
952
953
0
        goto on_error;
954
0
      }
955
10.0k
      if( memory_copy(
956
10.0k
           internal_record->value_data,
957
10.0k
           &( byte_stream[ byte_stream_offset ] ),
958
10.0k
           internal_record->value_data_size ) == NULL )
959
0
      {
960
0
        libcerror_error_set(
961
0
         error,
962
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
963
0
         LIBCERROR_MEMORY_ERROR_COPY_FAILED,
964
0
         "%s: unable to copy value data.",
965
0
         function );
966
967
0
        goto on_error;
968
0
      }
969
#if defined( HAVE_DEBUG_OUTPUT )
970
      byte_stream_offset += internal_record->value_data_size;
971
#endif
972
10.0k
    }
973
545k
  }
974
#if defined( HAVE_DEBUG_OUTPUT )
975
  if( libcnotify_verbose != 0 )
976
  {
977
    if( byte_stream_offset < internal_record->size )
978
    {
979
      libcnotify_printf(
980
       "%s: trailing data:\n",
981
       function );
982
      libcnotify_print_data(
983
       &( byte_stream[ byte_stream_offset ] ),
984
       internal_record->size - byte_stream_offset,
985
       LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
986
    }
987
  }
988
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
989
990
551k
  internal_record->ascii_codepage = ascii_codepage;
991
992
551k
  return( 1 );
993
994
2.10k
on_error:
995
#if defined( HAVE_DEBUG_OUTPUT )
996
  if( value_string != NULL )
997
  {
998
    memory_free(
999
     value_string );
1000
  }
1001
#endif
1002
2.10k
  if( internal_record->value_data != NULL )
1003
0
  {
1004
0
    memory_free(
1005
0
     internal_record->value_data );
1006
1007
0
    internal_record->value_data = NULL;
1008
0
  }
1009
2.10k
  internal_record->value_data_size = 0;
1010
1011
2.10k
  if( internal_record->value_name != NULL )
1012
126
  {
1013
126
    memory_free(
1014
126
     internal_record->value_name );
1015
1016
126
    internal_record->value_name = NULL;
1017
126
  }
1018
2.10k
  internal_record->value_name_size = 0;
1019
1020
2.10k
  if( internal_record->entry_name != NULL )
1021
222
  {
1022
222
    memory_free(
1023
222
     internal_record->entry_name );
1024
1025
222
    internal_record->entry_name = NULL;
1026
222
  }
1027
2.10k
  internal_record->entry_name_size = 0;
1028
1029
2.10k
  return( -1 );
1030
552k
}
1031
1032
/* Retrieves the size of the UTF-8 encoded entry name
1033
 * The returned size includes the end of string character
1034
 * Returns 1 if successful or -1 on error
1035
 */
1036
int libfwps_record_get_utf8_entry_name_size(
1037
     libfwps_record_t *record,
1038
     size_t *utf8_string_size,
1039
     libcerror_error_t **error )
1040
1.93k
{
1041
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1042
1.93k
  static char *function                      = "libfwps_record_get_utf8_entry_name_size";
1043
1044
1.93k
  if( record == NULL )
1045
0
  {
1046
0
    libcerror_error_set(
1047
0
     error,
1048
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1049
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1050
0
     "%s: invalid record.",
1051
0
     function );
1052
1053
0
    return( -1 );
1054
0
  }
1055
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1056
1057
1.93k
  if( internal_record->type != LIBFWPS_RECORD_TYPE_NAMED )
1058
1.72k
  {
1059
1.72k
    return( 0 );
1060
1.72k
  }
1061
210
  if( ( internal_record->entry_name_size == 0 )
1062
57
   || ( internal_record->entry_name == NULL ) )
1063
153
  {
1064
153
    return( 0 );
1065
153
  }
1066
57
  if( libuna_utf8_string_size_from_utf16_stream(
1067
57
       internal_record->entry_name,
1068
57
       internal_record->entry_name_size,
1069
57
       LIBUNA_ENDIAN_LITTLE,
1070
57
       utf8_string_size,
1071
57
       error ) != 1 )
1072
24
  {
1073
24
    libcerror_error_set(
1074
24
     error,
1075
24
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1076
24
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1077
24
     "%s: unable to retrieve size of entry name as UTF-8 string.",
1078
24
     function );
1079
1080
24
    return( -1 );
1081
24
  }
1082
33
  return( 1 );
1083
57
}
1084
1085
/* Retrieves the UTF-8 encoded entry name
1086
 * The size should include the end of string character
1087
 * Returns 1 if successful or -1 on error
1088
 */
1089
int libfwps_record_get_utf8_entry_name(
1090
     libfwps_record_t *record,
1091
     uint8_t *utf8_string,
1092
     size_t utf8_string_size,
1093
     libcerror_error_t **error )
1094
32
{
1095
32
  libfwps_internal_record_t *internal_record = NULL;
1096
32
  static char *function                      = "libfwps_record_get_utf8_entry_name";
1097
1098
32
  if( record == NULL )
1099
0
  {
1100
0
    libcerror_error_set(
1101
0
     error,
1102
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1103
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1104
0
     "%s: invalid record.",
1105
0
     function );
1106
1107
0
    return( -1 );
1108
0
  }
1109
32
  internal_record = (libfwps_internal_record_t *) record;
1110
1111
32
  if( internal_record->type != LIBFWPS_RECORD_TYPE_NAMED )
1112
0
  {
1113
0
    return( 0 );
1114
0
  }
1115
32
  if( ( internal_record->entry_name_size == 0 )
1116
32
   || ( internal_record->entry_name == NULL ) )
1117
0
  {
1118
0
    return( 0 );
1119
0
  }
1120
32
  if( libuna_utf8_string_copy_from_utf16_stream(
1121
32
       utf8_string,
1122
32
       utf8_string_size,
1123
32
       internal_record->entry_name,
1124
32
       internal_record->entry_name_size,
1125
32
       LIBUNA_ENDIAN_LITTLE,
1126
32
       error ) != 1 )
1127
0
  {
1128
0
    libcerror_error_set(
1129
0
     error,
1130
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1131
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1132
0
     "%s: unable to retrieve entry name as UTF-8 string.",
1133
0
     function );
1134
1135
0
    return( -1 );
1136
0
  }
1137
32
  return( 1 );
1138
32
}
1139
1140
/* Retrieves the size of the UTF-16 encoded entry name
1141
 * The returned size includes the end of string character
1142
 * Returns 1 if successful or -1 on error
1143
 */
1144
int libfwps_record_get_utf16_entry_name_size(
1145
     libfwps_record_t *record,
1146
     size_t *utf16_string_size,
1147
     libcerror_error_t **error )
1148
1.93k
{
1149
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1150
1.93k
  static char *function                      = "libfwps_record_get_utf16_entry_name_size";
1151
1152
1.93k
  if( record == NULL )
1153
0
  {
1154
0
    libcerror_error_set(
1155
0
     error,
1156
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1157
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1158
0
     "%s: invalid record.",
1159
0
     function );
1160
1161
0
    return( -1 );
1162
0
  }
1163
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1164
1165
1.93k
  if( internal_record->type != LIBFWPS_RECORD_TYPE_NAMED )
1166
1.72k
  {
1167
1.72k
    return( 0 );
1168
1.72k
  }
1169
210
  if( ( internal_record->entry_name_size == 0 )
1170
57
   || ( internal_record->entry_name == NULL ) )
1171
153
  {
1172
153
    return( 0 );
1173
153
  }
1174
57
  if( libuna_utf16_string_size_from_utf16_stream(
1175
57
       internal_record->entry_name,
1176
57
       internal_record->entry_name_size,
1177
57
       LIBUNA_ENDIAN_LITTLE,
1178
57
       utf16_string_size,
1179
57
       error ) != 1 )
1180
24
  {
1181
24
    libcerror_error_set(
1182
24
     error,
1183
24
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1184
24
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1185
24
     "%s: unable to retrieve size of entry name as UTF-16 string.",
1186
24
     function );
1187
1188
24
    return( -1 );
1189
24
  }
1190
33
  return( 1 );
1191
57
}
1192
1193
/* Retrieves the UTF-16 encoded entry name
1194
 * The size should include the end of string character
1195
 * Returns 1 if successful or -1 on error
1196
 */
1197
int libfwps_record_get_utf16_entry_name(
1198
     libfwps_record_t *record,
1199
     uint16_t *utf16_string,
1200
     size_t utf16_string_size,
1201
     libcerror_error_t **error )
1202
32
{
1203
32
  libfwps_internal_record_t *internal_record = NULL;
1204
32
  static char *function                      = "libfwps_record_get_utf16_entry_name";
1205
1206
32
  if( record == NULL )
1207
0
  {
1208
0
    libcerror_error_set(
1209
0
     error,
1210
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1211
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1212
0
     "%s: invalid record.",
1213
0
     function );
1214
1215
0
    return( -1 );
1216
0
  }
1217
32
  internal_record = (libfwps_internal_record_t *) record;
1218
1219
32
  if( internal_record->type != LIBFWPS_RECORD_TYPE_NAMED )
1220
0
  {
1221
0
    return( 0 );
1222
0
  }
1223
32
  if( ( internal_record->entry_name_size == 0 )
1224
32
   || ( internal_record->entry_name == NULL ) )
1225
0
  {
1226
0
    return( 0 );
1227
0
  }
1228
32
  if( libuna_utf16_string_copy_from_utf16_stream(
1229
32
       utf16_string,
1230
32
       utf16_string_size,
1231
32
       internal_record->entry_name,
1232
32
       internal_record->entry_name_size,
1233
32
       LIBUNA_ENDIAN_LITTLE,
1234
32
       error ) != 1 )
1235
0
  {
1236
0
    libcerror_error_set(
1237
0
     error,
1238
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1239
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1240
0
     "%s: unable to retrieve entry name as UTF-16 string.",
1241
0
     function );
1242
1243
0
    return( -1 );
1244
0
  }
1245
32
  return( 1 );
1246
32
}
1247
1248
/* Retrieves the entry type
1249
 * Returns 1 if successful, 0 if not available or -1 on error
1250
 */
1251
int libfwps_record_get_entry_type(
1252
     libfwps_record_t *record,
1253
     uint32_t *entry_type,
1254
     libcerror_error_t **error )
1255
1.93k
{
1256
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1257
1.93k
  static char *function                      = "libfwps_record_get_entry_type";
1258
1259
1.93k
  if( record == NULL )
1260
0
  {
1261
0
    libcerror_error_set(
1262
0
     error,
1263
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1264
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1265
0
     "%s: invalid record.",
1266
0
     function );
1267
1268
0
    return( -1 );
1269
0
  }
1270
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1271
1272
1.93k
  if( entry_type == NULL )
1273
0
  {
1274
0
    libcerror_error_set(
1275
0
     error,
1276
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1277
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1278
0
     "%s: invalid entry type.",
1279
0
     function );
1280
1281
0
    return( -1 );
1282
0
  }
1283
1.93k
  if( internal_record->type != LIBFWPS_RECORD_TYPE_NUMERIC )
1284
210
  {
1285
210
    return( 0 );
1286
210
  }
1287
1.72k
  *entry_type = internal_record->entry_type;
1288
1289
1.72k
  return( 1 );
1290
1.93k
}
1291
1292
/* Retrieves the size of the UTF-8 encoded value name
1293
 * The returned size includes the end of string character
1294
 * Returns 1 if successful or -1 on error
1295
 */
1296
int libfwps_record_get_utf8_value_name_size(
1297
     libfwps_record_t *record,
1298
     size_t *utf8_string_size,
1299
     libcerror_error_t **error )
1300
1.93k
{
1301
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1302
1.93k
  static char *function                      = "libfwps_record_get_utf8_value_name_size";
1303
1304
1.93k
  if( record == NULL )
1305
0
  {
1306
0
    libcerror_error_set(
1307
0
     error,
1308
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1309
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1310
0
     "%s: invalid record.",
1311
0
     function );
1312
1313
0
    return( -1 );
1314
0
  }
1315
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1316
1317
1.93k
  if( ( internal_record->value_name_size == 0 )
1318
53
   || ( internal_record->value_name == NULL ) )
1319
1.88k
  {
1320
1.88k
    return( 0 );
1321
1.88k
  }
1322
53
  if( libuna_utf8_string_size_from_utf16_stream(
1323
53
       internal_record->value_name,
1324
53
       internal_record->value_name_size,
1325
53
       LIBUNA_ENDIAN_LITTLE,
1326
53
       utf8_string_size,
1327
53
       error ) != 1 )
1328
24
  {
1329
24
    libcerror_error_set(
1330
24
     error,
1331
24
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1332
24
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1333
24
     "%s: unable to retrieve size of value name as UTF-8 string.",
1334
24
     function );
1335
1336
24
    return( -1 );
1337
24
  }
1338
29
  return( 1 );
1339
53
}
1340
1341
/* Retrieves the UTF-8 encoded value name
1342
 * The size should include the end of string character
1343
 * Returns 1 if successful or -1 on error
1344
 */
1345
int libfwps_record_get_utf8_value_name(
1346
     libfwps_record_t *record,
1347
     uint8_t *utf8_string,
1348
     size_t utf8_string_size,
1349
     libcerror_error_t **error )
1350
29
{
1351
29
  libfwps_internal_record_t *internal_record = NULL;
1352
29
  static char *function                      = "libfwps_record_get_utf8_value_name";
1353
1354
29
  if( record == NULL )
1355
0
  {
1356
0
    libcerror_error_set(
1357
0
     error,
1358
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1359
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1360
0
     "%s: invalid record.",
1361
0
     function );
1362
1363
0
    return( -1 );
1364
0
  }
1365
29
  internal_record = (libfwps_internal_record_t *) record;
1366
1367
29
  if( ( internal_record->value_name_size == 0 )
1368
29
   || ( internal_record->value_name == NULL ) )
1369
0
  {
1370
0
    return( 0 );
1371
0
  }
1372
29
  if( libuna_utf8_string_copy_from_utf16_stream(
1373
29
       utf8_string,
1374
29
       utf8_string_size,
1375
29
       internal_record->value_name,
1376
29
       internal_record->value_name_size,
1377
29
       LIBUNA_ENDIAN_LITTLE,
1378
29
       error ) != 1 )
1379
0
  {
1380
0
    libcerror_error_set(
1381
0
     error,
1382
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1383
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1384
0
     "%s: unable to retrieve value name as UTF-8 string.",
1385
0
     function );
1386
1387
0
    return( -1 );
1388
0
  }
1389
29
  return( 1 );
1390
29
}
1391
1392
/* Retrieves the size of the UTF-16 encoded value name
1393
 * The returned size includes the end of string character
1394
 * Returns 1 if successful or -1 on error
1395
 */
1396
int libfwps_record_get_utf16_value_name_size(
1397
     libfwps_record_t *record,
1398
     size_t *utf16_string_size,
1399
     libcerror_error_t **error )
1400
1.93k
{
1401
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1402
1.93k
  static char *function                      = "libfwps_record_get_utf16_value_name_size";
1403
1404
1.93k
  if( record == NULL )
1405
0
  {
1406
0
    libcerror_error_set(
1407
0
     error,
1408
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1409
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1410
0
     "%s: invalid record.",
1411
0
     function );
1412
1413
0
    return( -1 );
1414
0
  }
1415
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1416
1417
1.93k
  if( ( internal_record->value_name_size == 0 )
1418
53
   || ( internal_record->value_name == NULL ) )
1419
1.88k
  {
1420
1.88k
    return( 0 );
1421
1.88k
  }
1422
53
  if( libuna_utf16_string_size_from_utf16_stream(
1423
53
       internal_record->value_name,
1424
53
       internal_record->value_name_size,
1425
53
       LIBUNA_ENDIAN_LITTLE,
1426
53
       utf16_string_size,
1427
53
       error ) != 1 )
1428
24
  {
1429
24
    libcerror_error_set(
1430
24
     error,
1431
24
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1432
24
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1433
24
     "%s: unable to retrieve size of value name as UTF-16 string.",
1434
24
     function );
1435
1436
24
    return( -1 );
1437
24
  }
1438
29
  return( 1 );
1439
53
}
1440
1441
/* Retrieves the UTF-16 encoded value name
1442
 * The size should include the end of string character
1443
 * Returns 1 if successful or -1 on error
1444
 */
1445
int libfwps_record_get_utf16_value_name(
1446
     libfwps_record_t *record,
1447
     uint16_t *utf16_string,
1448
     size_t utf16_string_size,
1449
     libcerror_error_t **error )
1450
29
{
1451
29
  libfwps_internal_record_t *internal_record = NULL;
1452
29
  static char *function                      = "libfwps_record_get_utf16_value_name";
1453
1454
29
  if( record == NULL )
1455
0
  {
1456
0
    libcerror_error_set(
1457
0
     error,
1458
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1459
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1460
0
     "%s: invalid record.",
1461
0
     function );
1462
1463
0
    return( -1 );
1464
0
  }
1465
29
  internal_record = (libfwps_internal_record_t *) record;
1466
1467
29
  if( ( internal_record->value_name_size == 0 )
1468
29
   || ( internal_record->value_name == NULL ) )
1469
0
  {
1470
0
    return( 0 );
1471
0
  }
1472
29
  if( libuna_utf16_string_copy_from_utf16_stream(
1473
29
       utf16_string,
1474
29
       utf16_string_size,
1475
29
       internal_record->value_name,
1476
29
       internal_record->value_name_size,
1477
29
       LIBUNA_ENDIAN_LITTLE,
1478
29
       error ) != 1 )
1479
0
  {
1480
0
    libcerror_error_set(
1481
0
     error,
1482
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1483
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1484
0
     "%s: unable to retrieve value name as UTF-16 string.",
1485
0
     function );
1486
1487
0
    return( -1 );
1488
0
  }
1489
29
  return( 1 );
1490
29
}
1491
1492
/* Retrieves the value type
1493
 * Returns 1 if successful or -1 on error
1494
 */
1495
int libfwps_record_get_value_type(
1496
     libfwps_record_t *record,
1497
     uint32_t *value_type,
1498
     libcerror_error_t **error )
1499
1.93k
{
1500
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1501
1.93k
  static char *function                      = "libfwps_record_get_value_type";
1502
1503
1.93k
  if( record == NULL )
1504
0
  {
1505
0
    libcerror_error_set(
1506
0
     error,
1507
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1508
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1509
0
     "%s: invalid record.",
1510
0
     function );
1511
1512
0
    return( -1 );
1513
0
  }
1514
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1515
1516
1.93k
  if( value_type == NULL )
1517
0
  {
1518
0
    libcerror_error_set(
1519
0
     error,
1520
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1521
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1522
0
     "%s: invalid value type.",
1523
0
     function );
1524
1525
0
    return( -1 );
1526
0
  }
1527
1.93k
  *value_type = internal_record->value_type;
1528
1529
1.93k
  return( 1 );
1530
1.93k
}
1531
1532
/* Retrieves the data size
1533
 * Returns 1 if successful or -1 on error
1534
 */
1535
int libfwps_record_get_data_size(
1536
     libfwps_record_t *record,
1537
     size_t *data_size,
1538
     libcerror_error_t **error )
1539
1.93k
{
1540
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1541
1.93k
  static char *function                      = "libfwps_record_get_data_size";
1542
1543
1.93k
  if( record == NULL )
1544
0
  {
1545
0
    libcerror_error_set(
1546
0
     error,
1547
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1548
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1549
0
     "%s: invalid record.",
1550
0
     function );
1551
1552
0
    return( -1 );
1553
0
  }
1554
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1555
1556
1.93k
  if( data_size == NULL )
1557
0
  {
1558
0
    libcerror_error_set(
1559
0
     error,
1560
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1561
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1562
0
     "%s: invalid data size.",
1563
0
     function );
1564
1565
0
    return( -1 );
1566
0
  }
1567
1.93k
  *data_size = internal_record->value_data_size;
1568
1569
1.93k
  return( 1 );
1570
1.93k
}
1571
1572
/* Retrieves the data
1573
 * Returns 1 if successful or -1 on error
1574
 */
1575
int libfwps_record_get_data(
1576
     libfwps_record_t *record,
1577
     uint8_t *data,
1578
     size_t data_size,
1579
     libcerror_error_t **error )
1580
1.19k
{
1581
1.19k
  libfwps_internal_record_t *internal_record = NULL;
1582
1.19k
  static char *function                      = "libfwps_record_get_data";
1583
1584
1.19k
  if( record == NULL )
1585
0
  {
1586
0
    libcerror_error_set(
1587
0
     error,
1588
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1589
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1590
0
     "%s: invalid record.",
1591
0
     function );
1592
1593
0
    return( -1 );
1594
0
  }
1595
1.19k
  internal_record = (libfwps_internal_record_t *) record;
1596
1597
1.19k
  if( internal_record->value_data == NULL )
1598
24
  {
1599
24
    libcerror_error_set(
1600
24
     error,
1601
24
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1602
24
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1603
24
     "%s: invalid record entry - missing value data.",
1604
24
     function );
1605
1606
24
    return( -1 );
1607
24
  }
1608
1.17k
  if( data == NULL )
1609
0
  {
1610
0
    libcerror_error_set(
1611
0
     error,
1612
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1613
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1614
0
     "%s: invalid data.",
1615
0
     function );
1616
1617
0
    return( -1 );
1618
0
  }
1619
1.17k
  if( ( data_size < internal_record->value_data_size )
1620
1.17k
   || ( data_size > (size_t) SSIZE_MAX ) )
1621
0
  {
1622
0
    libcerror_error_set(
1623
0
     error,
1624
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1625
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1626
0
     "%s: invalid data size value out of bounds.",
1627
0
     function );
1628
1629
0
    return( -1 );
1630
0
  }
1631
1.17k
  if( memory_copy(
1632
1.17k
       data,
1633
1.17k
       internal_record->value_data,
1634
1.17k
       internal_record->value_data_size ) == NULL )
1635
0
  {
1636
0
    libcerror_error_set(
1637
0
     error,
1638
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1639
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1640
0
     "%s: unable to copy data.",
1641
0
     function );
1642
1643
0
    return( -1 );
1644
0
  }
1645
1.17k
  return( 1 );
1646
1.17k
}
1647
1648
/* Retrieves the data as a boolean value
1649
 * Returns 1 if successful or -1 on error
1650
 */
1651
int libfwps_record_get_data_as_boolean(
1652
     libfwps_record_t *record,
1653
     uint8_t *value_boolean,
1654
     libcerror_error_t **error )
1655
1.93k
{
1656
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1657
1.93k
  static char *function                      = "libfwps_record_get_data_as_boolean";
1658
1659
1.93k
  if( record == NULL )
1660
0
  {
1661
0
    libcerror_error_set(
1662
0
     error,
1663
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1664
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1665
0
     "%s: invalid record entry.",
1666
0
     function );
1667
1668
0
    return( -1 );
1669
0
  }
1670
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1671
1672
1.93k
  if( internal_record->value_type != LIBFWPS_VALUE_TYPE_BOOLEAN )
1673
1.93k
  {
1674
1.93k
    libcerror_error_set(
1675
1.93k
     error,
1676
1.93k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1677
1.93k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1678
1.93k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
1679
1.93k
     function,
1680
1.93k
     internal_record->value_type );
1681
1682
1.93k
    return( -1 );
1683
1.93k
  }
1684
3
  if( internal_record->value_data == NULL )
1685
1
  {
1686
1
    libcerror_error_set(
1687
1
     error,
1688
1
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1689
1
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1690
1
     "%s: invalid record entry - missing value data.",
1691
1
     function );
1692
1693
1
    return( -1 );
1694
1
  }
1695
2
  if( internal_record->value_data_size != 1 )
1696
0
  {
1697
0
    libcerror_error_set(
1698
0
     error,
1699
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1700
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1701
0
     "%s: unsupported value data size.",
1702
0
     function );
1703
1704
0
    return( -1 );
1705
0
  }
1706
2
  if( value_boolean == NULL )
1707
0
  {
1708
0
    libcerror_error_set(
1709
0
     error,
1710
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1711
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1712
0
     "%s: invalid value boolean.",
1713
0
     function );
1714
1715
0
    return( -1 );
1716
0
  }
1717
2
  *value_boolean = internal_record->value_data[ 0 ];
1718
1719
2
  return( 1 );
1720
2
}
1721
1722
/* Retrieves the data as a 8-bit integer value
1723
 * Returns 1 if successful or -1 on error
1724
 */
1725
int libfwps_record_get_data_as_8bit_integer(
1726
     libfwps_record_t *record,
1727
     uint8_t *value_8bit,
1728
     libcerror_error_t **error )
1729
1.93k
{
1730
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1731
1.93k
  static char *function                      = "libfwps_record_get_data_as_8bit_integer";
1732
1733
1.93k
  if( record == NULL )
1734
0
  {
1735
0
    libcerror_error_set(
1736
0
     error,
1737
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1738
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1739
0
     "%s: invalid record entry.",
1740
0
     function );
1741
1742
0
    return( -1 );
1743
0
  }
1744
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1745
1746
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_8BIT_SIGNED )
1747
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_8BIT_UNSIGNED ) )
1748
1.92k
  {
1749
1.92k
    libcerror_error_set(
1750
1.92k
     error,
1751
1.92k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1752
1.92k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1753
1.92k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
1754
1.92k
     function,
1755
1.92k
     internal_record->value_type );
1756
1757
1.92k
    return( -1 );
1758
1.92k
  }
1759
14
  if( internal_record->value_data == NULL )
1760
1
  {
1761
1
    libcerror_error_set(
1762
1
     error,
1763
1
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1764
1
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1765
1
     "%s: invalid record entry - missing value data.",
1766
1
     function );
1767
1768
1
    return( -1 );
1769
1
  }
1770
13
  if( internal_record->value_data_size != 1 )
1771
0
  {
1772
0
    libcerror_error_set(
1773
0
     error,
1774
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1775
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1776
0
     "%s: unsupported value data size.",
1777
0
     function );
1778
1779
0
    return( -1 );
1780
0
  }
1781
13
  if( value_8bit == NULL )
1782
0
  {
1783
0
    libcerror_error_set(
1784
0
     error,
1785
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1786
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1787
0
     "%s: invalid value 8-bit.",
1788
0
     function );
1789
1790
0
    return( -1 );
1791
0
  }
1792
13
  *value_8bit = internal_record->value_data[ 0 ];
1793
1794
13
  return( 1 );
1795
13
}
1796
1797
/* Retrieves the data as a 16-bit integer value
1798
 * Returns 1 if successful or -1 on error
1799
 */
1800
int libfwps_record_get_data_as_16bit_integer(
1801
     libfwps_record_t *record,
1802
     uint16_t *value_16bit,
1803
     libcerror_error_t **error )
1804
1.93k
{
1805
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1806
1.93k
  static char *function                      = "libfwps_record_get_data_as_16bit_integer";
1807
1808
1.93k
  if( record == NULL )
1809
0
  {
1810
0
    libcerror_error_set(
1811
0
     error,
1812
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1813
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1814
0
     "%s: invalid record entry.",
1815
0
     function );
1816
1817
0
    return( -1 );
1818
0
  }
1819
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1820
1821
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_16BIT_SIGNED )
1822
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_16BIT_UNSIGNED ) )
1823
1.93k
  {
1824
1.93k
    libcerror_error_set(
1825
1.93k
     error,
1826
1.93k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1827
1.93k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1828
1.93k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
1829
1.93k
     function,
1830
1.93k
     internal_record->value_type );
1831
1832
1.93k
    return( -1 );
1833
1.93k
  }
1834
4
  if( internal_record->value_data == NULL )
1835
1
  {
1836
1
    libcerror_error_set(
1837
1
     error,
1838
1
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1839
1
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1840
1
     "%s: invalid record entry - missing value data.",
1841
1
     function );
1842
1843
1
    return( -1 );
1844
1
  }
1845
3
  if( internal_record->value_data_size != 2 )
1846
0
  {
1847
0
    libcerror_error_set(
1848
0
     error,
1849
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1850
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1851
0
     "%s: unsupported value data size.",
1852
0
     function );
1853
1854
0
    return( -1 );
1855
0
  }
1856
3
  if( value_16bit == NULL )
1857
0
  {
1858
0
    libcerror_error_set(
1859
0
     error,
1860
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1861
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1862
0
     "%s: invalid value 16-bit.",
1863
0
     function );
1864
1865
0
    return( -1 );
1866
0
  }
1867
3
  byte_stream_copy_to_uint16_little_endian(
1868
3
   internal_record->value_data,
1869
3
   *value_16bit );
1870
1871
3
  return( 1 );
1872
3
}
1873
1874
/* Retrieves the data as a 32-bit integer value
1875
 * Returns 1 if successful or -1 on error
1876
 */
1877
int libfwps_record_get_data_as_32bit_integer(
1878
     libfwps_record_t *record,
1879
     uint32_t *value_32bit,
1880
     libcerror_error_t **error )
1881
1.93k
{
1882
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1883
1.93k
  static char *function                      = "libfwps_record_get_data_as_32bit_integer";
1884
1885
1.93k
  if( record == NULL )
1886
0
  {
1887
0
    libcerror_error_set(
1888
0
     error,
1889
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1890
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1891
0
     "%s: invalid record entry.",
1892
0
     function );
1893
1894
0
    return( -1 );
1895
0
  }
1896
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1897
1898
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_ERROR )
1899
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_32BIT_SIGNED )
1900
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_32BIT_UNSIGNED )
1901
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_SIGNED )
1902
1.92k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_UNSIGNED ) )
1903
1.92k
  {
1904
1.92k
    libcerror_error_set(
1905
1.92k
     error,
1906
1.92k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1907
1.92k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1908
1.92k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
1909
1.92k
     function,
1910
1.92k
     internal_record->value_type );
1911
1912
1.92k
    return( -1 );
1913
1.92k
  }
1914
9
  if( internal_record->value_data == NULL )
1915
5
  {
1916
5
    libcerror_error_set(
1917
5
     error,
1918
5
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1919
5
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1920
5
     "%s: invalid record entry - missing value data.",
1921
5
     function );
1922
1923
5
    return( -1 );
1924
5
  }
1925
4
  if( internal_record->value_data_size != 4 )
1926
0
  {
1927
0
    libcerror_error_set(
1928
0
     error,
1929
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1930
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1931
0
     "%s: unsupported value data size.",
1932
0
     function );
1933
1934
0
    return( -1 );
1935
0
  }
1936
4
  if( value_32bit == NULL )
1937
0
  {
1938
0
    libcerror_error_set(
1939
0
     error,
1940
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1941
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1942
0
     "%s: invalid value 32-bit.",
1943
0
     function );
1944
1945
0
    return( -1 );
1946
0
  }
1947
4
  byte_stream_copy_to_uint32_little_endian(
1948
4
   internal_record->value_data,
1949
4
   *value_32bit );
1950
1951
4
  return( 1 );
1952
4
}
1953
1954
/* Retrieves the data as a 64-bit integer value
1955
 * Returns 1 if successful or -1 on error
1956
 */
1957
int libfwps_record_get_data_as_64bit_integer(
1958
     libfwps_record_t *record,
1959
     uint64_t *value_64bit,
1960
     libcerror_error_t **error )
1961
1.93k
{
1962
1.93k
  libfwps_internal_record_t *internal_record = NULL;
1963
1.93k
  static char *function                      = "libfwps_record_get_data_as_64bit_integer";
1964
1965
1.93k
  if( record == NULL )
1966
0
  {
1967
0
    libcerror_error_set(
1968
0
     error,
1969
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1970
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1971
0
     "%s: invalid record entry.",
1972
0
     function );
1973
1974
0
    return( -1 );
1975
0
  }
1976
1.93k
  internal_record = (libfwps_internal_record_t *) record;
1977
1978
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_APPLICATION_TIME )
1979
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_CURRENCY )
1980
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_FILETIME )
1981
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_64BIT_SIGNED )
1982
1.92k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_INTEGER_64BIT_UNSIGNED ) )
1983
1.92k
  {
1984
1.92k
    libcerror_error_set(
1985
1.92k
     error,
1986
1.92k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1987
1.92k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1988
1.92k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
1989
1.92k
     function,
1990
1.92k
     internal_record->value_type );
1991
1992
1.92k
    return( -1 );
1993
1.92k
  }
1994
10
  if( internal_record->value_data == NULL )
1995
2
  {
1996
2
    libcerror_error_set(
1997
2
     error,
1998
2
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1999
2
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2000
2
     "%s: invalid record entry - missing value data.",
2001
2
     function );
2002
2003
2
    return( -1 );
2004
2
  }
2005
8
  if( internal_record->value_data_size != 8 )
2006
0
  {
2007
0
    libcerror_error_set(
2008
0
     error,
2009
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2010
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2011
0
     "%s: unsupported value data size.",
2012
0
     function );
2013
2014
0
    return( -1 );
2015
0
  }
2016
8
  if( value_64bit == NULL )
2017
0
  {
2018
0
    libcerror_error_set(
2019
0
     error,
2020
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2021
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2022
0
     "%s: invalid value 64-bit.",
2023
0
     function );
2024
2025
0
    return( -1 );
2026
0
  }
2027
8
  byte_stream_copy_to_uint64_little_endian(
2028
8
   internal_record->value_data,
2029
8
   *value_64bit );
2030
2031
8
  return( 1 );
2032
8
}
2033
2034
/* Retrieves the data as a 64-bit floatingtime value
2035
 * Returns 1 if successful or -1 on error
2036
 */
2037
int libfwps_record_get_data_as_floatingtime(
2038
     libfwps_record_t *record,
2039
     uint64_t *floatingtime,
2040
     libcerror_error_t **error )
2041
1.93k
{
2042
1.93k
  libfwps_internal_record_t *internal_record = NULL;
2043
1.93k
  static char *function                      = "libfwps_record_get_data_as_floatingtime";
2044
2045
1.93k
  if( record == 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 record entry.",
2052
0
     function );
2053
2054
0
    return( -1 );
2055
0
  }
2056
1.93k
  internal_record = (libfwps_internal_record_t *) record;
2057
2058
1.93k
  if( internal_record->value_type != LIBFWPS_VALUE_TYPE_APPLICATION_TIME )
2059
1.93k
  {
2060
1.93k
    libcerror_error_set(
2061
1.93k
     error,
2062
1.93k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2063
1.93k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2064
1.93k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2065
1.93k
     function,
2066
1.93k
     internal_record->value_type );
2067
2068
1.93k
    return( -1 );
2069
1.93k
  }
2070
3
  if( internal_record->value_data == NULL )
2071
1
  {
2072
1
    libcerror_error_set(
2073
1
     error,
2074
1
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2075
1
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2076
1
     "%s: invalid record entry - missing value data.",
2077
1
     function );
2078
2079
1
    return( -1 );
2080
1
  }
2081
2
  if( internal_record->value_data_size != 8 )
2082
0
  {
2083
0
    libcerror_error_set(
2084
0
     error,
2085
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2086
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2087
0
     "%s: unsupported value data size.",
2088
0
     function );
2089
2090
0
    return( -1 );
2091
0
  }
2092
2
  if( floatingtime == NULL )
2093
0
  {
2094
0
    libcerror_error_set(
2095
0
     error,
2096
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2097
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2098
0
     "%s: invalid floatingtime.",
2099
0
     function );
2100
2101
0
    return( -1 );
2102
0
  }
2103
2
  byte_stream_copy_to_uint64_little_endian(
2104
2
   internal_record->value_data,
2105
2
   *floatingtime );
2106
2107
2
  return( 1 );
2108
2
}
2109
2110
/* Retrieves the data as a 64-bit FILETIME value
2111
 * Returns 1 if successful or -1 on error
2112
 */
2113
int libfwps_record_get_data_as_filetime(
2114
     libfwps_record_t *record,
2115
     uint64_t *filetime,
2116
     libcerror_error_t **error )
2117
1.93k
{
2118
1.93k
  libfwps_internal_record_t *internal_record = NULL;
2119
1.93k
  static char *function                      = "libfwps_record_get_data_as_filetime";
2120
2121
1.93k
  if( record == NULL )
2122
0
  {
2123
0
    libcerror_error_set(
2124
0
     error,
2125
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2126
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2127
0
     "%s: invalid record entry.",
2128
0
     function );
2129
2130
0
    return( -1 );
2131
0
  }
2132
1.93k
  internal_record = (libfwps_internal_record_t *) record;
2133
2134
1.93k
  if( internal_record->value_type != LIBFWPS_VALUE_TYPE_FILETIME )
2135
1.93k
  {
2136
1.93k
    libcerror_error_set(
2137
1.93k
     error,
2138
1.93k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2139
1.93k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2140
1.93k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2141
1.93k
     function,
2142
1.93k
     internal_record->value_type );
2143
2144
1.93k
    return( -1 );
2145
1.93k
  }
2146
2
  if( internal_record->value_data == NULL )
2147
1
  {
2148
1
    libcerror_error_set(
2149
1
     error,
2150
1
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2151
1
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2152
1
     "%s: invalid record entry - missing value data.",
2153
1
     function );
2154
2155
1
    return( -1 );
2156
1
  }
2157
1
  if( internal_record->value_data_size != 8 )
2158
0
  {
2159
0
    libcerror_error_set(
2160
0
     error,
2161
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2162
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2163
0
     "%s: unsupported value data size.",
2164
0
     function );
2165
2166
0
    return( -1 );
2167
0
  }
2168
1
  if( filetime == NULL )
2169
0
  {
2170
0
    libcerror_error_set(
2171
0
     error,
2172
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2173
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2174
0
     "%s: invalid filetime.",
2175
0
     function );
2176
2177
0
    return( -1 );
2178
0
  }
2179
1
  byte_stream_copy_to_uint64_little_endian(
2180
1
   internal_record->value_data,
2181
1
   *filetime );
2182
2183
1
  return( 1 );
2184
1
}
2185
2186
/* Retrieves the floating point value
2187
 * Returns 1 if successful or -1 on error
2188
 */
2189
int libfwps_record_get_data_as_floating_point(
2190
     libfwps_record_t *record,
2191
     double *value_floating_point,
2192
     libcerror_error_t **error )
2193
1.93k
{
2194
1.93k
  byte_stream_float32_t value_float;
2195
1.93k
  byte_stream_float64_t value_double;
2196
2197
1.93k
  libfwps_internal_record_t *internal_record = NULL;
2198
1.93k
  static char *function                      = "libfwps_record_get_data_as_floating_point";
2199
2200
1.93k
  if( record == NULL )
2201
0
  {
2202
0
    libcerror_error_set(
2203
0
     error,
2204
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2205
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2206
0
     "%s: invalid record entry.",
2207
0
     function );
2208
2209
0
    return( -1 );
2210
0
  }
2211
1.93k
  internal_record = (libfwps_internal_record_t *) record;
2212
2213
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_APPLICATION_TIME )
2214
1.93k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_FLOAT_32BIT )
2215
1.92k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_DOUBLE_64BIT ) )
2216
1.92k
  {
2217
1.92k
    libcerror_error_set(
2218
1.92k
     error,
2219
1.92k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2220
1.92k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2221
1.92k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2222
1.92k
     function,
2223
1.92k
     internal_record->value_type );
2224
2225
1.92k
    return( -1 );
2226
1.92k
  }
2227
12
  if( internal_record->value_data == NULL )
2228
2
  {
2229
2
    libcerror_error_set(
2230
2
     error,
2231
2
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2232
2
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2233
2
     "%s: invalid record entry - missing value data.",
2234
2
     function );
2235
2236
2
    return( -1 );
2237
2
  }
2238
10
  if( value_floating_point == NULL )
2239
0
  {
2240
0
    libcerror_error_set(
2241
0
     error,
2242
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2243
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2244
0
     "%s: invalid value floating point.",
2245
0
     function );
2246
2247
0
    return( -1 );
2248
0
  }
2249
  /* The value data size of a floating point value is 4 or 8
2250
   */
2251
10
  if( ( internal_record->value_data_size != 4 )
2252
3
   && ( internal_record->value_data_size != 8 ) )
2253
0
  {
2254
0
    libcerror_error_set(
2255
0
     error,
2256
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2257
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2258
0
     "%s: unsupported value data size.",
2259
0
     function );
2260
2261
0
    return( -1 );
2262
0
  }
2263
10
  if( internal_record->value_data_size == 4 )
2264
7
  {
2265
7
    byte_stream_copy_to_uint32_little_endian(
2266
7
     internal_record->value_data,
2267
7
     value_float.integer );
2268
2269
7
    *value_floating_point = (double) value_float.floating_point;
2270
7
  }
2271
3
  else if( internal_record->value_data_size == 8 )
2272
3
  {
2273
3
    byte_stream_copy_to_uint64_little_endian(
2274
3
     internal_record->value_data,
2275
3
     value_double.integer );
2276
2277
3
    *value_floating_point = value_double.floating_point;
2278
3
  }
2279
10
  return( 1 );
2280
10
}
2281
2282
/* Retrieves the size of the data formatted as an UTF-8 string
2283
 * The function uses a codepage if necessary, it uses the codepage set for the library
2284
 * The returned size includes the end of string character
2285
 * Returns 1 if successful or -1 on error
2286
 */
2287
int libfwps_record_get_data_as_utf8_string_size(
2288
     libfwps_record_t *record,
2289
     size_t *utf8_string_size,
2290
     libcerror_error_t **error )
2291
1.93k
{
2292
1.93k
  libfwps_internal_record_t *internal_record = NULL;
2293
1.93k
  static char *function                      = "libfwps_record_get_data_as_utf8_string_size";
2294
1.93k
  uint8_t is_ascii_string                    = 0;
2295
1.93k
  int result                                 = 0;
2296
2297
1.93k
  if( record == NULL )
2298
0
  {
2299
0
    libcerror_error_set(
2300
0
     error,
2301
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2302
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2303
0
     "%s: invalid record entry.",
2304
0
     function );
2305
2306
0
    return( -1 );
2307
0
  }
2308
1.93k
  internal_record = (libfwps_internal_record_t *) record;
2309
2310
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
2311
1.87k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
2312
932
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
2313
740
  {
2314
740
    libcerror_error_set(
2315
740
     error,
2316
740
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2317
740
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2318
740
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2319
740
     function,
2320
740
     internal_record->value_type );
2321
2322
740
    return( -1 );
2323
740
  }
2324
1.19k
  if( utf8_string_size == NULL )
2325
0
  {
2326
0
    libcerror_error_set(
2327
0
     error,
2328
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2329
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2330
0
     "%s: invalid UTF-8 string size.",
2331
0
     function );
2332
2333
0
    return( -1 );
2334
0
  }
2335
1.19k
  if( ( internal_record->value_data == NULL )
2336
1.12k
   || ( internal_record->value_data_size == 0 ) )
2337
73
  {
2338
73
    *utf8_string_size = 0;
2339
2340
73
    return( 1 );
2341
73
  }
2342
1.12k
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
2343
906
  {
2344
906
    is_ascii_string = 1;
2345
906
  }
2346
  /* String is in UTF-16 little-endian
2347
   */
2348
1.12k
  if( is_ascii_string == 0 )
2349
218
  {
2350
218
    result = libuna_utf8_string_size_from_utf16_stream(
2351
218
              internal_record->value_data,
2352
218
              internal_record->value_data_size,
2353
218
              LIBUNA_ENDIAN_LITTLE,
2354
218
              utf8_string_size,
2355
218
              error );
2356
218
  }
2357
  /* Codepage 65000 represents UTF-7
2358
   */
2359
906
  else if( internal_record->ascii_codepage == 65000 )
2360
155
  {
2361
155
    result = libuna_utf8_string_size_from_utf7_stream(
2362
155
        internal_record->value_data,
2363
155
        internal_record->value_data_size,
2364
155
        utf8_string_size,
2365
155
        error );
2366
155
  }
2367
  /* Codepage 65001 represents UTF-8
2368
   */
2369
751
  else if( internal_record->ascii_codepage == 65001 )
2370
154
  {
2371
154
    result = libuna_utf8_string_size_from_utf8_stream(
2372
154
        internal_record->value_data,
2373
154
        internal_record->value_data_size,
2374
154
        utf8_string_size,
2375
154
        error );
2376
154
  }
2377
597
  else
2378
597
  {
2379
597
    result = libuna_utf8_string_size_from_byte_stream(
2380
597
        internal_record->value_data,
2381
597
        internal_record->value_data_size,
2382
597
        internal_record->ascii_codepage,
2383
597
        utf8_string_size,
2384
597
        error );
2385
597
  }
2386
1.12k
  if( result != 1 )
2387
242
  {
2388
242
    libcerror_error_set(
2389
242
     error,
2390
242
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2391
242
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2392
242
     "%s: unable to determine size of value data as UTF-8 string.",
2393
242
     function );
2394
2395
242
    return( -1 );
2396
242
  }
2397
882
  return( 1 );
2398
1.12k
}
2399
2400
/* Retrieves the data formatted as an UTF-8 string
2401
 * The function uses a codepage if necessary, it uses the codepage set for the library
2402
 * The size should include the end of string character
2403
 * Returns 1 if successful or -1 on error
2404
 */
2405
int libfwps_record_get_data_as_utf8_string(
2406
     libfwps_record_t *record,
2407
     uint8_t *utf8_string,
2408
     size_t utf8_string_size,
2409
     libcerror_error_t **error )
2410
880
{
2411
880
  libfwps_internal_record_t *internal_record = NULL;
2412
880
  static char *function                      = "libfwps_record_get_data_as_utf8_string";
2413
880
  uint8_t is_ascii_string                    = 0;
2414
880
  int result                                 = 0;
2415
2416
880
  if( record == NULL )
2417
0
  {
2418
0
    libcerror_error_set(
2419
0
     error,
2420
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2421
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2422
0
     "%s: invalid record entry.",
2423
0
     function );
2424
2425
0
    return( -1 );
2426
0
  }
2427
880
  internal_record = (libfwps_internal_record_t *) record;
2428
2429
880
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
2430
857
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
2431
113
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
2432
0
  {
2433
0
    libcerror_error_set(
2434
0
     error,
2435
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2436
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2437
0
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2438
0
     function,
2439
0
     internal_record->value_type );
2440
2441
0
    return( -1 );
2442
0
  }
2443
880
  if( utf8_string == NULL )
2444
0
  {
2445
0
    libcerror_error_set(
2446
0
     error,
2447
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2448
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2449
0
     "%s: invalid UTF-8 string.",
2450
0
     function );
2451
2452
0
    return( -1 );
2453
0
  }
2454
880
  if( ( utf8_string_size == 0 )
2455
880
   || ( utf8_string_size > (size_t) SSIZE_MAX ) )
2456
0
  {
2457
0
    libcerror_error_set(
2458
0
     error,
2459
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2460
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2461
0
     "%s: invalid UTF-8 string size value out of bounds.",
2462
0
     function );
2463
2464
0
    return( -1 );
2465
0
  }
2466
880
  if( ( internal_record->value_data == NULL )
2467
880
   || ( internal_record->value_data_size == 0 ) )
2468
0
  {
2469
0
    utf8_string[ 0 ] = 0;
2470
2471
0
    return( 1 );
2472
0
  }
2473
880
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
2474
744
  {
2475
744
    is_ascii_string = 1;
2476
744
  }
2477
  /* String is in UTF-16 little-endian
2478
   */
2479
880
  if( is_ascii_string == 0 )
2480
136
  {
2481
136
    result = libuna_utf8_string_copy_from_utf16_stream(
2482
136
              utf8_string,
2483
136
              utf8_string_size,
2484
136
              internal_record->value_data,
2485
136
              internal_record->value_data_size,
2486
136
              LIBUNA_ENDIAN_LITTLE,
2487
136
              error );
2488
136
  }
2489
  /* Codepage 65000 represents UTF-7
2490
   */
2491
744
  else if( internal_record->ascii_codepage == 65000 )
2492
63
  {
2493
63
    result = libuna_utf8_string_copy_from_utf7_stream(
2494
63
              utf8_string,
2495
63
              utf8_string_size,
2496
63
              internal_record->value_data,
2497
63
              internal_record->value_data_size,
2498
63
              error );
2499
63
  }
2500
  /* Codepage 65001 represents UTF-8
2501
   */
2502
681
  else if( internal_record->ascii_codepage == 65001 )
2503
84
  {
2504
84
    result = libuna_utf8_string_copy_from_utf8_stream(
2505
84
              utf8_string,
2506
84
              utf8_string_size,
2507
84
              internal_record->value_data,
2508
84
              internal_record->value_data_size,
2509
84
              error );
2510
84
  }
2511
597
  else
2512
597
  {
2513
597
    result = libuna_utf8_string_copy_from_byte_stream(
2514
597
              utf8_string,
2515
597
              utf8_string_size,
2516
597
              internal_record->value_data,
2517
597
              internal_record->value_data_size,
2518
597
              internal_record->ascii_codepage,
2519
597
              error );
2520
597
  }
2521
880
  if( result != 1 )
2522
0
  {
2523
0
    libcerror_error_set(
2524
0
     error,
2525
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2526
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2527
0
     "%s: unable to copy value data to UTF-8 string.",
2528
0
     function );
2529
2530
0
    return( -1 );
2531
0
  }
2532
880
  return( 1 );
2533
880
}
2534
2535
/* Retrieves the size of the data formatted as an UTF-16 string
2536
 * The function uses a codepage if necessary, it uses the codepage set for the library
2537
 * The returned size includes the end of string character
2538
 * Returns 1 if successful or -1 on error
2539
 */
2540
int libfwps_record_get_data_as_utf16_string_size(
2541
     libfwps_record_t *record,
2542
     size_t *utf16_string_size,
2543
     libcerror_error_t **error )
2544
1.93k
{
2545
1.93k
  libfwps_internal_record_t *internal_record = NULL;
2546
1.93k
  static char *function                      = "libfwps_record_get_data_as_utf16_string_size";
2547
1.93k
  uint8_t is_ascii_string                    = 0;
2548
1.93k
  int result                                 = 0;
2549
2550
1.93k
  if( record == NULL )
2551
0
  {
2552
0
    libcerror_error_set(
2553
0
     error,
2554
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2555
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2556
0
     "%s: invalid record entry.",
2557
0
     function );
2558
2559
0
    return( -1 );
2560
0
  }
2561
1.93k
  internal_record = (libfwps_internal_record_t *) record;
2562
2563
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
2564
1.87k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
2565
932
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
2566
740
  {
2567
740
    libcerror_error_set(
2568
740
     error,
2569
740
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2570
740
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2571
740
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2572
740
     function,
2573
740
     internal_record->value_type );
2574
2575
740
    return( -1 );
2576
740
  }
2577
1.19k
  if( utf16_string_size == NULL )
2578
0
  {
2579
0
    libcerror_error_set(
2580
0
     error,
2581
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2582
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2583
0
     "%s: invalid UTF-16 string size.",
2584
0
     function );
2585
2586
0
    return( -1 );
2587
0
  }
2588
1.19k
  if( ( internal_record->value_data == NULL )
2589
1.12k
   || ( internal_record->value_data_size == 0 ) )
2590
73
  {
2591
73
    *utf16_string_size = 0;
2592
2593
73
    return( 1 );
2594
73
  }
2595
1.12k
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
2596
906
  {
2597
906
    is_ascii_string = 1;
2598
906
  }
2599
  /* String is in UTF-16 little-endian
2600
   */
2601
1.12k
  if( is_ascii_string == 0 )
2602
218
  {
2603
218
    result = libuna_utf16_string_size_from_utf16_stream(
2604
218
              internal_record->value_data,
2605
218
              internal_record->value_data_size,
2606
218
              LIBUNA_ENDIAN_LITTLE,
2607
218
              utf16_string_size,
2608
218
              error );
2609
218
  }
2610
  /* Codepage 65000 represents UTF-7
2611
   */
2612
906
  else if( internal_record->ascii_codepage == 65000 )
2613
155
  {
2614
155
    result = libuna_utf16_string_size_from_utf7_stream(
2615
155
        internal_record->value_data,
2616
155
        internal_record->value_data_size,
2617
155
        utf16_string_size,
2618
155
        error );
2619
155
  }
2620
  /* Codepage 65001 represents UTF-8
2621
   */
2622
751
  else if( internal_record->ascii_codepage == 65001 )
2623
154
  {
2624
154
    result = libuna_utf16_string_size_from_utf8_stream(
2625
154
        internal_record->value_data,
2626
154
        internal_record->value_data_size,
2627
154
        utf16_string_size,
2628
154
        error );
2629
154
  }
2630
597
  else
2631
597
  {
2632
597
    result = libuna_utf16_string_size_from_byte_stream(
2633
597
        internal_record->value_data,
2634
597
        internal_record->value_data_size,
2635
597
        internal_record->ascii_codepage,
2636
597
        utf16_string_size,
2637
597
        error );
2638
597
  }
2639
1.12k
  if( result != 1 )
2640
242
  {
2641
242
    libcerror_error_set(
2642
242
     error,
2643
242
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2644
242
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2645
242
     "%s: unable to determine size of value data as UTF-16 string.",
2646
242
     function );
2647
2648
242
    return( -1 );
2649
242
  }
2650
882
  return( 1 );
2651
1.12k
}
2652
2653
/* Retrieves the data formatted as an UTF-16 string
2654
 * The function uses a codepage if necessary, it uses the codepage set for the library
2655
 * The size should include the end of string character
2656
 * Returns 1 if successful or -1 on error
2657
 */
2658
int libfwps_record_get_data_as_utf16_string(
2659
     libfwps_record_t *record,
2660
     uint16_t *utf16_string,
2661
     size_t utf16_string_size,
2662
     libcerror_error_t **error )
2663
880
{
2664
880
  libfwps_internal_record_t *internal_record = NULL;
2665
880
  static char *function                      = "libfwps_record_get_data_as_utf16_string";
2666
880
  uint8_t is_ascii_string                    = 0;
2667
880
  int result                                 = 0;
2668
2669
880
  if( record == NULL )
2670
0
  {
2671
0
    libcerror_error_set(
2672
0
     error,
2673
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2674
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2675
0
     "%s: invalid record entry.",
2676
0
     function );
2677
2678
0
    return( -1 );
2679
0
  }
2680
880
  internal_record = (libfwps_internal_record_t *) record;
2681
2682
880
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
2683
857
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
2684
113
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
2685
0
  {
2686
0
    libcerror_error_set(
2687
0
     error,
2688
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2689
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2690
0
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2691
0
     function,
2692
0
     internal_record->value_type );
2693
2694
0
    return( -1 );
2695
0
  }
2696
880
  if( utf16_string == NULL )
2697
0
  {
2698
0
    libcerror_error_set(
2699
0
     error,
2700
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2701
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2702
0
     "%s: invalid UTF-16 string.",
2703
0
     function );
2704
2705
0
    return( -1 );
2706
0
  }
2707
880
  if( ( utf16_string_size == 0 )
2708
880
   || ( utf16_string_size > (size_t) SSIZE_MAX ) )
2709
0
  {
2710
0
    libcerror_error_set(
2711
0
     error,
2712
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2713
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2714
0
     "%s: invalid UTF-16 string size value out of bounds.",
2715
0
     function );
2716
2717
0
    return( -1 );
2718
0
  }
2719
880
  if( ( internal_record->value_data == NULL )
2720
880
   || ( internal_record->value_data_size == 0 ) )
2721
0
  {
2722
0
    utf16_string[ 0 ] = 0;
2723
2724
0
    return( 1 );
2725
0
  }
2726
880
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
2727
744
  {
2728
744
    is_ascii_string = 1;
2729
744
  }
2730
  /* String is in UTF-16 little-endian
2731
   */
2732
880
  if( is_ascii_string == 0 )
2733
136
  {
2734
136
    result = libuna_utf16_string_copy_from_utf16_stream(
2735
136
              utf16_string,
2736
136
              utf16_string_size,
2737
136
              internal_record->value_data,
2738
136
              internal_record->value_data_size,
2739
136
              LIBUNA_ENDIAN_LITTLE,
2740
136
              error );
2741
136
  }
2742
  /* Codepage 65000 represents UTF-7
2743
   */
2744
744
  else if( internal_record->ascii_codepage == 65000 )
2745
63
  {
2746
63
    result = libuna_utf16_string_copy_from_utf7_stream(
2747
63
              utf16_string,
2748
63
              utf16_string_size,
2749
63
              internal_record->value_data,
2750
63
              internal_record->value_data_size,
2751
63
              error );
2752
63
  }
2753
  /* Codepage 65001 represents UTF-8
2754
   */
2755
681
  else if( internal_record->ascii_codepage == 65001 )
2756
84
  {
2757
84
    result = libuna_utf16_string_copy_from_utf8_stream(
2758
84
              utf16_string,
2759
84
              utf16_string_size,
2760
84
              internal_record->value_data,
2761
84
              internal_record->value_data_size,
2762
84
              error );
2763
84
  }
2764
597
  else
2765
597
  {
2766
597
    result = libuna_utf16_string_copy_from_byte_stream(
2767
597
              utf16_string,
2768
597
              utf16_string_size,
2769
597
              internal_record->value_data,
2770
597
              internal_record->value_data_size,
2771
597
              internal_record->ascii_codepage,
2772
597
              error );
2773
597
  }
2774
880
  if( result != 1 )
2775
0
  {
2776
0
    libcerror_error_set(
2777
0
     error,
2778
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2779
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2780
0
     "%s: unable to copy value data to UTF-16 string.",
2781
0
     function );
2782
2783
0
    return( -1 );
2784
0
  }
2785
880
  return( 1 );
2786
880
}
2787
2788
/* Retrieves the size of the data formatted as an UTF-8 path string
2789
 * The function uses a codepage if necessary, it uses the codepage set for the library
2790
 * This function uses UTF-8 RFC 2279 (or 6-byte UTF-8) to support characters outside Unicode
2791
 * The returned size includes the end of string character
2792
 * Returns 1 if successful or -1 on error
2793
 */
2794
int libfwps_record_get_data_as_utf8_path_string_size(
2795
     libfwps_record_t *record,
2796
     size_t *utf8_string_size,
2797
     libcerror_error_t **error )
2798
1.93k
{
2799
1.93k
  libfwps_internal_record_t *internal_record = NULL;
2800
1.93k
  static char *function                      = "libfwps_record_get_data_as_utf8_path_string_size";
2801
1.93k
  uint8_t is_ascii_string                    = 0;
2802
1.93k
  int result                                 = 0;
2803
2804
1.93k
  if( record == NULL )
2805
0
  {
2806
0
    libcerror_error_set(
2807
0
     error,
2808
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2809
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2810
0
     "%s: invalid record entry.",
2811
0
     function );
2812
2813
0
    return( -1 );
2814
0
  }
2815
1.93k
  internal_record = (libfwps_internal_record_t *) record;
2816
2817
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
2818
1.87k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
2819
932
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
2820
740
  {
2821
740
    libcerror_error_set(
2822
740
     error,
2823
740
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2824
740
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2825
740
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2826
740
     function,
2827
740
     internal_record->value_type );
2828
2829
740
    return( -1 );
2830
740
  }
2831
1.19k
  if( utf8_string_size == NULL )
2832
0
  {
2833
0
    libcerror_error_set(
2834
0
     error,
2835
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2836
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2837
0
     "%s: invalid UTF-8 string size.",
2838
0
     function );
2839
2840
0
    return( -1 );
2841
0
  }
2842
1.19k
  if( ( internal_record->value_data == NULL )
2843
1.12k
   || ( internal_record->value_data_size == 0 ) )
2844
73
  {
2845
73
    *utf8_string_size = 0;
2846
2847
73
    return( 1 );
2848
73
  }
2849
1.12k
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
2850
906
  {
2851
906
    is_ascii_string = 1;
2852
906
  }
2853
  /* String is in UTF-16 little-endian
2854
   */
2855
1.12k
  if( is_ascii_string == 0 )
2856
218
  {
2857
218
    result = libuna_utf8_string_size_from_utf16_stream(
2858
218
              internal_record->value_data,
2859
218
              internal_record->value_data_size,
2860
218
              LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE,
2861
218
              utf8_string_size,
2862
218
              error );
2863
218
  }
2864
  /* Codepage 65000 represents UTF-7
2865
   */
2866
906
  else if( internal_record->ascii_codepage == 65000 )
2867
155
  {
2868
155
    result = libuna_utf8_string_size_from_utf7_stream(
2869
155
        internal_record->value_data,
2870
155
        internal_record->value_data_size,
2871
155
        utf8_string_size,
2872
155
        error );
2873
155
  }
2874
  /* Codepage 65001 represents UTF-8
2875
   */
2876
751
  else if( internal_record->ascii_codepage == 65001 )
2877
154
  {
2878
154
    result = libuna_utf8_string_size_from_utf8_stream(
2879
154
        internal_record->value_data,
2880
154
        internal_record->value_data_size,
2881
154
        utf8_string_size,
2882
154
        error );
2883
154
  }
2884
597
  else
2885
597
  {
2886
597
    result = libuna_utf8_string_size_from_byte_stream(
2887
597
        internal_record->value_data,
2888
597
        internal_record->value_data_size,
2889
597
        internal_record->ascii_codepage,
2890
597
        utf8_string_size,
2891
597
        error );
2892
597
  }
2893
1.12k
  if( result != 1 )
2894
169
  {
2895
169
    libcerror_error_set(
2896
169
     error,
2897
169
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2898
169
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2899
169
     "%s: unable to determine size of value data as UTF-8 string.",
2900
169
     function );
2901
2902
169
    return( -1 );
2903
169
  }
2904
955
  return( 1 );
2905
1.12k
}
2906
2907
/* Retrieves the data formatted as an UTF-8 path string
2908
 * The function uses a codepage if necessary, it uses the codepage set for the library
2909
 * This function uses UTF-8 RFC 2279 (or 6-byte UTF-8) to support characters outside Unicode
2910
 * The size should include the end of string character
2911
 * Returns 1 if successful or -1 on error
2912
 */
2913
int libfwps_record_get_data_as_utf8_path_string(
2914
     libfwps_record_t *record,
2915
     uint8_t *utf8_string,
2916
     size_t utf8_string_size,
2917
     libcerror_error_t **error )
2918
953
{
2919
953
  libfwps_internal_record_t *internal_record = NULL;
2920
953
  static char *function                      = "libfwps_record_get_data_as_utf8_path_string";
2921
953
  uint8_t is_ascii_string                    = 0;
2922
953
  int result                                 = 0;
2923
2924
953
  if( record == NULL )
2925
0
  {
2926
0
    libcerror_error_set(
2927
0
     error,
2928
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2929
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2930
0
     "%s: invalid record entry.",
2931
0
     function );
2932
2933
0
    return( -1 );
2934
0
  }
2935
953
  internal_record = (libfwps_internal_record_t *) record;
2936
2937
953
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
2938
908
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
2939
164
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
2940
0
  {
2941
0
    libcerror_error_set(
2942
0
     error,
2943
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2944
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2945
0
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
2946
0
     function,
2947
0
     internal_record->value_type );
2948
2949
0
    return( -1 );
2950
0
  }
2951
953
  if( utf8_string == NULL )
2952
0
  {
2953
0
    libcerror_error_set(
2954
0
     error,
2955
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2956
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2957
0
     "%s: invalid UTF-8 string.",
2958
0
     function );
2959
2960
0
    return( -1 );
2961
0
  }
2962
953
  if( ( utf8_string_size == 0 )
2963
953
   || ( utf8_string_size > (size_t) SSIZE_MAX ) )
2964
0
  {
2965
0
    libcerror_error_set(
2966
0
     error,
2967
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2968
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2969
0
     "%s: invalid UTF-8 string size value out of bounds.",
2970
0
     function );
2971
2972
0
    return( -1 );
2973
0
  }
2974
953
  if( ( internal_record->value_data == NULL )
2975
953
   || ( internal_record->value_data_size == 0 ) )
2976
0
  {
2977
0
    utf8_string[ 0 ] = 0;
2978
2979
0
    return( 1 );
2980
0
  }
2981
953
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
2982
744
  {
2983
744
    is_ascii_string = 1;
2984
744
  }
2985
  /* String is in UTF-16 little-endian
2986
   */
2987
953
  if( is_ascii_string == 0 )
2988
209
  {
2989
209
    result = libuna_utf8_string_copy_from_utf16_stream(
2990
209
              utf8_string,
2991
209
              utf8_string_size,
2992
209
              internal_record->value_data,
2993
209
              internal_record->value_data_size,
2994
209
              LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE,
2995
209
              error );
2996
209
  }
2997
  /* Codepage 65000 represents UTF-7
2998
   */
2999
744
  else if( internal_record->ascii_codepage == 65000 )
3000
63
  {
3001
63
    result = libuna_utf8_string_copy_from_utf7_stream(
3002
63
              utf8_string,
3003
63
              utf8_string_size,
3004
63
              internal_record->value_data,
3005
63
              internal_record->value_data_size,
3006
63
              error );
3007
63
  }
3008
  /* Codepage 65001 represents UTF-8
3009
   */
3010
681
  else if( internal_record->ascii_codepage == 65001 )
3011
84
  {
3012
84
    result = libuna_utf8_string_copy_from_utf8_stream(
3013
84
              utf8_string,
3014
84
              utf8_string_size,
3015
84
              internal_record->value_data,
3016
84
              internal_record->value_data_size,
3017
84
              error );
3018
84
  }
3019
597
  else
3020
597
  {
3021
597
    result = libuna_utf8_string_copy_from_byte_stream(
3022
597
              utf8_string,
3023
597
              utf8_string_size,
3024
597
              internal_record->value_data,
3025
597
              internal_record->value_data_size,
3026
597
              internal_record->ascii_codepage,
3027
597
              error );
3028
597
  }
3029
953
  if( result != 1 )
3030
0
  {
3031
0
    libcerror_error_set(
3032
0
     error,
3033
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3034
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3035
0
     "%s: unable to copy value data to UTF-8 string.",
3036
0
     function );
3037
3038
0
    return( -1 );
3039
0
  }
3040
953
  return( 1 );
3041
953
}
3042
3043
/* Retrieves the size of the data formatted as an UTF-16 path string
3044
 * The function uses a codepage if necessary, it uses the codepage set for the library
3045
 * This function uses UCS-2 (with surrogates) to support characters outside Unicode
3046
 * The returned size includes the end of string character
3047
 * Returns 1 if successful or -1 on error
3048
 */
3049
int libfwps_record_get_data_as_utf16_path_string_size(
3050
     libfwps_record_t *record,
3051
     size_t *utf16_string_size,
3052
     libcerror_error_t **error )
3053
1.93k
{
3054
1.93k
  libfwps_internal_record_t *internal_record = NULL;
3055
1.93k
  static char *function                      = "libfwps_record_get_data_as_utf16_path_string_size";
3056
1.93k
  uint8_t is_ascii_string                    = 0;
3057
1.93k
  int result                                 = 0;
3058
3059
1.93k
  if( record == NULL )
3060
0
  {
3061
0
    libcerror_error_set(
3062
0
     error,
3063
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3064
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3065
0
     "%s: invalid record entry.",
3066
0
     function );
3067
3068
0
    return( -1 );
3069
0
  }
3070
1.93k
  internal_record = (libfwps_internal_record_t *) record;
3071
3072
1.93k
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
3073
1.87k
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
3074
932
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
3075
740
  {
3076
740
    libcerror_error_set(
3077
740
     error,
3078
740
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3079
740
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
3080
740
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
3081
740
     function,
3082
740
     internal_record->value_type );
3083
3084
740
    return( -1 );
3085
740
  }
3086
1.19k
  if( utf16_string_size == NULL )
3087
0
  {
3088
0
    libcerror_error_set(
3089
0
     error,
3090
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3091
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3092
0
     "%s: invalid UTF-16 string size.",
3093
0
     function );
3094
3095
0
    return( -1 );
3096
0
  }
3097
1.19k
  if( ( internal_record->value_data == NULL )
3098
1.12k
   || ( internal_record->value_data_size == 0 ) )
3099
73
  {
3100
73
    *utf16_string_size = 0;
3101
3102
73
    return( 1 );
3103
73
  }
3104
1.12k
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
3105
906
  {
3106
906
    is_ascii_string = 1;
3107
906
  }
3108
  /* String is in UTF-16 little-endian
3109
   */
3110
1.12k
  if( is_ascii_string == 0 )
3111
218
  {
3112
218
    result = libuna_utf16_string_size_from_utf16_stream(
3113
218
              internal_record->value_data,
3114
218
              internal_record->value_data_size,
3115
218
              LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE,
3116
218
              utf16_string_size,
3117
218
              error );
3118
218
  }
3119
  /* Codepage 65000 represents UTF-7
3120
   */
3121
906
  else if( internal_record->ascii_codepage == 65000 )
3122
155
  {
3123
155
    result = libuna_utf16_string_size_from_utf7_stream(
3124
155
        internal_record->value_data,
3125
155
        internal_record->value_data_size,
3126
155
        utf16_string_size,
3127
155
        error );
3128
155
  }
3129
  /* Codepage 65001 represents UTF-8
3130
   */
3131
751
  else if( internal_record->ascii_codepage == 65001 )
3132
154
  {
3133
154
    result = libuna_utf16_string_size_from_utf8_stream(
3134
154
        internal_record->value_data,
3135
154
        internal_record->value_data_size,
3136
154
        utf16_string_size,
3137
154
        error );
3138
154
  }
3139
597
  else
3140
597
  {
3141
597
    result = libuna_utf16_string_size_from_byte_stream(
3142
597
        internal_record->value_data,
3143
597
        internal_record->value_data_size,
3144
597
        internal_record->ascii_codepage,
3145
597
        utf16_string_size,
3146
597
        error );
3147
597
  }
3148
1.12k
  if( result != 1 )
3149
169
  {
3150
169
    libcerror_error_set(
3151
169
     error,
3152
169
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3153
169
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3154
169
     "%s: unable to determine size of value data as UTF-16 string.",
3155
169
     function );
3156
3157
169
    return( -1 );
3158
169
  }
3159
955
  return( 1 );
3160
1.12k
}
3161
3162
/* Retrieves the data formatted as an UTF-16 path string
3163
 * The function uses a codepage if necessary, it uses the codepage set for the library
3164
 * This function uses UCS-2 (with surrogates) to support characters outside Unicode
3165
 * The size should include the end of string character
3166
 * Returns 1 if successful or -1 on error
3167
 */
3168
int libfwps_record_get_data_as_utf16_path_string(
3169
     libfwps_record_t *record,
3170
     uint16_t *utf16_string,
3171
     size_t utf16_string_size,
3172
     libcerror_error_t **error )
3173
953
{
3174
953
  libfwps_internal_record_t *internal_record = NULL;
3175
953
  static char *function                      = "libfwps_record_get_data_as_utf16_path_string";
3176
953
  uint8_t is_ascii_string                    = 0;
3177
953
  int result                                 = 0;
3178
3179
953
  if( record == NULL )
3180
0
  {
3181
0
    libcerror_error_set(
3182
0
     error,
3183
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3184
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3185
0
     "%s: invalid record entry.",
3186
0
     function );
3187
3188
0
    return( -1 );
3189
0
  }
3190
953
  internal_record = (libfwps_internal_record_t *) record;
3191
3192
953
  if( ( internal_record->value_type != LIBFWPS_VALUE_TYPE_BINARY_STRING )
3193
908
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_ASCII )
3194
164
   && ( internal_record->value_type != LIBFWPS_VALUE_TYPE_STRING_UNICODE ) )
3195
0
  {
3196
0
    libcerror_error_set(
3197
0
     error,
3198
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3199
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
3200
0
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
3201
0
     function,
3202
0
     internal_record->value_type );
3203
3204
0
    return( -1 );
3205
0
  }
3206
953
  if( utf16_string == NULL )
3207
0
  {
3208
0
    libcerror_error_set(
3209
0
     error,
3210
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3211
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3212
0
     "%s: invalid UTF-16 string.",
3213
0
     function );
3214
3215
0
    return( -1 );
3216
0
  }
3217
953
  if( ( utf16_string_size == 0 )
3218
953
   || ( utf16_string_size > (size_t) SSIZE_MAX ) )
3219
0
  {
3220
0
    libcerror_error_set(
3221
0
     error,
3222
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3223
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
3224
0
     "%s: invalid UTF-16 string size value out of bounds.",
3225
0
     function );
3226
3227
0
    return( -1 );
3228
0
  }
3229
953
  if( ( internal_record->value_data == NULL )
3230
953
   || ( internal_record->value_data_size == 0 ) )
3231
0
  {
3232
0
    utf16_string[ 0 ] = 0;
3233
3234
0
    return( 1 );
3235
0
  }
3236
953
  if( internal_record->value_type == LIBFWPS_VALUE_TYPE_STRING_ASCII )
3237
744
  {
3238
744
    is_ascii_string = 1;
3239
744
  }
3240
  /* String is in UTF-16 little-endian
3241
   */
3242
953
  if( is_ascii_string == 0 )
3243
209
  {
3244
209
    result = libuna_utf16_string_copy_from_utf16_stream(
3245
209
              utf16_string,
3246
209
              utf16_string_size,
3247
209
              internal_record->value_data,
3248
209
              internal_record->value_data_size,
3249
209
              LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE,
3250
209
              error );
3251
209
  }
3252
  /* Codepage 65000 represents UTF-7
3253
   */
3254
744
  else if( internal_record->ascii_codepage == 65000 )
3255
63
  {
3256
63
    result = libuna_utf16_string_copy_from_utf7_stream(
3257
63
              utf16_string,
3258
63
              utf16_string_size,
3259
63
              internal_record->value_data,
3260
63
              internal_record->value_data_size,
3261
63
              error );
3262
63
  }
3263
  /* Codepage 65001 represents UTF-8
3264
   */
3265
681
  else if( internal_record->ascii_codepage == 65001 )
3266
84
  {
3267
84
    result = libuna_utf16_string_copy_from_utf8_stream(
3268
84
              utf16_string,
3269
84
              utf16_string_size,
3270
84
              internal_record->value_data,
3271
84
              internal_record->value_data_size,
3272
84
              error );
3273
84
  }
3274
597
  else
3275
597
  {
3276
597
    result = libuna_utf16_string_copy_from_byte_stream(
3277
597
              utf16_string,
3278
597
              utf16_string_size,
3279
597
              internal_record->value_data,
3280
597
              internal_record->value_data_size,
3281
597
              internal_record->ascii_codepage,
3282
597
              error );
3283
597
  }
3284
953
  if( result != 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 value data to UTF-16 string.",
3291
0
     function );
3292
3293
0
    return( -1 );
3294
0
  }
3295
953
  return( 1 );
3296
953
}
3297
3298
/* Retrieves the data as a GUID value
3299
 * Returns 1 if successful or -1 on error
3300
 */
3301
int libfwps_record_get_data_as_guid(
3302
     libfwps_record_t *record,
3303
     uint8_t *guid_data,
3304
     size_t guid_data_size,
3305
     libcerror_error_t **error )
3306
1.93k
{
3307
1.93k
  libfwps_internal_record_t *internal_record = NULL;
3308
1.93k
  static char *function                      = "libfwps_record_get_data_as_guid";
3309
3310
1.93k
  if( record == NULL )
3311
0
  {
3312
0
    libcerror_error_set(
3313
0
     error,
3314
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3315
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3316
0
     "%s: invalid record entry.",
3317
0
     function );
3318
3319
0
    return( -1 );
3320
0
  }
3321
1.93k
  internal_record = (libfwps_internal_record_t *) record;
3322
3323
1.93k
  if( internal_record->value_type != LIBFWPS_VALUE_TYPE_GUID )
3324
1.93k
  {
3325
1.93k
    libcerror_error_set(
3326
1.93k
     error,
3327
1.93k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3328
1.93k
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
3329
1.93k
     "%s: invalid record entry - unsupported value type: 0x%04" PRIx32 ".",
3330
1.93k
     function,
3331
1.93k
     internal_record->value_type );
3332
3333
1.93k
    return( -1 );
3334
1.93k
  }
3335
2
  if( internal_record->value_data == NULL )
3336
1
  {
3337
1
    libcerror_error_set(
3338
1
     error,
3339
1
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3340
1
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3341
1
     "%s: invalid record entry - missing value data.",
3342
1
     function );
3343
3344
1
    return( -1 );
3345
1
  }
3346
1
  if( internal_record->value_data_size != 16 )
3347
0
  {
3348
0
    libcerror_error_set(
3349
0
     error,
3350
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3351
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
3352
0
     "%s: unsupported value data size.",
3353
0
     function );
3354
3355
0
    return( -1 );
3356
0
  }
3357
1
  if( guid_data == NULL )
3358
0
  {
3359
0
    libcerror_error_set(
3360
0
     error,
3361
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3362
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3363
0
     "%s: invalid GUID data.",
3364
0
     function );
3365
3366
0
    return( -1 );
3367
0
  }
3368
1
  if( guid_data_size > (size_t) SSIZE_MAX )
3369
0
  {
3370
0
    libcerror_error_set(
3371
0
     error,
3372
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3373
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
3374
0
     "%s: GUID data size value exceeds maximum.",
3375
0
     function );
3376
3377
0
    return( -1 );
3378
0
  }
3379
1
  if( guid_data_size < 16 )
3380
0
  {
3381
0
    libcerror_error_set(
3382
0
     error,
3383
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3384
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
3385
0
     "%s: GUID data size value too small.",
3386
0
     function );
3387
3388
0
    return( -1 );
3389
0
  }
3390
1
  if( memory_copy(
3391
1
       guid_data,
3392
1
       internal_record->value_data,
3393
1
       16 ) == NULL )
3394
0
  {
3395
0
    libcerror_error_set(
3396
0
     error,
3397
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
3398
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
3399
0
     "%s: unable to copy value data.",
3400
0
     function );
3401
3402
0
    return( -1 );
3403
0
  }
3404
1
  return( 1 );
3405
1
}
3406