Coverage Report

Created: 2025-06-13 07:22

/src/libevtx/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.43M
{
219
1.43M
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
220
1.43M
  static char *function                             = "libfwevt_xml_value_get_type";
221
222
1.43M
  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.43M
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
234
235
1.43M
  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.43M
  *value_type = internal_xml_value->value_type;
247
248
1.43M
  return( 1 );
249
1.43M
}
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.75M
{
586
2.75M
  libfwevt_data_segment_t *data_segment             = NULL;
587
2.75M
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
588
2.75M
  static char *function                             = "libfwevt_xml_value_append_data_segment";
589
590
2.75M
  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.75M
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
602
603
2.75M
  if( libfwevt_data_segment_initialize(
604
2.75M
       &data_segment,
605
2.75M
       data,
606
2.75M
       data_size,
607
2.75M
       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.75M
  if( libcdata_array_append_entry(
619
2.75M
       internal_xml_value->data_segments,
620
2.75M
       data_segment_index,
621
2.75M
       (intptr_t *) data_segment,
622
2.75M
       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.75M
  internal_xml_value->data_size += data_size;
634
635
2.75M
  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.75M
}
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 not 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 not 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 not 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 not 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
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
2129
0
  static char *function                             = "libfwevt_xml_value_get_utf8_string_size";
2130
2131
0
  if( xml_value == NULL )
2132
0
  {
2133
0
    libcerror_error_set(
2134
0
     error,
2135
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2136
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2137
0
     "%s: invalid XML value.",
2138
0
     function );
2139
2140
0
    return( -1 );
2141
0
  }
2142
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
2143
2144
0
  if( libfwevt_internal_xml_value_get_data_as_utf8_string_size(
2145
0
       internal_xml_value,
2146
0
       utf8_string_size,
2147
0
       0,
2148
0
       error ) != 1 )
2149
0
  {
2150
0
    libcerror_error_set(
2151
0
     error,
2152
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2153
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2154
0
     "%s: unable to retrieve size of UTF-8 string.",
2155
0
     function );
2156
2157
0
    return( -1 );
2158
0
  }
2159
0
  return( 1 );
2160
0
}
2161
2162
/* Copies the value data to an UTF-8 encoded string
2163
 * Returns 1 if successful or -1 on error
2164
 */
2165
int libfwevt_xml_value_copy_to_utf8_string(
2166
     libfwevt_xml_value_t *xml_value,
2167
     uint8_t *utf8_string,
2168
     size_t utf8_string_size,
2169
     libcerror_error_t **error )
2170
0
{
2171
0
  static char *function = "libfwevt_xml_value_copy_to_utf8_string";
2172
2173
0
  if( libfwevt_xml_value_get_data_as_utf8_string(
2174
0
       xml_value,
2175
0
       utf8_string,
2176
0
       utf8_string_size,
2177
0
       error ) != 1 )
2178
0
  {
2179
0
    libcerror_error_set(
2180
0
     error,
2181
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2182
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2183
0
     "%s: unable to retrieve size of UTF-8 string.",
2184
0
     function );
2185
2186
0
    return( -1 );
2187
0
  }
2188
0
  return( 1 );
2189
0
}
2190
2191
/* Retrieves the size of the value data formatted as an UTF-8 string
2192
 * The string size includes the end of string character
2193
 * Returns 1 if successful or -1 on error
2194
 */
2195
int libfwevt_xml_value_get_data_as_utf8_string_size(
2196
     libfwevt_xml_value_t *xml_value,
2197
     size_t *utf8_string_size,
2198
     libcerror_error_t **error )
2199
0
{
2200
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
2201
0
  static char *function                             = "libfwevt_xml_value_get_data_as_utf8_string_size";
2202
2203
0
  if( xml_value == NULL )
2204
0
  {
2205
0
    libcerror_error_set(
2206
0
     error,
2207
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2208
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2209
0
     "%s: invalid XML value.",
2210
0
     function );
2211
2212
0
    return( -1 );
2213
0
  }
2214
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
2215
2216
0
  if( libfwevt_internal_xml_value_get_data_as_utf8_string_size(
2217
0
       internal_xml_value,
2218
0
       utf8_string_size,
2219
0
       0,
2220
0
       error ) != 1 )
2221
0
  {
2222
0
    libcerror_error_set(
2223
0
     error,
2224
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2225
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2226
0
     "%s: unable to retrieve UTF-8 string size.",
2227
0
     function );
2228
2229
0
    return( -1 );
2230
0
  }
2231
0
  return( 1 );
2232
0
}
2233
2234
/* Retrieves the data formatted as an UTF-8 string
2235
 * The string size should include the end of string character
2236
 * Returns 1 if successful or -1 on error
2237
 */
2238
int libfwevt_xml_value_get_data_as_utf8_string(
2239
     libfwevt_xml_value_t *xml_value,
2240
     uint8_t *utf8_string,
2241
     size_t utf8_string_size,
2242
     libcerror_error_t **error )
2243
0
{
2244
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
2245
0
  static char *function                             = "libfwevt_xml_value_get_data_as_utf8_string";
2246
0
  size_t utf8_string_index                          = 0;
2247
2248
0
  if( xml_value == NULL )
2249
0
  {
2250
0
    libcerror_error_set(
2251
0
     error,
2252
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2253
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2254
0
     "%s: invalid XML value.",
2255
0
     function );
2256
2257
0
    return( -1 );
2258
0
  }
2259
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
2260
2261
0
  if( libfwevt_internal_xml_value_get_data_as_utf8_string_with_index(
2262
0
       internal_xml_value,
2263
0
       utf8_string,
2264
0
       utf8_string_size,
2265
0
       &utf8_string_index,
2266
0
       0,
2267
0
       error ) != 1 )
2268
0
  {
2269
0
    libcerror_error_set(
2270
0
     error,
2271
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2272
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2273
0
     "%s: unable to retrieve size of UTF-8 string.",
2274
0
     function );
2275
2276
0
    return( -1 );
2277
0
  }
2278
0
  return( 1 );
2279
0
}
2280
2281
/* Retrieves the size of the data segment formatted as an UTF-16 string
2282
 * The string size includes the end of string character
2283
 * Returns 1 if successful or -1 on error
2284
 */
2285
int libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size(
2286
     libfwevt_internal_xml_value_t *internal_xml_value,
2287
     int data_segment_index,
2288
     libfwevt_data_segment_t *data_segment,
2289
     size_t *utf16_string_size,
2290
     uint8_t escape_characters,
2291
     libcerror_error_t **error )
2292
0
{
2293
0
  static char *function         = "libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size";
2294
0
  size_t base16_stream_size     = 0;
2295
0
  size_t safe_utf16_string_size = 0;
2296
0
  uint32_t format_flags         = 0;
2297
0
  int result                    = 0;
2298
2299
0
  if( internal_xml_value == NULL )
2300
0
  {
2301
0
    libcerror_error_set(
2302
0
     error,
2303
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2304
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2305
0
     "%s: invalid XML value.",
2306
0
     function );
2307
2308
0
    return( -1 );
2309
0
  }
2310
0
  if( data_segment == NULL )
2311
0
  {
2312
0
    libcerror_error_set(
2313
0
     error,
2314
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2315
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2316
0
     "%s: invalid data segment.",
2317
0
     function );
2318
2319
0
    return( -1 );
2320
0
  }
2321
0
  if( utf16_string_size == NULL )
2322
0
  {
2323
0
    libcerror_error_set(
2324
0
     error,
2325
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2326
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2327
0
     "%s: invalid UTF-16 string size.",
2328
0
     function );
2329
2330
0
    return( -1 );
2331
0
  }
2332
0
  switch( internal_xml_value->value_type & 0x7f )
2333
0
  {
2334
0
    case LIBFWEVT_VALUE_TYPE_STRING_UTF16:
2335
0
      if( data_segment->data_size == 0 )
2336
0
      {
2337
0
        result = 1;
2338
0
      }
2339
0
      else if( escape_characters == 0 )
2340
0
      {
2341
0
        result = libuna_utf16_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
      else
2349
0
      {
2350
0
        result = libfwevt_utf16_xml_string_size_from_utf16_stream(
2351
0
                  data_segment->data,
2352
0
                  data_segment->data_size,
2353
0
                  LIBUNA_ENDIAN_LITTLE,
2354
0
                  &safe_utf16_string_size,
2355
0
                  error );
2356
0
      }
2357
0
      break;
2358
2359
0
    case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM:
2360
0
      if( data_segment->data_size == 0 )
2361
0
      {
2362
0
        result = 1;
2363
0
      }
2364
0
      else
2365
0
      {
2366
/* TODO pass codepage */
2367
0
        result = libuna_utf16_string_size_from_byte_stream(
2368
0
                  data_segment->data,
2369
0
                  data_segment->data_size,
2370
0
                  LIBUNA_CODEPAGE_WINDOWS_1252,
2371
0
                  &safe_utf16_string_size,
2372
0
                  error );
2373
0
      }
2374
/* TODO add support for escape_characters */
2375
0
      break;
2376
2377
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT:
2378
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2379
0
                data_segment->value_64bit,
2380
0
                8,
2381
0
                &safe_utf16_string_size,
2382
0
                error );
2383
0
      break;
2384
2385
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT:
2386
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2387
0
                data_segment->value_64bit,
2388
0
                16,
2389
0
                &safe_utf16_string_size,
2390
0
                error );
2391
0
      break;
2392
2393
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT:
2394
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2395
0
                data_segment->value_64bit,
2396
0
                32,
2397
0
                &safe_utf16_string_size,
2398
0
                error );
2399
0
      break;
2400
2401
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT:
2402
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2403
0
                data_segment->value_64bit,
2404
0
                64,
2405
0
                &safe_utf16_string_size,
2406
0
                error );
2407
0
      break;
2408
2409
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT:
2410
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT:
2411
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT:
2412
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT:
2413
0
      result = libfwevt_integer_as_unsigned_decimal_get_string_size(
2414
0
                data_segment->value_64bit,
2415
0
                &safe_utf16_string_size,
2416
0
                error );
2417
0
      break;
2418
2419
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT:
2420
0
      result = libfwevt_float32_get_string_size(
2421
0
                (uint32_t) data_segment->value_64bit,
2422
0
                &safe_utf16_string_size,
2423
0
                error );
2424
0
      break;
2425
2426
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT:
2427
0
      result = libfwevt_float64_get_string_size(
2428
0
                data_segment->value_64bit,
2429
0
                &safe_utf16_string_size,
2430
0
                error );
2431
0
      break;
2432
2433
0
    case LIBFWEVT_VALUE_TYPE_BOOLEAN:
2434
0
      if( data_segment->value_64bit == 0 )
2435
0
      {
2436
0
        safe_utf16_string_size += 6;
2437
0
      }
2438
0
      else
2439
0
      {
2440
0
        safe_utf16_string_size += 5;
2441
0
      }
2442
0
      result = 1;
2443
2444
0
      break;
2445
2446
0
    case LIBFWEVT_VALUE_TYPE_BINARY_DATA:
2447
0
      if( data_segment->data_size == 0 )
2448
0
      {
2449
0
        result = 1;
2450
0
      }
2451
0
      else
2452
0
      {
2453
0
        format_flags = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE;
2454
2455
0
        if( _BYTE_STREAM_HOST_IS_ENDIAN_BIG )
2456
0
        {
2457
0
          format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN;
2458
0
        }
2459
0
        else if( _BYTE_STREAM_HOST_IS_ENDIAN_LITTLE )
2460
0
        {
2461
0
          format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN;
2462
0
        }
2463
0
        result = libuna_base16_stream_size_from_byte_stream(
2464
0
                  data_segment->data,
2465
0
                  data_segment->data_size,
2466
0
                  &base16_stream_size,
2467
0
                  format_flags,
2468
0
                  error );
2469
2470
0
        if( result == 1 )
2471
0
        {
2472
0
          safe_utf16_string_size += ( base16_stream_size / 2 ) + 1;
2473
0
        }
2474
0
      }
2475
0
      break;
2476
2477
0
    case LIBFWEVT_VALUE_TYPE_GUID:
2478
0
      result = libfguid_identifier_get_string_size(
2479
0
                data_segment->guid,
2480
0
                &safe_utf16_string_size,
2481
0
                LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
2482
0
                error );
2483
0
      break;
2484
2485
0
    case LIBFWEVT_VALUE_TYPE_FILETIME:
2486
0
      result = libfdatetime_filetime_get_string_size(
2487
0
                data_segment->filetime,
2488
0
                &safe_utf16_string_size,
2489
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2490
0
                error );
2491
0
      break;
2492
2493
0
    case LIBFWEVT_VALUE_TYPE_SYSTEMTIME:
2494
0
      result = libfdatetime_systemtime_get_string_size(
2495
0
                data_segment->systemtime,
2496
0
                &safe_utf16_string_size,
2497
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2498
0
                error );
2499
0
      break;
2500
2501
0
    case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER:
2502
0
      result = libfwnt_security_identifier_get_string_size(
2503
0
                data_segment->security_identifier,
2504
0
                &safe_utf16_string_size,
2505
0
          0,
2506
0
                error );
2507
0
      break;
2508
2509
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT:
2510
0
      safe_utf16_string_size = 11;
2511
2512
0
      result = 1;
2513
0
      break;
2514
2515
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT:
2516
0
      safe_utf16_string_size = 19;
2517
2518
0
      result = 1;
2519
0
      break;
2520
2521
0
    default:
2522
0
      break;
2523
0
  }
2524
0
  if( result != 1 )
2525
0
  {
2526
0
    libcerror_error_set(
2527
0
     error,
2528
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2529
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2530
0
     "%s: unable to determine size UTF-16 string of data segment: %d.",
2531
0
     function,
2532
0
     data_segment_index );
2533
2534
0
    return( -1 );
2535
0
  }
2536
0
  *utf16_string_size = safe_utf16_string_size;
2537
2538
0
  return( 1 );
2539
0
}
2540
2541
/* Retrieves the data segment formatted as an UTF-16 string
2542
 * Returns 1 if successful or -1 on error
2543
 */
