Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libscca/libfdatetime/libfdatetime_systemtime.c
Line
Count
Source
1
/*
2
 * SYSTEMTIME functions
3
 *
4
 * Copyright (C) 2009-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 <types.h>
26
27
#include "libfdatetime_definitions.h"
28
#include "libfdatetime_date_time_values.h"
29
#include "libfdatetime_libcerror.h"
30
#include "libfdatetime_systemtime.h"
31
#include "libfdatetime_types.h"
32
33
/* Creates a SYSTEMTIME
34
 * Make sure the value systemtime is referencing, is set to NULL
35
 * Returns 1 if successful or -1 on error
36
 */
37
int libfdatetime_systemtime_initialize(
38
     libfdatetime_systemtime_t **systemtime,
39
     libcerror_error_t **error )
40
73.1k
{
41
73.1k
  libfdatetime_internal_systemtime_t *internal_systemtime = NULL;
42
73.1k
  static char *function                                   = "libfdatetime_systemtime_initialize";
43
44
73.1k
  if( systemtime == NULL )
45
0
  {
46
0
    libcerror_error_set(
47
0
     error,
48
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
49
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
50
0
     "%s: invalid SYSTEMTIME.",
51
0
     function );
52
53
0
    return( -1 );
54
0
  }
55
73.1k
  if( *systemtime != NULL )
56
0
  {
57
0
    libcerror_error_set(
58
0
     error,
59
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
60
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
61
0
     "%s: invalid SYSTEMTIME value already set.",
62
0
     function );
63
64
0
    return( -1 );
65
0
  }
66
73.1k
  internal_systemtime = memory_allocate_structure(
67
73.1k
                         libfdatetime_internal_systemtime_t );
68
69
73.1k
  if( internal_systemtime == NULL )
70
0
  {
71
0
    libcerror_error_set(
72
0
     error,
73
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
74
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
75
0
     "%s: unable to create SYSTEMTIME.",
76
0
     function );
77
78
0
    goto on_error;
79
0
  }
80
73.1k
  if( memory_set(
81
73.1k
       internal_systemtime,
82
73.1k
       0,
83
73.1k
       sizeof( libfdatetime_internal_systemtime_t ) ) == NULL )
84
0
  {
85
0
    libcerror_error_set(
86
0
     error,
87
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
88
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
89
0
     "%s: unable to clear SYSTEMTIME.",
90
0
     function );
91
92
0
    goto on_error;
93
0
  }
94
73.1k
  *systemtime = (libfdatetime_systemtime_t *) internal_systemtime;
95
96
73.1k
  return( 1 );
97
98
0
on_error:
99
0
  if( internal_systemtime != NULL )
100
0
  {
101
0
    memory_free(
102
0
     internal_systemtime );
103
0
  }
104
0
  return( -1 );
105
73.1k
}
106
107
/* Frees a SYSTEMTIME
108
 * Returns 1 if successful or -1 on error
109
 */
110
int libfdatetime_systemtime_free(
111
     libfdatetime_systemtime_t **systemtime,
112
     libcerror_error_t **error )
113
73.1k
{
114
73.1k
  libfdatetime_internal_systemtime_t *internal_systemtime = NULL;
115
73.1k
  static char *function                                   = "libfdatetime_systemtime_free";
116
117
73.1k
  if( systemtime == NULL )
118
0
  {
119
0
    libcerror_error_set(
120
0
     error,
121
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
122
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
123
0
     "%s: invalid SYSTEMTIME.",
124
0
     function );
125
126
0
    return( -1 );
127
0
  }
128
73.1k
  if( *systemtime != NULL )
129
73.1k
  {
130
73.1k
    internal_systemtime = (libfdatetime_internal_systemtime_t *) *systemtime;
131
73.1k
    *systemtime         = NULL;
132
133
73.1k
    memory_free(
134
73.1k
     internal_systemtime );
135
73.1k
  }
136
73.1k
  return( 1 );
137
73.1k
}
138
139
/* Converts a byte stream into a systemtime
140
 * Returns 1 if successful or -1 on error
141
 */
142
int libfdatetime_systemtime_copy_from_byte_stream(
143
     libfdatetime_systemtime_t *systemtime,
144
     const uint8_t *byte_stream,
145
     size_t byte_stream_size,
146
     int byte_order,
147
     libcerror_error_t **error )
