Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libevtx/libfwevt/libfwevt_xml_value.c
Line
Count
Source
1
/*
2
 * XML value functions
3
 *
4
 * Copyright (C) 2011-2026, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <byte_stream.h>
24
#include <memory.h>
25
#include <narrow_string.h>
26
#include <system_string.h>
27
#include <types.h>
28
#include <wide_string.h>
29
30
#include "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.75M
{
54
1.75M
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
55
1.75M
  static char *function                             = "libfwevt_xml_value_initialize";
56
57
1.75M
  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.75M
  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.75M
  internal_xml_value = memory_allocate_structure(
80
1.75M
                        libfwevt_internal_xml_value_t );
81
82
1.75M
  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.75M
  if( memory_set(
94
1.75M
       internal_xml_value,
95
1.75M
       0,
96
1.75M
       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.75M
  if( libcdata_array_initialize(
111
1.75M
       &( internal_xml_value->data_segments ),
112
1.75M
       0,
113
1.75M
       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.75M
  internal_xml_value->value_type = value_type;
125
126
1.75M
  *xml_value = (libfwevt_xml_value_t *) internal_xml_value;
127
128
1.75M
  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.75M
}
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.75M
{
173
1.75M
  static char *function = "libfwevt_internal_xml_value_free";
174
1.75M
  int result            = 1;
175
176
1.75M
  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.75M
  if( *internal_xml_value != NULL )
188
1.75M
  {
189
1.75M
    if( libcdata_array_free(
190
1.75M
         &( ( *internal_xml_value )->data_segments ),
191
1.75M
         (int (*)(intptr_t **, libcerror_error_t **)) &libfwevt_data_segment_free,
192
1.75M
         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.75M
    memory_free(
204
1.75M
     *internal_xml_value );
205
206
1.75M
    *internal_xml_value = NULL;
207
1.75M
  }
208
1.75M
  return( result );
209
1.75M
}
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
621k
{
219
621k
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
220
621k
  static char *function                             = "libfwevt_xml_value_get_type";
221
222
621k
  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
621k
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
234
235
621k
  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
621k
  *value_type = internal_xml_value->value_type;
247
248
621k
  return( 1 );
249
621k
}
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.37M
{
586
2.37M
  libfwevt_data_segment_t *data_segment             = NULL;
587
2.37M
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
588
2.37M
  static char *function                             = "libfwevt_xml_value_append_data_segment";
589
590
2.37M
  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.37M
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
602
603
2.37M
  if( libfwevt_data_segment_initialize(
604
2.37M
       &data_segment,
605
2.37M
       data,
606
2.37M
       data_size,
607
2.37M
       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.37M
  if( libcdata_array_append_entry(
619
2.37M
       internal_xml_value->data_segments,
620
2.37M
       data_segment_index,
621
2.37M
       (intptr_t *) data_segment,
622
2.37M
       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.37M
  internal_xml_value->data_size += data_size;
634
635
2.37M
  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.37M
}
646
647
/* Retrieves the data size
648
 * Returns 1 if successful or -1 on error
649
 */
650
int libfwevt_xml_value_get_data_size(
651
     libfwevt_xml_value_t *xml_value,
652
     size_t *data_size,
653
     libcerror_error_t **error )
654
0
{
655
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
656
0
  static char *function                             = "libfwevt_xml_value_get_data_size";
657
658
0
  if( xml_value == NULL )
659
0
  {
660
0
    libcerror_error_set(
661
0
     error,
662
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
663
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
664
0
     "%s: invalid XML value.",
665
0
     function );
666
667
0
    return( -1 );
668
0
  }
669
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
670
671
0
  if( data_size == NULL )
672
0
  {
673
0
    libcerror_error_set(
674
0
     error,
675
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
676
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
677
0
     "%s: invalid data size.",
678
0
     function );
679
680
0
    return( -1 );
681
0
  }
682
0
  *data_size = internal_xml_value->data_size;
683
684
0
  return( 1 );
685
0
}
686
687
/* Copies the data
688
 * Returns 1 if successful or -1 on error
689
 */
690
int libfwevt_xml_value_copy_data(
691
     libfwevt_xml_value_t *xml_value,
692
     uint8_t *data,
693
     size_t data_size,
694
     libcerror_error_t **error )
695
0
{
696
0
  libfwevt_data_segment_t *data_segment             = NULL;
697
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
698
0
  static char *function                             = "libfwevt_xml_value_copy_data";
699
0
  size_t data_offset                                = 0;
700
0
  int data_segment_index                            = 0;
701
0
  int number_of_data_segments                       = 0;
702
703
0
  if( xml_value == NULL )
704
0
  {
705
0
    libcerror_error_set(
706
0
     error,
707
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
708
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
709
0
     "%s: invalid XML value.",
710
0
     function );
711
712
0
    return( -1 );
713
0
  }
714
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
715
716
0
  if( data == NULL )
717
0
  {
718
0
    libcerror_error_set(
719
0
     error,
720
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
721
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
722
0
     "%s: invalid data.",
723
0
     function );
724
725
0
    return( -1 );
726
0
  }
727
0
  if( ( data_size < internal_xml_value->data_size )
728
0
   || ( data_size > (size_t) SSIZE_MAX ) )
729
0
  {
730
0
    libcerror_error_set(
731
0
     error,
732
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
733
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
734
0
     "%s: invalid data size value out of bounds.",
735
0
     function );
736
737
0
    return( -1 );
738
0
  }
739
0
  if( libcdata_array_get_number_of_entries(
740
0
       internal_xml_value->data_segments,
741
0
       &number_of_data_segments,
742
0
       error ) != 1 )
743
0
  {
744
0
    libcerror_error_set(
745
0
     error,
746
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
747
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
748
0
     "%s: unable to retrieve number of data segments.",
749
0
     function );
750
751
0
    return( -1 );
752
0
  }
753
0
  for( data_segment_index = 0;
754
0
       data_segment_index < number_of_data_segments;
755
0
       data_segment_index++ )
756
0
  {
757
0
    if( libcdata_array_get_entry_by_index(
758
0
         internal_xml_value->data_segments,
759
0
         data_segment_index,
760
0
         (intptr_t **) &data_segment,
761
0
         error ) != 1 )
762
0
    {
763
0
      libcerror_error_set(
764
0
       error,
765
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
766
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
767
0
       "%s: unable to retrieve data segment: %d.",
768
0
       function,
769
0
       data_segment_index );
770
771
0
      return( -1 );
772
0
    }
773
0
    if( data_segment == NULL )
774
0
    {
775
0
      libcerror_error_set(
776
0
       error,
777
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
778
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
779
0
       "%s: missing data segment: %d.",
780
0
       function,
781
0
       data_segment_index );
782
783
0
      return( -1 );
784
0
    }
785
0
    if( data_segment->data == NULL )
786
0
    {
787
0
      libcerror_error_set(
788
0
       error,
789
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
790
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
791
0
       "%s: invalid data segment: %d - missing data.",
792
0
       function,
793
0
       data_segment_index );
794
795
0
      return( -1 );
796
0
    }
797
0
    if( ( data_segment->data_size > data_size )
798
0
     || ( data_offset > ( data_size - data_segment->data_size ) ) )
799
0
    {
800
0
      libcerror_error_set(
801
0
       error,
802
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
803
0
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
804
0
       "%s: invalid data segment: %d - data size value out of bounds.",
805
0
       function,
806
0
       data_segment_index );
807
808
0
      return( -1 );
809
0
    }
810
0
    if( memory_copy(
811
0
         &( data[ data_offset ] ),
812
0
         data_segment->data,
813
0
         data_segment->data_size ) == NULL )
814
0
    {
815
0
      libcerror_error_set(
816
0
       error,
817
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
818
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
819
0
       "%s: unable to copy data segment: %d.",
820
0
       function,
821
0
       data_segment_index );
822
823
0
      return( -1 );
824
0
    }
825
0
    data_offset += data_segment->data_size;
826
0
  }
827
0
  return( 1 );
828
0
}
829
830
/* Retrieves the value data as a 8-bit integer value
831
 * Returns 1 if successful, 0 if value cannot be retrieved or -1 on error
832
 */
833
int libfwevt_value_get_data_as_8bit_integer(
834
     libfwevt_xml_value_t *xml_value,
835
     uint8_t *value_8bit,
836
     libcerror_error_t **error )
837
0
{
838
0
  libfwevt_data_segment_t *data_segment             = NULL;
839
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
840
0
  static char *function                             = "libfwevt_value_get_data_as_8bit_integer";
841
842
0
  if( xml_value == NULL )
843
0
  {
844
0
    libcerror_error_set(
845
0
     error,
846
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
847
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
848
0
     "%s: invalid XML value.",
849
0
     function );
850
851
0
    return( -1 );
852
0
  }
853
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
854
855
0
  if( value_8bit == NULL )
856
0
  {
857
0
    libcerror_error_set(
858
0
     error,
859
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
860
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
861
0
     "%s: invalid value 8-bit.",
862
0
     function );
863
864
0
    return( -1 );
865
0
  }
866
0
  if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_8BIT )
867
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT )
868
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_16BIT )
869
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT )
870
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_32BIT )
871
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT )
872
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_64BIT )
873
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT )
874
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) )
875
0
  {
876
0
    return( 0 );
877
0
  }
878
0
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
879
0
       internal_xml_value,
880
0
       0,
881
0
       &data_segment,
882
0
       error ) != 1 )
883
0
  {
884
0
    libcerror_error_set(
885
0
     error,
886
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
887
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
888
0
     "%s: unable to retrieve data segment: 0.",
889
0
     function );
890
891
0
    return( -1 );
892
0
  }
893
0
  if( data_segment == NULL )
894
0
  {
895
0
    libcerror_error_set(
896
0
     error,
897
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
898
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
899
0
     "%s: missing data segment: 0.",
900
0
     function );
901
902
0
    return( -1 );
903
0
  }
904
0
  if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 )
905
0
  {
906
0
    if( libfwevt_integer_copy_from_utf16_stream(
907
0
         &( data_segment->value_64bit ),
908
0
         data_segment->data,
909
0
         data_segment->data_size,
910
0
         error ) != 1 )
911
0
    {
912
0
      libcerror_error_set(
913
0
       error,
914
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
915
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
916
0
       "%s: unable to determine integer value from UTF-16 string data segment: 0.",
917
0
       function );
918
919
0
      return( -1 );
920
0
    }
921
0
    data_segment->cached_value_type = internal_xml_value->value_type;
922
0
  }
923
0
  if( data_segment->value_64bit > (uint64_t) UINT8_MAX )
924
0
  {
925
0
    libcerror_error_set(
926
0
     error,
927
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
928
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
929
0
     "%s: invalid data segment: 0 - integer value out of bounds.",
930
0
     function );
931
932
0
    return( -1 );
933
0
  }
934
0
  *value_8bit = (uint8_t) data_segment->value_64bit;
935
936
0
  return( 1 );
937
0
}
938
939
/* Retrieves the value data as a 32-bit integer value
940
 * Returns 1 if successful, 0 if value cannot be retrieved or -1 on error
941
 */
942
int libfwevt_value_get_data_as_32bit_integer(
943
     libfwevt_xml_value_t *xml_value,
944
     uint32_t *value_32bit,
945
     libcerror_error_t **error )
946
0
{
947
0
  libfwevt_data_segment_t *data_segment             = NULL;
948
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
949
0
  static char *function                             = "libfwevt_value_get_data_as_32bit_integer";
950
951
0
  if( xml_value == NULL )
952
0
  {
953
0
    libcerror_error_set(
954
0
     error,
955
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
956
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
957
0
     "%s: invalid XML value.",
958
0
     function );
959
960
0
    return( -1 );
961
0
  }
962
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
963
964
0
  if( value_32bit == NULL )
965
0
  {
966
0
    libcerror_error_set(
967
0
     error,
968
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
969
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
970
0
     "%s: invalid value 32-bit.",
971
0
     function );
972
973
0
    return( -1 );
974
0
  }
975
0
  if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_8BIT )