2544
int libfwevt_internal_xml_value_get_data_segment_as_utf16_string(
2545
     libfwevt_internal_xml_value_t *internal_xml_value,
2546
     int data_segment_index,
2547
     libfwevt_data_segment_t *data_segment,
2548
     uint16_t *utf16_string,
2549
     size_t utf16_string_size,
2550
     size_t *utf16_string_index,
2551
     uint8_t escape_characters,
2552
     libcerror_error_t **error )
2553
0
{
2554
0
  static char *function          = "libfwevt_internal_xml_value_get_data_segment_as_utf16_string";
2555
0
  size_t base16_stream_index     = 0;
2556
0
  size_t safe_utf16_string_index = 0;
2557
0
  uint32_t format_flags          = 0;
2558
0
  uint8_t number_of_characters   = 0;
2559
0
  int result                     = 0;
2560
2561
0
  if( internal_xml_value == NULL )
2562
0
  {
2563
0
    libcerror_error_set(
2564
0
     error,
2565
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2566
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2567
0
     "%s: invalid XML value.",
2568
0
     function );
2569
2570
0
    return( -1 );
2571
0
  }
2572
0
  if( data_segment == NULL )
2573
0
  {
2574
0
    libcerror_error_set(
2575
0
     error,
2576
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2577
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2578
0
     "%s: invalid data segment.",
2579
0
     function );
2580
2581
0
    return( -1 );
2582
0
  }
2583
0
  if( utf16_string == NULL )
2584
0
  {
2585
0
    libcerror_error_set(
2586
0
     error,
2587
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2588
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2589
0
     "%s: invalid UTF-16 string.",
2590
0
     function );
2591
2592
0
    return( -1 );
2593
0
  }
2594
0
  if( utf16_string_size > (size_t) SSIZE_MAX )
2595
0
  {
2596
0
    libcerror_error_set(
2597
0
     error,
2598
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2599
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
2600
0
     "%s: invalid UTF-16 string size value exceeds maximum.",
2601
0
     function );
2602
2603
0
    return( -1 );
2604
0
  }
2605
0
  if( utf16_string_index == NULL )
2606
0
  {
2607
0
    libcerror_error_set(
2608
0
     error,
2609
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2610
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2611
0
     "%s: invalid UTF-16 string index.",
2612
0
     function );
2613
2614
0
    return( -1 );
2615
0
  }
2616
0
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
2617
0
       internal_xml_value,
2618
0
       data_segment_index,
2619
0
       &data_segment,
2620
0
       error ) != 1 )