148
73.1k
{
149
73.1k
  libfdatetime_internal_systemtime_t *internal_systemtime = NULL;
150
73.1k
  static char *function                                   = "libfdatetime_systemtime_copy_from_byte_stream";
151
152
73.1k
  if( systemtime == NULL )
153
0
  {
154
0
    libcerror_error_set(
155
0
     error,
156
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
157
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
158
0
     "%s: invalid SYSTEMTIME.",
159
0
     function );
160
161
0
    return( -1 );
162
0
  }
163
73.1k
  internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime;
164
165
73.1k
  if( byte_stream == NULL )
166
0
  {
167
0
    libcerror_error_set(
168
0
     error,
169
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
170
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
171
0
     "%s: invalid byte stream.",
172
0
     function );
173
174
0
    return( -1 );
175
0
  }
176
73.1k
  if( byte_stream_size < 16 )
177
0
  {
178
0
    libcerror_error_set(
179
0
     error,
180
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
181
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
182
0
     "%s: byte stream too small.",
183
0
     function );
184
185
0
    return( -1 );
186
0
  }
187
73.1k
  if( byte_stream_size > (size_t) SSIZE_MAX )
188
0
  {
189
0
    libcerror_error_set(
190
0
     error,
191
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
192
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
193
0
     "%s: byte stream size exceeds maximum.",
194
0
     function );
195
196
0
    return( -1 );
197
0
  }
198
73.1k
  if( ( byte_order != LIBFDATETIME_ENDIAN_BIG )
199
73.1k
   && ( byte_order != LIBFDATETIME_ENDIAN_LITTLE ) )
200
0
  {
201
0
    libcerror_error_set(
202
0
     error,
203
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
204
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
205
0
     "%s: unsupported byte order.",
206
0
     function );
207
208
0
    return( -1 );
209
0
  }
210
73.1k
  if( byte_order == LIBFDATETIME_ENDIAN_LITTLE )
211
73.1k
  {
212
73.1k
    byte_stream_copy_to_uint16_little_endian(
213
73.1k
     byte_stream,
214
73.1k
     internal_systemtime->year );
215
216
73.1k
    byte_stream += 2;
217
218
73.1k
    byte_stream_copy_to_uint16_little_endian(
219
73.1k
     byte_stream,
220
73.1k
     internal_systemtime->month );
221
222
73.1k
    byte_stream += 2;
223
224
73.1k
    byte_stream_copy_to_uint16_little_endian(
225
73.1k
     byte_stream,
226
73.1k
     internal_systemtime->day_of_week );
227
228
73.1k
    byte_stream += 2;
229
230
73.1k
    byte_stream_copy_to_uint16_little_endian(
231
73.1k
     byte_stream,
232
73.1k
     internal_systemtime->day_of_month );
233
234
73.1k
    byte_stream += 2;
235
236
73.1k
    byte_stream_copy_to_uint16_little_endian(
237
73.1k
     byte_stream,
238
73.1k
     internal_systemtime->hours );
239
240
73.1k
    byte_stream += 2;
241
242
73.1k
    byte_stream_copy_to_uint16_little_endian(
243
73.1k
     byte_stream,
244
73.1k
     internal_systemtime->minutes );
245
246
73.1k
    byte_stream += 2;
247
248
73.1k
    byte_stream_copy_to_uint16_little_endian(
249
73.1k
     byte_stream,
250
73.1k
     internal_systemtime->seconds );
251
252
73.1k
    byte_stream += 2;
253
254
73.1k
    byte_stream_copy_to_uint16_little_endian(
255
73.1k
     byte_stream,
256
73.1k
     internal_systemtime->milli_seconds );
257
73.1k
  }
258
0
  else if( byte_order == LIBFDATETIME_ENDIAN_BIG )
259
0
  {
260
0
    byte_stream_copy_to_uint16_big_endian(
261
0
     byte_stream,
262
0
     internal_systemtime->year );
263
264
0
    byte_stream += 2;
265
266
0
    byte_stream_copy_to_uint16_big_endian(
267
0
     byte_stream,
268
0
     internal_systemtime->month );
269
270
0
    byte_stream += 2;
271
272
0
    byte_stream_copy_to_uint16_big_endian(
273
0
     byte_stream,
274
0
     internal_systemtime->day_of_week );
275
276
0
    byte_stream += 2;
277
278
0
    byte_stream_copy_to_uint16_big_endian(
279
0
     byte_stream,
280
0
     internal_systemtime->day_of_month );
281
282
0
    byte_stream += 2;
283
284
0
    byte_stream_copy_to_uint16_big_endian(
285
0
     byte_stream,
286
0
     internal_systemtime->hours );
287
288
0
    byte_stream += 2;
289
290
0
    byte_stream_copy_to_uint16_big_endian(
291
0
     byte_stream,
292
0
     internal_systemtime->minutes );
293
294
0
    byte_stream += 2;
295
296
0
    byte_stream_copy_to_uint16_big_endian(
297
0
     byte_stream,
298
0
     internal_systemtime->seconds );
299
300
0
    byte_stream += 2;
301
302
0
    byte_stream_copy_to_uint16_big_endian(
303
0
     byte_stream,
304
0
     internal_systemtime->milli_seconds );
305
0
  }
306
73.1k
  return( 1 );
307
73.1k
}
308
309
/* Converts a SYSTEMTIME into date time values
310
 * Returns 1 if successful or -1 on error
311
 */
312
int libfdatetime_internal_systemtime_copy_to_date_time_values(
313
     libfdatetime_internal_systemtime_t *internal_systemtime,
314
     libfdatetime_date_time_values_t *date_time_values,
315
     libcerror_error_t **error )
316
375k
{
317
375k
  static char *function = "libfdatetime_internal_systemtime_copy_to_date_time_values";
318
375k
  uint8_t days_in_month = 0;
319
320
375k
  if( internal_systemtime == NULL )
321
0
  {
322
0
    libcerror_error_set(
323
0
     error,
324
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
325
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
326
0
     "%s: invalid SYSTEMTIME.",
327
0
     function );
328
329
0
    return( -1 );
330
0
  }
331
375k
  if( date_time_values == NULL )
332
0
  {
333
0
    libcerror_error_set(
334
0
     error,
335
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
336
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
337
0
     "%s: invalid date time values.",
338
0
     function );
339
340
0
    return( -1 );
341
0
  }
342
375k
  if( internal_systemtime->milli_seconds > 999 )
343
150k
  {
344
150k
    libcerror_error_set(
345
150k
     error,
346
150k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
347
150k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
348
150k
     "%s: invalid SYSTEMTIME - milli seconds value out of bounds.",
349
150k
     function );
350
351
150k
    return( -1 );
352
150k
  }
353
224k
  date_time_values->nano_seconds  = 0;
354
224k
  date_time_values->micro_seconds = 0;
355
224k
  date_time_values->milli_seconds = internal_systemtime->milli_seconds;
356
357
224k
  if( internal_systemtime->seconds > 59 )
358
80.7k
  {
359
80.7k
    libcerror_error_set(
360
80.7k
     error,
361
80.7k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
362
80.7k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
363
80.7k
     "%s: invalid SYSTEMTIME - seconds value out of bounds.",
364
80.7k
     function );
365
366
80.7k
    return( -1 );
367
80.7k
  }
368
143k
  date_time_values->seconds = (uint8_t) internal_systemtime->seconds;
369
370
143k
  if( internal_systemtime->minutes > 59 )
371
37.2k
  {
372
37.2k
    libcerror_error_set(
373
37.2k
     error,
374
37.2k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
375
37.2k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
376
37.2k
     "%s: invalid SYSTEMTIME - minutes value out of bounds.",
377
37.2k
     function );
378
379
37.2k
    return( -1 );
380
37.2k
  }
381
106k
  date_time_values->minutes = (uint8_t) internal_systemtime->minutes;
382
383
106k
  if( internal_systemtime->hours > 23 )
384
35.1k
  {
385
35.1k
    libcerror_error_set(
386
35.1k
     error,
387
35.1k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
388
35.1k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
389
35.1k
     "%s: invalid SYSTEMTIME - hours value out of bounds.",
390
35.1k
     function );
391
392
35.1k
    return( -1 );
393
35.1k
  }
394
71.0k
  date_time_values->hours = (uint8_t) internal_systemtime->hours;
395
396
71.0k
  if( internal_systemtime->year > 9999 )
397
9.89k
  {
398
9.89k
    libcerror_error_set(
399
9.89k
     error,
400
9.89k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
401
9.89k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
402
9.89k
     "%s: invalid SYSTEMTIME - year value out of bounds.",
403
9.89k
     function );
404
405
9.89k
    return( -1 );
406
9.89k
  }
407
61.1k
  date_time_values->year = (uint16_t) internal_systemtime->year;
408
409
61.1k
  if( ( internal_systemtime->month == 0 )
410
47.1k
   || ( internal_systemtime->month > 12 ) )
411
35.1k
  {
412
35.1k
    libcerror_error_set(
413
35.1k
     error,
414
35.1k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
415
35.1k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
416
35.1k
     "%s: invalid SYSTEMTIME - month value out of bounds.",
417
35.1k
     function );
418
419
35.1k
    return( -1 );
420
35.1k
  }
421
26.0k
  date_time_values->month = (uint8_t) internal_systemtime->month;
422
423
26.0k
  if( internal_systemtime->day_of_week > 6 )
424
1.81k
  {
425
1.81k
    libcerror_error_set(
426
1.81k
     error,
427
1.81k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
428
1.81k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
429
1.81k
     "%s: invalid SYSTEMTIME - day of week value out of bounds.",
430
1.81k
     function );
431
432
1.81k
    return( -1 );
433
1.81k
  }
434
  /* February (2)
435
   */
436
24.2k
  if( date_time_values->month == 2 )
437
2.89k
  {
438
2.89k
    if( ( ( ( date_time_values->year % 4 ) == 0 )
439
2.37k
      &&  ( ( date_time_values->year % 100 ) != 0 ) )
440
2.40k
     || ( ( date_time_values->year % 400 ) == 0 ) )
441
2.37k
    {
442
2.37k
      days_in_month = 29;
443
2.37k
    }
444
519
    else
445
519
    {
446
519
      days_in_month = 28;
447
519
    }
448
2.89k
  }
449
  /* April (4), June (6), September (9), November (11)
450
   */
451
21.3k
  else if( ( date_time_values->month == 4 )
452
20.7k
        || ( date_time_values->month == 6 )
453
20.3k
        || ( date_time_values->month == 9 )
454
19.6k
        || ( date_time_values->month == 11 ) )
455
2.46k
  {
456
2.46k
    days_in_month = 30;
457
2.46k
  }
458
  /* January (1), March (3), May (5), July (7), August (8), October (10), December (12)
459
   */
460
18.8k
  else if( ( date_time_values->month == 1 )
461
8.71k
        || ( date_time_values->month == 3 )
462
8.21k
        || ( date_time_values->month == 5 )
463
6.98k
        || ( date_time_values->month == 7 )
464
5.96k
        || ( date_time_values->month == 8 )
465
927
        || ( date_time_values->month == 10 )
466
408
        || ( date_time_values->month == 12 ) )
467
18.8k
  {
468
18.8k
    days_in_month = 31;
469
18.8k
  }
470
  /* This should never happen, but just in case
471
   */
472
0
  else
473
0
  {
474
0
    libcerror_error_set(
475
0
     error,
476
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
477
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
478
0
     "%s: unsupported month: %d.",
479
0
     function,
480
0
     date_time_values->month );
481
482
0
    return( -1 );
483
0
  }
484
24.2k
  if( internal_systemtime->day_of_month > (uint16_t) days_in_month )
485
7.22k
  {
486
7.22k
    libcerror_error_set(
487
7.22k
     error,
488
7.22k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
489
7.22k
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
490
7.22k
     "%s: invalid SYSTEMTIME - day of month value out of bounds.",
491
7.22k
     function );
492
493
7.22k
    return( -1 );
494
7.22k
  }
495
16.9k
  date_time_values->day = (uint8_t) internal_systemtime->day_of_month;
496
497
16.9k
  return( 1 );
498
24.2k
}
499
500
/* Deterimes the size of the string for the SYSTEMTIME
501
 * The string size includes the end of string character
502
 * Returns 1 if successful or -1 on error
503
 */