976
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT )
977
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_16BIT )
978
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT )
979
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_32BIT )
980
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT )
981
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_64BIT )
982
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT )
983
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) )
984
0
  {
985
0
    return( 0 );
986
0
  }
987
0
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
988
0
       internal_xml_value,
989
0
       0,
990
0
       &data_segment,
991
0
       error ) != 1 )
992
0
  {
993
0
    libcerror_error_set(
994
0
     error,
995
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
996
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
997
0
     "%s: unable to retrieve data segment: 0.",
998
0
     function );
999
1000
0
    return( -1 );
1001
0
  }
1002
0
  if( data_segment == NULL )
1003
0
  {
1004
0
    libcerror_error_set(
1005
0
     error,
1006
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1007
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1008
0
     "%s: missing data segment: 0.",
1009
0
     function );
1010
1011
0
    return( -1 );
1012
0
  }
1013
0
  if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 )
1014
0
  {
1015
0
    if( libfwevt_integer_copy_from_utf16_stream(
1016
0
         &( data_segment->value_64bit ),
1017
0
         data_segment->data,
1018
0
         data_segment->data_size,
1019
0
         error ) != 1 )
1020
0
    {
1021
0
      libcerror_error_set(
1022
0
       error,
1023
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1024
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1025
0
       "%s: unable to determine integer value from UTF-16 string data segment: 0.",
1026
0
       function );
1027
1028
0
      return( -1 );
1029
0
    }
1030
0
    data_segment->cached_value_type = internal_xml_value->value_type;
1031
0
  }
1032
0
  if( data_segment->value_64bit > (uint64_t) UINT32_MAX )
1033
0
  {
1034
0
    libcerror_error_set(
1035
0
     error,
1036
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1037
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
1038
0
     "%s: invalid data segment: 0 - integer value out of bounds.",
1039
0
     function );
1040
1041
0
    return( -1 );
1042
0
  }
1043
0
  *value_32bit = (uint32_t) data_segment->value_64bit;
1044
1045
0
  return( 1 );
1046
0
}
1047
1048
/* Retrieves the value data as a 64-bit integer value
1049
 * Returns 1 if successful, 0 if value cannot be retrieved or -1 on error
1050
 */
1051
int libfwevt_value_get_data_as_64bit_integer(
1052
     libfwevt_xml_value_t *xml_value,
1053
     uint64_t *value_64bit,
1054
     libcerror_error_t **error )
1055
0
{
1056
0
  libfwevt_data_segment_t *data_segment             = NULL;
1057
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
1058
0
  static char *function                             = "libfwevt_value_get_data_as_64bit_integer";
1059
1060
0
  if( xml_value == NULL )
1061
0
  {
1062
0
    libcerror_error_set(
1063
0
     error,
1064
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1065
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1066
0
     "%s: invalid XML value.",
1067
0
     function );
1068
1069
0
    return( -1 );
1070
0
  }
1071
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
1072
1073
0
  if( value_64bit == NULL )
1074
0
  {
1075
0
    libcerror_error_set(
1076
0
     error,
1077
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1078
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1079
0
     "%s: invalid value 64-bit.",
1080
0
     function );
1081
1082
0
    return( -1 );
1083
0
  }
1084
0
  if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_8BIT )
1085
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT )
1086
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_16BIT )
1087
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT )
1088
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_32BIT )
1089
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT )
1090
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_64BIT )
1091
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT )
1092
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) )
1093
0
  {
1094
0
    return( 0 );
1095
0
  }
1096
0
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
1097
0
       internal_xml_value,
1098
0
       0,
1099
0
       &data_segment,
1100
0
       error ) != 1 )
1101
0
  {
1102
0
    libcerror_error_set(
1103
0
     error,
1104
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1105
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1106
0
     "%s: unable to retrieve data segment: 0.",
1107
0
     function );
1108
1109
0
    return( -1 );
1110
0
  }
1111
0
  if( data_segment == NULL )
1112
0
  {
1113
0
    libcerror_error_set(
1114
0
     error,
1115
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1116
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1117
0
     "%s: missing data segment: 0.",
1118
0
     function );
1119
1120
0
    return( -1 );
1121
0
  }
1122
0
  if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 )
1123
0
  {
1124
0
    if( libfwevt_integer_copy_from_utf16_stream(
1125
0
         &( data_segment->value_64bit ),
1126
0
         data_segment->data,
1127
0
         data_segment->data_size,
1128
0
         error ) != 1 )
1129
0
    {
1130
0
      libcerror_error_set(
1131
0
       error,
1132
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1133
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1134
0
       "%s: unable to determine integer value from UTF-16 string data segment: 0.",
1135
0
       function );
1136
1137
0
      return( -1 );
1138
0
    }
1139
0
    data_segment->cached_value_type = internal_xml_value->value_type;
1140
0
  }
1141
0
  *value_64bit = data_segment->value_64bit;
1142
1143
0
  return( 1 );
1144
0
}
1145
1146
/* Retrieves the value data as a 64-bit FILETIME value
1147
 * Returns 1 if successful, 0 if value cannot be retrieved or -1 on error
1148
 */
1149
int libfwevt_value_get_data_as_filetime(
1150
     libfwevt_xml_value_t *xml_value,
1151
     uint64_t *filetime,
1152
     libcerror_error_t **error )
1153
0
{
1154
0
  libfwevt_data_segment_t *data_segment             = NULL;
1155
0
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
1156
0
  static char *function                             = "libfwevt_value_get_data_as_filetime";
1157
0
  uint64_t safe_filetime                            = 0;
1158
1159
0
  if( xml_value == NULL )
1160
0
  {
1161
0
    libcerror_error_set(
1162
0
     error,
1163
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1164
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1165
0
     "%s: invalid XML value.",
1166
0
     function );
1167
1168
0
    return( -1 );
1169
0
  }
1170
0
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
1171
1172
0
  if( filetime == NULL )
1173
0
  {
1174
0
    libcerror_error_set(
1175
0
     error,
1176
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1177
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1178
0
     "%s: invalid FILETIME value.",
1179
0
     function );
1180
1181
0
    return( -1 );
1182
0
  }
1183
0
  if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_FILETIME )
1184
0
   && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) )
1185
0
  {
1186
0
    return( 0 );
1187
0
  }
1188
0
  if( libcdata_array_get_entry_by_index(
1189
0
       internal_xml_value->data_segments,
1190
0
       0,
1191
0
       (intptr_t **) &data_segment,
1192
0
       error ) != 1 )
1193
0
  {
1194
0
    libcerror_error_set(
1195
0
     error,
1196
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1197
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1198
0
     "%s: unable to retrieve data segment: 0.",
1199
0
     function );
1200
1201
0
    return( -1 );
1202
0
  }
1203
0
  if( data_segment == NULL )
1204
0
  {
1205
0
    libcerror_error_set(
1206
0
     error,
1207
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1208
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1209
0
     "%s: missing data segment: 0.",
1210
0
     function );
1211
1212
0
    return( -1 );
1213
0
  }
1214
0
  if( data_segment->data == NULL )
1215
0
  {
1216
0
    libcerror_error_set(
1217
0
     error,
1218
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1219
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1220
0
     "%s: invalid data segment: 0 - missing data.",
1221
0
     function );
1222
1223
0
    return( -1 );
1224
0
  }
1225
0
  if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 )
1226
0
  {
1227
0
    if( libfwevt_filetime_copy_from_utf16_stream(
1228
0
         &safe_filetime,
1229
0
         data_segment->data,
1230
0
         data_segment->data_size,
1231
0
         error ) != 1 )
1232
0
    {
1233
0
      libcerror_error_set(
1234
0
       error,
1235
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1236
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1237
0
       "%s: unable to copy data segment: 0 to FILTEIME.",
1238
0
       function );
1239
1240
0
      return( -1 );
1241
0
    }
1242
0
  }
1243
0
  else
1244
0
  {
1245
0
    if( data_segment->data_size != 8 )
1246
0
    {
1247
0
      libcerror_error_set(
1248
0
       error,
1249
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1250
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1251
0
       "%s: invalid data segment: 0 - unsupported data size.",
1252
0
       function );
1253
1254
0
      return( -1 );
1255
0
    }
1256
0
    byte_stream_copy_to_uint64_little_endian(
1257
0
     data_segment->data,
1258
0
     safe_filetime );
1259
0
  }
1260
0
  *filetime = safe_filetime;
1261
1262
0
  return( 1 );
1263
0
}
1264
1265
/* Retrieves the size of the data segment formatted as an UTF-8 string
1266
 * The string size includes the end of string character
1267
 * Returns 1 if successful or -1 on error
1268
 */
1269
int libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size(
1270
     libfwevt_internal_xml_value_t *internal_xml_value,
1271
     int data_segment_index,
1272
     libfwevt_data_segment_t *data_segment,
1273
     size_t *utf8_string_size,
1274
     uint8_t escape_characters,
1275
     int ascii_codepage,
1276
     libcerror_error_t **error )