2621
0
  {
2622
0
    libcerror_error_set(
2623
0
     error,
2624
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2625
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2626
0
     "%s: unable to retrieve data segment: %d.",
2627
0
     function,
2628
0
     data_segment_index );
2629
2630
0
    return( -1 );
2631
0
  }
2632
0
  switch( internal_xml_value->value_type & 0x7f )
2633
0
  {
2634
0
    case LIBFWEVT_VALUE_TYPE_STRING_UTF16:
2635
0
      if( data_segment->data_size == 0 )
2636
0
      {
2637
0
        result = 1;
2638
0
      }
2639
0
      else if( escape_characters == 0 )
2640
0
      {
2641
0
        result = libuna_utf16_string_with_index_copy_from_utf16_stream(
2642
0
                  utf16_string,
2643
0
                  utf16_string_size,
2644
0
                  utf16_string_index,
2645
0
                  data_segment->data,
2646
0
                  data_segment->data_size,
2647
0
                  LIBUNA_ENDIAN_LITTLE,
2648
0
                  error );
2649
0
      }
2650
0
      else
2651
0
      {
2652
0
        result = libfwevt_utf16_xml_string_with_index_copy_from_utf16_stream(
2653
0
                  utf16_string,
2654
0
                  utf16_string_size,
2655
0
                  utf16_string_index,
2656
0
                  data_segment->data,
2657
0
                  data_segment->data_size,
2658
0
                  LIBUNA_ENDIAN_LITTLE,
2659
0
                  error );
2660
0
      }
2661
0
      break;
2662
2663
0
    case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM:
2664
/* TODO pass codepage */
2665
0
      result = libuna_utf16_string_with_index_copy_from_byte_stream(
2666
0
                utf16_string,
2667
0
                utf16_string_size,
2668
0
                utf16_string_index,
2669
0
                data_segment->data,
2670
0
                data_segment->data_size,
2671
0
                LIBUNA_CODEPAGE_WINDOWS_1252,
2672
0
                error );
2673
/* TODO add support for escape_characters */
2674
0
      break;
2675
2676
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT:
2677
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2678
0
                data_segment->value_64bit,
2679
0
                8,
2680
0
                utf16_string,
2681
0
                utf16_string_size,
2682
0
                utf16_string_index,
2683
0
                error );