504
int libfdatetime_systemtime_get_string_size(
505
     libfdatetime_systemtime_t *systemtime,
506
     size_t *string_size,
507
     uint32_t string_format_flags,
508
     libcerror_error_t **error )
509
254k
{
510
254k
  libfdatetime_date_time_values_t date_time_values;
511
512
254k
  static char *function = "libfdatetime_systemtime_get_string_size";
513
254k
  int result            = 0;
514
515
254k
  if( systemtime == NULL )
516
0
  {
517
0
    libcerror_error_set(
518
0
     error,
519
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
520
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
521
0
     "%s: invalid SYSTEMTIME.",
522
0
     function );
523
524
0
    return( -1 );
525
0
  }
526
254k
  if( string_size == NULL )
527
0
  {
528
0
    libcerror_error_set(
529
0
     error,
530
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
531
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
532
0
     "%s: invalid string size.",
533
0
     function );
534
535
0
    return( -1 );
536
0
  }
537
254k
  result = libfdatetime_internal_systemtime_copy_to_date_time_values(
538
254k
            (libfdatetime_internal_systemtime_t *) systemtime,
539
254k
            &date_time_values,
540
254k
            error );
541
542
254k
  if( result != 1 )
543
242k
  {
544
#if defined( HAVE_DEBUG_OUTPUT )
545
    libcerror_error_set(
546
     error,
547
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
548
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
549
     "%s: unable to set date time values.",
550
     function );
551
552
/* TODO debug print error */
553
554
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
555
556
242k
    if( ( error != NULL )
557
0
     && ( *error != NULL ) )
558
0
    {
559
0
      libcerror_error_free(
560
0
       error );
561
0
    }
562
242k
  }
563
11.5k
  else
564
11.5k
  {
565
11.5k
    result = libfdatetime_date_time_values_get_string_size(
566
11.5k
              &date_time_values,
567
11.5k
              string_size,
568
11.5k
              string_format_flags,
569
11.5k
              error );
570
571
11.5k
    if( result == -1 )
572
0
    {
573
0
      libcerror_error_set(
574
0
       error,
575
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
576
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
577
0
       "%s: unable to get string size.",
578
0
       function );
579
580
0
      return( -1 );
581
0
    }
582
11.5k
  }
583
254k
  if( result != 1 )
584
248k
  {
585
    /* Make sure the string can hold the hexadecimal representation of the SYSTEMTIME
586
     */
587
248k
    *string_size = 58;
588
248k
  }
589
254k
  return( 1 );
590
254k
}
591
592
/* Converts the SYSTEMTIME into an UTF-8 string in hexadecimal representation
593
 * The string size should include the end of string character
594
 * Returns 1 if successful or -1 on error
595
 */
596
int libfdatetime_internal_systemtime_copy_to_utf8_string_in_hexadecimal(
597
     libfdatetime_internal_systemtime_t *internal_systemtime,
598
     uint8_t *utf8_string,
599
     size_t utf8_string_size,
600
     size_t *utf8_string_index,
601
     libcerror_error_t **error )