1277
0
{
1278
0
  static char *function        = "libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size";
1279
0
  size_t base16_stream_size    = 0;
1280
0
  size_t safe_utf8_string_size = 0;
1281
0
  uint32_t format_flags        = 0;
1282
0
  int result                   = 0;
1283
1284
0
  if( internal_xml_value == NULL )
1285
0
  {
1286
0
    libcerror_error_set(
1287
0
     error,
1288
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1289
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1290
0
     "%s: invalid XML value.",
1291
0
     function );
1292
1293
0
    return( -1 );
1294
0
  }
1295
0
  if( data_segment == NULL )
1296
0
  {
1297
0
    libcerror_error_set(
1298
0
     error,
1299
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1300
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1301
0
     "%s: invalid data segment.",
1302
0
     function );
1303
1304
0
    return( -1 );
1305
0
  }
1306
0
  if( utf8_string_size == NULL )
1307
0
  {
1308
0
    libcerror_error_set(
1309
0
     error,
1310
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1311
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1312
0
     "%s: invalid UTF-8 string size.",
1313
0
     function );
1314
1315
0
    return( -1 );
1316
0
  }
1317
0
  switch( internal_xml_value->value_type & 0x7f )
1318
0
  {
1319
0
    case LIBFWEVT_VALUE_TYPE_STRING_UTF16:
1320
0
      if( data_segment->data_size == 0 )
1321
0
      {
1322
0
        result = 1;
1323
0
      }
1324
0
      else if( escape_characters == 0 )
1325
0
      {
1326
0
        result = libuna_utf8_string_size_from_utf16_stream(
1327
0
                  data_segment->data,
1328
0
                  data_segment->data_size,
1329
0
                  LIBUNA_ENDIAN_LITTLE,
1330
0
                  &safe_utf8_string_size,
1331
0
                  error );
1332
0
      }
1333
0
      else
1334
0
      {
1335
0
        result = libfwevt_utf8_xml_string_size_from_utf16_stream(
1336
0
                  data_segment->data,
1337
0
                  data_segment->data_size,
1338
0
                  LIBUNA_ENDIAN_LITTLE,
1339
0
                  &safe_utf8_string_size,
1340
0
                  error );
1341
0
      }
1342
0
      break;
1343
1344
0
    case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM:
1345
0
      if( data_segment->data_size == 0 )
1346
0
      {
1347
0
        result = 1;
1348
0
      }
1349
0
      else
1350
0
      {
1351
0
        result = libuna_utf8_string_size_from_byte_stream(
1352
0
                  data_segment->data,
1353
0
                  data_segment->data_size,
1354
0
                  ascii_codepage,
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
    case LIBFWEVT_VALUE_TYPE_SIZE:
1498
0
      if( data_segment->data_size == 4 )
1499
0
      {
1500
0
        safe_utf8_string_size = 11;
1501
1502
0
        result = 1;
1503
0
      }
1504
0
      else if( data_segment->data_size == 8 )
1505
0
      {
1506
0
        safe_utf8_string_size = 19;
1507
1508
0
        result = 1;
1509
0
      }
1510
0
      break;
1511
1512
0
    default:
1513
0
      break;
1514
0
  }
1515
0
  if( result != 1 )
1516
0
  {
1517
0
    libcerror_error_set(
1518
0
     error,
1519
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1520
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1521
0
     "%s: unable to determine size UTF-8 string of data segment: %d.",
1522
0
     function,
1523
0
     data_segment_index );
1524
1525
0
    return( -1 );
1526
0
  }
1527
0
  *utf8_string_size = safe_utf8_string_size;
1528
1529
0
  return( 1 );
1530
0
}
1531
1532
/* Retrieves the data segment formatted as an UTF-8 string
1533
 * Returns 1 if successful or -1 on error
1534
 */
1535
int libfwevt_internal_xml_value_get_data_segment_as_utf8_string(
1536
     libfwevt_internal_xml_value_t *internal_xml_value,
1537
     int data_segment_index,
1538
     libfwevt_data_segment_t *data_segment,
1539
     uint8_t *utf8_string,
1540
     size_t utf8_string_size,
1541
     size_t *utf8_string_index,
1542
     uint8_t escape_characters,
1543
     int ascii_codepage,
1544
     libcerror_error_t **error )
1545
0
{
1546
0
  static char *function         = "libfwevt_internal_xml_value_get_data_segment_as_utf8_string";
1547
0
  size_t base16_stream_index    = 0;
1548
0
  size_t safe_utf8_string_index = 0;
1549
0
  uint32_t format_flags         = 0;
1550
0
  uint8_t number_of_characters  = 0;
1551
0
  int result                    = 0;
1552
1553
0
  if( internal_xml_value == NULL )
1554
0
  {
1555
0
    libcerror_error_set(
1556
0
     error,
1557
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1558
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1559
0
     "%s: invalid XML value.",
1560
0
     function );
1561
1562
0
    return( -1 );
1563
0
  }
1564
0
  if( data_segment == NULL )
1565
0
  {
1566
0
    libcerror_error_set(
1567
0
     error,
1568
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1569
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1570
0
     "%s: invalid data segment.",
1571
0
     function );
1572
1573
0
    return( -1 );
1574
0
  }
1575
0
  if( utf8_string == NULL )
1576
0
  {
1577
0
    libcerror_error_set(
1578
0
     error,
1579
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1580
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1581
0
     "%s: invalid UTF-8 string.",
1582
0
     function );
1583
1584
0
    return( -1 );
1585
0
  }
1586
0
  if( utf8_string_size > (size_t) SSIZE_MAX )
1587
0
  {
1588
0
    libcerror_error_set(
1589
0
     error,
1590
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1591
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1592
0
     "%s: invalid UTF-8 string size value exceeds maximum.",
1593
0
     function );
1594
1595
0
    return( -1 );
1596
0
  }
1597
0
  if( utf8_string_index == NULL )
1598
0
  {
1599
0
    libcerror_error_set(
1600
0
     error,
1601
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1602
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1603
0
     "%s: invalid UTF-8 string index.",
1604
0
     function );
1605
1606
0
    return( -1 );
1607
0
  }
1608
0
  switch( internal_xml_value->value_type & 0x7f )
1609
0
  {
1610
0
    case LIBFWEVT_VALUE_TYPE_STRING_UTF16:
1611
0
      if( data_segment->data_size == 0 )
1612
0
      {
1613
0
        result = 1;
1614
0
      }
1615
0
      else if( escape_characters == 0 )
1616
0
      {
1617
0
        result = libuna_utf8_string_with_index_copy_from_utf16_stream(
1618
0
                  utf8_string,
1619
0
                  utf8_string_size,
1620
0
                  utf8_string_index,
1621
0
                  data_segment->data,
1622
0
                  data_segment->data_size,
1623
0
                  LIBUNA_ENDIAN_LITTLE,
1624
0
                  error );
1625
0
      }
1626
0
      else
1627
0
      {
1628
0
        result = libfwevt_utf8_xml_string_with_index_copy_from_utf16_stream(
1629
0
                  utf8_string,
1630
0
                  utf8_string_size,
1631
0
                  utf8_string_index,
1632
0
                  data_segment->data,
1633
0
                  data_segment->data_size,
1634
0
                  LIBUNA_ENDIAN_LITTLE,
1635
0
                  error );
1636
0
      }
1637
0
      break;
1638
1639
0
    case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM:
1640
0
      result = libuna_utf8_string_with_index_copy_from_byte_stream(
1641
0
                utf8_string,
1642
0
                utf8_string_size,
1643
0
                utf8_string_index,
1644
0
                data_segment->data,
1645
0
                data_segment->data_size,
1646
0
                ascii_codepage,
1647
0
                error );
1648
/* TODO add support for escape_characters */
1649
0
      break;
1650
1651
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT:
1652
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index(
1653
0
                data_segment->value_64bit,
1654
0
                8,
1655
0
                utf8_string,
1656
0
                utf8_string_size,
1657
0
                utf8_string_index,
1658
0
                error );
1659
0
      break;
1660
1661
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT:
1662
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index(
1663
0
                data_segment->value_64bit,
1664
0
                16,
1665
0
                utf8_string,
1666
0
                utf8_string_size,
1667
0
                utf8_string_index,
1668
0
                error );
1669
0
      break;
1670
1671
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT:
1672
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index(
1673
0
                data_segment->value_64bit,
1674
0
                32,
1675
0
                utf8_string,
1676
0
                utf8_string_size,
1677
0
                utf8_string_index,
1678
0
                error );
1679
0
      break;
1680
1681
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT:
1682
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index(
1683
0
                data_segment->value_64bit,
1684
0
                64,
1685
0
                utf8_string,
1686
0
                utf8_string_size,
1687
0
                utf8_string_index,
1688
0
                error );
1689
0
      break;
1690
1691
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT:
1692
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT:
1693
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT:
1694
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT:
1695
0
      result = libfwevt_integer_as_unsigned_decimal_copy_to_utf8_string_with_index(
1696
0
                data_segment->value_64bit,
1697
0
                utf8_string,
1698
0
                utf8_string_size,
1699
0
                utf8_string_index,
1700
0
                error );
1701
0
      break;
1702
1703
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT:
1704
0
      result = libfwevt_float32_copy_to_utf8_string_with_index(
1705
0
                (uint32_t) data_segment->value_64bit,
1706
0
                utf8_string,
1707
0
                utf8_string_size,
1708
0
                utf8_string_index,
1709
0
                error );
1710
0
      break;
1711
1712
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT:
1713
0
      result = libfwevt_float64_copy_to_utf8_string_with_index(
1714
0
                data_segment->value_64bit,
1715
0
                utf8_string,
1716
0
                utf8_string_size,
1717
0
                utf8_string_index,
1718
0
                error );
1719
0
      break;
1720
1721
0
    case LIBFWEVT_VALUE_TYPE_BOOLEAN:
1722
0
      if( data_segment->value_64bit == 0 )
1723
0
      {
1724
0
        number_of_characters = 6;
1725
0
      }
1726
0
      else
1727
0
      {
1728
0
        number_of_characters = 5;
1729
0
      }
1730
0
      safe_utf8_string_index = *utf8_string_index;
1731
1732
0
      if( ( number_of_characters > utf8_string_size )
1733
0
       || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) )
1734
0
      {
1735
0
        libcerror_error_set(
1736
0
         error,
1737
0
         LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1738
0
         LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1739
0
         "%s: invalid UTF-8 string size value too small.",
1740
0
         function );
1741
1742
0
        return( -1 );
1743
0
      }
1744
0
      if( data_segment->value_64bit == 0 )
1745
0
      {
1746
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'f';
1747
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'a';
1748
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'l';
1749
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 's';
1750
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'e';
1751
0
      }
1752
0
      else
1753
0
      {
1754
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 't';
1755
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'r';
1756
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'u';
1757
0
        utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'e';
1758
0
      }
1759
0
      utf8_string[ safe_utf8_string_index++ ] = 0;
1760
1761
0
      *utf8_string_index = safe_utf8_string_index;
1762
1763
0
      result = 1;
1764
1765
0
      break;
1766
1767
0
    case LIBFWEVT_VALUE_TYPE_BINARY_DATA:
1768
0
      base16_stream_index = *utf8_string_index;
1769
0
      format_flags        = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE;
1770
1771
0
      result = libuna_base16_stream_with_index_copy_from_byte_stream(
1772
0
                (uint8_t *) utf8_string,
1773
0
                utf8_string_size,
1774
0
                &base16_stream_index,
1775
0
                data_segment->data,
1776
0
                data_segment->data_size,
1777
0
                format_flags,
1778
0
                error );
1779
1780
0
      if( result == 1 )
1781
0
      {
1782
0
        *utf8_string_index = base16_stream_index + 1;
1783
0
      }
1784
0
      break;
1785
1786
0
    case LIBFWEVT_VALUE_TYPE_GUID:
1787
0
      result = libfguid_identifier_copy_to_utf8_string_with_index(
1788
0
                data_segment->guid,
1789
0
                utf8_string,
1790
0
                utf8_string_size,
1791
0
                utf8_string_index,
1792
0
                LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
1793
0
                error );
1794
0
      break;
1795
1796
0
    case LIBFWEVT_VALUE_TYPE_FILETIME:
1797
0
      result = libfdatetime_filetime_copy_to_utf8_string_with_index(
1798
0
                data_segment->filetime,
1799
0
                utf8_string,
1800
0
                utf8_string_size,
1801
0
                utf8_string_index,
1802
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
1803
0
                error );
1804
0
      break;
1805
1806
0
    case LIBFWEVT_VALUE_TYPE_SYSTEMTIME:
1807
0
      result = libfdatetime_systemtime_copy_to_utf8_string_with_index(
1808
0
                data_segment->systemtime,
1809
0
                utf8_string,
1810
0
                utf8_string_size,
1811
0
                utf8_string_index,
1812
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
1813
0
                error );
1814
0
      break;
1815
1816
0
    case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER:
1817
0
      result = libfwnt_security_identifier_copy_to_utf8_string_with_index(
1818
0
                data_segment->security_identifier,
1819
0
                utf8_string,
1820
0
                utf8_string_size,
1821
0
                utf8_string_index,
1822
0
          0,
1823
0
                error );
1824
0
      break;
1825
1826
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT:
1827
0
      result = libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index(
1828
0
                data_segment->value_64bit,
1829
0
                32,
1830
0
                utf8_string,
1831
0
                utf8_string_size,
1832
0
                utf8_string_index,
1833
0
                error );
1834
0
      break;
1835
1836
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT:
1837
0
      result = libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index(
1838
0
                data_segment->value_64bit,
1839
0
                64,
1840
0
                utf8_string,
1841
0
                utf8_string_size,
1842
0
                utf8_string_index,
1843
0
                error );
1844
0
      break;
1845
1846
0
    case LIBFWEVT_VALUE_TYPE_SIZE:
1847
0
      if( data_segment->data_size == 4 )
1848
0
      {
1849
0
        result = libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index(
1850
0
                  data_segment->value_64bit,
1851
0
                  32,
1852
0
                  utf8_string,
1853
0
                  utf8_string_size,
1854
0
                  utf8_string_index,
1855
0
                  error );
1856
0
      }
1857
0
      else if( data_segment->data_size == 8 )
1858
0
      {
1859
0
        result = libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index(
1860
0
                  data_segment->value_64bit,
1861
0
                  64,
1862
0
                  utf8_string,
1863
0
                  utf8_string_size,
1864
0
                  utf8_string_index,
1865
0
                  error );
1866
0
      }
1867
0
      break;
1868
1869
0
    default:
1870
0
      break;
1871
0
  }
1872
0
  if( result != 1 )
1873
0
  {
1874
0
    libcerror_error_set(
1875
0
     error,
1876
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1877
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1878
0
     "%s: unable to copy data segment: %d to UTF-8 string.",
1879
0
     function,
1880
0
     data_segment_index );
1881
1882
0
    return( -1 );
1883
0
  }
1884
0
  return( 1 );
1885
0
}
1886
1887
/* Retrieves the size of the value data formatted as an UTF-8 string
1888
 * The string size includes the end of string character
1889
 * Returns 1 if successful or -1 on error
1890
 */
1891
int libfwevt_internal_xml_value_get_data_as_utf8_string_size(
1892
     libfwevt_internal_xml_value_t *internal_xml_value,
1893
     size_t *utf8_string_size,
1894
     uint8_t escape_characters,
1895
     int ascii_codepage,
1896
     libcerror_error_t **error )
1897
0
{
1898
0
  libfwevt_data_segment_t *data_segment = NULL;
1899
0
  static char *function                 = "libfwevt_internal_xml_value_get_data_as_utf8_string_size";
1900
0
  size_t data_segment_size              = 0;
1901
0
  size_t safe_utf8_string_size          = 0;
1902
0
  int data_segment_index                = 0;
1903
0
  int number_of_data_segments           = 0;
1904
1905
0
  if( internal_xml_value == NULL )
1906
0
  {
1907
0
    libcerror_error_set(
1908
0
     error,
1909
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1910
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1911
0
     "%s: invalid XML value.",
1912
0
     function );
1913
1914
0
    return( -1 );
1915
0
  }
1916
0
  if( utf8_string_size == NULL )
1917
0
  {
1918
0
    libcerror_error_set(
1919
0
     error,
1920
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1921
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1922
0
     "%s: invalid UTF-8 string size.",
1923
0
     function );
1924
1925
0
    return( -1 );
1926
0
  }
1927
0
  if( libcdata_array_get_number_of_entries(
1928
0
       internal_xml_value->data_segments,
1929
0
       &number_of_data_segments,
1930
0
       error ) != 1 )
1931
0
  {
1932
0
    libcerror_error_set(
1933
0
     error,
1934
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1935
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1936
0
     "%s: unable to retrieve number of data segments.",
1937
0
     function );
1938
1939
0
    return( -1 );
1940
0
  }
1941
0
  for( data_segment_index = 0;
1942
0
       data_segment_index < number_of_data_segments;
1943
0
       data_segment_index++ )
1944
0
  {
1945
0
    if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
1946
0
         internal_xml_value,
1947
0
         data_segment_index,
1948
0
         &data_segment,
1949
0
         error ) != 1 )
1950
0
    {
1951
0
      libcerror_error_set(
1952
0
       error,
1953
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1954
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1955
0
       "%s: unable to retrieve data segment: %d.",
1956
0
       function,
1957
0
       data_segment_index );
1958
1959
0
      return( -1 );
1960
0
    }
1961
0
    if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size(
1962
0
         internal_xml_value,
1963
0
         data_segment_index,
1964
0
         data_segment,
1965
0
         &data_segment_size,
1966
0
         escape_characters,
1967
0
         ascii_codepage,
1968
0
         error ) != 1 )