2684
0
      break;
2685
2686
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT:
2687
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2688
0
                data_segment->value_64bit,
2689
0
                16,
2690
0
                utf16_string,
2691
0
                utf16_string_size,
2692
0
                utf16_string_index,
2693
0
                error );
2694
0
      break;
2695
2696
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT:
2697
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2698
0
                data_segment->value_64bit,
2699
0
                32,
2700
0
                utf16_string,
2701
0
                utf16_string_size,
2702
0
                utf16_string_index,
2703
0
                error );
2704
0
      break;
2705
2706
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT:
2707
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2708
0
                data_segment->value_64bit,
2709
0
                64,
2710
0
                utf16_string,
2711
0
                utf16_string_size,
2712
0
                utf16_string_index,
2713
0
                error );
2714
0
      break;
2715
2716
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT:
2717
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT:
2718
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT:
2719
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT:
2720
0
      result = libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index(
2721
0
                data_segment->value_64bit,
2722
0
                utf16_string,
2723
0
                utf16_string_size,
2724
0
                utf16_string_index,
2725
0
                error );
2726
0
      break;
2727
2728
2729
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT:
2730
0
      result = libfwevt_float32_copy_to_utf16_string_with_index(
2731
0
                (uint32_t) 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_FLOATING_POINT_64BIT:
2739
0
      result = libfwevt_float64_copy_to_utf16_string_with_index(
2740
0
                data_segment->value_64bit,
2741
0
                utf16_string,
2742
0
                utf16_string_size,
2743
0
                utf16_string_index,
2744
0
                error );
2745
0
      break;
2746
2747
0
    case LIBFWEVT_VALUE_TYPE_BOOLEAN:
2748
0
      if( data_segment->value_64bit == 0 )
2749
0
      {
2750
0
        number_of_characters = 6;
2751
0
      }
2752
0
      else
2753
0
      {
2754
0
        number_of_characters = 5;
2755
0
      }
2756
0
      safe_utf16_string_index = *utf16_string_index;
2757
2758
0
      if( ( number_of_characters > utf16_string_size )
2759
0
       || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) )
2760
0
      {
2761
0
        libcerror_error_set(
2762
0
         error,
2763
0
         LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2764
0
         LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
2765
0
         "%s: invalid UTF-16 string size value too small.",
2766
0
         function );
2767
2768
0
        return( -1 );
2769
0
      }
2770
0
      if( data_segment->value_64bit == 0 )
2771
0
      {
2772
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'f';
2773
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'a';
2774
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'l';
2775
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 's';
2776
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e';
2777
0
      }
2778
0
      else
2779
0
      {
2780
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 't';
2781
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'r';
2782
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'u';
2783
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e';
2784
0
      }
2785
0
      utf16_string[ safe_utf16_string_index++ ] = 0;
2786
2787
0
      *utf16_string_index = safe_utf16_string_index;
2788
2789
0
      result = 1;
2790
2791
0
      break;
2792
2793
0
    case LIBFWEVT_VALUE_TYPE_BINARY_DATA:
2794
0
      base16_stream_index = *utf16_string_index * 2;
2795
0
      format_flags        = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE;
2796
2797
0
      if( _BYTE_STREAM_HOST_IS_ENDIAN_BIG )
2798
0
      {
2799
0
        format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN;
2800
0
      }
2801
0
      else if( _BYTE_STREAM_HOST_IS_ENDIAN_LITTLE )
2802
0
      {
2803
0
        format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN;
2804
0
      }
2805
0
      result = libuna_base16_stream_with_index_copy_from_byte_stream(
2806
0
                (uint8_t *) utf16_string,
2807
0
                utf16_string_size * 2,
2808
0
                &base16_stream_index,
2809
0
                data_segment->data,
2810
0
                data_segment->data_size,
2811
0
                format_flags,
2812
0
                error );
2813
2814
0
      if( result == 1 )
2815
0
      {
2816
0
        *utf16_string_index = ( base16_stream_index / 2 ) + 1;
2817
0
      }
2818
0
      break;
2819
2820
0
    case LIBFWEVT_VALUE_TYPE_GUID:
2821
0
      result = libfguid_identifier_copy_to_utf16_string_with_index(
2822
0
                data_segment->guid,
2823
0
                utf16_string,
2824
0
                utf16_string_size,
2825
0
                utf16_string_index,
2826
0
                LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
2827
0
                error );
2828
0
      break;
2829
2830
0
    case LIBFWEVT_VALUE_TYPE_FILETIME:
2831
0
      result = libfdatetime_filetime_copy_to_utf16_string_with_index(
2832
0
                data_segment->filetime,
2833
0
                utf16_string,
2834
0
                utf16_string_size,
2835
0
                utf16_string_index,
2836
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2837
0
                error );