602
63.5k
{
603
63.5k
  static char *function = "libfdatetime_internal_systemtime_copy_to_utf8_string_in_hexadecimal";
604
63.5k
  size_t string_index   = 0;
605
63.5k
  uint8_t byte_value    = 0;
606
63.5k
  int8_t byte_shift     = 0;
607
608
63.5k
  if( internal_systemtime == NULL )
609
0
  {
610
0
    libcerror_error_set(
611
0
     error,
612
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
613
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
614
0
     "%s: invalid SYSTEMTIME.",
615
0
     function );
616
617
0
    return( -1 );
618
0
  }
619
63.5k
  if( utf8_string == NULL )
620
0
  {
621
0
    libcerror_error_set(
622
0
     error,
623
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
624
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
625
0
     "%s: invalid UTF-8 string.",
626
0
     function );
627
628
0
    return( -1 );
629
0
  }
630
63.5k
  if( utf8_string_size > (size_t) SSIZE_MAX )
631
0
  {
632
0
    libcerror_error_set(
633
0
     error,
634
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
635
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
636
0
     "%s: invalid UTF-8 string size value exceeds maximum.",
637
0
     function );
638
639
0
    return( -1 );
640
0
  }
641
63.5k
  if( utf8_string_index == NULL )
642
0
  {
643
0
    libcerror_error_set(
644
0
     error,
645
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
646
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
647
0
     "%s: invalid UTF-8 string index.",
648
0
     function );
649
650
0
    return( -1 );
651
0
  }
652
63.5k
  if( ( utf8_string_size < 58 )
653
63.5k
   || ( *utf8_string_index > ( utf8_string_size - 58 ) ) )
654
0
  {
655
0
    libcerror_error_set(
656
0
     error,
657
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
658
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
659
0
     "%s: UTF-8 string is too small.",
660
0
     function );
661
662
0
    return( -1 );
663
0
  }
664
63.5k
  string_index = *utf8_string_index;
665
666
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '(';
667
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
668
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
669
670
63.5k
  byte_shift = 14;
671
672
63.5k
  do
673
254k
  {
674
254k
    byte_value = ( internal_systemtime->year >> byte_shift ) & 0x0f;
675
676
254k
    if( byte_value <= 9 )
677
220k
    {
678
220k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
679
220k
    }
680
33.4k
    else
681
33.4k
    {
682
33.4k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
683
33.4k
    }
684
254k
    byte_shift -= 4;
685
254k
  }
686
254k
  while( byte_shift >= 0 );
687
688
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
689
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
690
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
691
692
63.5k
  byte_shift = 14;
693
694
63.5k
  do
695
254k
  {
696
254k
    byte_value = ( internal_systemtime->month >> byte_shift ) & 0x0f;
697
698
254k
    if( byte_value <= 9 )
699
218k
    {
700
218k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
701
218k
    }
702
35.3k
    else
703
35.3k
    {
704
35.3k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
705
35.3k
    }
706
254k
    byte_shift -= 4;
707
254k
  }
708
254k
  while( byte_shift >= 0 );
709
710
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
711
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
712
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
713
714
63.5k
  byte_shift = 14;
715
716
63.5k
  do
717
254k
  {
718
254k
    byte_value = ( internal_systemtime->day_of_week >> byte_shift ) & 0x0f;
719
720
254k
    if( byte_value <= 9 )
721
213k
    {
722
213k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
723
213k
    }
724
41.1k
    else
725
41.1k
    {
726
41.1k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
727
41.1k
    }
728
254k
    byte_shift -= 4;
729
254k
  }
730
254k
  while( byte_shift >= 0 );
731
732
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
733
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
734
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
735
736
63.5k
  byte_shift = 14;
737
738
63.5k
  do
739
254k
  {
740
254k
    byte_value = ( internal_systemtime->day_of_month >> byte_shift ) & 0x0f;
741
742
254k
    if( byte_value <= 9 )
743
217k
    {
744
217k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
745
217k
    }
746
36.3k
    else
747
36.3k
    {
748
36.3k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
749
36.3k
    }
750
254k
    byte_shift -= 4;
751
254k
  }
752
254k
  while( byte_shift >= 0 );
753
754
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
755
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
756
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
757
758
63.5k
  byte_shift = 14;
759
760
63.5k
  do
761
254k
  {
762
254k
    byte_value = ( internal_systemtime->hours >> byte_shift ) & 0x0f;
763
764
254k
    if( byte_value <= 9 )
765
223k
    {
766
223k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
767
223k
    }
768
30.5k
    else
769
30.5k
    {
770
30.5k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
771
30.5k
    }
772
254k
    byte_shift -= 4;
773
254k
  }
774
254k
  while( byte_shift >= 0 );
775
776
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
777
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
778
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
779
780
63.5k
  byte_shift = 14;
781
782
63.5k
  do
783
254k
  {
784
254k
    byte_value = ( internal_systemtime->minutes >> byte_shift ) & 0x0f;
785
786
254k
    if( byte_value <= 9 )
787
220k
    {
788
220k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
789
220k
    }
790
33.8k
    else
791
33.8k
    {
792
33.8k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
793
33.8k
    }
794
254k
    byte_shift -= 4;
795
254k
  }
796
254k
  while( byte_shift >= 0 );
797
798
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
799
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
800
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
801
802
63.5k
  byte_shift = 14;
803
804
63.5k
  do
805
254k
  {
806
254k
    byte_value = ( internal_systemtime->seconds >> byte_shift ) & 0x0f;
807
808
254k
    if( byte_value <= 9 )
809
217k
    {
810
217k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
811
217k
    }
812
36.4k
    else
813
36.4k
    {
814
36.4k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
815
36.4k
    }
816
254k
    byte_shift -= 4;
817
254k
  }
818
254k
  while( byte_shift >= 0 );
819
820
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ' ';
821
63.5k
  utf8_string[ string_index++ ] = (uint8_t) '0';
822
63.5k
  utf8_string[ string_index++ ] = (uint8_t) 'x';
823
824
63.5k
  byte_shift = 14;
825
826
63.5k
  do
827
254k
  {
828
254k
    byte_value = ( internal_systemtime->milli_seconds >> byte_shift ) & 0x0f;
829
830
254k
    if( byte_value <= 9 )
831
217k
    {
832
217k
      utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value;
833
217k
    }
834
36.5k
    else
835
36.5k
    {
836
36.5k
      utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10;
837
36.5k
    }
838
254k
    byte_shift -= 4;
839
254k
  }
840
254k
  while( byte_shift >= 0 );
841
842
63.5k
  utf8_string[ string_index++ ] = (uint8_t) ')';
843
844
63.5k
  utf8_string[ string_index++ ] = 0;
845
846
63.5k
  *utf8_string_index = string_index;
847
848
63.5k
  return( 1 );
849
63.5k
}
850
851
/* Converts the SYSTEMTIME into an UTF-8 string
852
 * The string size should include the end of string character
853
 * Returns 1 if successful or -1 on error
854
 */
855
int libfdatetime_systemtime_copy_to_utf8_string(
856
     libfdatetime_systemtime_t *systemtime,
857
     uint8_t *utf8_string,
858
     size_t utf8_string_size,
859
     uint32_t string_format_flags,
860
     libcerror_error_t **error )
861
0
{
862
0
  static char *function    = "libfdatetime_systemtime_copy_to_utf8_string";
863
0
  size_t utf8_string_index = 0;
864
865
0
  if( libfdatetime_systemtime_copy_to_utf8_string_with_index(
866
0
       systemtime,
867
0
       utf8_string,
868
0
       utf8_string_size,
869
0
       &utf8_string_index,
870
0
       string_format_flags,
871
0
       error ) != 1 )
872
0
  {
873
0
    libcerror_error_set(
874
0
     error,
875
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
876
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
877
0
     "%s: unable to copy SYSTEMTIME to UTF-8 string.",
878
0
     function );
879
880
0
    return( -1 );
881
0
  }
882
0
  return( 1 );
883
0
}
884
885
/* Converts the SYSTEMTIME into an UTF-8 string
886
 * The string size should include the end of string character
887
 * Returns 1 if successful or -1 on error
888
 */
