/src/libfwevt/libfdatetime/libfdatetime_nsf_timedate.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Notes Storage Facility (NSF) timedate 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_nsf_timedate.h" |
31 | | #include "libfdatetime_types.h" |
32 | | |
33 | | /* Creates a NSF timedate |
34 | | * Make sure the value nsf_timedate is referencing, is set to NULL |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libfdatetime_nsf_timedate_initialize( |
38 | | libfdatetime_nsf_timedate_t **nsf_timedate, |
39 | | libcerror_error_t **error ) |
40 | 0 | { |
41 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
42 | 0 | static char *function = "libfdatetime_nsf_timedate_initialize"; |
43 | |
|
44 | 0 | if( nsf_timedate == 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 NSF timedate.", |
51 | 0 | function ); |
52 | |
|
53 | 0 | return( -1 ); |
54 | 0 | } |
55 | 0 | if( *nsf_timedate != 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 NSF timedate value already set.", |
62 | 0 | function ); |
63 | |
|
64 | 0 | return( -1 ); |
65 | 0 | } |
66 | 0 | internal_nsf_timedate = memory_allocate_structure( |
67 | 0 | libfdatetime_internal_nsf_timedate_t ); |
68 | |
|
69 | 0 | if( internal_nsf_timedate == 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 NSF timedate.", |
76 | 0 | function ); |
77 | |
|
78 | 0 | goto on_error; |
79 | 0 | } |
80 | 0 | if( memory_set( |
81 | 0 | internal_nsf_timedate, |
82 | 0 | 0, |
83 | 0 | sizeof( libfdatetime_internal_nsf_timedate_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 NSF timedate.", |
90 | 0 | function ); |
91 | |
|
92 | 0 | goto on_error; |
93 | 0 | } |
94 | 0 | *nsf_timedate = (libfdatetime_nsf_timedate_t *) internal_nsf_timedate; |
95 | |
|
96 | 0 | return( 1 ); |
97 | | |
98 | 0 | on_error: |
99 | 0 | if( internal_nsf_timedate != NULL ) |
100 | 0 | { |
101 | 0 | memory_free( |
102 | 0 | internal_nsf_timedate ); |
103 | 0 | } |
104 | 0 | return( -1 ); |
105 | 0 | } |
106 | | |
107 | | /* Frees a NSF timedate |
108 | | * Returns 1 if successful or -1 on error |
109 | | */ |
110 | | int libfdatetime_nsf_timedate_free( |
111 | | libfdatetime_nsf_timedate_t **nsf_timedate, |
112 | | libcerror_error_t **error ) |
113 | 0 | { |
114 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
115 | 0 | static char *function = "libfdatetime_nsf_timedate_free"; |
116 | |
|
117 | 0 | if( nsf_timedate == 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 NSF timedate.", |
124 | 0 | function ); |
125 | |
|
126 | 0 | return( -1 ); |
127 | 0 | } |
128 | 0 | if( *nsf_timedate != NULL ) |
129 | 0 | { |
130 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) *nsf_timedate; |
131 | 0 | *nsf_timedate = NULL; |
132 | |
|
133 | 0 | memory_free( |
134 | 0 | internal_nsf_timedate ); |
135 | 0 | } |
136 | 0 | return( 1 ); |
137 | 0 | } |
138 | | |
139 | | /* Converts a byte stream into a NSF timedate |
140 | | * Returns 1 if successful or -1 on error |
141 | | */ |
142 | | int libfdatetime_nsf_timedate_copy_from_byte_stream( |
143 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
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_nsf_timedate_t *internal_nsf_timedate = NULL; |
150 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_from_byte_stream"; |
151 | |
|
152 | 0 | if( nsf_timedate == 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 NSF timedate.", |
159 | 0 | function ); |
160 | |
|
161 | 0 | return( -1 ); |
162 | 0 | } |
163 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) nsf_timedate; |
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 < 8 ) |
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_uint32_little_endian( |
213 | 0 | byte_stream, |
214 | 0 | internal_nsf_timedate->lower ); |
215 | |
|
216 | 0 | byte_stream += 4; |
217 | |
|
218 | 0 | byte_stream_copy_to_uint32_little_endian( |
219 | 0 | byte_stream, |
220 | 0 | internal_nsf_timedate->upper ); |
221 | 0 | } |
222 | 0 | else if( byte_order == LIBFDATETIME_ENDIAN_BIG ) |
223 | 0 | { |
224 | 0 | byte_stream_copy_to_uint32_big_endian( |
225 | 0 | byte_stream, |
226 | 0 | internal_nsf_timedate->upper ); |
227 | |
|
228 | 0 | byte_stream += 4; |
229 | |
|
230 | 0 | byte_stream_copy_to_uint32_big_endian( |
231 | 0 | byte_stream, |
232 | 0 | internal_nsf_timedate->lower ); |
233 | 0 | } |
234 | 0 | return( 1 ); |
235 | 0 | } |
236 | | |
237 | | /* Converts a 64-bit value into a NSF timedate |
238 | | * Returns 1 if successful or -1 on error |
239 | | */ |
240 | | int libfdatetime_nsf_timedate_copy_from_64bit( |
241 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
242 | | uint64_t value_64bit, |
243 | | libcerror_error_t **error ) |
244 | 0 | { |
245 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
246 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_from_64bit"; |
247 | |
|
248 | 0 | if( nsf_timedate == NULL ) |
249 | 0 | { |
250 | 0 | libcerror_error_set( |
251 | 0 | error, |
252 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
253 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
254 | 0 | "%s: invalid NSF timedate.", |
255 | 0 | function ); |
256 | |
|
257 | 0 | return( -1 ); |
258 | 0 | } |
259 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) nsf_timedate; |
260 | |
|
261 | 0 | internal_nsf_timedate->upper = value_64bit >> 32; |
262 | 0 | internal_nsf_timedate->lower = value_64bit & 0xffffffffUL; |
263 | |
|
264 | 0 | return( 1 ); |
265 | 0 | } |
266 | | |
267 | | /* Converts a NSF timedate into a 64-bit value |
268 | | * Returns 1 if successful or -1 on error |
269 | | */ |
270 | | int libfdatetime_nsf_timedate_copy_to_64bit( |
271 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
272 | | uint64_t *value_64bit, |
273 | | libcerror_error_t **error ) |
274 | 0 | { |
275 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
276 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_64bit"; |
277 | |
|
278 | 0 | if( nsf_timedate == NULL ) |
279 | 0 | { |
280 | 0 | libcerror_error_set( |
281 | 0 | error, |
282 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
283 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
284 | 0 | "%s: invalid NSF timedate.", |
285 | 0 | function ); |
286 | |
|
287 | 0 | return( -1 ); |
288 | 0 | } |
289 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) nsf_timedate; |
290 | |
|
291 | 0 | if( value_64bit == NULL ) |
292 | 0 | { |
293 | 0 | libcerror_error_set( |
294 | 0 | error, |
295 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
296 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
297 | 0 | "%s: invalid 64-bit value.", |
298 | 0 | function ); |
299 | |
|
300 | 0 | return( -1 ); |
301 | 0 | } |
302 | 0 | *value_64bit = internal_nsf_timedate->upper; |
303 | 0 | *value_64bit <<= 32; |
304 | 0 | *value_64bit |= internal_nsf_timedate->lower; |
305 | |
|
306 | 0 | return( 1 ); |
307 | 0 | } |
308 | | |
309 | | /* Converts a NSF timedate into date time values |
310 | | * Returns 1 if successful or -1 on error |
311 | | */ |
312 | | int libfdatetime_internal_nsf_timedate_copy_to_date_time_values( |
313 | | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate, |
314 | | libfdatetime_date_time_values_t *date_time_values, |
315 | | libcerror_error_t **error ) |
316 | 0 | { |
317 | 0 | static char *function = "libfdatetime_internal_nsf_timedate_copy_to_date_time_values"; |
318 | 0 | uint32_t nsf_julian_day = 0; |
319 | 0 | uint32_t nsf_time = 0; |
320 | 0 | uint32_t number_of_years = 0; |
321 | 0 | uint32_t number_of_months = 0; |
322 | 0 | uint32_t julian_quad_cycles = 0; |
323 | 0 | uint32_t gregorian_cent_cycles = 0; |
324 | 0 | uint32_t gregorian_quad_cycles = 0; |
325 | 0 | uint32_t roman_annual_cycles = 0; |
326 | |
|
327 | 0 | if( internal_nsf_timedate == NULL ) |
328 | 0 | { |
329 | 0 | libcerror_error_set( |
330 | 0 | error, |
331 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
332 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
333 | 0 | "%s: invalid NSF timedate.", |
334 | 0 | function ); |
335 | |
|
336 | 0 | return( -1 ); |
337 | 0 | } |
338 | 0 | if( date_time_values == NULL ) |
339 | 0 | { |
340 | 0 | libcerror_error_set( |
341 | 0 | error, |
342 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
343 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
344 | 0 | "%s: invalid date time values.", |
345 | 0 | function ); |
346 | |
|
347 | 0 | return( -1 ); |
348 | 0 | } |
349 | | /* TODO what about dates before 1582 ? */ |
350 | | |
351 | | /* Retrieve the Julian day value which is stored in the 24 LSB of the upper value |
352 | | * the NSF Julian day starts with January 1, 4713 BC 00:00 UTC |
353 | | * instead of January 1, 4713 BC 12:00 UTC |
354 | | */ |
355 | 0 | nsf_julian_day = internal_nsf_timedate->upper & 0x00ffffffUL; |
356 | | |
357 | | /* Shift the epoch back to March 1, 4800 BC 00:00 |
358 | | * This is the beginning of the Gregorian quadricentennial |
359 | | * which is 32044 days before the Julian period |
360 | | */ |
361 | 0 | nsf_julian_day += 32044; |
362 | | |
363 | | /* Determine the number of Gregorian quadricentennial cycles |
364 | | * 1 cycle consists of 146097 days |
365 | | */ |
366 | 0 | gregorian_quad_cycles = nsf_julian_day / 146097; |
367 | |
|
368 | 0 | nsf_julian_day %= 146097; |
369 | | |
370 | | /* Determine the number of Gregorian centennial cycles |
371 | | * 1 cycle consists of 36524 days |
372 | | * Correct for leap years per cycle, either 3 or 4 |
373 | | */ |
374 | 0 | gregorian_cent_cycles = ( ( ( nsf_julian_day / 36524 ) + 1 ) * 3 ) / 4; |
375 | |
|
376 | 0 | nsf_julian_day -= gregorian_cent_cycles * 36524; |
377 | | |
378 | | /* Determine the number of Julian quadrennial cycles |
379 | | * 1 cycle consists of 1461 days per 4 year |
380 | | */ |
381 | 0 | julian_quad_cycles = nsf_julian_day / 1461; |
382 | |
|
383 | 0 | nsf_julian_day %= 1461; |
384 | | |
385 | | /* Determine the number of Roman annual cycles |
386 | | * 1 cycle consists of 365 days |
387 | | * Correct for leap years per cycle, either 3 or 4 |
388 | | */ |
389 | 0 | roman_annual_cycles = ( ( ( nsf_julian_day / 365 ) + 1 ) * 3 ) / 4; |
390 | | |
391 | | /* The number of days remaining in the current Julian year |
392 | | */ |
393 | 0 | nsf_julian_day -= roman_annual_cycles * 365; |
394 | | |
395 | | /* Determine the number of years since March 1, 4801 BC |
396 | | */ |
397 | 0 | number_of_years = ( gregorian_quad_cycles * 400 ) |
398 | 0 | + ( gregorian_cent_cycles * 100 ) |
399 | 0 | + ( julian_quad_cycles * 4 ) |
400 | 0 | + roman_annual_cycles; |
401 | | |
402 | | /* Determine the number of months since March |
403 | | */ |
404 | 0 | number_of_months = ( ( ( nsf_julian_day * 5 ) + 308 ) / 153 ) - 2; |
405 | | |
406 | | /* Determine the number of days since the 1st of the month |
407 | | */ |
408 | 0 | nsf_julian_day -= ( ( ( number_of_months + 4 ) * 153 ) / 5 ); |
409 | 0 | nsf_julian_day += 122; |
410 | | |
411 | | /* Determine the year |
412 | | */ |
413 | 0 | date_time_values->year = (uint16_t) ( number_of_years - 4800 + ( ( number_of_months + 2 ) / 12 ) ); |
414 | |
|
415 | 0 | if( date_time_values->year > 9999 ) |
416 | 0 | { |
417 | 0 | libcerror_error_set( |
418 | 0 | error, |
419 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
420 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
421 | 0 | "%s: invalid NSF timedate - year value out of bounds.", |
422 | 0 | function ); |
423 | |
|
424 | 0 | return( -1 ); |
425 | 0 | } |
426 | | /* Determine the month |
427 | | */ |
428 | 0 | date_time_values->month = ( ( number_of_months + 2 ) % 12 ) + 1; |
429 | | |
430 | | /* Determine the day of the month |
431 | | */ |
432 | 0 | date_time_values->day = (uint8_t) ( nsf_julian_day + 1 ); |
433 | | |
434 | | /* Retrieve the number of seconds from the lower part of the NFS timedate |
435 | | */ |
436 | 0 | nsf_time = internal_nsf_timedate->lower; |
437 | | |
438 | | /* The timestamp is in units of 10 milli seconds correct the value to seconds |
439 | | */ |
440 | 0 | date_time_values->nano_seconds = 0; |
441 | 0 | date_time_values->micro_seconds = 0; |
442 | 0 | date_time_values->milli_seconds = ( nsf_time % 100 ) * 10; |
443 | 0 | nsf_time /= 100; |
444 | | |
445 | | /* There are 60 seconds in a minute correct the value to minutes |
446 | | */ |
447 | 0 | date_time_values->seconds = nsf_time % 60; |
448 | 0 | nsf_time /= 60; |
449 | | |
450 | | /* There are 60 minutes in an hour correct the value to hours |
451 | | */ |
452 | 0 | date_time_values->minutes = nsf_time % 60; |
453 | 0 | nsf_time /= 60; |
454 | | |
455 | | /* There are 24 hours in a day correct the value to days |
456 | | */ |
457 | 0 | if( nsf_time >= 24 ) |
458 | 0 | { |
459 | 0 | libcerror_error_set( |
460 | 0 | error, |
461 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
462 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
463 | 0 | "%s: unsupported number of hours: %d.", |
464 | 0 | function, |
465 | 0 | nsf_time ); |
466 | |
|
467 | 0 | return( -1 ); |
468 | 0 | } |
469 | 0 | date_time_values->hours = (uint8_t) nsf_time; |
470 | | |
471 | | /* TODO day light savings and timezone */ |
472 | |
|
473 | 0 | return( 1 ); |
474 | 0 | } |
475 | | |
476 | | /* Deterimes the size of the string for the NSF timedate |
477 | | * The string size includes the end of string character |
478 | | * Returns 1 if successful or -1 on error |
479 | | */ |
480 | | int libfdatetime_nsf_timedate_get_string_size( |
481 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
482 | | size_t *string_size, |
483 | | uint32_t string_format_flags, |
484 | | libcerror_error_t **error ) |
485 | 0 | { |
486 | 0 | libfdatetime_date_time_values_t date_time_values; |
487 | |
|
488 | 0 | static char *function = "libfdatetime_nsf_timedate_get_string_size"; |
489 | 0 | int result = 0; |
490 | |
|
491 | 0 | if( nsf_timedate == NULL ) |
492 | 0 | { |
493 | 0 | libcerror_error_set( |
494 | 0 | error, |
495 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
496 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
497 | 0 | "%s: invalid NSF timedate.", |
498 | 0 | function ); |
499 | |
|
500 | 0 | return( -1 ); |
501 | 0 | } |
502 | 0 | if( string_size == NULL ) |
503 | 0 | { |
504 | 0 | libcerror_error_set( |
505 | 0 | error, |
506 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
507 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
508 | 0 | "%s: invalid string size.", |
509 | 0 | function ); |
510 | |
|
511 | 0 | return( -1 ); |
512 | 0 | } |
513 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_date_time_values( |
514 | 0 | (libfdatetime_internal_nsf_timedate_t *) nsf_timedate, |
515 | 0 | &date_time_values, |
516 | 0 | error ); |
517 | |
|
518 | 0 | if( result != 1 ) |
519 | 0 | { |
520 | | #if defined( HAVE_DEBUG_OUTPUT ) |
521 | | libcerror_error_set( |
522 | | error, |
523 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
524 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
525 | | "%s: unable to set date time values.", |
526 | | function ); |
527 | | |
528 | | /* TODO debug print error */ |
529 | | |
530 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
531 | |
|
532 | 0 | if( ( error != NULL ) |
533 | 0 | && ( *error != NULL ) ) |
534 | 0 | { |
535 | 0 | libcerror_error_free( |
536 | 0 | error ); |
537 | 0 | } |
538 | 0 | } |
539 | 0 | else |
540 | 0 | { |
541 | 0 | result = libfdatetime_date_time_values_get_string_size( |
542 | 0 | &date_time_values, |
543 | 0 | string_size, |
544 | 0 | string_format_flags, |
545 | 0 | error ); |
546 | |
|
547 | 0 | if( result == -1 ) |
548 | 0 | { |
549 | 0 | libcerror_error_set( |
550 | 0 | error, |
551 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
552 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
553 | 0 | "%s: unable to get string size.", |
554 | 0 | function ); |
555 | |
|
556 | 0 | return( -1 ); |
557 | 0 | } |
558 | 0 | } |
559 | 0 | if( result != 1 ) |
560 | 0 | { |
561 | | /* Make sure the string can hold the hexadecimal representation of the NSF timedate |
562 | | */ |
563 | 0 | *string_size = 24; |
564 | 0 | } |
565 | 0 | return( 1 ); |
566 | 0 | } |
567 | | |
568 | | /* Converts the NSF timedate into an UTF-8 string in hexadecimal representation |
569 | | * The string size should include the end of string character |
570 | | * Returns 1 if successful or -1 on error |
571 | | */ |
572 | | int libfdatetime_internal_nsf_timedate_copy_to_utf8_string_in_hexadecimal( |
573 | | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate, |
574 | | uint8_t *utf8_string, |
575 | | size_t utf8_string_size, |
576 | | size_t *utf8_string_index, |
577 | | libcerror_error_t **error ) |
578 | 0 | { |
579 | 0 | static char *function = "libfdatetime_internal_nsf_timedate_copy_to_utf8_string_in_hexadecimal"; |
580 | 0 | size_t string_index = 0; |
581 | 0 | uint8_t byte_value = 0; |
582 | 0 | int8_t byte_shift = 0; |
583 | |
|
584 | 0 | if( internal_nsf_timedate == NULL ) |
585 | 0 | { |
586 | 0 | libcerror_error_set( |
587 | 0 | error, |
588 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
589 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
590 | 0 | "%s: invalid NSF timedate.", |
591 | 0 | function ); |
592 | |
|
593 | 0 | return( -1 ); |
594 | 0 | } |
595 | 0 | if( utf8_string == NULL ) |
596 | 0 | { |
597 | 0 | libcerror_error_set( |
598 | 0 | error, |
599 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
600 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
601 | 0 | "%s: invalid UTF-8 string.", |
602 | 0 | function ); |
603 | |
|
604 | 0 | return( -1 ); |
605 | 0 | } |
606 | 0 | if( utf8_string_size > (size_t) SSIZE_MAX ) |
607 | 0 | { |
608 | 0 | libcerror_error_set( |
609 | 0 | error, |
610 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
611 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
612 | 0 | "%s: invalid UTF-8 string size value exceeds maximum.", |
613 | 0 | function ); |
614 | |
|
615 | 0 | return( -1 ); |
616 | 0 | } |
617 | 0 | if( utf8_string_index == NULL ) |
618 | 0 | { |
619 | 0 | libcerror_error_set( |
620 | 0 | error, |
621 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
622 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
623 | 0 | "%s: invalid UTF-8 string index.", |
624 | 0 | function ); |
625 | |
|
626 | 0 | return( -1 ); |
627 | 0 | } |
628 | 0 | if( ( utf8_string_size < 24 ) |
629 | 0 | || ( *utf8_string_index > ( utf8_string_size - 24 ) ) ) |
630 | 0 | { |
631 | 0 | libcerror_error_set( |
632 | 0 | error, |
633 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
634 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
635 | 0 | "%s: UTF-8 string is too small.", |
636 | 0 | function ); |
637 | |
|
638 | 0 | return( -1 ); |
639 | 0 | } |
640 | 0 | string_index = *utf8_string_index; |
641 | |
|
642 | 0 | utf8_string[ string_index++ ] = (uint8_t) '('; |
643 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
644 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
645 | |
|
646 | 0 | byte_shift = 28; |
647 | |
|
648 | 0 | do |
649 | 0 | { |
650 | 0 | byte_value = ( internal_nsf_timedate->upper >> byte_shift ) & 0x0f; |
651 | |
|
652 | 0 | if( byte_value <= 9 ) |
653 | 0 | { |
654 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
655 | 0 | } |
656 | 0 | else |
657 | 0 | { |
658 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
659 | 0 | } |
660 | 0 | byte_shift -= 4; |
661 | 0 | } |
662 | 0 | while( byte_shift >= 0 ); |
663 | |
|
664 | 0 | utf8_string[ string_index++ ] = (uint8_t) ' '; |
665 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0'; |
666 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'x'; |
667 | |
|
668 | 0 | byte_shift = 28; |
669 | |
|
670 | 0 | do |
671 | 0 | { |
672 | 0 | byte_value = ( internal_nsf_timedate->lower >> byte_shift ) & 0x0f; |
673 | |
|
674 | 0 | if( byte_value <= 9 ) |
675 | 0 | { |
676 | 0 | utf8_string[ string_index++ ] = (uint8_t) '0' + byte_value; |
677 | 0 | } |
678 | 0 | else |
679 | 0 | { |
680 | 0 | utf8_string[ string_index++ ] = (uint8_t) 'a' + byte_value - 10; |
681 | 0 | } |
682 | 0 | byte_shift -= 4; |
683 | 0 | } |
684 | 0 | while( byte_shift >= 0 ); |
685 | |
|
686 | 0 | utf8_string[ string_index++ ] = (uint8_t) ')'; |
687 | |
|
688 | 0 | utf8_string[ string_index++ ] = 0; |
689 | |
|
690 | 0 | *utf8_string_index = string_index; |
691 | |
|
692 | 0 | return( 1 ); |
693 | 0 | } |
694 | | |
695 | | /* Converts the NSF timedate into an UTF-8 string |
696 | | * The string size should include the end of string character |
697 | | * Returns 1 if successful or -1 on error |
698 | | */ |
699 | | int libfdatetime_nsf_timedate_copy_to_utf8_string( |
700 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
701 | | uint8_t *utf8_string, |
702 | | size_t utf8_string_size, |
703 | | uint32_t string_format_flags, |
704 | | libcerror_error_t **error ) |
705 | 0 | { |
706 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_utf8_string"; |
707 | 0 | size_t utf8_string_index = 0; |
708 | |
|
709 | 0 | if( libfdatetime_nsf_timedate_copy_to_utf8_string_with_index( |
710 | 0 | nsf_timedate, |
711 | 0 | utf8_string, |
712 | 0 | utf8_string_size, |
713 | 0 | &utf8_string_index, |
714 | 0 | string_format_flags, |
715 | 0 | error ) != 1 ) |
716 | 0 | { |
717 | 0 | libcerror_error_set( |
718 | 0 | error, |
719 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
720 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
721 | 0 | "%s: unable to copy NSF timedate to UTF-8 string.", |
722 | 0 | function ); |
723 | |
|
724 | 0 | return( -1 ); |
725 | 0 | } |
726 | 0 | return( 1 ); |
727 | 0 | } |
728 | | |
729 | | /* Converts the NSF timedate into an UTF-8 string |
730 | | * The string size should include the end of string character |
731 | | * Returns 1 if successful or -1 on error |
732 | | */ |
733 | | int libfdatetime_nsf_timedate_copy_to_utf8_string_with_index( |
734 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
735 | | uint8_t *utf8_string, |
736 | | size_t utf8_string_size, |
737 | | size_t *utf8_string_index, |
738 | | uint32_t string_format_flags, |
739 | | libcerror_error_t **error ) |
740 | 0 | { |
741 | 0 | libfdatetime_date_time_values_t date_time_values; |
742 | |
|
743 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
744 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_utf8_string_with_index"; |
745 | 0 | int result = 0; |
746 | |
|
747 | 0 | if( nsf_timedate == NULL ) |
748 | 0 | { |
749 | 0 | libcerror_error_set( |
750 | 0 | error, |
751 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
752 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
753 | 0 | "%s: invalid NSF timedate.", |
754 | 0 | function ); |
755 | |
|
756 | 0 | return( -1 ); |
757 | 0 | } |
758 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) nsf_timedate; |
759 | |
|
760 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_date_time_values( |
761 | 0 | internal_nsf_timedate, |
762 | 0 | &date_time_values, |
763 | 0 | error ); |
764 | |
|
765 | 0 | if( result != 1 ) |
766 | 0 | { |
767 | | #if defined( HAVE_DEBUG_OUTPUT ) |
768 | | libcerror_error_set( |
769 | | error, |
770 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
771 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
772 | | "%s: unable to set date time values.", |
773 | | function ); |
774 | | |
775 | | /* TODO debug print error */ |
776 | | |
777 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
778 | |
|
779 | 0 | if( ( error != NULL ) |
780 | 0 | && ( *error != NULL ) ) |
781 | 0 | { |
782 | 0 | libcerror_error_free( |
783 | 0 | error ); |
784 | 0 | } |
785 | 0 | } |
786 | 0 | else |
787 | 0 | { |
788 | 0 | result = libfdatetime_date_time_values_copy_to_utf8_string_with_index( |
789 | 0 | &date_time_values, |
790 | 0 | utf8_string, |
791 | 0 | utf8_string_size, |
792 | 0 | utf8_string_index, |
793 | 0 | string_format_flags, |
794 | 0 | error ); |
795 | |
|
796 | 0 | if( result == -1 ) |
797 | 0 | { |
798 | 0 | libcerror_error_set( |
799 | 0 | error, |
800 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
801 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
802 | 0 | "%s: unable to copy date time values to UTF-8 string.", |
803 | 0 | function ); |
804 | |
|
805 | 0 | return( -1 ); |
806 | 0 | } |
807 | 0 | } |
808 | 0 | if( result != 1 ) |
809 | 0 | { |
810 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_utf8_string_in_hexadecimal( |
811 | 0 | internal_nsf_timedate, |
812 | 0 | utf8_string, |
813 | 0 | utf8_string_size, |
814 | 0 | utf8_string_index, |
815 | 0 | error ); |
816 | |
|
817 | 0 | if( result == -1 ) |
818 | 0 | { |
819 | 0 | libcerror_error_set( |
820 | 0 | error, |
821 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
822 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
823 | 0 | "%s: unable to NSF timedate to hexadecimal UTF-8 string.", |
824 | 0 | function ); |
825 | |
|
826 | 0 | return( -1 ); |
827 | 0 | } |
828 | 0 | } |
829 | 0 | return( 1 ); |
830 | 0 | } |
831 | | |
832 | | /* Converts the NSF timedate into an UTF-16 string in hexadecimal representation |
833 | | * The string size should include the end of string character |
834 | | * Returns 1 if successful or -1 on error |
835 | | */ |
836 | | int libfdatetime_internal_nsf_timedate_copy_to_utf16_string_in_hexadecimal( |
837 | | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate, |
838 | | uint16_t *utf16_string, |
839 | | size_t utf16_string_size, |
840 | | size_t *utf16_string_index, |
841 | | libcerror_error_t **error ) |
842 | 0 | { |
843 | 0 | static char *function = "libfdatetime_internal_nsf_timedate_copy_to_utf16_string_in_hexadecimal"; |
844 | 0 | size_t string_index = 0; |
845 | 0 | uint8_t byte_value = 0; |
846 | 0 | int8_t byte_shift = 0; |
847 | |
|
848 | 0 | if( internal_nsf_timedate == NULL ) |
849 | 0 | { |
850 | 0 | libcerror_error_set( |
851 | 0 | error, |
852 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
853 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
854 | 0 | "%s: invalid NSF timedate.", |
855 | 0 | function ); |
856 | |
|
857 | 0 | return( -1 ); |
858 | 0 | } |
859 | 0 | if( utf16_string == NULL ) |
860 | 0 | { |
861 | 0 | libcerror_error_set( |
862 | 0 | error, |
863 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
864 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
865 | 0 | "%s: invalid UTF-16 string.", |
866 | 0 | function ); |
867 | |
|
868 | 0 | return( -1 ); |
869 | 0 | } |
870 | 0 | if( utf16_string_size > (size_t) SSIZE_MAX ) |
871 | 0 | { |
872 | 0 | libcerror_error_set( |
873 | 0 | error, |
874 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
875 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
876 | 0 | "%s: invalid UTF-16 string size value exceeds maximum.", |
877 | 0 | function ); |
878 | |
|
879 | 0 | return( -1 ); |
880 | 0 | } |
881 | 0 | if( utf16_string_index == NULL ) |
882 | 0 | { |
883 | 0 | libcerror_error_set( |
884 | 0 | error, |
885 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
886 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
887 | 0 | "%s: invalid UTF-16 string index.", |
888 | 0 | function ); |
889 | |
|
890 | 0 | return( -1 ); |
891 | 0 | } |
892 | 0 | if( ( utf16_string_size < 24 ) |
893 | 0 | || ( *utf16_string_index > ( utf16_string_size - 24 ) ) ) |
894 | 0 | { |
895 | 0 | libcerror_error_set( |
896 | 0 | error, |
897 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
898 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
899 | 0 | "%s: UTF-16 string is too small.", |
900 | 0 | function ); |
901 | |
|
902 | 0 | return( -1 ); |
903 | 0 | } |
904 | 0 | string_index = *utf16_string_index; |
905 | |
|
906 | 0 | utf16_string[ string_index++ ] = (uint16_t) '('; |
907 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
908 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
909 | |
|
910 | 0 | byte_shift = 28; |
911 | |
|
912 | 0 | do |
913 | 0 | { |
914 | 0 | byte_value = ( internal_nsf_timedate->upper >> byte_shift ) & 0x0f; |
915 | |
|
916 | 0 | if( byte_value <= 9 ) |
917 | 0 | { |
918 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
919 | 0 | } |
920 | 0 | else |
921 | 0 | { |
922 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
923 | 0 | } |
924 | 0 | byte_shift -= 4; |
925 | 0 | } |
926 | 0 | while( byte_shift >= 0 ); |
927 | |
|
928 | 0 | utf16_string[ string_index++ ] = (uint16_t) ' '; |
929 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0'; |
930 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'x'; |
931 | |
|
932 | 0 | byte_shift = 28; |
933 | |
|
934 | 0 | do |
935 | 0 | { |
936 | 0 | byte_value = ( internal_nsf_timedate->lower >> byte_shift ) & 0x0f; |
937 | |
|
938 | 0 | if( byte_value <= 9 ) |
939 | 0 | { |
940 | 0 | utf16_string[ string_index++ ] = (uint16_t) '0' + byte_value; |
941 | 0 | } |
942 | 0 | else |
943 | 0 | { |
944 | 0 | utf16_string[ string_index++ ] = (uint16_t) 'a' + byte_value - 10; |
945 | 0 | } |
946 | 0 | byte_shift -= 4; |
947 | 0 | } |
948 | 0 | while( byte_shift >= 0 ); |
949 | |
|
950 | 0 | utf16_string[ string_index++ ] = (uint16_t) ')'; |
951 | |
|
952 | 0 | utf16_string[ string_index++ ] = 0; |
953 | |
|
954 | 0 | *utf16_string_index = string_index; |
955 | |
|
956 | 0 | return( 1 ); |
957 | 0 | } |
958 | | |
959 | | /* Converts the NSF timedate into an UTF-16 string |
960 | | * The string size should include the end of string character |
961 | | * Returns 1 if successful or -1 on error |
962 | | */ |
963 | | int libfdatetime_nsf_timedate_copy_to_utf16_string( |
964 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
965 | | uint16_t *utf16_string, |
966 | | size_t utf16_string_size, |
967 | | uint32_t string_format_flags, |
968 | | libcerror_error_t **error ) |
969 | 0 | { |
970 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_utf16_string"; |
971 | 0 | size_t utf16_string_index = 0; |
972 | |
|
973 | 0 | if( libfdatetime_nsf_timedate_copy_to_utf16_string_with_index( |
974 | 0 | nsf_timedate, |
975 | 0 | utf16_string, |
976 | 0 | utf16_string_size, |
977 | 0 | &utf16_string_index, |
978 | 0 | string_format_flags, |
979 | 0 | error ) != 1 ) |
980 | 0 | { |
981 | 0 | libcerror_error_set( |
982 | 0 | error, |
983 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
984 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
985 | 0 | "%s: unable to copy NSF timedate to UTF-16 string.", |
986 | 0 | function ); |
987 | |
|
988 | 0 | return( -1 ); |
989 | 0 | } |
990 | 0 | return( 1 ); |
991 | 0 | } |
992 | | |
993 | | /* Converts the NSF timedate into an UTF-16 string |
994 | | * The string size should include the end of string character |
995 | | * Returns 1 if successful or -1 on error |
996 | | */ |
997 | | int libfdatetime_nsf_timedate_copy_to_utf16_string_with_index( |
998 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
999 | | uint16_t *utf16_string, |
1000 | | size_t utf16_string_size, |
1001 | | size_t *utf16_string_index, |
1002 | | uint32_t string_format_flags, |
1003 | | libcerror_error_t **error ) |
1004 | 0 | { |
1005 | 0 | libfdatetime_date_time_values_t date_time_values; |
1006 | |
|
1007 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
1008 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_utf16_string_with_index"; |
1009 | 0 | int result = 0; |
1010 | |
|
1011 | 0 | if( nsf_timedate == NULL ) |
1012 | 0 | { |
1013 | 0 | libcerror_error_set( |
1014 | 0 | error, |
1015 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1016 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1017 | 0 | "%s: invalid NSF timedate.", |
1018 | 0 | function ); |
1019 | |
|
1020 | 0 | return( -1 ); |
1021 | 0 | } |
1022 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) nsf_timedate; |
1023 | |
|
1024 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_date_time_values( |
1025 | 0 | internal_nsf_timedate, |
1026 | 0 | &date_time_values, |
1027 | 0 | error ); |
1028 | |
|
1029 | 0 | if( result != 1 ) |
1030 | 0 | { |
1031 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1032 | | libcerror_error_set( |
1033 | | error, |
1034 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1035 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1036 | | "%s: unable to set date time values.", |
1037 | | function ); |
1038 | | |
1039 | | /* TODO debug print error */ |
1040 | | |
1041 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1042 | |
|
1043 | 0 | if( ( error != NULL ) |
1044 | 0 | && ( *error != NULL ) ) |
1045 | 0 | { |
1046 | 0 | libcerror_error_free( |
1047 | 0 | error ); |
1048 | 0 | } |
1049 | 0 | } |
1050 | 0 | else |
1051 | 0 | { |
1052 | 0 | result = libfdatetime_date_time_values_copy_to_utf16_string_with_index( |
1053 | 0 | &date_time_values, |
1054 | 0 | utf16_string, |
1055 | 0 | utf16_string_size, |
1056 | 0 | utf16_string_index, |
1057 | 0 | string_format_flags, |
1058 | 0 | error ); |
1059 | |
|
1060 | 0 | if( result == -1 ) |
1061 | 0 | { |
1062 | 0 | libcerror_error_set( |
1063 | 0 | error, |
1064 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1065 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1066 | 0 | "%s: unable to copy date time values to UTF-16 string.", |
1067 | 0 | function ); |
1068 | |
|
1069 | 0 | return( -1 ); |
1070 | 0 | } |
1071 | 0 | } |
1072 | 0 | if( result != 1 ) |
1073 | 0 | { |
1074 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_utf16_string_in_hexadecimal( |
1075 | 0 | internal_nsf_timedate, |
1076 | 0 | utf16_string, |
1077 | 0 | utf16_string_size, |
1078 | 0 | utf16_string_index, |
1079 | 0 | error ); |
1080 | |
|
1081 | 0 | if( result == -1 ) |
1082 | 0 | { |
1083 | 0 | libcerror_error_set( |
1084 | 0 | error, |
1085 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1086 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1087 | 0 | "%s: unable to NSF timedate to hexadecimal UTF-16 string.", |
1088 | 0 | function ); |
1089 | |
|
1090 | 0 | return( -1 ); |
1091 | 0 | } |
1092 | 0 | } |
1093 | 0 | return( 1 ); |
1094 | 0 | } |
1095 | | |
1096 | | /* Converts the NSF timedate into an UTF-32 string in hexadecimal representation |
1097 | | * The string size should include the end of string character |
1098 | | * Returns 1 if successful or -1 on error |
1099 | | */ |
1100 | | int libfdatetime_internal_nsf_timedate_copy_to_utf32_string_in_hexadecimal( |
1101 | | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate, |
1102 | | uint32_t *utf32_string, |
1103 | | size_t utf32_string_size, |
1104 | | size_t *utf32_string_index, |
1105 | | libcerror_error_t **error ) |
1106 | 0 | { |
1107 | 0 | static char *function = "libfdatetime_internal_nsf_timedate_copy_to_utf32_string_in_hexadecimal"; |
1108 | 0 | size_t string_index = 0; |
1109 | 0 | uint8_t byte_value = 0; |
1110 | 0 | int8_t byte_shift = 0; |
1111 | |
|
1112 | 0 | if( internal_nsf_timedate == NULL ) |
1113 | 0 | { |
1114 | 0 | libcerror_error_set( |
1115 | 0 | error, |
1116 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1117 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1118 | 0 | "%s: invalid NSF timedate.", |
1119 | 0 | function ); |
1120 | |
|
1121 | 0 | return( -1 ); |
1122 | 0 | } |
1123 | 0 | if( utf32_string == NULL ) |
1124 | 0 | { |
1125 | 0 | libcerror_error_set( |
1126 | 0 | error, |
1127 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1128 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1129 | 0 | "%s: invalid UTF-32 string.", |
1130 | 0 | function ); |
1131 | |
|
1132 | 0 | return( -1 ); |
1133 | 0 | } |
1134 | 0 | if( utf32_string_size > (size_t) SSIZE_MAX ) |
1135 | 0 | { |
1136 | 0 | libcerror_error_set( |
1137 | 0 | error, |
1138 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1139 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
1140 | 0 | "%s: invalid UTF-32 string size value exceeds maximum.", |
1141 | 0 | function ); |
1142 | |
|
1143 | 0 | return( -1 ); |
1144 | 0 | } |
1145 | 0 | if( utf32_string_index == NULL ) |
1146 | 0 | { |
1147 | 0 | libcerror_error_set( |
1148 | 0 | error, |
1149 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1150 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1151 | 0 | "%s: invalid UTF-32 string index.", |
1152 | 0 | function ); |
1153 | |
|
1154 | 0 | return( -1 ); |
1155 | 0 | } |
1156 | 0 | if( ( utf32_string_size < 24 ) |
1157 | 0 | || ( *utf32_string_index > ( utf32_string_size - 24 ) ) ) |
1158 | 0 | { |
1159 | 0 | libcerror_error_set( |
1160 | 0 | error, |
1161 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1162 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1163 | 0 | "%s: UTF-32 string is too small.", |
1164 | 0 | function ); |
1165 | |
|
1166 | 0 | return( -1 ); |
1167 | 0 | } |
1168 | 0 | string_index = *utf32_string_index; |
1169 | |
|
1170 | 0 | utf32_string[ string_index++ ] = (uint32_t) '('; |
1171 | 0 | utf32_string[ string_index++ ] = (uint32_t) '0'; |
1172 | 0 | utf32_string[ string_index++ ] = (uint32_t) 'x'; |
1173 | |
|
1174 | 0 | byte_shift = 28; |
1175 | |
|
1176 | 0 | do |
1177 | 0 | { |
1178 | 0 | byte_value = ( internal_nsf_timedate->upper >> byte_shift ) & 0x0f; |
1179 | |
|
1180 | 0 | if( byte_value <= 9 ) |
1181 | 0 | { |
1182 | 0 | utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value; |
1183 | 0 | } |
1184 | 0 | else |
1185 | 0 | { |
1186 | 0 | utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10; |
1187 | 0 | } |
1188 | 0 | byte_shift -= 4; |
1189 | 0 | } |
1190 | 0 | while( byte_shift >= 0 ); |
1191 | |
|
1192 | 0 | utf32_string[ string_index++ ] = (uint32_t) ' '; |
1193 | 0 | utf32_string[ string_index++ ] = (uint32_t) '0'; |
1194 | 0 | utf32_string[ string_index++ ] = (uint32_t) 'x'; |
1195 | |
|
1196 | 0 | byte_shift = 28; |
1197 | |
|
1198 | 0 | do |
1199 | 0 | { |
1200 | 0 | byte_value = ( internal_nsf_timedate->lower >> byte_shift ) & 0x0f; |
1201 | |
|
1202 | 0 | if( byte_value <= 9 ) |
1203 | 0 | { |
1204 | 0 | utf32_string[ string_index++ ] = (uint32_t) '0' + byte_value; |
1205 | 0 | } |
1206 | 0 | else |
1207 | 0 | { |
1208 | 0 | utf32_string[ string_index++ ] = (uint32_t) 'a' + byte_value - 10; |
1209 | 0 | } |
1210 | 0 | byte_shift -= 4; |
1211 | 0 | } |
1212 | 0 | while( byte_shift >= 0 ); |
1213 | |
|
1214 | 0 | utf32_string[ string_index++ ] = (uint32_t) ')'; |
1215 | |
|
1216 | 0 | utf32_string[ string_index++ ] = 0; |
1217 | |
|
1218 | 0 | *utf32_string_index = string_index; |
1219 | |
|
1220 | 0 | return( 1 ); |
1221 | 0 | } |
1222 | | |
1223 | | /* Converts the NSF timedate into an UTF-32 string |
1224 | | * The string size should include the end of string character |
1225 | | * Returns 1 if successful or -1 on error |
1226 | | */ |
1227 | | int libfdatetime_nsf_timedate_copy_to_utf32_string( |
1228 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
1229 | | uint32_t *utf32_string, |
1230 | | size_t utf32_string_size, |
1231 | | uint32_t string_format_flags, |
1232 | | libcerror_error_t **error ) |
1233 | 0 | { |
1234 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_utf32_string"; |
1235 | 0 | size_t utf32_string_index = 0; |
1236 | |
|
1237 | 0 | if( libfdatetime_nsf_timedate_copy_to_utf32_string_with_index( |
1238 | 0 | nsf_timedate, |
1239 | 0 | utf32_string, |
1240 | 0 | utf32_string_size, |
1241 | 0 | &utf32_string_index, |
1242 | 0 | string_format_flags, |
1243 | 0 | error ) != 1 ) |
1244 | 0 | { |
1245 | 0 | libcerror_error_set( |
1246 | 0 | error, |
1247 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1248 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1249 | 0 | "%s: unable to copy NSF timedate to UTF-32 string.", |
1250 | 0 | function ); |
1251 | |
|
1252 | 0 | return( -1 ); |
1253 | 0 | } |
1254 | 0 | return( 1 ); |
1255 | 0 | } |
1256 | | |
1257 | | /* Converts the NSF timedate into an UTF-32 string |
1258 | | * The string size should include the end of string character |
1259 | | * Returns 1 if successful or -1 on error |
1260 | | */ |
1261 | | int libfdatetime_nsf_timedate_copy_to_utf32_string_with_index( |
1262 | | libfdatetime_nsf_timedate_t *nsf_timedate, |
1263 | | uint32_t *utf32_string, |
1264 | | size_t utf32_string_size, |
1265 | | size_t *utf32_string_index, |
1266 | | uint32_t string_format_flags, |
1267 | | libcerror_error_t **error ) |
1268 | 0 | { |
1269 | 0 | libfdatetime_date_time_values_t date_time_values; |
1270 | |
|
1271 | 0 | libfdatetime_internal_nsf_timedate_t *internal_nsf_timedate = NULL; |
1272 | 0 | static char *function = "libfdatetime_nsf_timedate_copy_to_utf32_string_with_index"; |
1273 | 0 | int result = 0; |
1274 | |
|
1275 | 0 | if( nsf_timedate == NULL ) |
1276 | 0 | { |
1277 | 0 | libcerror_error_set( |
1278 | 0 | error, |
1279 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1280 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1281 | 0 | "%s: invalid NSF timedate.", |
1282 | 0 | function ); |
1283 | |
|
1284 | 0 | return( -1 ); |
1285 | 0 | } |
1286 | 0 | internal_nsf_timedate = (libfdatetime_internal_nsf_timedate_t *) nsf_timedate; |
1287 | |
|
1288 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_date_time_values( |
1289 | 0 | internal_nsf_timedate, |
1290 | 0 | &date_time_values, |
1291 | 0 | error ); |
1292 | |
|
1293 | 0 | if( result != 1 ) |
1294 | 0 | { |
1295 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1296 | | libcerror_error_set( |
1297 | | error, |
1298 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1299 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1300 | | "%s: unable to set date time values.", |
1301 | | function ); |
1302 | | |
1303 | | /* TODO debug print error */ |
1304 | | |
1305 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1306 | |
|
1307 | 0 | if( ( error != NULL ) |
1308 | 0 | && ( *error != NULL ) ) |
1309 | 0 | { |
1310 | 0 | libcerror_error_free( |
1311 | 0 | error ); |
1312 | 0 | } |
1313 | 0 | } |
1314 | 0 | else |
1315 | 0 | { |
1316 | 0 | result = libfdatetime_date_time_values_copy_to_utf32_string_with_index( |
1317 | 0 | &date_time_values, |
1318 | 0 | utf32_string, |
1319 | 0 | utf32_string_size, |
1320 | 0 | utf32_string_index, |
1321 | 0 | string_format_flags, |
1322 | 0 | error ); |
1323 | |
|
1324 | 0 | if( result == -1 ) |
1325 | 0 | { |
1326 | 0 | libcerror_error_set( |
1327 | 0 | error, |
1328 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1329 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1330 | 0 | "%s: unable to set UTF-32 string.", |
1331 | 0 | function ); |
1332 | |
|
1333 | 0 | return( -1 ); |
1334 | 0 | } |
1335 | 0 | } |
1336 | 0 | if( result != 1 ) |
1337 | 0 | { |
1338 | 0 | if( utf32_string == NULL ) |
1339 | 0 | { |
1340 | 0 | libcerror_error_set( |
1341 | 0 | error, |
1342 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1343 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1344 | 0 | "%s: unable to copy date time values to UTF-32 string.", |
1345 | 0 | function ); |
1346 | |
|
1347 | 0 | return( -1 ); |
1348 | 0 | } |
1349 | 0 | } |
1350 | 0 | if( result != 1 ) |
1351 | 0 | { |
1352 | 0 | result = libfdatetime_internal_nsf_timedate_copy_to_utf32_string_in_hexadecimal( |
1353 | 0 | internal_nsf_timedate, |
1354 | 0 | utf32_string, |
1355 | 0 | utf32_string_size, |
1356 | 0 | utf32_string_index, |
1357 | 0 | error ); |
1358 | |
|
1359 | 0 | if( result == -1 ) |
1360 | 0 | { |
1361 | 0 | libcerror_error_set( |
1362 | 0 | error, |
1363 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1364 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1365 | 0 | "%s: unable to NSF timedate to hexadecimal UTF-32 string.", |
1366 | 0 | function ); |
1367 | |
|
1368 | 0 | return( -1 ); |
1369 | 0 | } |
1370 | 0 | } |
1371 | 0 | return( 1 ); |
1372 | 0 | } |
1373 | | |