2838
0
      break;
2839
2840
0
    case LIBFWEVT_VALUE_TYPE_SYSTEMTIME:
2841
0
      result = libfdatetime_systemtime_copy_to_utf16_string_with_index(
2842
0
                data_segment->systemtime,
2843
0
                utf16_string,
2844
0
                utf16_string_size,
2845
0
                utf16_string_index,
2846
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2847
0
                error );
2848
0
      break;
2849
2850
0
    case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER:
2851
0
      result = libfwnt_security_identifier_copy_to_utf16_string_with_index(
2852
0
                data_segment->security_identifier,
2853
0
                utf16_string,
2854
0
                utf16_string_size,
2855
0
                utf16_string_index,
2856
0
          0,
2857
0
                error );
2858
0
      break;
2859
2860
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT:
2861
0
      result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index(
2862
0
                data_segment->value_64bit,
2863
0
                32,
2864
0
                utf16_string,
2865
0
                utf16_string_size,
2866
0
                utf16_string_index,
2867
0
                error );
2868
0
      break;
2869
2870
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT:
2871
0
      result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index(
2872
0
                data_segment->value_64bit,
2873
0
                64,
2874
0
                utf16_string,
2875
0
                utf16_string_size,
2876
0
                utf16_string_index,
2877
0
                error );
2878
0
      break;
2879
2880
0
    default:
2881
0
      break;
2882
0
  }
2883
0
  if( result != 1 )
2884
0
  {
2885
0
    libcerror_error_set(
2886
0
     error,
2887
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2888
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2889
0
     "%s: unable to copy data segment: %d to UTF-16 string.",
2890
0
     function,
2891
0
     data_segment_index );
2892
2893
0
    return( -1 );
2894
0
  }
2895
0
  return( 1 );
2896
0
}
2897
2898
/* Retrieves the size of the value data formatted as an UTF-16 string
2899
 * The string size includes the end of string character
2900
 * Returns 1 if successful or -1 on error
2901
 */
2902
int libfwevt_internal_xml_value_get_data_as_utf16_string_size(
2903
     libfwevt_internal_xml_value_t *internal_xml_value,
2904
     size_t *utf16_string_size,
2905
     uint8_t escape_characters,
2906
     libcerror_error_t **error )
2907
0
{
2908
0
  libfwevt_data_segment_t *data_segment = NULL;
2909
0
  static char *function                 = "libfwevt_internal_xml_value_get_data_as_utf16_string_size";
2910
0
  size_t data_segment_size              = 0;
2911
0
  size_t safe_utf16_string_size         = 0;
2912
0
  int data_segment_index                = 0;
2913
0
  int number_of_data_segments           = 0;
2914
2915
0
  if( internal_xml_value == NULL )
2916
0
  {
2917
0
    libcerror_error_set(
2918
0
     error,
2919
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2920
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2921
0
     "%s: invalid XML value.",
2922
0
     function );
2923
2924
0
    return( -1 );
2925
0
  }
2926
0
  if( utf16_string_size == NULL )
2927
0
  {
2928
0
    libcerror_error_set(
2929
0
     error,
2930
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2931
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2932
0
     "%s: invalid UTF-16 string size.",
2933
0
     function );
2934
2935
0
    return( -1 );
2936
0
  }
2937
0
  if( libcdata_array_get_number_of_entries(
2938
0
       internal_xml_value->data_segments,
2939
0
       &number_of_data_segments,
2940
0
       error ) != 1 )
2941
0
  {
2942
0
    libcerror_error_set(
2943
0
     error,
2944
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2945
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2946
0
     "%s: unable to retrieve number of data segments.",
2947
0
     function );
2948
2949
0
    return( -1 );
2950
0
  }
2951
0
  for( data_segment_index = 0;
2952
0
       data_segment_index < number_of_data_segments;
2953
0
       data_segment_index++ )
2954
0
  {
2955
0
    if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
2956
0
         internal_xml_value,
2957
0
         data_segment_index,
2958
0
         &data_segment,
2959
0
         error ) != 1 )
2960
0
    {
2961
0
      libcerror_error_set(
2962
0
       error,
2963
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2964
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2965
0
       "%s: unable to retrieve data segment: %d.",
2966
0
       function,
2967
0
       data_segment_index );
2968
2969
0
      return( -1 );
2970
0
    }
2971
0
    if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size(
2972
0
         internal_xml_value,
2973
0
         data_segment_index,
2974
0
         data_segment,
2975
0
         &data_segment_size,
2976
0
         escape_characters,
2977
0
         error ) != 1 )
2978
0
    {
2979
0
      libcerror_error_set(
2980
0
       error,
2981
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2982
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2983
0
       "%s: unable to retrieve UTF-16 string size of element data segment: %d.",
2984
0
       function,
2985
0
       data_segment_index );
2986
2987
0
      return( -1 );
2988
0
    }
2989
0
    if( data_segment_size > 1 )
2990
0
    {
2991
0
      safe_utf16_string_size += data_segment_size - 1;
2992
0
    }
2993
0
  }
2994
0
  if( ( number_of_data_segments == 1 )
2995
0
   && ( data_segment != NULL )
2996
0
   && ( safe_utf16_string_size == 1 ) )
2997
0
  {
2998
0
    if( ( data_segment->data_size >= 2 )
2999
0
     && ( data_segment->data[ 0 ] == '\n' )
3000
0
     && ( data_segment->data[ 1 ] == 0 ) )
3001
0
    {
3002
      /* The value data consists of a single linefeed consider it empty
3003
       */
3004
0
      safe_utf16_string_size = 0;
3005
0
    }
3006
0
  }
3007
0
  if( safe_utf16_string_size > 0 )
3008
0
  {
3009
0
    safe_utf16_string_size++;
3010
0
  }
3011
0
  *utf16_string_size = safe_utf16_string_size;
3012
3013
0
  return( 1 );
3014
0
}
3015
3016
/* Retrieves the data formatted as an UTF-16 string
3017
 * The string size should include the end of string character
3018
 * Returns 1 if successful or -1 on error
3019
 */