889
int libfdatetime_systemtime_copy_to_utf8_string_with_index(
890
     libfdatetime_systemtime_t *systemtime,
891
     uint8_t *utf8_string,
892
     size_t utf8_string_size,
893
     size_t *utf8_string_index,
894
     uint32_t string_format_flags,
895
     libcerror_error_t **error )
896
65.1k
{
897
65.1k
  libfdatetime_date_time_values_t date_time_values;
898
899
65.1k
  libfdatetime_internal_systemtime_t *internal_systemtime = NULL;
900
65.1k
  static char *function                                   = "libfdatetime_systemtime_copy_to_utf8_string_with_index";
901
65.1k
  int result                                              = 0;
902
903
65.1k
  if( systemtime == NULL )
904
0
  {
905
0
    libcerror_error_set(
906
0
     error,
907
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
908
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
909
0
     "%s: invalid SYSTEMTIME.",
910
0
     function );
911
912
0
    return( -1 );
913
0
  }
914
65.1k
  internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime;
915
916
65.1k
  result = libfdatetime_internal_systemtime_copy_to_date_time_values(
917
65.1k
            internal_systemtime,
918
65.1k
            &date_time_values,
919
65.1k
            error );
920
921
65.1k
  if( result != 1 )
922
62.0k
  {
923
#if defined( HAVE_DEBUG_OUTPUT )
924
    libcerror_error_set(
925
     error,
926
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
927
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
928
     "%s: unable to set date time values.",
929
     function );
930
931
/* TODO debug print error */
932
933
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
934
935
62.0k
    if( ( error != NULL )
936
0
     && ( *error != NULL ) )
937
0
    {
938
0
      libcerror_error_free(
939
0
       error );
940
0
    }
941
62.0k
  }
942
3.11k
  else
943
3.11k
  {
944
3.11k
    result = libfdatetime_date_time_values_copy_to_utf8_string_with_index(
945
3.11k
              &date_time_values,
946
3.11k
              utf8_string,
947
3.11k
              utf8_string_size,
948
3.11k
              utf8_string_index,
949
3.11k
              string_format_flags,
950
3.11k
              error );
951
952
3.11k
    if( result == -1 )
953
0
    {
954
0
      libcerror_error_set(
955
0
       error,
956
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
957
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
958
0
       "%s: unable to copy date time values to UTF-8 string.",
959
0
       function );
960
961
0
      return( -1 );
962
0
    }
963
3.11k
  }
964
65.1k
  if( result != 1 )
965
63.5k
  {
966
63.5k
    result = libfdatetime_internal_systemtime_copy_to_utf8_string_in_hexadecimal(
967
63.5k
              internal_systemtime,
968
63.5k
              utf8_string,
969
63.5k
              utf8_string_size,
970
63.5k
              utf8_string_index,
971
63.5k
              error );
972
973
63.5k
    if( result == -1 )
974
0
    {
975
0
      libcerror_error_set(
976
0
       error,
977
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
978
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
979
0
       "%s: unable to SYSTEMTIME to hexadecimal UTF-8 string.",
980
0
       function );
981
982
0
      return( -1 );
983
0
    }
984
63.5k
  }
985
65.1k
  return( 1 );
986
65.1k
}
987
988
/* Converts the SYSTEMTIME into an UTF-16 string in hexadecimal representation
989
 * The string size should include the end of string character
990
 * Returns 1 if successful or -1 on error
991
 */
992
int libfdatetime_internal_systemtime_copy_to_utf16_string_in_hexadecimal(
993
     libfdatetime_internal_systemtime_t *internal_systemtime,
994
     uint16_t *utf16_string,
995
     size_t utf16_string_size,
996
     size_t *utf16_string_index,
997
     libcerror_error_t **error )