1969
0
    {
1970
0
      libcerror_error_set(
1971
0
       error,
1972
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1973
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1974
0
       "%s: unable to retrieve UTF-8 string size of element data segment: %d.",
1975
0
       function,
1976
0
       data_segment_index );
1977
1978
0
      return( -1 );
1979
0
    }
1980
0
    if( data_segment_size > 1 )
1981
0
    {
1982
0
      safe_utf8_string_size += data_segment_size - 1;
1983
0
    }
1984
0
  }
1985
0
  if( ( number_of_data_segments == 1 )
1986
0
   && ( data_segment != NULL )
1987
0
   && ( safe_utf8_string_size == 1 ) )
1988
0
  {
1989
0
    if( ( data_segment->data_size >= 2 )
1990
0
     && ( data_segment->data[ 0 ] == '\n' )
1991
0
     && ( data_segment->data[ 1 ] == 0 ) )
1992
0
    {
1993
      /* The value data consists of a single linefeed consider it empty
1994
       */
1995
0
      safe_utf8_string_size = 0;
1996
0
    }
1997
0
  }
1998
0
  if( safe_utf8_string_size > 0 )
1999
0
  {
2000
0
    safe_utf8_string_size++;
2001
0
  }
2002
0
  *utf8_string_size = safe_utf8_string_size;
2003
2004
0
  return( 1 );
2005
0
}
2006
2007
/* Retrieves the data formatted as an UTF-8 string
2008
 * The string size should include the end of string character
2009
 * Returns 1 if successful or -1 on error
2010
 */
2011
int libfwevt_internal_xml_value_get_data_as_utf8_string_with_index(
2012
     libfwevt_internal_xml_value_t *internal_xml_value,
2013
     uint8_t *utf8_string,
2014
     size_t utf8_string_size,
2015
     size_t *utf8_string_index,
2016
     uint8_t escape_characters,
2017
     int ascii_codepage,
2018
     libcerror_error_t **error )
2019
0
{
2020
0
  libfwevt_data_segment_t *data_segment = NULL;
2021
0
  static char *function                 = "libfwevt_internal_xml_value_get_data_as_utf8_string_with_index";
2022
0
  size_t safe_utf8_string_index         = 0;
2023
0
  int data_segment_index                = 0;
2024
0
  int number_of_data_segments           = 0;
2025
2026
0
  if( internal_xml_value == NULL )
2027
0
  {
2028
0
    libcerror_error_set(
2029
0
     error,
2030
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2031
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2032
0
     "%s: invalid XML value.",
2033
0
     function );
2034
2035
0
    return( -1 );
2036
0
  }
2037
0
  if( utf8_string == NULL )
2038
0
  {
2039
0
    libcerror_error_set(
2040
0
     error,
2041
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2042
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2043
0
     "%s: invalid UTF-8 string.",
2044
0
     function );
2045
2046
0
    return( -1 );
2047
0
  }
2048
0
  if( utf8_string_size > (size_t) SSIZE_MAX )
2049
0
  {
2050
0
    libcerror_error_set(
2051
0
     error,
2052
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2053
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
2054
0
     "%s: invalid UTF-8 string size value exceeds maximum.",
2055
0
     function );
2056
2057
0
    return( -1 );
2058
0
  }
2059
0
  if( utf8_string_index == NULL )
2060
0
  {
2061
0
    libcerror_error_set(
2062
0
     error,
2063
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2064
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2065
0
     "%s: invalid UTF-8 string index.",
2066
0
     function );
2067
2068
0
    return( -1 );
2069
0
  }
2070
0
  safe_utf8_string_index = *utf8_string_index;
2071
2072
0
  if( libcdata_array_get_number_of_entries(
2073
0
       internal_xml_value->data_segments,
2074
0
       &number_of_data_segments,
2075
0
       error ) != 1 )
2076
0
  {
2077
0
    libcerror_error_set(
2078
0
     error,
2079
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2080
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2081
0
     "%s: unable to retrieve number of data segments.",
2082
0
     function );
2083
2084
0
    return( -1 );
2085
0
  }
2086
0
  for( data_segment_index = 0;
2087
0
       data_segment_index < number_of_data_segments;
2088
0
       data_segment_index++ )
2089
0
  {
2090
0
    if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
2091
0
         internal_xml_value,
2092
0
         data_segment_index,
2093
0
         &data_segment,
2094
0
         error ) != 1 )
2095
0
    {
2096
0
      libcerror_error_set(
2097
0
       error,
2098
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2099
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2100
0
       "%s: unable to retrieve data segment: %d.",
2101
0
       function,
2102
0
       data_segment_index );
2103
2104
0
      return( -1 );
2105
0
    }
2106
0
    if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string(
2107
0
         internal_xml_value,
2108
0
         data_segment_index,
2109
0
         data_segment,
2110
0
         utf8_string,
2111
0
         utf8_string_size,
2112
0
         &safe_utf8_string_index,
2113
0
         escape_characters,
2114
0
         ascii_codepage,
2115
0
         error ) != 1 )
2116
0
    {
2117
0
      libcerror_error_set(
2118
0
       error,
2119
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2120
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2121
0
       "%s: unable to copy data segment: %d to UTF-8 string.",
2122
0
       function,
2123
0
       data_segment_index );
2124
2125
0
      return( -1 );
2126
0
    }
2127
0
    safe_utf8_string_index--;
2128
0
  }
2129
0
  if( ( number_of_data_segments == 1 )
2130
0
   && ( data_segment != NULL )
2131
0
   && ( safe_utf8_string_index == 1 ) )
2132
0
  {
2133
0
    if( ( data_segment->data_size >= 2 )
2134
0
     && ( data_segment->data[ 0 ] == '\n' )
2135
0
     && ( data_segment->data[ 1 ] == 0 ) )
2136
0
    {
2137
      /* The value data consists of a single linefeed consider it empty
2138
       */
2139
0
      safe_utf8_string_index = 0;
2140
0
    }
2141
0
  }
2142
0
  if( safe_utf8_string_index > 0 )
2143
0
  {
2144
0
    if( safe_utf8_string_index >= utf8_string_size  )
2145
0
    {
2146
0
      libcerror_error_set(
2147
0
       error,
2148
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2149
0
       LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
2150
0
       "%s: invalid UTF-8 string size value too small.",
2151
0
       function );
2152
2153
0
      return( -1 );
2154
0
    }
2155
0
    utf8_string[ safe_utf8_string_index++ ] = 0;
2156
0
  }
2157
0
  *utf8_string_index = safe_utf8_string_index;
2158
2159
0
  return( 1 );
2160
0
}
2161
2162
/* Retrieves the size of an UTF-8 encoded string of the value data
2163
 * Returns 1 if successful or -1 on error
2164
 */
2165
int libfwevt_xml_value_get_utf8_string_size(
2166
     libfwevt_xml_value_t *xml_value,
2167
     size_t *utf8_string_size,
2168
     libcerror_error_t **error )
2169
0
{
2170
0
  static char *function = "libfwevt_xml_value_get_utf8_string_size";
2171
2172
0
  if( xml_value == NULL )
2173
0
  {
2174
0
    libcerror_error_set(
2175
0
     error,
2176
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2177
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2178
0
     "%s: invalid XML value.",
2179
0
     function );
2180
2181
0
    return( -1 );
2182
0
  }
2183
0
  if( libfwevt_internal_xml_value_get_data_as_utf8_string_size(
2184
0
       (libfwevt_internal_xml_value_t *) xml_value,
2185
0
       utf8_string_size,
2186
0
       0,
2187
0
       LIBUNA_CODEPAGE_WINDOWS_1252,
2188
0
       error ) != 1 )
2189
0
  {
2190
0
    libcerror_error_set(
2191
0
     error,
2192
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2193
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2194
0
     "%s: unable to retrieve size of UTF-8 string.",
2195
0
     function );
2196
2197
0
    return( -1 );
2198
0
  }
2199
0
  return( 1 );
2200
0
}
2201
2202
/* Copies the value data to an UTF-8 encoded string
2203
 * Returns 1 if successful or -1 on error
2204
 */
2205
int libfwevt_xml_value_copy_to_utf8_string(
2206
     libfwevt_xml_value_t *xml_value,
2207
     uint8_t *utf8_string,
2208
     size_t utf8_string_size,
2209
     libcerror_error_t **error )