3020
int libfwevt_internal_xml_value_get_data_as_utf16_string_with_index(
3021
     libfwevt_internal_xml_value_t *internal_xml_value,
3022
     uint16_t *utf16_string,
3023
     size_t utf16_string_size,
3024
     size_t *utf16_string_index,
3025
     uint8_t escape_characters,
3026
     libcerror_error_t **error )
3027
0
{
3028
0
  libfwevt_data_segment_t *data_segment = NULL;
3029
0
  static char *function                 = "libfwevt_internal_xml_value_get_data_as_utf16_string_with_index";
3030
0
  size_t safe_utf16_string_index        = 0;
3031
0
  int data_segment_index                = 0;
3032
0
  int number_of_data_segments           = 0;
3033
3034
0
  if( internal_xml_value == NULL )
3035
0
  {
3036
0
    libcerror_error_set(
3037
0
     error,
3038
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3039
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3040
0
     "%s: invalid XML value.",
3041
0
     function );
3042
3043
0
    return( -1 );
3044
0
  }
3045
0
  if( utf16_string == NULL )
3046
0
  {
3047
0
    libcerror_error_set(
3048
0
     error,
3049
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3050
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3051
0
     "%s: invalid UTF-16 string.",
3052
0
     function );
3053
3054
0
    return( -1 );
3055
0
  }
3056
0
  if( utf16_string_size > (size_t) SSIZE_MAX )
3057
0
  {
3058
0
    libcerror_error_set(
3059
0
     error,
3060
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3061
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
3062
0
     "%s: invalid UTF-16 string size value exceeds maximum.",
3063
0
     function );
3064
3065
0
    return( -1 );
3066
0
  }
3067
0
  if( utf16_string_index == NULL )
3068
0
  {
3069
0
    libcerror_error_set(
3070
0
     error,
3071
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3072
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3073
0
     "%s: invalid UTF-16 string index.",
3074
0
     function );
3075
3076
0
    return( -1 );
3077
0
  }
3078
0
  safe_utf16_string_index = *utf16_string_index;
3079
3080
0
  if( libcdata_array_get_number_of_entries(
3081
0
       internal_xml_value->data_segments,
3082
0
       &number_of_data_segments,
3083
0
       error ) != 1 )
3084
0
  {
3085
0
    libcerror_error_set(
3086
0
     error,
3087
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3088
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3089
0
     "%s: unable to retrieve number of data segments.",
3090
0
     function );
3091
3092
0
    return( -1 );
3093
0
  }
3094
0
  for( data_segment_index = 0;
3095
0
       data_segment_index < number_of_data_segments;
3096
0
       data_segment_index++ )
3097
0
  {
3098
0
    if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
3099
0
         internal_xml_value,
3100
0
         data_segment_index,
3101
0
         &data_segment,
3102
0
         error ) != 1 )
3103
0
    {
3104
0
      libcerror_error_set(
3105
0
       error,
3106
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3107
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3108
0
       "%s: unable to retrieve data segment: %d.",
3109
0
       function,
3110
0
       data_segment_index );
3111
3112
0
      return( -1 );
3113
0
    }
3114
0
    if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string(
3115
0
         internal_xml_value,
3116
0
         data_segment_index,
3117
0
         data_segment,
3118
0
         utf16_string,
3119
0
         utf16_string_size,
3120
0
         &safe_utf16_string_index,
3121
0
         escape_characters,
3122
0
         error ) != 1 )
3123
0
    {
3124
0
      libcerror_error_set(
3125
0
       error,
3126
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3127
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3128
0
       "%s: unable to copy data segment: %d to UTF-16 string.",
3129
0
       function,
3130
0
       data_segment_index );
3131
3132
0
      return( -1 );
3133
0
    }
3134
0
    safe_utf16_string_index--;
3135
0
  }
3136
0
  if( ( number_of_data_segments == 1 )
3137
0
   && ( data_segment != NULL )
3138
0
   && ( safe_utf16_string_index == 1 ) )
3139
0
  {
3140
0
    if( ( data_segment->data_size >= 2 )
3141
0
     && ( data_segment->data[ 0 ] == '\n' )
3142
0
     && ( data_segment->data[ 1 ] == 0 ) )
3143
0
    {
3144
      /* The value data consists of a single linefeed consider it empty
3145
       */
3146
0
      safe_utf16_string_index = 0;
3147
0
    }
3148
0
  }
3149
0
  if( safe_utf16_string_index > 0 )
3150
0
  {
3151
0
    if( safe_utf16_string_index >= utf16_string_size  )
3152
0
    {
3153
0
      libcerror_error_set(
3154
0
       error,
3155
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3156
0
       LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
3157
0
       "%s: invalid UTF-16 string size value too small.",
3158
0
       function );
3159
3160
0
      return( -1 );
3161
0
    }
3162
0
    utf16_string[ safe_utf16_string_index++ ] = 0;
3163
0
  }
3164
0
  *utf16_string_index = safe_utf16_string_index;
3165
3166
0
  return( 1 );
3167
0
}
3168
3169
/* Retrieves the size of an UTF-16 encoded string of the value data
3170
 * Returns 1 if successful or -1 on error
3171
 */
3172
int libfwevt_xml_value_get_utf16_string_size(
3173
     libfwevt_xml_value_t *xml_value,
3174
     size_t *utf16_string_size,
3175
     libcerror_error_t **error )
