/src/libesedb/libfdatetime/libfdatetime_systemtime.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SYSTEMTIME functions |
3 | | * |
4 | | * Copyright (C) 2009-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <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 | 0 | { |
41 | 0 | libfdatetime_internal_systemtime_t *internal_systemtime = NULL; |
42 | 0 | static char *function = "libfdatetime_systemtime_initialize"; |
43 | |
|
44 | 0 | 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 | 0 | 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 | 0 | internal_systemtime = memory_allocate_structure( |
67 | 0 | libfdatetime_internal_systemtime_t ); |
68 | |
|
69 | 0 | 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 | 0 | if( memory_set( |
81 | 0 | internal_systemtime, |
82 | 0 | 0, |
83 | 0 | 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 | 0 | *systemtime = (libfdatetime_systemtime_t *) internal_systemtime; |
95 | |
|
96 | 0 | 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 | 0 | } |
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 | 0 | { |
114 | 0 | libfdatetime_internal_systemtime_t *internal_systemtime = NULL; |
115 | 0 | static char *function = "libfdatetime_systemtime_free"; |
116 | |
|
117 | 0 | 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 | 0 | if( *systemtime != NULL ) |
129 | 0 | { |
130 | 0 | internal_systemtime = (libfdatetime_internal_systemtime_t *) *systemtime; |
131 | 0 | *systemtime = NULL; |
132 | |
|
133 | 0 | memory_free( |
134 | 0 | internal_systemtime ); |
135 | 0 | } |
136 | 0 | return( 1 ); |
137 | 0 | } |
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 | 0 | { |
149 | 0 | libfdatetime_internal_systemtime_t *internal_systemtime = NULL; |
150 | 0 | static char *function = "libfdatetime_systemtime_copy_from_byte_stream"; |
151 | |
|
152 | 0 | 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 | 0 | internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime; |
164 | |
|
165 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | if( ( byte_order != LIBFDATETIME_ENDIAN_BIG ) |
199 | 0 | && ( 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 | 0 | if( byte_order == LIBFDATETIME_ENDIAN_LITTLE ) |
211 | 0 | { |
212 | 0 | byte_stream_copy_to_uint16_little_endian( |
213 | 0 | byte_stream, |
214 | 0 | internal_systemtime->year ); |
215 | |
|
216 | 0 | byte_stream += 2; |
217 | |
|
218 | 0 | byte_stream_copy_to_uint16_little_endian( |
219 | 0 | byte_stream, |
220 | 0 | internal_systemtime->month ); |
221 | |
|
222 | 0 | byte_stream += 2; |
223 | |
|
224 | 0 | byte_stream_copy_to_uint16_little_endian( |
225 | 0 | byte_stream, |
226 | 0 | internal_systemtime->day_of_week ); |
227 | |
|
228 | 0 | byte_stream += 2; |
229 | |
|
230 | 0 | byte_stream_copy_to_uint16_little_endian( |
231 | 0 | byte_stream, |
232 | 0 | internal_systemtime->day_of_month ); |
233 | |
|
234 | 0 | byte_stream += 2; |
235 | |
|
236 | 0 | byte_stream_copy_to_uint16_little_endian( |
237 | 0 | byte_stream, |
238 | 0 | internal_systemtime->hours ); |
239 | |
|
240 | 0 | byte_stream += 2; |
241 | |
|
242 | 0 | byte_stream_copy_to_uint16_little_endian( |
243 | 0 | byte_stream, |
244 | 0 | internal_systemtime->minutes ); |
245 | |
|
246 | 0 | byte_stream += 2; |
247 | |
|
248 | 0 | byte_stream_copy_to_uint16_little_endian( |
249 | 0 | byte_stream, |
250 | 0 | internal_systemtime->seconds ); |
251 | |
|
252 | 0 | byte_stream += 2; |
253 | |
|
254 | 0 | byte_stream_copy_to_uint16_little_endian( |
255 | 0 | byte_stream, |
256 | 0 | internal_systemtime->milli_seconds ); |
257 | 0 | } |
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 | 0 | return( 1 ); |
307 | 0 | } |
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 | 0 | { |
317 | 0 | static char *function = "libfdatetime_internal_systemtime_copy_to_date_time_values"; |
318 | 0 | uint8_t days_in_month = 0; |
319 | |
|
320 | 0 | 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 | 0 | 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 | 0 | if( internal_systemtime->milli_seconds > 999 ) |
343 | 0 | { |
344 | 0 | libcerror_error_set( |
345 | 0 | error, |
346 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
347 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
348 | 0 | "%s: invalid SYSTEMTIME - milli seconds value out of bounds.", |
349 | 0 | function ); |
350 | |
|
351 | 0 | return( -1 ); |
352 | 0 | } |
353 | 0 | date_time_values->nano_seconds = 0; |
354 | 0 | date_time_values->micro_seconds = 0; |
355 | 0 | date_time_values->milli_seconds = internal_systemtime->milli_seconds; |
356 | |
|
357 | 0 | if( internal_systemtime->seconds > 59 ) |
358 | 0 | { |
359 | 0 | libcerror_error_set( |
360 | 0 | error, |
361 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
362 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
363 | 0 | "%s: invalid SYSTEMTIME - seconds value out of bounds.", |
364 | 0 | function ); |
365 | |
|
366 | 0 | return( -1 ); |
367 | 0 | } |
368 | 0 | date_time_values->seconds = (uint8_t) internal_systemtime->seconds; |
369 | |
|
370 | 0 | if( internal_systemtime->minutes > 59 ) |
371 | 0 | { |
372 | 0 | libcerror_error_set( |
373 | 0 | error, |
374 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
375 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
376 | 0 | "%s: invalid SYSTEMTIME - minutes value out of bounds.", |
377 | 0 | function ); |
378 | |
|
379 | 0 | return( -1 ); |
380 | 0 | } |
381 | 0 | date_time_values->minutes = (uint8_t) internal_systemtime->minutes; |
382 | |
|
383 | 0 | if( internal_systemtime->hours > 23 ) |
384 | 0 | { |
385 | 0 | libcerror_error_set( |
386 | 0 | error, |
387 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
388 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
389 | 0 | "%s: invalid SYSTEMTIME - hours value out of bounds.", |
390 | 0 | function ); |
391 | |
|
392 | 0 | return( -1 ); |
393 | 0 | } |
394 | 0 | date_time_values->hours = (uint8_t) internal_systemtime->hours; |
395 | |
|
396 | 0 | if( internal_systemtime->year > 9999 ) |
397 | 0 | { |
398 | 0 | libcerror_error_set( |
399 | 0 | error, |
400 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
401 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
402 | 0 | "%s: invalid SYSTEMTIME - year value out of bounds.", |
403 | 0 | function ); |
404 | |
|
405 | 0 | return( -1 ); |
406 | 0 | } |
407 | 0 | date_time_values->year = (uint16_t) internal_systemtime->year; |
408 | |
|
409 | 0 | if( ( internal_systemtime->month == 0 ) |
410 | 0 | || ( internal_systemtime->month > 12 ) ) |
411 | 0 | { |
412 | 0 | libcerror_error_set( |
413 | 0 | error, |
414 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
415 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
416 | 0 | "%s: invalid SYSTEMTIME - month value out of bounds.", |
417 | 0 | function ); |
418 | |
|
419 | 0 | return( -1 ); |
420 | 0 | } |
421 | 0 | date_time_values->month = (uint8_t) internal_systemtime->month; |
422 | |
|
423 | 0 | if( internal_systemtime->day_of_week > 6 ) |
424 | 0 | { |
425 | 0 | libcerror_error_set( |
426 | 0 | error, |
427 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
428 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
429 | 0 | "%s: invalid SYSTEMTIME - day of week value out of bounds.", |
430 | 0 | function ); |
431 | |
|
432 | 0 | return( -1 ); |
433 | 0 | } |
434 | | /* February (2) |
435 | | */ |
436 | 0 | if( date_time_values->month == 2 ) |
437 | 0 | { |
438 | 0 | if( ( ( ( date_time_values->year % 4 ) == 0 ) |
439 | 0 | && ( ( date_time_values->year % 100 ) != 0 ) ) |
440 | 0 | || ( ( date_time_values->year % 400 ) == 0 ) ) |
441 | 0 | { |
442 | 0 | days_in_month = 29; |
443 | 0 | } |
444 | 0 | else |
445 | 0 | { |
446 | 0 | days_in_month = 28; |
447 | 0 | } |
448 | 0 | } |
449 | | /* April (4), June (6), September (9), November (11) |
450 | | */ |
451 | 0 | else if( ( date_time_values->month == 4 ) |
452 | 0 | || ( date_time_values->month == 6 ) |
453 | 0 | || ( date_time_values->month == 9 ) |
454 | 0 | || ( date_time_values->month == 11 ) ) |
455 | 0 | { |
456 | 0 | days_in_month = 30; |
457 | 0 | } |
458 | | /* January (1), March (3), May (5), July (7), August (8), October (10), December (12) |
459 | | */ |
460 | 0 | else if( ( date_time_values->month == 1 ) |
461 | 0 | || ( date_time_values->month == 3 ) |
462 | 0 | || ( date_time_values->month == 5 ) |
463 | 0 | || ( date_time_values->month == 7 ) |
464 | 0 | || ( date_time_values->month == 8 ) |
465 | 0 | || ( date_time_values->month == 10 ) |
466 | 0 | || ( date_time_values->month == 12 ) ) |
467 | 0 | { |
468 | 0 | days_in_month = 31; |
469 | 0 | } |
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 | 0 | if( internal_systemtime->day_of_month > (uint16_t) days_in_month ) |
485 | 0 | { |
486 | 0 | libcerror_error_set( |
487 | 0 | error, |
488 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
489 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
490 | 0 | "%s: invalid SYSTEMTIME - day of month value out of bounds.", |
491 | 0 | function ); |
492 | |
|
493 | 0 | return( -1 ); |
494 | 0 | } |
495 | 0 | date_time_values->day = (uint8_t) internal_systemtime->day_of_month; |
496 | |
|
497 | 0 | return( 1 ); |
498 | 0 | } |
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 | 0 | { |
510 | 0 | libfdatetime_date_time_values_t date_time_values; |
511 | |
|
512 | 0 | static char *function = "libfdatetime_systemtime_get_string_size"; |
513 | 0 | int result = 0; |
514 | |
|
515 | 0 | 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 | 0 | 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 | 0 | result = libfdatetime_internal_systemtime_copy_to_date_time_values( |
538 | 0 | (libfdatetime_internal_systemtime_t *) systemtime, |
539 | 0 | &date_time_values, |
540 | 0 | error ); |
541 | |
|
542 | 0 | if( result != 1 ) |
543 | 0 | { |
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 | 0 | if( ( error != NULL ) |
557 | 0 | && ( *error != NULL ) ) |
558 | 0 | { |
559 | 0 | libcerror_error_free( |
560 | 0 | error ); |
561 | 0 | } |
562 | 0 | } |
563 | 0 | else |
564 | 0 | { |
565 | 0 | result = libfdatetime_date_time_values_get_string_size( |
566 | 0 | &date_time_values, |
567 | 0 | string_size, |
568 | 0 | string_format_flags, |
569 | 0 | error ); |
570 | |
|
571 | 0 | 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 | 0 | } |
583 | 0 | if( result != 1 ) |
584 | 0 | { |
585 | | /* Make sure the string can hold the hexadecimal representation of the SYSTEMTIME |
586 | | */ |
587 | 0 | *string_size = 58; |
588 | 0 | } |
589 | 0 | return( 1 ); |
590 | 0 | } |
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 | 0 | { |
603 | 0 | static char *function = "libfdatetime_internal_systemtime_copy_to_utf8_string_in_hexadecimal"; |
604 | 0 | size_t string_index = 0; |
605 | 0 | uint8_t byte_value = 0; |
606 | 0 | int8_t byte_shift = 0; |
607 | |
|
608 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | if( ( utf8_string_size < 58 ) |
653 | 0 | || ( *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 | 0 | string_index = *utf8_string_index; |
665 | |
|
666 | 0 | utf8_string[ string_index++ ] = (uint8_t) '('; |
667 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
668 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
669 | |
|
670 | 0 | byte_shift = 14; |
671 | |
|
672 | 0 | do |
673 | 0 | { |
674 | 0 | byte_value = ( internal_systemtime->year >> byte_shift ) & 0x0f; |
675 | |
|
676 | 0 | if( byte_value <= 9 ) |
677 | 0 | { |
678 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
679 | 0 | } |
680 | 0 | else |
681 | 0 | { |
682 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
683 | 0 | } |
684 | 0 | byte_shift -= 4; |
685 | 0 | } |
686 | 0 | while( byte_shift >= 0 ); |
687 | |
|
688 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
689 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
690 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
691 | |
|
692 | 0 | byte_shift = 14; |
693 | |
|
694 | 0 | do |
695 | 0 | { |
696 | 0 | byte_value = ( internal_systemtime->month >> byte_shift ) & 0x0f; |
697 | |
|
698 | 0 | if( byte_value <= 9 ) |
699 | 0 | { |
700 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
701 | 0 | } |
702 | 0 | else |
703 | 0 | { |
704 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
705 | 0 | } |
706 | 0 | byte_shift -= 4; |
707 | 0 | } |
708 | 0 | while( byte_shift >= 0 ); |
709 | |
|
710 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
711 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
712 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
713 | |
|
714 | 0 | byte_shift = 14; |
715 | |
|
716 | 0 | do |
717 | 0 | { |
718 | 0 | byte_value = ( internal_systemtime->day_of_week >> byte_shift ) & 0x0f; |
719 | |
|
720 | 0 | if( byte_value <= 9 ) |
721 | 0 | { |
722 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
723 | 0 | } |
724 | 0 | else |
725 | 0 | { |
726 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
727 | 0 | } |
728 | 0 | byte_shift -= 4; |
729 | 0 | } |
730 | 0 | while( byte_shift >= 0 ); |
731 | |
|
732 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
733 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
734 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
735 | |
|
736 | 0 | byte_shift = 14; |
737 | |
|
738 | 0 | do |
739 | 0 | { |
740 | 0 | byte_value = ( internal_systemtime->day_of_month >> byte_shift ) & 0x0f; |
741 | |
|
742 | 0 | if( byte_value <= 9 ) |
743 | 0 | { |
744 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
745 | 0 | } |
746 | 0 | else |
747 | 0 | { |
748 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
749 | 0 | } |
750 | 0 | byte_shift -= 4; |
751 | 0 | } |
752 | 0 | while( byte_shift >= 0 ); |
753 | |
|
754 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
755 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
756 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
757 | |
|
758 | 0 | byte_shift = 14; |
759 | |
|
760 | 0 | do |
761 | 0 | { |
762 | 0 | byte_value = ( internal_systemtime->hours >> byte_shift ) & 0x0f; |
763 | |
|
764 | 0 | if( byte_value <= 9 ) |
765 | 0 | { |
766 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
767 | 0 | } |
768 | 0 | else |
769 | 0 | { |
770 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
771 | 0 | } |
772 | 0 | byte_shift -= 4; |
773 | 0 | } |
774 | 0 | while( byte_shift >= 0 ); |
775 | |
|
776 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
777 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
778 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
779 | |
|
780 | 0 | byte_shift = 14; |
781 | |
|
782 | 0 | do |
783 | 0 | { |
784 | 0 | byte_value = ( internal_systemtime->minutes >> byte_shift ) & 0x0f; |
785 | |
|
786 | 0 | if( byte_value <= 9 ) |
787 | 0 | { |
788 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
789 | 0 | } |
790 | 0 | else |
791 | 0 | { |
792 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
793 | 0 | } |
794 | 0 | byte_shift -= 4; |
795 | 0 | } |
796 | 0 | while( byte_shift >= 0 ); |
797 | |
|
798 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
799 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
800 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
801 | |
|
802 | 0 | byte_shift = 14; |
803 | |
|
804 | 0 | do |
805 | 0 | { |
806 | 0 | byte_value = ( internal_systemtime->seconds >> byte_shift ) & 0x0f; |
807 | |
|
808 | 0 | if( byte_value <= 9 ) |
809 | 0 | { |
810 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
811 | 0 | } |
812 | 0 | else |
813 | 0 | { |
814 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
815 | 0 | } |
816 | 0 | byte_shift -= 4; |
817 | 0 | } |
818 | 0 | while( byte_shift >= 0 ); |
819 | |
|
820 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
821 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
822 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
823 | |
|
824 | 0 | byte_shift = 14; |
825 | |
|
826 | 0 | do |
827 | 0 | { |
828 | 0 | byte_value = ( internal_systemtime->milli_seconds >> byte_shift ) & 0x0f; |
829 | |
|
830 | 0 | if( byte_value <= 9 ) |
831 | 0 | { |
832 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
833 | 0 | } |
834 | 0 | else |
835 | 0 | { |
836 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
837 | 0 | } |
838 | 0 | byte_shift -= 4; |
839 | 0 | } |
840 | 0 | while( byte_shift >= 0 ); |
841 | |
|
842 | 0 | utf8_string[ string_index++ ] = (uint8_t) ')'; |
843 | |
|
844 | 0 | utf8_string[ string_index++ ] = 0; |
845 | |
|
846 | 0 | *utf8_string_index = string_index; |
847 | |
|
848 | 0 | return( 1 ); |
849 | 0 | } |
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 | 0 | { |
897 | 0 | libfdatetime_date_time_values_t date_time_values; |
898 | |
|
899 | 0 | libfdatetime_internal_systemtime_t *internal_systemtime = NULL; |
900 | 0 | static char *function = "libfdatetime_systemtime_copy_to_utf8_string_with_index"; |
901 | 0 | int result = 0; |
902 | |
|
903 | 0 | 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 | 0 | internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime; |
915 | |
|
916 | 0 | result = libfdatetime_internal_systemtime_copy_to_date_time_values( |
917 | 0 | internal_systemtime, |
918 | 0 | &date_time_values, |
919 | 0 | error ); |
920 | |
|
921 | 0 | if( result != 1 ) |
922 | 0 | { |
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 | 0 | if( ( error != NULL ) |
936 | 0 | && ( *error != NULL ) ) |
937 | 0 | { |
938 | 0 | libcerror_error_free( |
939 | 0 | error ); |
940 | 0 | } |
941 | 0 | } |
942 | 0 | else |
943 | 0 | { |
944 | 0 | result = libfdatetime_date_time_values_copy_to_utf8_string_with_index( |
945 | 0 | &date_time_values, |
946 | 0 | utf8_string, |
947 | 0 | utf8_string_size, |
948 | 0 | utf8_string_index, |
949 | 0 | string_format_flags, |
950 | 0 | error ); |
951 | |
|
952 | 0 | 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 | 0 | } |
964 | 0 | if( result != 1 ) |
965 | 0 | { |
966 | 0 | result = libfdatetime_internal_systemtime_copy_to_utf8_string_in_hexadecimal( |
967 | 0 | internal_systemtime, |
968 | 0 | utf8_string, |
969 | 0 | utf8_string_size, |
970 | 0 | utf8_string_index, |
971 | 0 | error ); |
972 | |
|
973 | 0 | 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 | 0 | } |
985 | 0 | return( 1 ); |
986 | 0 | } |
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 | 0 | { |
999 | 0 | static char *function = "libfdatetime_internal_systemtime_copy_to_utf16_string_in_hexadecimal"; |
1000 | 0 | size_t string_index = 0; |
1001 | 0 | uint8_t byte_value = 0; |
1002 | 0 | int8_t byte_shift = 0; |
1003 | |
|
1004 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | if( ( utf16_string_size < 58 ) |
1049 | 0 | || ( *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 | 0 | string_index = *utf16_string_index; |
1061 | |
|
1062 | 0 | utf16_string[ string_index++ ] = (uint16_t) '('; |
1063 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1064 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1065 | |
|
1066 | 0 | byte_shift = 14; |
1067 | |
|
1068 | 0 | do |
1069 | 0 | { |
1070 | 0 | byte_value = ( internal_systemtime->year >> byte_shift ) & 0x0f; |
1071 | |
|
1072 | 0 | if( byte_value <= 9 ) |
1073 | 0 | { |
1074 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1075 | 0 | } |
1076 | 0 | else |
1077 | 0 | { |
1078 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1079 | 0 | } |
1080 | 0 | byte_shift -= 4; |
1081 | 0 | } |
1082 | 0 | while( byte_shift >= 0 ); |
1083 | |
|
1084 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1085 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1086 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1087 | |
|
1088 | 0 | byte_shift = 14; |
1089 | |
|
1090 | 0 | do |
1091 | 0 | { |
1092 | 0 | byte_value = ( internal_systemtime->month >> byte_shift ) & 0x0f; |
1093 | |
|
1094 | 0 | if( byte_value <= 9 ) |
1095 | 0 | { |
1096 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1097 | 0 | } |
1098 | 0 | else |
1099 | 0 | { |
1100 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1101 | 0 | } |
1102 | 0 | byte_shift -= 4; |
1103 | 0 | } |
1104 | 0 | while( byte_shift >= 0 ); |
1105 | |
|
1106 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1107 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1108 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1109 | |
|
1110 | 0 | byte_shift = 14; |
1111 | |
|
1112 | 0 | do |
1113 | 0 | { |
1114 | 0 | byte_value = ( internal_systemtime->day_of_week >> byte_shift ) & 0x0f; |
1115 | |
|
1116 | 0 | if( byte_value <= 9 ) |
1117 | 0 | { |
1118 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1119 | 0 | } |
1120 | 0 | else |
1121 | 0 | { |
1122 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1123 | 0 | } |
1124 | 0 | byte_shift -= 4; |
1125 | 0 | } |
1126 | 0 | while( byte_shift >= 0 ); |
1127 | |
|
1128 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1129 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1130 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1131 | |
|
1132 | 0 | byte_shift = 14; |
1133 | |
|
1134 | 0 | do |
1135 | 0 | { |
1136 | 0 | byte_value = ( internal_systemtime->day_of_month >> byte_shift ) & 0x0f; |
1137 | |
|
1138 | 0 | if( byte_value <= 9 ) |
1139 | 0 | { |
1140 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1141 | 0 | } |
1142 | 0 | else |
1143 | 0 | { |
1144 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1145 | 0 | } |
1146 | 0 | byte_shift -= 4; |
1147 | 0 | } |
1148 | 0 | while( byte_shift >= 0 ); |
1149 | |
|
1150 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1151 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1152 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1153 | |
|
1154 | 0 | byte_shift = 14; |
1155 | |
|
1156 | 0 | do |
1157 | 0 | { |
1158 | 0 | byte_value = ( internal_systemtime->hours >> byte_shift ) & 0x0f; |
1159 | |
|
1160 | 0 | if( byte_value <= 9 ) |
1161 | 0 | { |
1162 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1163 | 0 | } |
1164 | 0 | else |
1165 | 0 | { |
1166 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1167 | 0 | } |
1168 | 0 | byte_shift -= 4; |
1169 | 0 | } |
1170 | 0 | while( byte_shift >= 0 ); |
1171 | |
|
1172 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1173 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1174 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1175 | |
|
1176 | 0 | byte_shift = 14; |
1177 | |
|
1178 | 0 | do |
1179 | 0 | { |
1180 | 0 | byte_value = ( internal_systemtime->minutes >> byte_shift ) & 0x0f; |
1181 | |
|
1182 | 0 | if( byte_value <= 9 ) |
1183 | 0 | { |
1184 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1185 | 0 | } |
1186 | 0 | else |
1187 | 0 | { |
1188 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1189 | 0 | } |
1190 | 0 | byte_shift -= 4; |
1191 | 0 | } |
1192 | 0 | while( byte_shift >= 0 ); |
1193 | |
|
1194 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1195 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1196 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1197 | |
|
1198 | 0 | byte_shift = 14; |
1199 | |
|
1200 | 0 | do |
1201 | 0 | { |
1202 | 0 | byte_value = ( internal_systemtime->seconds >> byte_shift ) & 0x0f; |
1203 | |
|
1204 | 0 | if( byte_value <= 9 ) |
1205 | 0 | { |
1206 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1207 | 0 | } |
1208 | 0 | else |
1209 | 0 | { |
1210 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1211 | 0 | } |
1212 | 0 | byte_shift -= 4; |
1213 | 0 | } |
1214 | 0 | while( byte_shift >= 0 ); |
1215 | |
|
1216 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
1217 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
1218 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
1219 | |
|
1220 | 0 | byte_shift = 14; |
1221 | |
|
1222 | 0 | do |
1223 | 0 | { |
1224 | 0 | byte_value = ( internal_systemtime->milli_seconds >> byte_shift ) & 0x0f; |
1225 | |
|
1226 | 0 | if( byte_value <= 9 ) |
1227 | 0 | { |
1228 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
1229 | 0 | } |
1230 | 0 | else |
1231 | 0 | { |
1232 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
1233 | 0 | } |
1234 | 0 | byte_shift -= 4; |
1235 | 0 | } |
1236 | 0 | while( byte_shift >= 0 ); |
1237 | |
|
1238 | 0 | utf16_string[ string_index++ ] = (uint16_t) ')'; |
1239 | |
|
1240 | 0 | utf16_string[ string_index++ ] = 0; |
1241 | |
|
1242 | 0 | *utf16_string_index = string_index; |
1243 | |
|
1244 | 0 | return( 1 ); |
1245 | 0 | } |
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 | 0 | { |
1293 | 0 | libfdatetime_date_time_values_t date_time_values; |
1294 | |
|
1295 | 0 | libfdatetime_internal_systemtime_t *internal_systemtime = NULL; |
1296 | 0 | static char *function = "libfdatetime_systemtime_copy_to_utf16_string_with_index"; |
1297 | 0 | int result = 0; |
1298 | |
|
1299 | 0 | 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 | 0 | internal_systemtime = (libfdatetime_internal_systemtime_t *) systemtime; |
1311 | |
|
1312 | 0 | result = libfdatetime_internal_systemtime_copy_to_date_time_values( |
1313 | 0 | internal_systemtime, |
1314 | 0 | &date_time_values, |
1315 | 0 | error ); |
1316 | |
|
1317 | 0 | if( result != 1 ) |
1318 | 0 | { |
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 | 0 | if( ( error != NULL ) |
1332 | 0 | && ( *error != NULL ) ) |
1333 | 0 | { |
1334 | 0 | libcerror_error_free( |
1335 | 0 | error ); |
1336 | 0 | } |
1337 | 0 | } |
1338 | 0 | else |
1339 | 0 | { |
1340 | 0 | result = libfdatetime_date_time_values_copy_to_utf16_string_with_index( |
1341 | 0 | &date_time_values, |
1342 | 0 | utf16_string, |
1343 | 0 | utf16_string_size, |
1344 | 0 | utf16_string_index, |
1345 | 0 | string_format_flags, |
1346 | 0 | error ); |
1347 | |
|
1348 | 0 | 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 | 0 | } |
1360 | 0 | if( result != 1 ) |
1361 | 0 | { |
1362 | 0 | result = libfdatetime_internal_systemtime_copy_to_utf16_string_in_hexadecimal( |
1363 | 0 | internal_systemtime, |
1364 | 0 | utf16_string, |
1365 | 0 | utf16_string_size, |
1366 | 0 | utf16_string_index, |
1367 | 0 | error ); |
1368 | |
|
1369 | 0 | 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 | 0 | } |
1381 | 0 | return( 1 ); |
1382 | 0 | } |
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 | | |