998
54.1k
{
999
54.1k
  static char *function = "libfdatetime_internal_systemtime_copy_to_utf16_string_in_hexadecimal";
1000
54.1k
  size_t string_index   = 0;
1001
54.1k
  uint8_t byte_value    = 0;
1002
54.1k
  int8_t byte_shift     = 0;
1003
1004
54.1k
  if( internal_systemtime == NULL )
1005
0
  {
1006
0
    libcerror_error_set(
1007
0
     error,
1008
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1009
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1010
0
     "%s: invalid SYSTEMTIME.",
1011
0
     function );
1012
1013
0
    return( -1 );
1014
0
  }
1015
54.1k
  if( utf16_string == NULL )
1016
0
  {
1017
0
    libcerror_error_set(
1018
0
     error,
1019
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1020
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1021
0
     "%s: invalid UTF-16 string.",
1022
0
     function );
1023
1024
0
    return( -1 );
1025
0
  }
1026
54.1k
  if( utf16_string_size > (size_t) SSIZE_MAX )
1027
0
  {
1028
0
    libcerror_error_set(
1029
0
     error,
1030
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1031
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1032
0
     "%s: invalid UTF-16 string size value exceeds maximum.",
1033
0
     function );
1034
1035
0
    return( -1 );
1036
0
  }
1037
54.1k
  if( utf16_string_index == NULL )
1038
0
  {
1039
0
    libcerror_error_set(
1040
0
     error,
1041
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1042
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1043
0
     "%s: invalid UTF-16 string index.",
1044
0
     function );
1045
1046
0
    return( -1 );
1047
0
  }
1048
54.1k
  if( ( utf16_string_size < 58 )
1049
54.1k
   || ( *utf16_string_index > ( utf16_string_size - 58 ) ) )
1050
0
  {
1051
0
    libcerror_error_set(
1052
0
     error,
1053
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1054
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1055
0
     "%s: UTF-16 string is too small.",
1056
0
     function );
1057
1058
0
    return( -1 );
1059
0
  }
1060
54.1k
  string_index = *utf16_string_index;
1061
1062
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '(';
1063
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1064
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1065
1066
54.1k
  byte_shift = 14;
1067
1068
54.1k
  do
1069
216k
  {
1070
216k
    byte_value = ( internal_systemtime->year >> byte_shift ) & 0x0f;
1071
1072
216k
    if( byte_value <= 9 )
1073
191k
    {
1074
191k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1075
191k
    }
1076
25.0k
    else
1077
25.0k
    {
1078
25.0k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1079
25.0k
    }
1080
216k
    byte_shift -= 4;
1081
216k
  }
1082
216k
  while( byte_shift >= 0 );
1083
1084
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1085
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1086
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1087
1088
54.1k
  byte_shift = 14;
1089
1090
54.1k
  do
1091
216k
  {
1092
216k
    byte_value = ( internal_systemtime->month >> byte_shift ) & 0x0f;
1093
1094
216k
    if( byte_value <= 9 )
1095
188k
    {
1096
188k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1097
188k
    }
1098
28.3k
    else
1099
28.3k
    {
1100
28.3k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1101
28.3k
    }
1102
216k
    byte_shift -= 4;
1103
216k
  }
1104
216k
  while( byte_shift >= 0 );
1105
1106
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1107
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1108
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1109
1110
54.1k
  byte_shift = 14;
1111
1112
54.1k
  do
1113
216k
  {
1114
216k
    byte_value = ( internal_systemtime->day_of_week >> byte_shift ) & 0x0f;
1115
1116
216k
    if( byte_value <= 9 )
1117
181k
    {
1118
181k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1119
181k
    }
1120
35.4k
    else
1121
35.4k
    {
1122
35.4k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1123
35.4k
    }
1124
216k
    byte_shift -= 4;
1125
216k
  }
1126
216k
  while( byte_shift >= 0 );
1127
1128
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1129
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1130
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1131
1132
54.1k
  byte_shift = 14;
1133
1134
54.1k
  do
1135
216k
  {
1136
216k
    byte_value = ( internal_systemtime->day_of_month >> byte_shift ) & 0x0f;
1137
1138
216k
    if( byte_value <= 9 )
1139
186k
    {
1140
186k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1141
186k
    }
1142
29.6k
    else
1143
29.6k
    {
1144
29.6k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1145
29.6k
    }
1146
216k
    byte_shift -= 4;
1147
216k
  }
1148
216k
  while( byte_shift >= 0 );
1149
1150
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1151
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1152
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1153
1154
54.1k
  byte_shift = 14;
1155
1156
54.1k
  do
1157
216k
  {
1158
216k
    byte_value = ( internal_systemtime->hours >> byte_shift ) & 0x0f;
1159
1160
216k
    if( byte_value <= 9 )
1161
192k
    {
1162
192k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1163
192k
    }
1164
24.0k
    else
1165
24.0k
    {
1166
24.0k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1167
24.0k
    }
1168
216k
    byte_shift -= 4;
1169
216k
  }
1170
216k
  while( byte_shift >= 0 );
1171
1172
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1173
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1174
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1175
1176
54.1k
  byte_shift = 14;
1177
1178
54.1k
  do
1179
216k
  {
1180
216k
    byte_value = ( internal_systemtime->minutes >> byte_shift ) & 0x0f;
1181
1182
216k
    if( byte_value <= 9 )
1183
187k
    {
1184
187k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1185
187k
    }
1186
28.5k
    else
1187
28.5k
    {
1188
28.5k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1189
28.5k
    }
1190
216k
    byte_shift -= 4;
1191
216k
  }
1192
216k
  while( byte_shift >= 0 );
1193
1194
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1195
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1196
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1197
1198
54.1k
  byte_shift = 14;
1199
1200
54.1k
  do
1201
216k
  {
1202
216k
    byte_value = ( internal_systemtime->seconds >> byte_shift ) & 0x0f;
1203
1204
216k
    if( byte_value <= 9 )
1205
186k
    {
1206
186k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1207
186k
    }
1208
29.6k
    else
1209
29.6k
    {
1210
29.6k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1211
29.6k
    }
1212
216k
    byte_shift -= 4;
1213
216k
  }
1214
216k
  while( byte_shift >= 0 );
1215
1216
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ' ';
1217
54.1k
  utf16_string[ string_index++ ] = (uint16_t) '0';
1218
54.1k
  utf16_string[ string_index++ ] = (uint16_t) 'x';
1219
1220
54.1k
  byte_shift = 14;
1221
1222
54.1k
  do
1223
216k
  {
1224
216k
    byte_value = ( internal_systemtime->milli_seconds >> byte_shift ) & 0x0f;
1225
1226
216k
    if( byte_value <= 9 )
1227
186k
    {
1228
186k
      utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value;
1229
186k
    }
1230
30.2k
    else
1231
30.2k
    {
1232
30.2k
      utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10;
1233
30.2k
    }
1234
216k
    byte_shift -= 4;
1235
216k
  }
1236
216k
  while( byte_shift >= 0 );
1237
1238
54.1k
  utf16_string[ string_index++ ] = (uint16_t) ')';
1239
1240
54.1k
  utf16_string[ string_index++ ] = 0;
1241
1242
54.1k
  *utf16_string_index = string_index;
1243
1244
54.1k
  return( 1 );
1245
54.1k
}
1246
1247
/* Converts the SYSTEMTIME into an UTF-16 string
1248
 * The string size should include the end of string character
1249
 * Returns 1 if successful or -1 on error
1250
 */
1251
int libfdatetime_systemtime_copy_to_utf16_string(
1252
     libfdatetime_systemtime_t *systemtime,
1253
     uint16_t *utf16_string,
1254
     size_t utf16_string_size,
1255
     uint32_t string_format_flags,
1256
     libcerror_error_t **error )
1257
0
{
1258
0
  static char *function     = "libfdatetime_systemtime_copy_to_utf16_string";
1259
0
  size_t utf16_string_index = 0;
1260
1261
0
  if( libfdatetime_systemtime_copy_to_utf16_string_with_index(
1262
0
       systemtime,
1263
0
       utf16_string,
1264
0
       utf16_string_size,
1265
0
       &utf16_string_index,
1266
0
       string_format_flags,
1267
0
       error ) != 1 )
1268
0
  {
1269
0
    libcerror_error_set(
1270
0
     error,
1271
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1272
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1273
0
     "%s: unable to copy SYSTEMTIME to UTF-16 string.",
1274
0
     function );
1275
1276
0
    return( -1 );
1277
0
  }
1278
0
  return( 1 );
1279
0
}
1280
1281
/* Converts the SYSTEMTIME into an UTF-16 string
1282
 * The string size should include the end of string character
1283
 * Returns 1 if successful or -1 on error
1284
 */
1285
int libfdatetime_systemtime_copy_to_utf16_string_with_index(
1286
     libfdatetime_systemtime_t *systemtime,
1287
     uint16_t *utf16_string,
1288
     size_t utf16_string_size,
1289
     size_t *utf16_string_index,
1290
     uint32_t string_format_flags,
1291
     libcerror_error_t **error )