3176
0
{
3177
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3178
0
  static char *function                             = "libfwevt_xml_value_get_utf16_string_size";
3179
3180
0
  if( xml_value == NULL )
3181
0
  {
3182
0
    libcerror_error_set(
3183
0
     error,
3184
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3185
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3186
0
     "%s: invalid XML value.",
3187
0
     function );
3188
3189
0
    return( -1 );
3190
0
  }
3191
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3192
3193
0
  if( libfwevt_internal_xml_value_get_data_as_utf16_string_size(
3194
0
       internal_xml_value,
3195
0
       utf16_string_size,
3196
0
       0,
3197
0
       error ) != 1 )
3198
0
  {
3199
0
    libcerror_error_set(
3200
0
     error,
3201
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3202
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3203
0
     "%s: unable to retrieve size of UTF-16 string.",
3204
0
     function );
3205
3206
0
    return( -1 );
3207
0
  }
3208
0
  return( 1 );
3209
0
}
3210
3211
/* Copies the value data to an UTF-16 encoded string
3212
 * Returns 1 if successful or -1 on error
3213
 */
3214
int libfwevt_xml_value_copy_to_utf16_string(
3215
     libfwevt_xml_value_t *xml_value,
3216
     uint16_t *utf16_string,
3217
     size_t utf16_string_size,
3218
     libcerror_error_t **error )
3219
0
{
3220
0
  static char *function = "libfwevt_xml_value_copy_to_utf16_string";
3221
3222
0
  if( libfwevt_xml_value_get_data_as_utf16_string(
3223
0
       xml_value,
3224
0
       utf16_string,
3225
0
       utf16_string_size,
3226
0
       error ) != 1 )
3227
0
  {
3228
0
    libcerror_error_set(
3229
0
     error,
3230
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3231
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3232
0
     "%s: unable to retrieve size of UTF-16 string.",
3233
0
     function );
3234
3235
0
    return( -1 );
3236
0
  }
3237
0
  return( 1 );
3238
0
}
3239
3240
/* Retrieves the size of the value data formatted as an UTF-16 string
3241
 * The string size includes the end of string character
3242
 * Returns 1 if successful or -1 on error
3243
 */
3244
int libfwevt_xml_value_get_data_as_utf16_string_size(
3245
     libfwevt_xml_value_t *xml_value,
3246
     size_t *utf16_string_size,
3247
     libcerror_error_t **error )
3248
0
{
3249
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3250
0
  static char *function                             = "libfwevt_xml_value_get_data_as_utf16_string_size";
3251
3252
0
  if( xml_value == NULL )
3253
0
  {
3254
0
    libcerror_error_set(
3255
0
     error,
3256
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3257
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3258
0
     "%s: invalid XML value.",
3259
0
     function );
3260
3261
0
    return( -1 );
3262
0
  }
3263
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3264
3265
0
  if( libfwevt_internal_xml_value_get_data_as_utf16_string_size(
3266
0
       internal_xml_value,
3267
0
       utf16_string_size,
3268
0
       0,
3269
0
       error ) != 1 )
3270
0
  {
3271
0
    libcerror_error_set(
3272
0
     error,
3273
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3274
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3275
0
     "%s: unable to retrieve UTF-16 string size.",
3276
0
     function );
3277
3278
0
    return( -1 );
3279
0
  }
3280
0
  return( 1 );
3281
0
}
3282
3283
/* Retrieves the data formatted as an UTF-16 string
3284
 * The string size should include the end of string character
3285
 * Returns 1 if successful or -1 on error
3286
 */
3287
int libfwevt_xml_value_get_data_as_utf16_string(
3288
     libfwevt_xml_value_t *xml_value,
3289
     uint16_t *utf16_string,
3290
     size_t utf16_string_size,
3291
     libcerror_error_t **error )
3292
0
{
3293
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3294
0
  static char *function                             = "libfwevt_xml_value_get_data_as_utf16_string";
3295
0
  size_t utf16_string_index                         = 0;
3296
3297
0
  if( xml_value == NULL )
3298
0
  {
3299
0
    libcerror_error_set(
3300
0
     error,
3301
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3302
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3303
0
     "%s: invalid XML value.",
3304
0
     function );
3305
3306
0
    return( -1 );
3307
0
  }
3308
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3309
3310
0
  if( libfwevt_internal_xml_value_get_data_as_utf16_string_with_index(
3311
0
       internal_xml_value,
3312
0
       utf16_string,
3313
0
       utf16_string_size,
3314
0
       &utf16_string_index,
3315
0
       0,
3316
0
       error ) != 1 )
3317
0
  {
3318
0
    libcerror_error_set(
3319
0
     error,
3320
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3321
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3322
0
     "%s: unable to retrieve size of UTF-16 string.",
3323
0
     function );
3324
3325
0
    return( -1 );
3326
0
  }
3327
0
  return( 1 );
3328
0
}
3329
3330
#if defined( HAVE_DEBUG_OUTPUT )
3331
3332
/* Prints the value
3333
 * Returns 1 if successful or -1 on error
3334
 */
3335
int libfwevt_xml_value_debug_print(
3336
     libfwevt_xml_value_t *xml_value,
3337
     uint8_t escape_characters,
3338
     libcerror_error_t **error )
3339
{
3340
  system_character_t *value_string                  = NULL;
3341
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3342
  static char *function                             = "libfwevt_xml_value_debug_print";
3343
  size_t value_string_index                         = 0;
3344
  size_t value_string_size                          = 0;
3345
  int result                                        = 0;
3346
3347
  if( xml_value == NULL )
3348
  {
3349
    libcerror_error_set(
3350
     error,
3351
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3352
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3353
     "%s: invalid XML value.",
3354
     function );
3355
3356
    return( -1 );
3357
  }
3358
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3359
3360
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3361
  result = libfwevt_internal_xml_value_get_data_as_utf16_string_size(
3362
      internal_xml_value,
3363
      &value_string_size,
3364
      escape_characters,
3365
      error );
3366
#else
3367
  result = libfwevt_internal_xml_value_get_data_as_utf8_string_size(
3368
      internal_xml_value,
3369
      &value_string_size,
3370
      escape_characters,
3371
      error );
3372
#endif
3373
  if( result != 1 )
3374
  {
3375
    libcerror_error_set(
3376
     error,
3377
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3378
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3379
     "%s: unable to determine size of value string.",
3380
     function );
3381
3382
    goto on_error;
3383
  }
3384
  if( value_string_size > 0 )
3385
  {
3386
    if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( system_character_t ) ) )