2210
0
{
2211
0
  static char *function = "libfwevt_xml_value_copy_to_utf8_string";
2212
2213
0
  if( libfwevt_xml_value_get_data_as_utf8_string(
2214
0
       xml_value,
2215
0
       utf8_string,
2216
0
       utf8_string_size,
2217
0
       error ) != 1 )
2218
0
  {
2219
0
    libcerror_error_set(
2220
0
     error,
2221
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2222
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2223
0
     "%s: unable to retrieve size of UTF-8 string.",
2224
0
     function );
2225
2226
0
    return( -1 );
2227
0
  }
2228
0
  return( 1 );
2229
0
}
2230
2231
/* Retrieves the size of the value data formatted as an UTF-8 string
2232
 * The string size includes the end of string character
2233
 * Returns 1 if successful or -1 on error
2234
 */
2235
int libfwevt_xml_value_get_data_as_utf8_string_size(
2236
     libfwevt_xml_value_t *xml_value,
2237
     size_t *utf8_string_size,
2238
     libcerror_error_t **error )
2239
0
{
2240
0
  static char *function = "libfwevt_xml_value_get_data_as_utf8_string_size";
2241
2242
0
  if( xml_value == NULL )
2243
0
  {
2244
0
    libcerror_error_set(
2245
0
     error,
2246
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2247
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2248
0
     "%s: invalid XML value.",
2249
0
     function );
2250
2251
0
    return( -1 );
2252
0
  }
2253
/* TODO pass codepage */
2254
0
  if( libfwevt_internal_xml_value_get_data_as_utf8_string_size(
2255
0
       (libfwevt_internal_xml_value_t *) xml_value,
2256
0
       utf8_string_size,
2257
0
       0,
2258
0
       LIBUNA_CODEPAGE_WINDOWS_1252,
2259
0
       error ) != 1 )
2260
0
  {
2261
0
    libcerror_error_set(
2262
0
     error,
2263
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2264
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2265
0
     "%s: unable to retrieve UTF-8 string size.",
2266
0
     function );
2267
2268
0
    return( -1 );
2269
0
  }
2270
0
  return( 1 );
2271
0
}
2272
2273
/* Retrieves the data formatted as an UTF-8 string
2274
 * The string size should include the end of string character
2275
 * Returns 1 if successful or -1 on error
2276
 */
2277
int libfwevt_xml_value_get_data_as_utf8_string(
2278
     libfwevt_xml_value_t *xml_value,
2279
     uint8_t *utf8_string,
2280
     size_t utf8_string_size,
2281
     libcerror_error_t **error )
2282
0
{
2283
0
  static char *function    = "libfwevt_xml_value_get_data_as_utf8_string";
2284
0
  size_t utf8_string_index = 0;
2285
2286
0
  if( xml_value == NULL )
2287
0
  {
2288
0
    libcerror_error_set(
2289
0
     error,
2290
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2291
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2292
0
     "%s: invalid XML value.",
2293
0
     function );
2294
2295
0
    return( -1 );
2296
0
  }
2297
/* TODO pass codepage */
2298
0
  if( libfwevt_internal_xml_value_get_data_as_utf8_string_with_index(
2299
0
       (libfwevt_internal_xml_value_t *) xml_value,
2300
0
       utf8_string,
2301
0
       utf8_string_size,
2302
0
       &utf8_string_index,
2303
0
       0,
2304
0
       LIBUNA_CODEPAGE_WINDOWS_1252,
2305
0
       error ) != 1 )
2306
0
  {
2307
0
    libcerror_error_set(
2308
0
     error,
2309
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2310
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2311
0
     "%s: unable to retrieve size of UTF-8 string.",
2312
0
     function );
2313
2314
0
    return( -1 );
2315
0
  }
2316
0
  return( 1 );
2317
0
}
2318
2319
/* Retrieves the size of the data segment formatted as an UTF-16 string
2320
 * The string size includes the end of string character
2321
 * Returns 1 if successful or -1 on error
2322
 */
2323
int libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size(
2324
     libfwevt_internal_xml_value_t *internal_xml_value,
2325
     int data_segment_index,
2326
     libfwevt_data_segment_t *data_segment,
2327
     size_t *utf16_string_size,
2328
     uint8_t escape_characters,
2329
     int ascii_codepage,
2330
     libcerror_error_t **error )
2331
0
{
2332
0
  static char *function         = "libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size";
2333
0
  size_t base16_stream_size     = 0;
2334
0
  size_t safe_utf16_string_size = 0;
2335
0
  uint32_t format_flags         = 0;
2336
0
  int result                    = 0;
2337
2338
0
  if( internal_xml_value == NULL )
2339
0
  {
2340
0
    libcerror_error_set(
2341
0
     error,
2342
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2343
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2344
0
     "%s: invalid XML value.",
2345
0
     function );
2346
2347
0
    return( -1 );
2348
0
  }
2349
0
  if( data_segment == NULL )
2350
0
  {
2351
0
    libcerror_error_set(
2352
0
     error,
2353
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2354
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2355
0
     "%s: invalid data segment.",
2356
0
     function );
2357
2358
0
    return( -1 );
2359
0
  }
2360
0
  if( utf16_string_size == NULL )
2361
0
  {
2362
0
    libcerror_error_set(
2363
0
     error,
2364
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2365
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2366
0
     "%s: invalid UTF-16 string size.",
2367
0
     function );
2368
2369
0
    return( -1 );
2370
0
  }
2371
0
  switch( internal_xml_value->value_type & 0x7f )
2372
0
  {
2373
0
    case LIBFWEVT_VALUE_TYPE_STRING_UTF16:
2374
0
      if( data_segment->data_size == 0 )
2375
0
      {
2376
0
        result = 1;
2377
0
      }
2378
0
      else if( escape_characters == 0 )
2379
0
      {
2380
0
        result = libuna_utf16_string_size_from_utf16_stream(
2381
0
                  data_segment->data,
2382
0
                  data_segment->data_size,
2383
0
                  LIBUNA_ENDIAN_LITTLE,
2384
0
                  &safe_utf16_string_size,
2385
0
                  error );
2386
0
      }
2387
0
      else
2388
0
      {
2389
0
        result = libfwevt_utf16_xml_string_size_from_utf16_stream(
2390
0
                  data_segment->data,
2391
0
                  data_segment->data_size,
2392
0
                  LIBUNA_ENDIAN_LITTLE,
2393
0
                  &safe_utf16_string_size,
2394
0
                  error );
2395
0
      }
2396
0
      break;
2397
2398
0
    case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM:
2399
0
      if( data_segment->data_size == 0 )
2400
0
      {
2401
0
        result = 1;
2402
0
      }
2403
0
      else
2404
0
      {
2405
0
        result = libuna_utf16_string_size_from_byte_stream(
2406
0
                  data_segment->data,
2407
0
                  data_segment->data_size,
2408
0
                  ascii_codepage,
2409
0
                  &safe_utf16_string_size,
2410
0
                  error );
2411
0
      }
2412
/* TODO add support for escape_characters */
2413
0
      break;
2414
2415
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT:
2416
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2417
0
                data_segment->value_64bit,
2418
0
                8,
2419
0
                &safe_utf16_string_size,
2420
0
                error );
2421
0
      break;
2422
2423
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT:
2424
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2425
0
                data_segment->value_64bit,
2426
0
                16,
2427
0
                &safe_utf16_string_size,
2428
0
                error );
2429
0
      break;
2430
2431
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT:
2432
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2433
0
                data_segment->value_64bit,
2434
0
                32,
2435
0
                &safe_utf16_string_size,
2436
0
                error );
2437
0
      break;
2438
2439
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT:
2440
0
      result = libfwevt_integer_as_signed_decimal_get_string_size(
2441
0
                data_segment->value_64bit,
2442
0
                64,
2443
0
                &safe_utf16_string_size,
2444
0
                error );
2445
0
      break;
2446
2447
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT:
2448
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT:
2449
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT:
2450
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT:
2451
0
      result = libfwevt_integer_as_unsigned_decimal_get_string_size(
2452
0
                data_segment->value_64bit,
2453
0
                &safe_utf16_string_size,
2454
0
                error );
2455
0
      break;
2456
2457
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT:
2458
0
      result = libfwevt_float32_get_string_size(
2459
0
                (uint32_t) data_segment->value_64bit,
2460
0
                &safe_utf16_string_size,
2461
0
                error );
2462
0
      break;
2463
2464
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT:
2465
0
      result = libfwevt_float64_get_string_size(
2466
0
                data_segment->value_64bit,
2467
0
                &safe_utf16_string_size,
2468
0
                error );
2469
0
      break;
2470
2471
0
    case LIBFWEVT_VALUE_TYPE_BOOLEAN:
2472
0
      if( data_segment->value_64bit == 0 )
2473
0
      {
2474
0
        safe_utf16_string_size += 6;
2475
0
      }
2476
0
      else
2477
0
      {
2478
0
        safe_utf16_string_size += 5;
2479
0
      }
2480
0
      result = 1;
2481
2482
0
      break;
2483
2484
0
    case LIBFWEVT_VALUE_TYPE_BINARY_DATA:
2485
0
      if( data_segment->data_size == 0 )
2486
0
      {
2487
0
        result = 1;
2488
0
      }
2489
0
      else
2490
0
      {
2491
0
        format_flags = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE;
2492
2493
#if _BYTE_STREAM_HOST_BYTE_ORDER == _BYTE_STREAM_ENDIAN_BIG
2494
        format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN;
2495
#else
2496
0
        format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN;
2497
0
#endif
2498
0
        result = libuna_base16_stream_size_from_byte_stream(
2499
0
                  data_segment->data,
2500
0
                  data_segment->data_size,
2501
0
                  &base16_stream_size,
2502
0
                  format_flags,
2503
0
                  error );
2504
2505
0
        if( result == 1 )
2506
0
        {
2507
0
          safe_utf16_string_size += ( base16_stream_size / 2 ) + 1;
2508
0
        }
2509
0
      }
2510
0
      break;
2511
2512
0
    case LIBFWEVT_VALUE_TYPE_GUID:
2513
0
      result = libfguid_identifier_get_string_size(
2514
0
                data_segment->guid,
2515
0
                &safe_utf16_string_size,
2516
0
                LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
2517
0
                error );
2518
0
      break;
2519
2520
0
    case LIBFWEVT_VALUE_TYPE_FILETIME:
2521
0
      result = libfdatetime_filetime_get_string_size(
2522
0
                data_segment->filetime,
2523
0
                &safe_utf16_string_size,
2524
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2525
0
                error );
2526
0
      break;
2527
2528
0
    case LIBFWEVT_VALUE_TYPE_SYSTEMTIME:
2529
0
      result = libfdatetime_systemtime_get_string_size(
2530
0
                data_segment->systemtime,
2531
0
                &safe_utf16_string_size,
2532
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2533
0
                error );
2534
0
      break;
2535
2536
0
    case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER:
2537
0
      result = libfwnt_security_identifier_get_string_size(
2538
0
                data_segment->security_identifier,
2539
0
                &safe_utf16_string_size,
2540
0
          0,
2541
0
                error );
2542
0
      break;
2543
2544
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT:
2545
0
      safe_utf16_string_size = 11;
2546
2547
0
      result = 1;
2548
0
      break;
2549
2550
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT:
2551
0
      safe_utf16_string_size = 19;
2552
2553
0
      result = 1;
2554
0
      break;
2555
2556
0
    case LIBFWEVT_VALUE_TYPE_SIZE:
2557
0
      if( data_segment->data_size == 4 )
2558
0
      {
2559
0
        safe_utf16_string_size = 11;
2560
2561
0
        result = 1;
2562
0
      }
2563
0
      else if( data_segment->data_size == 8 )