1292
55.5k
{
1293
55.5k
  libfdatetime_date_time_values_t date_time_values;
1294
1295
55.5k
  libfdatetime_internal_systemtime_t *internal_systemtime = NULL;
1296
55.5k
  static char *function                                   = "libfdatetime_systemtime_copy_to_utf16_string_with_index";
1297
55.5k
  int result                                              = 0;
1298
1299
55.5k
  if( systemtime == NULL )
1300
0
  {
1301
0
    libcerror_error_set(
1302
0
     error,
1303
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1304
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1305
0
     "%s: invalid SYSTEMTIME.",
1306
0
     function );
1307
1308
0
    return( -1 );
1309
0
  }
1310
55.5k
  internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime;
1311
1312
55.5k
  result = libfdatetime_internal_systemtime_copy_to_date_time_values(
1313
55.5k
            internal_systemtime,
1314
55.5k
            &date_time_values,
1315
55.5k
            error );
1316
1317
55.5k
  if( result != 1 )
1318
53.1k
  {
1319
#if defined( HAVE_DEBUG_OUTPUT )
1320
    libcerror_error_set(
1321
     error,
1322
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1323
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1324
     "%s: unable to set date time values.",
1325
     function );
1326
1327
/* TODO debug print error */
1328
1329
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
1330
1331
53.1k
    if( ( error != NULL )
1332
0
     && ( *error != NULL ) )
1333
0
    {
1334
0
      libcerror_error_free(
1335
0
       error );
1336
0
    }
1337
53.1k
  }
1338
2.35k
  else
1339
2.35k
  {
1340
2.35k
    result = libfdatetime_date_time_values_copy_to_utf16_string_with_index(
1341
2.35k
              &date_time_values,
1342
2.35k
              utf16_string,
1343
2.35k
              utf16_string_size,
1344
2.35k
              utf16_string_index,
1345
2.35k
              string_format_flags,
1346
2.35k
              error );
1347
1348
2.35k
    if( result == -1 )
1349
0
    {
1350
0
      libcerror_error_set(
1351
0
       error,
1352
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1353
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1354
0
       "%s: unable to copy date time values to UTF-16 string.",
1355
0
       function );
1356
1357
0
      return( -1 );
1358
0
    }
1359
2.35k
  }
1360
55.5k
  if( result != 1 )
1361
54.1k
  {
1362
54.1k
    result = libfdatetime_internal_systemtime_copy_to_utf16_string_in_hexadecimal(
1363
54.1k
              internal_systemtime,
1364
54.1k
              utf16_string,
1365
54.1k
              utf16_string_size,
1366
54.1k
              utf16_string_index,
1367
54.1k
              error );
1368
1369
54.1k
    if( result == -1 )
1370
0
    {
1371
0
      libcerror_error_set(
1372
0
       error,
1373
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1374
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1375
0
       "%s: unable to SYSTEMTIME to hexadecimal UTF-16 string.",
1376
0
       function );
1377
1378
0
      return( -1 );
1379
0
    }
1380
54.1k
  }
1381
55.5k
  return( 1 );
1382
55.5k
}
1383
1384
/* Converts the SYSTEMTIME into an UTF-32 string in hexadecimal representation
1385
 * The string size should include the end of string character
1386
 * Returns 1 if successful or -1 on error
1387
 */
1388
int libfdatetime_internal_systemtime_copy_to_utf32_string_in_hexadecimal(
1389
     libfdatetime_internal_systemtime_t *internal_systemtime,
1390
     uint32_t *utf32_string,
1391
     size_t utf32_string_size,
1392
     size_t *utf32_string_index,
1393
     libcerror_error_t **error )
1394
0
{
1395
0
  static char *function = "libfdatetime_internal_systemtime_copy_to_utf32_string_in_hexadecimal";
1396
0
  size_t string_index   = 0;
1397
0
  uint8_t byte_value    = 0;
1398
0
  int8_t byte_shift     = 0;
1399
1400
0
  if( internal_systemtime == NULL )
1401
0
  {
1402
0
    libcerror_error_set(
1403
0
     error,
1404
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1405
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1406
0
     "%s: invalid SYSTEMTIME.",
1407
0
     function );
1408
1409
0
    return( -1 );
1410
0
  }
1411
0
  if( utf32_string == NULL )
1412
0
  {
1413
0
    libcerror_error_set(
1414
0
     error,
1415
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1416
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1417
0
     "%s: invalid UTF-32 string.",
1418
0
     function );
1419
1420
0
    return( -1 );
1421
0
  }
1422
0
  if( utf32_string_size > (size_t) SSIZE_MAX )
1423
0
  {
1424
0
    libcerror_error_set(
1425
0
     error,
1426
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1427
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1428
0
     "%s: invalid UTF-32 string size value exceeds maximum.",
1429
0
     function );
1430
1431
0
    return( -1 );
1432
0
  }
1433
0
  if( utf32_string_index == NULL )
1434
0
  {
1435
0
    libcerror_error_set(
1436
0
     error,
1437
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1438
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1439
0
     "%s: invalid UTF-32 string index.",
1440
0
     function );
1441
1442
0
    return( -1 );
1443
0
  }
1444
0
  if( ( utf32_string_size < 58 )
1445
0
   || ( *utf32_string_index > ( utf32_string_size - 58 ) ) )
1446
0
  {
1447
0
    libcerror_error_set(
1448
0
     error,
1449
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1450
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1451
0
     "%s: UTF-32 string is too small.",
1452
0
     function );
1453
1454
0
    return( -1 );
1455
0
  }
1456
0
  string_index = *utf32_string_index;
1457
1458
0
  utf32_string[ string_index++ ] = (uint32_t) '(';
1459
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1460
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1461
1462
0
  byte_shift = 14;
1463
1464
0
  do
1465
0
  {
1466
0
    byte_value = ( internal_systemtime->year >> byte_shift ) & 0x0f;
1467
1468
0
    if( byte_value <= 9 )
1469
0
    {
1470
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1471
0
    }
1472
0
    else
1473
0
    {
1474
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1475
0
    }
1476
0
    byte_shift -= 4;
1477
0
  }
1478
0
  while( byte_shift >= 0 );
1479
1480
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1481
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1482
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1483
1484
0
  byte_shift = 14;
1485
1486
0
  do
1487
0
  {
1488
0
    byte_value = ( internal_systemtime->month >> byte_shift ) & 0x0f;
1489
1490
0
    if( byte_value <= 9 )
1491
0
    {
1492
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1493
0
    }
1494
0
    else
1495
0
    {
1496
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1497
0
    }
1498
0
    byte_shift -= 4;
1499
0
  }
1500
0
  while( byte_shift >= 0 );
1501
1502
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1503
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1504
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1505
1506
0
  byte_shift = 14;
1507
1508
0
  do
1509
0
  {
1510
0
    byte_value = ( internal_systemtime->day_of_week >> byte_shift ) & 0x0f;
1511
1512
0
    if( byte_value <= 9 )
1513
0
    {
1514
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1515
0
    }
1516
0
    else
1517
0
    {
1518
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1519
0
    }
1520
0
    byte_shift -= 4;
1521
0
  }
1522
0
  while( byte_shift >= 0 );
1523
1524
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1525
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1526
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1527
1528
0
  byte_shift = 14;
1529
1530
0
  do
1531
0
  {
1532
0
    byte_value = ( internal_systemtime->day_of_month >> byte_shift ) & 0x0f;
1533
1534
0
    if( byte_value <= 9 )
1535
0
    {
1536
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1537
0
    }
1538
0
    else
1539
0
    {
1540
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1541
0
    }
1542
0
    byte_shift -= 4;
1543
0
  }
1544
0
  while( byte_shift >= 0 );
1545
1546
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1547
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1548
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1549
1550
0
  byte_shift = 14;
1551
1552
0
  do
1553
0
  {
1554
0
    byte_value = ( internal_systemtime->hours >> byte_shift ) & 0x0f;
1555
1556
0
    if( byte_value <= 9 )
1557
0
    {
1558
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1559
0
    }
1560
0
    else
1561
0
    {
1562
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1563
0
    }
1564
0
    byte_shift -= 4;
1565
0
  }
1566
0
  while( byte_shift >= 0 );
1567
1568
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1569
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1570
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1571
1572
0
  byte_shift = 14;
1573
1574
0
  do
1575
0
  {
1576
0
    byte_value = ( internal_systemtime->minutes >> byte_shift ) & 0x0f;
1577
1578
0
    if( byte_value <= 9 )
1579
0
    {
1580
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1581
0
    }
1582
0
    else
1583
0
    {
1584
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1585
0
    }
1586
0
    byte_shift -= 4;
1587
0
  }
1588
0
  while( byte_shift >= 0 );
1589
1590
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1591
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1592
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1593
1594
0
  byte_shift = 14;
1595
1596
0
  do
1597
0
  {
1598
0
    byte_value = ( internal_systemtime->seconds >> byte_shift ) & 0x0f;
1599
1600
0
    if( byte_value <= 9 )
1601
0
    {
1602
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1603
0
    }
1604
0
    else
1605
0
    {
1606
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1607
0
    }
1608
0
    byte_shift -= 4;
1609
0
  }
1610
0
  while( byte_shift >= 0 );
1611
1612
0
  utf32_string[ string_index++ ] = (uint32_t) ' ';
1613
0
  utf32_string[ string_index++ ] = (uint32_t) '0';
1614
0
  utf32_string[ string_index++ ] = (uint32_t) 'x';
1615
1616
0
  byte_shift = 14;
1617
1618
0
  do
1619
0
  {
1620
0
    byte_value = ( internal_systemtime->milli_seconds >> byte_shift ) & 0x0f;
1621
1622
0
    if( byte_value <= 9 )
1623
0
    {
1624
0
      utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value;
1625
0
    }
1626
0
    else
1627
0
    {
1628
0
      utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10;
1629
0
    }
1630
0
    byte_shift -= 4;
1631
0
  }
1632
0
  while( byte_shift >= 0 );
1633
1634
0
  utf32_string[ string_index++ ] = (uint32_t) ')';
1635
1636
0
  utf32_string[ string_index++ ] = 0;
1637
1638
0
  *utf32_string_index = string_index;
1639
1640
0
  return( 1 );
1641
0
}
1642
1643
/* Converts the SYSTEMTIME into an UTF-32 string
1644
 * The string size should include the end of string character
1645
 * Returns 1 if successful or -1 on error
1646
 */