3387
    {
3388
      libcerror_error_set(
3389
       error,
3390
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3391
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3392
       "%s: invalid name string size value exceeds maximum.",
3393
       function );
3394
3395
      goto on_error;
3396
    }
3397
    value_string = system_string_allocate(
3398
                    value_string_size );
3399
3400
    if( value_string == NULL )
3401
    {
3402
      libcerror_error_set(
3403
       error,
3404
       LIBCERROR_ERROR_DOMAIN_MEMORY,
3405
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
3406
       "%s: unable to create value string.",
3407
       function );
3408
3409
      goto on_error;
3410
    }
3411
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3412
    result = libfwevt_internal_xml_value_get_data_as_utf16_string_with_index(
3413
        internal_xml_value,
3414
        (libuna_utf16_character_t *) value_string,
3415
        value_string_size,
3416
        &value_string_index,
3417
        escape_characters,
3418
        error );
3419
#else
3420
    result = libfwevt_internal_xml_value_get_data_as_utf8_string_with_index(
3421
        internal_xml_value,
3422
        (libuna_utf8_character_t *) value_string,
3423
        value_string_size,
3424
        &value_string_index,
3425
        escape_characters,
3426
        error );
3427
#endif
3428
    if( result != 1 )
3429
    {
3430
      libcerror_error_set(
3431
       error,
3432
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3433
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3434
       "%s: unable to retrieve value string.",
3435
       function );
3436
3437
      goto on_error;
3438
    }
3439
    libcnotify_printf(
3440
     "%" PRIs_SYSTEM "",
3441
     value_string );
3442
3443
    memory_free(
3444
     value_string );
3445
  }
3446
  return( 1 );
3447
3448
on_error:
3449
  if( value_string != NULL )
3450
  {
3451
    memory_free(
3452
     value_string );
3453
  }
3454
  return( -1 );
3455
}
3456
3457
/* Prints the value of a specific data segment
3458
 * Returns 1 if successful or -1 on error
3459
 */
3460
int libfwevt_xml_value_debug_print_data_segment(
3461
     libfwevt_xml_value_t *xml_value,
3462
     int data_segment_index,
3463
     uint8_t escape_characters,
3464
     libcerror_error_t **error )
3465
{
3466
  libfwevt_data_segment_t *data_segment             = NULL;
3467
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3468
  system_character_t *value_string                  = NULL;
3469
  static char *function                             = "libfwevt_xml_value_debug_print_data_segment";
3470
  size_t value_string_index                         = 0;
3471
  size_t value_string_size                          = 0;
3472
  int result                                        = 0;
3473
3474
  if( xml_value == NULL )
3475
  {
3476
    libcerror_error_set(
3477
     error,
3478
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3479
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3480
     "%s: invalid XML value.",
3481
     function );
3482
3483
    return( -1 );
3484
  }
3485
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3486
3487
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
3488
       internal_xml_value,
3489
       data_segment_index,
3490
       &data_segment,
3491
       error ) != 1 )
3492
  {
3493
    libcerror_error_set(
3494
     error,
3495
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3496
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3497
     "%s: unable to retrieve data segment: %d.",
3498
     function,
3499
     data_segment_index );
3500
3501
    return( -1 );
3502
  }
3503
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3504
  result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size(
3505
      internal_xml_value,
3506
      data_segment_index,
3507
            data_segment,
3508
      &value_string_size,
3509
      escape_characters,
3510
      error );
3511
#else
3512
  result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size(
3513
      internal_xml_value,
3514
      data_segment_index,
3515
            data_segment,
3516
      &value_string_size,
3517
      escape_characters,
3518
      error );
3519
#endif
3520
  if( result != 1 )
3521
  {
3522
    libcerror_error_set(
3523
     error,
3524
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3525
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3526
     "%s: unable to determine size of value string of data segment: %d.",
3527
     function,
3528
     data_segment_index );
3529
3530
    goto on_error;
3531
  }
3532
  if( value_string_size > 0 )
3533
  {
3534
    if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( system_character_t ) ) )
3535
    {
3536
      libcerror_error_set(
3537
       error,
3538
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3539
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3540
       "%s: invalid name string size value exceeds maximum.",
3541
       function );
3542
3543
      goto on_error;
3544
    }
3545
    value_string = system_string_allocate(
3546
                    value_string_size );
3547
3548
    if( value_string == NULL )
3549
    {
3550
      libcerror_error_set(
3551
       error,
3552
       LIBCERROR_ERROR_DOMAIN_MEMORY,
3553
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
3554
       "%s: unable to create value string.",
3555
       function );
3556
3557
      goto on_error;
3558
    }
3559
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3560
    result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string(
3561
        internal_xml_value,
3562
        data_segment_index,
3563
              data_segment,
3564
        (libuna_utf16_character_t *) value_string,
3565
        value_string_size,
3566
        &value_string_index,
3567
              escape_characters,
3568
        error );
3569
#else
3570
    result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string(
3571
        internal_xml_value,
3572
        data_segment_index,
3573
              data_segment,
3574
        (libuna_utf8_character_t *) value_string,
3575
        value_string_size,
3576
        &value_string_index,
3577
              escape_characters,
3578
        error );
3579
#endif
3580
    if( result != 1 )
3581
    {
3582
      libcerror_error_set(
3583
       error,
3584
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3585
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3586
       "%s: unable to retrieve value string of data segment: %d.",
3587
       function,
3588
       data_segment_index );
3589
3590
      goto on_error;
3591
    }
3592
    libcnotify_printf(
3593
     "%" PRIs_SYSTEM "",
3594
     value_string );
3595
3596
    memory_free(
3597
     value_string );
3598
  }
3599
  return( 1 );
3600
3601
on_error:
3602
  if( value_string != NULL )
3603
  {
3604
    memory_free(
3605
     value_string );
3606
  }
3607
  return( -1 );
3608
}
3609
3610
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
3611