2564
0
      {
2565
0
        safe_utf16_string_size = 19;
2566
2567
0
        result = 1;
2568
0
      }
2569
0
      break;
2570
2571
0
    default:
2572
0
      break;
2573
0
  }
2574
0
  if( result != 1 )
2575
0
  {
2576
0
    libcerror_error_set(
2577
0
     error,
2578
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2579
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2580
0
     "%s: unable to determine size UTF-16 string of data segment: %d.",
2581
0
     function,
2582
0
     data_segment_index );
2583
2584
0
    return( -1 );
2585
0
  }
2586
0
  *utf16_string_size = safe_utf16_string_size;
2587
2588
0
  return( 1 );
2589
0
}
2590
2591
/* Retrieves the data segment formatted as an UTF-16 string
2592
 * Returns 1 if successful or -1 on error
2593
 */
2594
int libfwevt_internal_xml_value_get_data_segment_as_utf16_string(
2595
     libfwevt_internal_xml_value_t *internal_xml_value,
2596
     int data_segment_index,
2597
     libfwevt_data_segment_t *data_segment,
2598
     uint16_t *utf16_string,
2599
     size_t utf16_string_size,
2600
     size_t *utf16_string_index,
2601
     uint8_t escape_characters,
2602
     int ascii_codepage,
2603
     libcerror_error_t **error )
2604
0
{
2605
0
  static char *function          = "libfwevt_internal_xml_value_get_data_segment_as_utf16_string";
2606
0
  size_t base16_stream_index     = 0;
2607
0
  size_t safe_utf16_string_index = 0;
2608
0
  uint32_t format_flags          = 0;
2609
0
  uint8_t number_of_characters   = 0;
2610
0
  int result                     = 0;
2611
2612
0
  if( internal_xml_value == NULL )
2613
0
  {
2614
0
    libcerror_error_set(
2615
0
     error,
2616
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2617
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2618
0
     "%s: invalid XML value.",
2619
0
     function );
2620
2621
0
    return( -1 );
2622
0
  }
2623
0
  if( data_segment == NULL )
2624
0
  {
2625
0
    libcerror_error_set(
2626
0
     error,
2627
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2628
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2629
0
     "%s: invalid data segment.",
2630
0
     function );
2631
2632
0
    return( -1 );
2633
0
  }
2634
0
  if( utf16_string == NULL )
2635
0
  {
2636
0
    libcerror_error_set(
2637
0
     error,
2638
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2639
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2640
0
     "%s: invalid UTF-16 string.",
2641
0
     function );
2642
2643
0
    return( -1 );
2644
0
  }
2645
0
  if( utf16_string_size > (size_t) SSIZE_MAX )
2646
0
  {
2647
0
    libcerror_error_set(
2648
0
     error,
2649
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2650
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
2651
0
     "%s: invalid UTF-16 string size value exceeds maximum.",
2652
0
     function );
2653
2654
0
    return( -1 );
2655
0
  }
2656
0
  if( utf16_string_index == NULL )
2657
0
  {
2658
0
    libcerror_error_set(
2659
0
     error,
2660
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2661
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2662
0
     "%s: invalid UTF-16 string index.",
2663
0
     function );
2664
2665
0
    return( -1 );
2666
0
  }
2667
0
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
2668
0
       internal_xml_value,
2669
0
       data_segment_index,
2670
0
       &data_segment,
2671
0
       error ) != 1 )
2672
0
  {
2673
0
    libcerror_error_set(
2674
0
     error,
2675
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2676
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2677
0
     "%s: unable to retrieve data segment: %d.",
2678
0
     function,
2679
0
     data_segment_index );
2680
2681
0
    return( -1 );
2682
0
  }
2683
0
  switch( internal_xml_value->value_type & 0x7f )
2684
0
  {
2685
0
    case LIBFWEVT_VALUE_TYPE_STRING_UTF16:
2686
0
      if( data_segment->data_size == 0 )
2687
0
      {
2688
0
        result = 1;
2689
0
      }
2690
0
      else if( escape_characters == 0 )
2691
0
      {
2692
0
        result = libuna_utf16_string_with_index_copy_from_utf16_stream(
2693
0
                  utf16_string,
2694
0
                  utf16_string_size,
2695
0
                  utf16_string_index,
2696
0
                  data_segment->data,
2697
0
                  data_segment->data_size,
2698
0
                  LIBUNA_ENDIAN_LITTLE,
2699
0
                  error );
2700
0
      }
2701
0
      else
2702
0
      {
2703
0
        result = libfwevt_utf16_xml_string_with_index_copy_from_utf16_stream(
2704
0
                  utf16_string,
2705
0
                  utf16_string_size,
2706
0
                  utf16_string_index,
2707
0
                  data_segment->data,
2708
0
                  data_segment->data_size,
2709
0
                  LIBUNA_ENDIAN_LITTLE,
2710
0
                  error );
2711
0
      }
2712
0
      break;
2713
2714
0
    case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM:
2715
0
      result = libuna_utf16_string_with_index_copy_from_byte_stream(
2716
0
                utf16_string,
2717
0
                utf16_string_size,
2718
0
                utf16_string_index,
2719
0
                data_segment->data,
2720
0
                data_segment->data_size,
2721
0
                ascii_codepage,
2722
0
                error );
2723
/* TODO add support for escape_characters */
2724
0
      break;
2725
2726
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT:
2727
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2728
0
                data_segment->value_64bit,
2729
0
                8,
2730
0
                utf16_string,
2731
0
                utf16_string_size,
2732
0
                utf16_string_index,
2733
0
                error );
2734
0
      break;
2735
2736
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT:
2737
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2738
0
                data_segment->value_64bit,
2739
0
                16,
2740
0
                utf16_string,
2741
0
                utf16_string_size,
2742
0
                utf16_string_index,
2743
0
                error );
2744
0
      break;
2745
2746
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT:
2747
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2748
0
                data_segment->value_64bit,
2749
0
                32,
2750
0
                utf16_string,
2751
0
                utf16_string_size,
2752
0
                utf16_string_index,
2753
0
                error );
2754
0
      break;
2755
2756
0
    case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT:
2757
0
      result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index(
2758
0
                data_segment->value_64bit,
2759
0
                64,
2760
0
                utf16_string,
2761
0
                utf16_string_size,
2762
0
                utf16_string_index,
2763
0
                error );
2764
0
      break;
2765
2766
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT:
2767
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT:
2768
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT:
2769
0
    case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT:
2770
0
      result = libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index(
2771
0
                data_segment->value_64bit,
2772
0
                utf16_string,
2773
0
                utf16_string_size,
2774
0
                utf16_string_index,
2775
0
                error );
2776
0
      break;
2777
2778
2779
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT:
2780
0
      result = libfwevt_float32_copy_to_utf16_string_with_index(
2781
0
                (uint32_t) data_segment->value_64bit,
2782
0
                utf16_string,
2783
0
                utf16_string_size,
2784
0
                utf16_string_index,
2785
0
                error );
2786
0
      break;
2787
2788
0
    case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT:
2789
0
      result = libfwevt_float64_copy_to_utf16_string_with_index(
2790
0
                data_segment->value_64bit,
2791
0
                utf16_string,
2792
0
                utf16_string_size,
2793
0
                utf16_string_index,
2794
0
                error );
2795
0
      break;
2796
2797
0
    case LIBFWEVT_VALUE_TYPE_BOOLEAN:
2798
0
      if( data_segment->value_64bit == 0 )
2799
0
      {
2800
0
        number_of_characters = 6;
2801
0
      }
2802
0
      else
2803
0
      {
2804
0
        number_of_characters = 5;
2805
0
      }
2806
0
      safe_utf16_string_index = *utf16_string_index;
2807
2808
0
      if( ( number_of_characters > utf16_string_size )
2809
0
       || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) )
2810
0
      {
2811
0
        libcerror_error_set(
2812
0
         error,
2813
0
         LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2814
0
         LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
2815
0
         "%s: invalid UTF-16 string size value too small.",
2816
0
         function );
2817
2818
0
        return( -1 );
2819
0
      }
2820
0
      if( data_segment->value_64bit == 0 )
2821
0
      {
2822
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'f';
2823
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'a';
2824
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'l';
2825
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 's';
2826
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e';
2827
0
      }
2828
0
      else
2829
0
      {
2830
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 't';
2831
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'r';
2832
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'u';
2833
0
        utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e';
2834
0
      }
2835
0
      utf16_string[ safe_utf16_string_index++ ] = 0;
2836
2837
0
      *utf16_string_index = safe_utf16_string_index;
2838
2839
0
      result = 1;
2840
2841
0
      break;
2842
2843
0
    case LIBFWEVT_VALUE_TYPE_BINARY_DATA:
2844
0
      base16_stream_index = *utf16_string_index * 2;
2845
0
      format_flags        = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE;
2846
2847
#if _BYTE_STREAM_HOST_BYTE_ORDER == _BYTE_STREAM_ENDIAN_BIG
2848
      format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN;
2849
#else
2850
0
      format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN;
2851
0
#endif
2852
0
      result = libuna_base16_stream_with_index_copy_from_byte_stream(
2853
0
                (uint8_t *) utf16_string,
2854
0
                utf16_string_size * 2,
2855
0
                &base16_stream_index,
2856
0
                data_segment->data,
2857
0
                data_segment->data_size,
2858
0
                format_flags,
2859
0
                error );
2860
2861
0
      if( result == 1 )
2862
0
      {
2863
0
        *utf16_string_index = ( base16_stream_index / 2 ) + 1;
2864
0
      }
2865
0
      break;
2866
2867
0
    case LIBFWEVT_VALUE_TYPE_GUID:
2868
0
      result = libfguid_identifier_copy_to_utf16_string_with_index(
2869
0
                data_segment->guid,
2870
0
                utf16_string,
2871
0
                utf16_string_size,
2872
0
                utf16_string_index,
2873
0
                LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
2874
0
                error );
2875
0
      break;
2876
2877
0
    case LIBFWEVT_VALUE_TYPE_FILETIME:
2878
0
      result = libfdatetime_filetime_copy_to_utf16_string_with_index(
2879
0
                data_segment->filetime,
2880
0
                utf16_string,
2881
0
                utf16_string_size,
2882
0
                utf16_string_index,
2883
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2884
0
                error );
2885
0
      break;
2886
2887
0
    case LIBFWEVT_VALUE_TYPE_SYSTEMTIME:
2888
0
      result = libfdatetime_systemtime_copy_to_utf16_string_with_index(
2889
0
                data_segment->systemtime,
2890
0
                utf16_string,
2891
0
                utf16_string_size,
2892
0
                utf16_string_index,
2893
0
                LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR,
2894
0
                error );
2895
0
      break;
2896
2897
0
    case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER:
2898
0
      result = libfwnt_security_identifier_copy_to_utf16_string_with_index(
2899
0
                data_segment->security_identifier,
2900
0
                utf16_string,
2901
0
                utf16_string_size,
2902
0
                utf16_string_index,
2903
0
          0,
2904
0
                error );
2905
0
      break;
2906
2907
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT:
2908
0
      result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index(
2909
0
                data_segment->value_64bit,
2910
0
                32,
2911
0
                utf16_string,
2912
0
                utf16_string_size,
2913
0
                utf16_string_index,
2914
0
                error );
2915
0
      break;
2916
2917
0
    case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT:
2918
0
      result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index(
2919
0
                data_segment->value_64bit,
2920
0
                64,
2921
0
                utf16_string,
2922
0
                utf16_string_size,
2923
0
                utf16_string_index,
2924
0
                error );
2925
0
      break;
2926
2927
0
    case LIBFWEVT_VALUE_TYPE_SIZE:
2928
0
      if( data_segment->data_size == 4 )