1647
int libfdatetime_systemtime_copy_to_utf32_string(
1648
     libfdatetime_systemtime_t *systemtime,
1649
     uint32_t *utf32_string,
1650
     size_t utf32_string_size,
1651
     uint32_t string_format_flags,
1652
     libcerror_error_t **error )
1653
0
{
1654
0
  static char *function     = "libfdatetime_systemtime_copy_to_utf32_string";
1655
0
  size_t utf32_string_index = 0;
1656
1657
0
  if( libfdatetime_systemtime_copy_to_utf32_string_with_index(
1658
0
       systemtime,
1659
0
       utf32_string,
1660
0
       utf32_string_size,
1661
0
       &utf32_string_index,
1662
0
       string_format_flags,
1663
0
       error ) != 1 )
1664
0
  {
1665
0
    libcerror_error_set(
1666
0
     error,
1667
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1668
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1669
0
     "%s: unable to copy SYSTEMTIME to UTF-32 string.",
1670
0
     function );
1671
1672
0
    return( -1 );
1673
0
  }
1674
0
  return( 1 );
1675
0
}
1676
1677
/* Converts the SYSTEMTIME into an UTF-32 string
1678
 * The string size should include the end of string character
1679
 * Returns 1 if successful or -1 on error
1680
 */
1681
int libfdatetime_systemtime_copy_to_utf32_string_with_index(
1682
     libfdatetime_systemtime_t *systemtime,
1683
     uint32_t *utf32_string,
1684
     size_t utf32_string_size,
1685
     size_t *utf32_string_index,
1686
     uint32_t string_format_flags,
1687
     libcerror_error_t **error )
1688
0
{
1689
0
  libfdatetime_date_time_values_t date_time_values;
1690
1691
0
  libfdatetime_internal_systemtime_t *internal_systemtime = NULL;
1692
0
  static char *function                                   = "libfdatetime_systemtime_copy_to_utf32_string_with_index";
1693
0
  int result                                              = 0;
1694
1695
0
  if( systemtime == NULL )
1696
0
  {
1697
0
    libcerror_error_set(
1698
0
     error,
1699
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1700
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1701
0
     "%s: invalid SYSTEMTIME.",
1702
0
     function );
1703
1704
0
    return( -1 );
1705
0
  }
1706
0
  internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime;
1707
1708
0
  result = libfdatetime_internal_systemtime_copy_to_date_time_values(
1709
0
            internal_systemtime,
1710
0
            &date_time_values,
1711
0
            error );
1712
1713
0
  if( result != 1 )
1714
0
  {
1715
#if defined( HAVE_DEBUG_OUTPUT )
1716
    libcerror_error_set(
1717
     error,
1718
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1719
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1720
     "%s: unable to set date time values.",
1721
     function );
1722
1723
/* TODO debug print error */
1724
1725
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
1726
1727
0
    if( ( error != NULL )
1728
0
     && ( *error != NULL ) )
1729
0
    {
1730
0
      libcerror_error_free(
1731
0
       error );
1732
0
    }
1733
0
  }
1734
0
  else
1735
0
  {
1736
0
    result = libfdatetime_date_time_values_copy_to_utf32_string_with_index(
1737
0
              &date_time_values,
1738
0
              utf32_string,
1739
0
              utf32_string_size,
1740
0
              utf32_string_index,
1741
0
              string_format_flags,
1742
0
              error );
1743
1744
0
    if( result == -1 )
1745
0
    {
1746
0
      libcerror_error_set(
1747
0
       error,
1748
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1749
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1750
0
       "%s: unable to copy date time values to UTF-32 string.",
1751
0
       function );
1752
1753
0
      return( -1 );
1754
0
    }
1755
0
  }
1756
0
  if( result != 1 )
1757
0
  {
1758
0
    result = libfdatetime_internal_systemtime_copy_to_utf32_string_in_hexadecimal(
1759
0
              internal_systemtime,
1760
0
              utf32_string,
1761
0
              utf32_string_size,
1762
0
              utf32_string_index,
1763
0
              error );
1764
1765
0
    if( result == -1 )
1766
0
    {
1767
0
      libcerror_error_set(
1768
0
       error,
1769
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1770
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1771
0
       "%s: unable to SYSTEMTIME to hexadecimal UTF-32 string.",
1772
0
       function );
1773
1774
0
      return( -1 );
1775
0
    }
1776
0
  }
1777
0
  return( 1 );
1778
0
}
1779