Coverage Report

Created: 2025-07-04 07:01

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