2929
0
      {
2930
0
        result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index(
2931
0
                  data_segment->value_64bit,
2932
0
                  32,
2933
0
                  utf16_string,
2934
0
                  utf16_string_size,
2935
0
                  utf16_string_index,
2936
0
                  error );
2937
0
      }
2938
0
      else if( data_segment->data_size == 8 )
2939
0
      {
2940
0
        result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index(
2941
0
                  data_segment->value_64bit,
2942
0
                  64,
2943
0
                  utf16_string,
2944
0
                  utf16_string_size,
2945
0
                  utf16_string_index,
2946
0
                  error );
2947
0
      }
2948
0
      break;
2949
2950
0
    default:
2951
0
      break;
2952
0
  }
2953
0
  if( result != 1 )
2954
0
  {
2955
0
    libcerror_error_set(
2956
0
     error,
2957
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2958
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2959
0
     "%s: unable to copy data segment: %d to UTF-16 string.",
2960
0
     function,
2961
0
     data_segment_index );
2962
2963
0
    return( -1 );
2964
0
  }
2965
0
  return( 1 );
2966
0
}
2967
2968
/* Retrieves the size of the value data formatted as an UTF-16 string
2969
 * The string size includes the end of string character
2970
 * Returns 1 if successful or -1 on error
2971
 */
2972
int libfwevt_internal_xml_value_get_data_as_utf16_string_size(
2973
     libfwevt_internal_xml_value_t *internal_xml_value,
2974
     size_t *utf16_string_size,
2975
     uint8_t escape_characters,
2976
     int ascii_codepage,
2977
     libcerror_error_t **error )
2978
0
{
2979
0
  libfwevt_data_segment_t *data_segment = NULL;
2980
0
  static char *function                 = "libfwevt_internal_xml_value_get_data_as_utf16_string_size";
2981
0
  size_t data_segment_size              = 0;
2982
0
  size_t safe_utf16_string_size         = 0;
2983
0
  int data_segment_index                = 0;
2984
0
  int number_of_data_segments           = 0;
2985
2986
0
  if( internal_xml_value == NULL )
2987
0
  {
2988
0
    libcerror_error_set(
2989
0
     error,
2990
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2991
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2992
0
     "%s: invalid XML value.",
2993
0
     function );
2994
2995
0
    return( -1 );
2996
0
  }
2997
0
  if( utf16_string_size == NULL )
2998
0
  {
2999
0
    libcerror_error_set(
3000
0
     error,
3001
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3002
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3003
0
     "%s: invalid UTF-16 string size.",
3004
0
     function );
3005
3006
0
    return( -1 );
3007
0
  }
3008
0
  if( libcdata_array_get_number_of_entries(
3009
0
       internal_xml_value->data_segments,
3010
0
       &number_of_data_segments,
3011
0
       error ) != 1 )
3012
0
  {
3013
0
    libcerror_error_set(
3014
0
     error,
3015
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3016
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3017
0
     "%s: unable to retrieve number of data segments.",
3018
0
     function );
3019
3020
0
    return( -1 );
3021
0
  }
3022
0
  for( data_segment_index = 0;
3023
0
       data_segment_index < number_of_data_segments;
3024
0
       data_segment_index++ )
3025
0
  {
3026
0
    if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
3027
0
         internal_xml_value,
3028
0
         data_segment_index,
3029
0
         &data_segment,
3030
0
         error ) != 1 )
3031
0
    {
3032
0
      libcerror_error_set(
3033
0
       error,
3034
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3035
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3036
0
       "%s: unable to retrieve data segment: %d.",
3037
0
       function,
3038
0
       data_segment_index );
3039
3040
0
      return( -1 );
3041
0
    }
3042
0
    if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size(
3043
0
         internal_xml_value,
3044
0
         data_segment_index,
3045
0
         data_segment,
3046
0
         &data_segment_size,
3047
0
         escape_characters,
3048
0
         ascii_codepage,
3049
0
         error ) != 1 )
3050
0
    {
3051
0
      libcerror_error_set(
3052
0
       error,
3053
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3054
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3055
0
       "%s: unable to retrieve UTF-16 string size of element data segment: %d.",
3056
0
       function,
3057
0
       data_segment_index );
3058
3059
0
      return( -1 );
3060
0
    }
3061
0
    if( data_segment_size > 1 )
3062
0
    {
3063
0
      safe_utf16_string_size += data_segment_size - 1;
3064
0
    }
3065
0
  }
3066
0
  if( ( number_of_data_segments == 1 )
3067
0
   && ( data_segment != NULL )
3068
0
   && ( safe_utf16_string_size == 1 ) )
3069
0
  {
3070
0
    if( ( data_segment->data_size >= 2 )
3071
0
     && ( data_segment->data[ 0 ] == '\n' )
3072
0
     && ( data_segment->data[ 1 ] == 0 ) )
3073
0
    {
3074
      /* The value data consists of a single linefeed consider it empty
3075
       */
3076
0
      safe_utf16_string_size = 0;
3077
0
    }
3078
0
  }
3079
0
  if( safe_utf16_string_size > 0 )
3080
0
  {
3081
0
    safe_utf16_string_size++;
3082
0
  }
3083
0
  *utf16_string_size = safe_utf16_string_size;
3084
3085
0
  return( 1 );
3086
0
}
3087
3088
/* Retrieves the data formatted as an UTF-16 string
3089
 * The string size should include the end of string character
3090
 * Returns 1 if successful or -1 on error
3091
 */
3092
int libfwevt_internal_xml_value_get_data_as_utf16_string_with_index(
3093
     libfwevt_internal_xml_value_t *internal_xml_value,
3094
     uint16_t *utf16_string,
3095
     size_t utf16_string_size,
3096
     size_t *utf16_string_index,
3097
     uint8_t escape_characters,
3098
     int ascii_codepage,
3099
     libcerror_error_t **error )
3100
0
{
3101
0
  libfwevt_data_segment_t *data_segment = NULL;
3102
0
  static char *function                 = "libfwevt_internal_xml_value_get_data_as_utf16_string_with_index";
3103
0
  size_t safe_utf16_string_index        = 0;
3104
0
  int data_segment_index                = 0;
3105
0
  int number_of_data_segments           = 0;
3106
3107
0
  if( internal_xml_value == NULL )
3108
0
  {
3109
0
    libcerror_error_set(
3110
0
     error,
3111
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3112
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3113
0
     "%s: invalid XML value.",
3114
0
     function );
3115
3116
0
    return( -1 );
3117
0
  }
3118
0
  if( utf16_string == NULL )
3119
0
  {
3120
0
    libcerror_error_set(
3121
0
     error,
3122
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3123
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3124
0
     "%s: invalid UTF-16 string.",
3125
0
     function );
3126
3127
0
    return( -1 );
3128
0
  }
3129
0
  if( utf16_string_size > (size_t) SSIZE_MAX )
3130
0
  {
3131
0
    libcerror_error_set(
3132
0
     error,
3133
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3134
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
3135
0
     "%s: invalid UTF-16 string size value exceeds maximum.",
3136
0
     function );
3137
3138
0
    return( -1 );
3139
0
  }
3140
0
  if( utf16_string_index == NULL )
3141
0
  {
3142
0
    libcerror_error_set(
3143
0
     error,
3144
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3145
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3146
0
     "%s: invalid UTF-16 string index.",
3147
0
     function );
3148
3149
0
    return( -1 );
3150
0
  }
3151
0
  safe_utf16_string_index = *utf16_string_index;
3152
3153
0
  if( libcdata_array_get_number_of_entries(
3154
0
       internal_xml_value->data_segments,
3155
0
       &number_of_data_segments,
3156
0
       error ) != 1 )
3157
0
  {
3158
0
    libcerror_error_set(
3159
0
     error,
3160
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3161
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3162
0
     "%s: unable to retrieve number of data segments.",
3163
0
     function );
3164
3165
0
    return( -1 );
3166
0
  }
3167
0
  for( data_segment_index = 0;
3168
0
       data_segment_index < number_of_data_segments;
3169
0
       data_segment_index++ )
3170
0
  {
3171
0
    if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
3172
0
         internal_xml_value,
3173
0
         data_segment_index,
3174
0
         &data_segment,
3175
0
         error ) != 1 )
3176
0
    {
3177
0
      libcerror_error_set(
3178
0
       error,
3179
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3180
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3181
0
       "%s: unable to retrieve data segment: %d.",
3182
0
       function,
3183
0
       data_segment_index );
3184
3185
0
      return( -1 );
3186
0
    }
3187
0
    if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string(
3188
0
         internal_xml_value,
3189
0
         data_segment_index,
3190
0
         data_segment,
3191
0
         utf16_string,
3192
0
         utf16_string_size,
3193
0
         &safe_utf16_string_index,
3194
0
         escape_characters,
3195
0
         ascii_codepage,
3196
0
         error ) != 1 )
3197
0
    {
3198
0
      libcerror_error_set(
3199
0
       error,
3200
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3201
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3202
0
       "%s: unable to copy data segment: %d to UTF-16 string.",
3203
0
       function,
3204
0
       data_segment_index );
3205
3206
0
      return( -1 );
3207
0
    }
3208
0
    safe_utf16_string_index--;
3209
0
  }
3210
0
  if( ( number_of_data_segments == 1 )
3211
0
   && ( data_segment != NULL )
3212
0
   && ( safe_utf16_string_index == 1 ) )
3213
0
  {
3214
0
    if( ( data_segment->data_size >= 2 )
3215
0
     && ( data_segment->data[ 0 ] == '\n' )
3216
0
     && ( data_segment->data[ 1 ] == 0 ) )
3217
0
    {
3218
      /* The value data consists of a single linefeed consider it empty
3219
       */
3220
0
      safe_utf16_string_index = 0;
3221
0
    }
3222
0
  }
3223
0
  if( safe_utf16_string_index > 0 )
3224
0
  {
3225
0
    if( safe_utf16_string_index >= utf16_string_size  )
3226
0
    {
3227
0
      libcerror_error_set(
3228
0
       error,
3229
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3230
0
       LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
3231
0
       "%s: invalid UTF-16 string size value too small.",
3232
0
       function );
3233
3234
0
      return( -1 );
3235
0
    }
3236
0
    utf16_string[ safe_utf16_string_index++ ] = 0;
3237
0
  }
3238
0
  *utf16_string_index = safe_utf16_string_index;
3239
3240
0
  return( 1 );
3241
0
}
3242
3243
/* Retrieves the size of an UTF-16 encoded string of the value data
3244
 * Returns 1 if successful or -1 on error
3245
 */
3246
int libfwevt_xml_value_get_utf16_string_size(
3247
     libfwevt_xml_value_t *xml_value,
3248
     size_t *utf16_string_size,
3249
     libcerror_error_t **error )
3250
0
{
3251
0
  static char *function = "libfwevt_xml_value_get_utf16_string_size";
3252
3253
0
  if( xml_value == NULL )
3254
0
  {
3255
0
    libcerror_error_set(
3256
0
     error,
3257
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3258
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3259
0
     "%s: invalid XML value.",
3260
0
     function );
3261
3262
0
    return( -1 );
3263
0
  }
3264
0
  if( libfwevt_internal_xml_value_get_data_as_utf16_string_size(
3265
0
       (libfwevt_internal_xml_value_t *) xml_value,
3266
0
       utf16_string_size,
3267
0
       0,
3268
0
       LIBUNA_CODEPAGE_WINDOWS_1252,
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 size of UTF-16 string.",
3276
0
     function );
3277
3278
0
    return( -1 );
3279
0
  }
3280
0
  return( 1 );
3281
0
}
3282
3283
/* Copies the value data to an UTF-16 encoded string
3284
 * Returns 1 if successful or -1 on error
3285
 */
3286
int libfwevt_xml_value_copy_to_utf16_string(
3287
     libfwevt_xml_value_t *xml_value,
3288
     uint16_t *utf16_string,
3289
     size_t utf16_string_size,
3290
     libcerror_error_t **error )
3291
0
{
3292
0
  static char *function = "libfwevt_xml_value_copy_to_utf16_string";
3293
3294
0
  if( libfwevt_xml_value_get_data_as_utf16_string(
3295
0
       xml_value,
3296
0
       utf16_string,
3297
0
       utf16_string_size,
3298
0
       error ) != 1 )
3299
0
  {
3300
0
    libcerror_error_set(
3301
0
     error,
3302
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3303
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3304
0
     "%s: unable to retrieve size of UTF-16 string.",
3305
0
     function );
3306
3307
0
    return( -1 );
3308
0
  }
3309
0
  return( 1 );
3310
0
}
3311
3312
/* Retrieves the size of the value data formatted as an UTF-16 string
3313
 * The string size includes the end of string character
3314
 * Returns 1 if successful or -1 on error
3315
 */
3316
int libfwevt_xml_value_get_data_as_utf16_string_size(
3317
     libfwevt_xml_value_t *xml_value,
3318
     size_t *utf16_string_size,
3319
     libcerror_error_t **error )
3320
0
{
3321
0
  static char *function = "libfwevt_xml_value_get_data_as_utf16_string_size";
3322
3323
0
  if( xml_value == NULL )
3324
0
  {
3325
0
    libcerror_error_set(
3326
0
     error,
3327
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3328
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3329
0
     "%s: invalid XML value.",
3330
0
     function );
3331
3332
0
    return( -1 );
3333
0
  }
3334
/* TODO pass codepage */
3335
0
  if( libfwevt_internal_xml_value_get_data_as_utf16_string_size(
3336
0
       (libfwevt_internal_xml_value_t *) xml_value,
3337
0
       utf16_string_size,
3338
0
       0,
3339
0
       LIBUNA_CODEPAGE_WINDOWS_1252,
3340
0
       error ) != 1 )
3341
0
  {
3342
0
    libcerror_error_set(
3343
0
     error,
3344
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3345
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3346
0
     "%s: unable to retrieve UTF-16 string size.",
3347
0
     function );
3348
3349
0
    return( -1 );
3350
0
  }
3351
0
  return( 1 );
3352
0
}
3353
3354
/* Retrieves the data formatted as an UTF-16 string
3355
 * The string size should include the end of string character
3356
 * Returns 1 if successful or -1 on error
3357
 */
3358
int libfwevt_xml_value_get_data_as_utf16_string(
3359
     libfwevt_xml_value_t *xml_value,
3360
     uint16_t *utf16_string,
3361
     size_t utf16_string_size,
3362
     libcerror_error_t **error )
3363
0
{
3364
0
  static char *function     = "libfwevt_xml_value_get_data_as_utf16_string";
3365
0
  size_t utf16_string_index = 0;
3366
3367
0
  if( xml_value == NULL )
3368
0
  {
3369
0
    libcerror_error_set(
3370
0
     error,
3371
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3372
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3373
0
     "%s: invalid XML value.",
3374
0
     function );
3375
3376
0
    return( -1 );
3377
0
  }
3378
/* TODO pass codepage */
3379
0
  if( libfwevt_internal_xml_value_get_data_as_utf16_string_with_index(
3380
0
       (libfwevt_internal_xml_value_t *) xml_value,
3381
0
       utf16_string,
3382
0
       utf16_string_size,
3383
0
       &utf16_string_index,
3384
0
       0,
3385
0
       LIBUNA_CODEPAGE_WINDOWS_1252,
3386
0
       error ) != 1 )
3387
0
  {
3388
0
    libcerror_error_set(
3389
0
     error,
3390
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3391
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3392
0
     "%s: unable to retrieve size of UTF-16 string.",
3393
0
     function );
3394
3395
0
    return( -1 );
3396
0
  }
3397
0
  return( 1 );
3398
0
}
3399
3400
#if defined( HAVE_DEBUG_OUTPUT )
3401
3402
/* Prints the value
3403
 * Returns 1 if successful or -1 on error
3404
 */
3405
int libfwevt_xml_value_debug_print(
3406
     libfwevt_xml_value_t *xml_value,
3407
     uint8_t escape_characters,
3408
     int ascii_codepage,
3409
     libcerror_error_t **error )
3410
{
3411
  system_character_t *value_string                  = NULL;
3412
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3413
  static char *function                             = "libfwevt_xml_value_debug_print";
3414
  size_t value_string_index                         = 0;
3415
  size_t value_string_size                          = 0;
3416
  int result                                        = 0;
3417
3418
  if( xml_value == NULL )
3419
  {
3420
    libcerror_error_set(
3421
     error,
3422
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3423
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3424
     "%s: invalid XML value.",
3425
     function );
3426
3427
    return( -1 );
3428
  }
3429
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3430
3431
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3432
  result = libfwevt_internal_xml_value_get_data_as_utf16_string_size(
3433
      internal_xml_value,
3434
      &value_string_size,
3435
      escape_characters,
3436
            ascii_codepage,
3437
      error );
3438
#else
3439
  result = libfwevt_internal_xml_value_get_data_as_utf8_string_size(
3440
      internal_xml_value,
3441
      &value_string_size,
3442
      escape_characters,
3443
            ascii_codepage,
3444
      error );
3445
#endif
3446
  if( result != 1 )
3447
  {
3448
    libcerror_error_set(
3449
     error,
3450
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3451
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3452
     "%s: unable to determine size of value string.",
3453
     function );
3454
3455
    goto on_error;
3456
  }
3457
  if( value_string_size > 0 )
3458
  {
3459
    if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( system_character_t ) ) )
3460
    {
3461
      libcerror_error_set(
3462
       error,
3463
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3464
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3465
       "%s: invalid name string size value exceeds maximum.",
3466
       function );
3467
3468
      goto on_error;
3469
    }
3470
    value_string = system_string_allocate(
3471
                    value_string_size );
3472
3473
    if( value_string == NULL )
3474
    {
3475
      libcerror_error_set(
3476
       error,
3477
       LIBCERROR_ERROR_DOMAIN_MEMORY,
3478
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
3479
       "%s: unable to create value string.",
3480
       function );
3481
3482
      goto on_error;
3483
    }
3484
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3485
    result = libfwevt_internal_xml_value_get_data_as_utf16_string_with_index(
3486
        internal_xml_value,
3487
        (libuna_utf16_character_t *) value_string,
3488
        value_string_size,
3489
        &value_string_index,
3490
        escape_characters,
3491
              ascii_codepage,
3492
        error );
3493
#else
3494
    result = libfwevt_internal_xml_value_get_data_as_utf8_string_with_index(
3495
        internal_xml_value,
3496
        (libuna_utf8_character_t *) value_string,
3497
        value_string_size,
3498
        &value_string_index,
3499
        escape_characters,
3500
              ascii_codepage,
3501
        error );
3502
#endif
3503
    if( result != 1 )
3504
    {
3505
      libcerror_error_set(
3506
       error,
3507
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3508
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3509
       "%s: unable to retrieve value string.",
3510
       function );
3511
3512
      goto on_error;
3513
    }
3514
    libcnotify_printf(
3515
     "%" PRIs_SYSTEM "",
3516
     value_string );
3517
3518
    memory_free(
3519
     value_string );
3520
  }
3521
  return( 1 );
3522
3523
on_error:
3524
  if( value_string != NULL )
3525
  {
3526
    memory_free(
3527
     value_string );
3528
  }
3529
  return( -1 );
3530
}
3531
3532
/* Prints the value of a specific data segment
3533
 * Returns 1 if successful or -1 on error
3534
 */
3535
int libfwevt_xml_value_debug_print_data_segment(
3536
     libfwevt_xml_value_t *xml_value,
3537
     int data_segment_index,
3538
     uint8_t escape_characters,
3539
     int ascii_codepage,
3540
     libcerror_error_t **error )
3541
{
3542
  libfwevt_data_segment_t *data_segment             = NULL;
3543
  libfwevt_internal_xml_value_t *internal_xml_value = NULL;
3544
  system_character_t *value_string                  = NULL;
3545
  static char *function                             = "libfwevt_xml_value_debug_print_data_segment";
3546
  size_t value_string_index                         = 0;
3547
  size_t value_string_size                          = 0;
3548
  int result                                        = 0;
3549
3550
  if( xml_value == NULL )
3551
  {
3552
    libcerror_error_set(
3553
     error,
3554
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3555
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3556
     "%s: invalid XML value.",
3557
     function );
3558
3559
    return( -1 );
3560
  }
3561
  internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value;
3562
3563
  if( libfwevt_internal_xml_value_get_data_segment_with_cached_value(
3564
       internal_xml_value,
3565
       data_segment_index,
3566
       &data_segment,
3567
       error ) != 1 )
3568
  {
3569
    libcerror_error_set(
3570
     error,
3571
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3572
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3573
     "%s: unable to retrieve data segment: %d.",
3574
     function,
3575
     data_segment_index );
3576
3577
    return( -1 );
3578
  }
3579
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3580
  result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size(
3581
      internal_xml_value,
3582
      data_segment_index,
3583
            data_segment,
3584
      &value_string_size,
3585
      escape_characters,
3586
      ascii_codepage,
3587
      error );
3588
#else
3589
  result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size(
3590
      internal_xml_value,
3591
      data_segment_index,
3592
            data_segment,
3593
      &value_string_size,
3594
      escape_characters,
3595
      ascii_codepage,
3596
      error );
3597
#endif
3598
  if( result != 1 )
3599
  {
3600
    libcerror_error_set(
3601
     error,
3602
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3603
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3604
     "%s: unable to determine size of value string of data segment: %d.",
3605
     function,
3606
     data_segment_index );
3607
3608
    goto on_error;
3609
  }
3610
  if( value_string_size > 0 )
3611
  {
3612
    if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( system_character_t ) ) )
3613
    {
3614
      libcerror_error_set(
3615
       error,
3616
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3617
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3618
       "%s: invalid name string size value exceeds maximum.",
3619
       function );
3620
3621
      goto on_error;
3622
    }
3623
    value_string = system_string_allocate(
3624
                    value_string_size );
3625
3626
    if( value_string == NULL )
3627
    {
3628
      libcerror_error_set(
3629
       error,
3630
       LIBCERROR_ERROR_DOMAIN_MEMORY,
3631
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
3632
       "%s: unable to create value string.",
3633
       function );
3634
3635
      goto on_error;
3636
    }
3637
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
3638
    result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string(
3639
        internal_xml_value,
3640
        data_segment_index,
3641
              data_segment,
3642
        (libuna_utf16_character_t *) value_string,
3643
        value_string_size,
3644
        &value_string_index,
3645
              escape_characters,
3646
              ascii_codepage,
3647
        error );
3648
#else
3649
    result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string(
3650
        internal_xml_value,
3651
        data_segment_index,
3652
              data_segment,
3653
        (libuna_utf8_character_t *) value_string,
3654
        value_string_size,
3655
        &value_string_index,
3656
              escape_characters,
3657
              ascii_codepage,
3658
        error );
3659
#endif
3660
    if( result != 1 )
3661
    {
3662
      libcerror_error_set(
3663
       error,
3664
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3665
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3666
       "%s: unable to retrieve value string of data segment: %d.",
3667
       function,
3668
       data_segment_index );
3669
3670
      goto on_error;
3671
    }
3672
    libcnotify_printf(
3673
     "%" PRIs_SYSTEM "",
3674
     value_string );
3675
3676
    memory_free(
3677
     value_string );
3678
  }
3679
  return( 1 );
3680
3681
on_error:
3682
  if( value_string != NULL )
3683
  {
3684
    memory_free(
3685
     value_string );
3686
  }
3687
  return( -1 );
3688
}
3689
3690
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
3691