/src/libewf/libewf/libewf_header_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Header values functions |
3 | | * |
4 | | * Copyright (C) 2006-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 <memory.h> |
24 | | #include <narrow_string.h> |
25 | | #include <types.h> |
26 | | |
27 | | |
28 | | #if defined( HAVE_SYS_TIME_H ) |
29 | | #include <sys/time.h> |
30 | | #endif |
31 | | |
32 | | #include <time.h> |
33 | | |
34 | | #include "libewf_date_time.h" |
35 | | #include "libewf_date_time_values.h" |
36 | | #include "libewf_definitions.h" |
37 | | #include "libewf_header_values.h" |
38 | | #include "libewf_libcerror.h" |
39 | | #include "libewf_libcnotify.h" |
40 | | #include "libewf_libfvalue.h" |
41 | | #include "libewf_libuna.h" |
42 | | #include "libewf_value_table.h" |
43 | | |
44 | | /* Creates header values |
45 | | * Make sure the value header_values is referencing, is set to NULL |
46 | | * Returns 1 if successful or -1 on error |
47 | | */ |
48 | | int libewf_header_values_initialize( |
49 | | libfvalue_table_t **header_values, |
50 | | libcerror_error_t **error ) |
51 | 3.23k | { |
52 | 3.23k | static char *function = "libewf_header_values_initialize"; |
53 | | |
54 | 3.23k | if( header_values == NULL ) |
55 | 0 | { |
56 | 0 | libcerror_error_set( |
57 | 0 | error, |
58 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
59 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
60 | 0 | "%s: invalid header values.", |
61 | 0 | function ); |
62 | |
|
63 | 0 | return( -1 ); |
64 | 0 | } |
65 | 3.23k | if( libfvalue_table_initialize( |
66 | 3.23k | header_values, |
67 | 3.23k | LIBEWF_HEADER_VALUES_DEFAULT_AMOUNT, |
68 | 3.23k | error ) != 1 ) |
69 | 0 | { |
70 | 0 | libcerror_error_set( |
71 | 0 | error, |
72 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
73 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
74 | 0 | "%s: unable to create header values table.", |
75 | 0 | function ); |
76 | |
|
77 | 0 | goto on_error; |
78 | 0 | } |
79 | 3.23k | if( libewf_value_table_set_value_by_index( |
80 | 3.23k | *header_values, |
81 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_CASE_NUMBER, |
82 | 3.23k | (uint8_t *) "case_number", |
83 | 3.23k | 12, |
84 | 3.23k | error ) != 1 ) |
85 | 0 | { |
86 | 0 | libcerror_error_set( |
87 | 0 | error, |
88 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
89 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
90 | 0 | "%s: unable to set header value: case_number.", |
91 | 0 | function ); |
92 | |
|
93 | 0 | goto on_error; |
94 | 0 | } |
95 | 3.23k | if( libewf_value_table_set_value_by_index( |
96 | 3.23k | *header_values, |
97 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_DESCRIPTION, |
98 | 3.23k | (uint8_t *) "description", |
99 | 3.23k | 12, |
100 | 3.23k | error ) != 1 ) |
101 | 0 | { |
102 | 0 | libcerror_error_set( |
103 | 0 | error, |
104 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
105 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
106 | 0 | "%s: unable to set header value: description.", |
107 | 0 | function ); |
108 | |
|
109 | 0 | goto on_error; |
110 | 0 | } |
111 | 3.23k | if( libewf_value_table_set_value_by_index( |
112 | 3.23k | *header_values, |
113 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_EXAMINER_NAME, |
114 | 3.23k | (uint8_t *) "examiner_name", |
115 | 3.23k | 14, |
116 | 3.23k | error ) != 1 ) |
117 | 0 | { |
118 | 0 | libcerror_error_set( |
119 | 0 | error, |
120 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
121 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
122 | 0 | "%s: unable to set header value: examiner_name.", |
123 | 0 | function ); |
124 | |
|
125 | 0 | goto on_error; |
126 | 0 | } |
127 | 3.23k | if( libewf_value_table_set_value_by_index( |
128 | 3.23k | *header_values, |
129 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_EVIDENCE_NUMBER, |
130 | 3.23k | (uint8_t *) "evidence_number", |
131 | 3.23k | 16, |
132 | 3.23k | error ) != 1 ) |
133 | 0 | { |
134 | 0 | libcerror_error_set( |
135 | 0 | error, |
136 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
137 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
138 | 0 | "%s: unable to set header value: evidence_number.", |
139 | 0 | function ); |
140 | |
|
141 | 0 | goto on_error; |
142 | 0 | } |
143 | 3.23k | if( libewf_value_table_set_value_by_index( |
144 | 3.23k | *header_values, |
145 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_NOTES, |
146 | 3.23k | (uint8_t *) "notes", |
147 | 3.23k | 6, |
148 | 3.23k | error ) != 1 ) |
149 | 0 | { |
150 | 0 | libcerror_error_set( |
151 | 0 | error, |
152 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
153 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
154 | 0 | "%s: unable to set header value: notes.", |
155 | 0 | function ); |
156 | |
|
157 | 0 | goto on_error; |
158 | 0 | } |
159 | 3.23k | if( libewf_value_table_set_value_by_index( |
160 | 3.23k | *header_values, |
161 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_ACQUIRY_DATE, |
162 | 3.23k | (uint8_t *) "acquiry_date", |
163 | 3.23k | 13, |
164 | 3.23k | error ) != 1 ) |
165 | 0 | { |
166 | 0 | libcerror_error_set( |
167 | 0 | error, |
168 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
169 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
170 | 0 | "%s: unable to set header value: acquiry_date.", |
171 | 0 | function ); |
172 | |
|
173 | 0 | goto on_error; |
174 | 0 | } |
175 | 3.23k | if( libewf_value_table_set_value_by_index( |
176 | 3.23k | *header_values, |
177 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_SYSTEM_DATE, |
178 | 3.23k | (uint8_t *) "system_date", |
179 | 3.23k | 12, |
180 | 3.23k | error ) != 1 ) |
181 | 0 | { |
182 | 0 | libcerror_error_set( |
183 | 0 | error, |
184 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
185 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
186 | 0 | "%s: unable to set header value: system_date.", |
187 | 0 | function ); |
188 | |
|
189 | 0 | goto on_error; |
190 | 0 | } |
191 | 3.23k | if( libewf_value_table_set_value_by_index( |
192 | 3.23k | *header_values, |
193 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_ACQUIRY_SOFTWARE_VERSION, |
194 | 3.23k | (uint8_t *) "acquiry_software_version", |
195 | 3.23k | 25, |
196 | 3.23k | error ) != 1 ) |
197 | 0 | { |
198 | 0 | libcerror_error_set( |
199 | 0 | error, |
200 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
201 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
202 | 0 | "%s: unable to set header value: acquiry_software_version.", |
203 | 0 | function ); |
204 | |
|
205 | 0 | goto on_error; |
206 | 0 | } |
207 | 3.23k | if( libewf_value_table_set_value_by_index( |
208 | 3.23k | *header_values, |
209 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_ACQUIRY_OPERATING_SYSTEM, |
210 | 3.23k | (uint8_t *) "acquiry_operating_system", |
211 | 3.23k | 25, |
212 | 3.23k | error ) != 1 ) |
213 | 0 | { |
214 | 0 | libcerror_error_set( |
215 | 0 | error, |
216 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
217 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
218 | 0 | "%s: unable to set header value: acquiry_operating_system.", |
219 | 0 | function ); |
220 | |
|
221 | 0 | goto on_error; |
222 | 0 | } |
223 | 3.23k | if( libewf_value_table_set_value_by_index( |
224 | 3.23k | *header_values, |
225 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_PASSWORD, |
226 | 3.23k | (uint8_t *) "password", |
227 | 3.23k | 9, |
228 | 3.23k | error ) != 1 ) |
229 | 0 | { |
230 | 0 | libcerror_error_set( |
231 | 0 | error, |
232 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
233 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
234 | 0 | "%s: unable to set header value: password.", |
235 | 0 | function ); |
236 | |
|
237 | 0 | goto on_error; |
238 | 0 | } |
239 | 3.23k | if( libewf_value_table_set_value_by_index( |
240 | 3.23k | *header_values, |
241 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_COMPRESSION_TYPE, |
242 | 3.23k | (uint8_t *) "compression_level", |
243 | 3.23k | 18, |
244 | 3.23k | error ) != 1 ) |
245 | 0 | { |
246 | 0 | libcerror_error_set( |
247 | 0 | error, |
248 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
249 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
250 | 0 | "%s: unable to set header value: compression_level.", |
251 | 0 | function ); |
252 | |
|
253 | 0 | goto on_error; |
254 | 0 | } |
255 | 3.23k | if( libewf_value_table_set_value_by_index( |
256 | 3.23k | *header_values, |
257 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_MODEL, |
258 | 3.23k | (uint8_t *) "model", |
259 | 3.23k | 6, |
260 | 3.23k | error ) != 1 ) |
261 | 0 | { |
262 | 0 | libcerror_error_set( |
263 | 0 | error, |
264 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
265 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
266 | 0 | "%s: unable to set header value: model.", |
267 | 0 | function ); |
268 | |
|
269 | 0 | goto on_error; |
270 | 0 | } |
271 | 3.23k | if( libewf_value_table_set_value_by_index( |
272 | 3.23k | *header_values, |
273 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_SERIAL_NUMBER, |
274 | 3.23k | (uint8_t *) "serial_number", |
275 | 3.23k | 14, |
276 | 3.23k | error ) != 1 ) |
277 | 0 | { |
278 | 0 | libcerror_error_set( |
279 | 0 | error, |
280 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
281 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
282 | 0 | "%s: unable to set header value: serial_number.", |
283 | 0 | function ); |
284 | |
|
285 | 0 | goto on_error; |
286 | 0 | } |
287 | 3.23k | if( libewf_value_table_set_value_by_index( |
288 | 3.23k | *header_values, |
289 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_DEVICE_LABEL, |
290 | 3.23k | (uint8_t *) "device_label", |
291 | 3.23k | 13, |
292 | 3.23k | error ) != 1 ) |
293 | 0 | { |
294 | 0 | libcerror_error_set( |
295 | 0 | error, |
296 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
297 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
298 | 0 | "%s: unable to set header value: device_label.", |
299 | 0 | function ); |
300 | |
|
301 | 0 | goto on_error; |
302 | 0 | } |
303 | 3.23k | if( libewf_value_table_set_value_by_index( |
304 | 3.23k | *header_values, |
305 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_PROCESS_IDENTIFIER, |
306 | 3.23k | (uint8_t *) "process_identifier", |
307 | 3.23k | 19, |
308 | 3.23k | error ) != 1 ) |
309 | 0 | { |
310 | 0 | libcerror_error_set( |
311 | 0 | error, |
312 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
313 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
314 | 0 | "%s: unable to set header value: process_identifier.", |
315 | 0 | function ); |
316 | |
|
317 | 0 | goto on_error; |
318 | 0 | } |
319 | 3.23k | if( libewf_value_table_set_value_by_index( |
320 | 3.23k | *header_values, |
321 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_UNKNOWN_DC, |
322 | 3.23k | (uint8_t *) "unknown_dc", |
323 | 3.23k | 11, |
324 | 3.23k | error ) != 1 ) |
325 | 0 | { |
326 | 0 | libcerror_error_set( |
327 | 0 | error, |
328 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
329 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
330 | 0 | "%s: unable to set header value: unknown_dc.", |
331 | 0 | function ); |
332 | |
|
333 | 0 | goto on_error; |
334 | 0 | } |
335 | 3.23k | if( libewf_value_table_set_value_by_index( |
336 | 3.23k | *header_values, |
337 | 3.23k | LIBEWF_HEADER_VALUES_INDEX_EXTENTS, |
338 | 3.23k | (uint8_t *) "extents", |
339 | 3.23k | 8, |
340 | 3.23k | error ) != 1 ) |
341 | 0 | { |
342 | 0 | libcerror_error_set( |
343 | 0 | error, |
344 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
345 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
346 | 0 | "%s: unable to set header value: extents.", |
347 | 0 | function ); |
348 | |
|
349 | 0 | goto on_error; |
350 | 0 | } |
351 | 3.23k | return( 1 ); |
352 | | |
353 | 0 | on_error: |
354 | 0 | if( *header_values != NULL ) |
355 | 0 | { |
356 | 0 | libfvalue_table_free( |
357 | 0 | header_values, |
358 | 0 | NULL ); |
359 | 0 | } |
360 | 0 | return( -1 ); |
361 | 3.23k | } |
362 | | |
363 | | /* Convert a header value into a date time values string |
364 | | * Sets date time values string and size |
365 | | * Returns 1 if successful or -1 on error |
366 | | */ |
367 | | int libewf_convert_date_header_value( |
368 | | const uint8_t *header_value, |
369 | | size_t header_value_size, |
370 | | uint8_t **date_time_values_string, |
371 | | size_t *date_time_values_string_size, |
372 | | libcerror_error_t **error ) |
373 | 760 | { |
374 | 760 | struct tm time_elements; |
375 | | |
376 | 760 | libfvalue_split_utf8_string_t *date_time_values = NULL; |
377 | 760 | uint8_t *date_time_value_string = NULL; |
378 | 760 | static char *function = "libewf_convert_date_header_value"; |
379 | 760 | size_t date_time_value_string_size = 0; |
380 | 760 | time_t timestamp = 0; |
381 | 760 | int number_of_date_time_values = 0; |
382 | | |
383 | 760 | if( date_time_values_string == NULL ) |
384 | 0 | { |
385 | 0 | libcerror_error_set( |
386 | 0 | error, |
387 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
388 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
389 | 0 | "%s: invalid date time values string.", |
390 | 0 | function ); |
391 | |
|
392 | 0 | return( -1 ); |
393 | 0 | } |
394 | 760 | if( date_time_values_string_size == NULL ) |
395 | 0 | { |
396 | 0 | libcerror_error_set( |
397 | 0 | error, |
398 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
399 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
400 | 0 | "%s: invalid date time values string size.", |
401 | 0 | function ); |
402 | |
|
403 | 0 | return( -1 ); |
404 | 0 | } |
405 | 760 | if( libfvalue_utf8_string_split( |
406 | 760 | header_value, |
407 | 760 | header_value_size, |
408 | 760 | (uint8_t) ' ', |
409 | 760 | &date_time_values, |
410 | 760 | error ) != 1 ) |
411 | 0 | { |
412 | 0 | libcerror_error_set( |
413 | 0 | error, |
414 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
415 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
416 | 0 | "%s: unable to split header value.", |
417 | 0 | function ); |
418 | |
|
419 | 0 | goto on_error; |
420 | 0 | } |
421 | 760 | if( libfvalue_split_utf8_string_get_number_of_segments( |
422 | 760 | date_time_values, |
423 | 760 | &number_of_date_time_values, |
424 | 760 | error ) != 1 ) |
425 | 0 | { |
426 | 0 | libcerror_error_set( |
427 | 0 | error, |
428 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
429 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
430 | 0 | "%s: unable to retrieve number of date time values.", |
431 | 0 | function ); |
432 | |
|
433 | 0 | goto on_error; |
434 | 0 | } |
435 | 760 | if( number_of_date_time_values != 6 ) |
436 | 121 | { |
437 | 121 | libcerror_error_set( |
438 | 121 | error, |
439 | 121 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
440 | 121 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
441 | 121 | "%s: unsupported number date time values in header value.", |
442 | 121 | function ); |
443 | | |
444 | 121 | goto on_error; |
445 | 121 | } |
446 | 639 | if( libfvalue_split_utf8_string_get_segment_by_index( |
447 | 639 | date_time_values, |
448 | 639 | 0, |
449 | 639 | &date_time_value_string, |
450 | 639 | &date_time_value_string_size, |
451 | 639 | error ) != 1 ) |
452 | 0 | { |
453 | 0 | libcerror_error_set( |
454 | 0 | error, |
455 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
456 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
457 | 0 | "%s: unable to retrieve date time value string: 0.", |
458 | 0 | function ); |
459 | |
|
460 | 0 | goto on_error; |
461 | 0 | } |
462 | 639 | if( libewf_utf8_string_year_copy_to_time_elements( |
463 | 639 | date_time_value_string, |
464 | 639 | date_time_value_string_size, |
465 | 639 | &time_elements, |
466 | 639 | error ) != 1 ) |
467 | 79 | { |
468 | 79 | libcerror_error_set( |
469 | 79 | error, |
470 | 79 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
471 | 79 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
472 | 79 | "%s: unable to copy year value.", |
473 | 79 | function ); |
474 | | |
475 | 79 | goto on_error; |
476 | 79 | } |
477 | | /* Set the month |
478 | | */ |
479 | 560 | if( libfvalue_split_utf8_string_get_segment_by_index( |
480 | 560 | date_time_values, |
481 | 560 | 1, |
482 | 560 | &date_time_value_string, |
483 | 560 | &date_time_value_string_size, |
484 | 560 | error ) != 1 ) |
485 | 0 | { |
486 | 0 | libcerror_error_set( |
487 | 0 | error, |
488 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
489 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
490 | 0 | "%s: unable to retrieve date time value string: 1.", |
491 | 0 | function ); |
492 | |
|
493 | 0 | goto on_error; |
494 | 0 | } |
495 | 560 | if( ( date_time_value_string_size != 2 ) |
496 | 560 | && ( date_time_value_string_size != 3 ) ) |
497 | 11 | { |
498 | 11 | libcerror_error_set( |
499 | 11 | error, |
500 | 11 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
501 | 11 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
502 | 11 | "%s: unsupported date time value string size: 1.", |
503 | 11 | function ); |
504 | | |
505 | 11 | goto on_error; |
506 | 11 | } |
507 | 549 | if( libewf_utf8_string_month_copy_to_time_elements( |
508 | 549 | date_time_value_string, |
509 | 549 | date_time_value_string_size, |
510 | 549 | &time_elements, |
511 | 549 | error ) != 1 ) |
512 | 51 | { |
513 | 51 | libcerror_error_set( |
514 | 51 | error, |
515 | 51 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
516 | 51 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
517 | 51 | "%s: unable to copy month value.", |
518 | 51 | function ); |
519 | | |
520 | 51 | goto on_error; |
521 | 51 | } |
522 | | /* Set the day of the month |
523 | | */ |
524 | 498 | if( libfvalue_split_utf8_string_get_segment_by_index( |
525 | 498 | date_time_values, |
526 | 498 | 2, |
527 | 498 | &date_time_value_string, |
528 | 498 | &date_time_value_string_size, |
529 | 498 | error ) != 1 ) |
530 | 0 | { |
531 | 0 | libcerror_error_set( |
532 | 0 | error, |
533 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
534 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
535 | 0 | "%s: unable to retrieve date time value string: 2.", |
536 | 0 | function ); |
537 | |
|
538 | 0 | goto on_error; |
539 | 0 | } |
540 | 498 | if( ( date_time_value_string_size != 2 ) |
541 | 498 | && ( date_time_value_string_size != 3 ) ) |
542 | 11 | { |
543 | 11 | libcerror_error_set( |
544 | 11 | error, |
545 | 11 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
546 | 11 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
547 | 11 | "%s: unsupported date time value string size: 2.", |
548 | 11 | function ); |
549 | | |
550 | 11 | goto on_error; |
551 | 11 | } |
552 | 487 | if( libewf_utf8_string_day_of_month_copy_to_time_elements( |
553 | 487 | date_time_value_string, |
554 | 487 | date_time_value_string_size, |
555 | 487 | &time_elements, |
556 | 487 | error ) != 1 ) |
557 | 26 | { |
558 | 26 | libcerror_error_set( |
559 | 26 | error, |
560 | 26 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
561 | 26 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
562 | 26 | "%s: unable to copy day of month value.", |
563 | 26 | function ); |
564 | | |
565 | 26 | goto on_error; |
566 | 26 | } |
567 | | /* Set the hours |
568 | | */ |
569 | 461 | if( libfvalue_split_utf8_string_get_segment_by_index( |
570 | 461 | date_time_values, |
571 | 461 | 3, |
572 | 461 | &date_time_value_string, |
573 | 461 | &date_time_value_string_size, |
574 | 461 | error ) != 1 ) |
575 | 0 | { |
576 | 0 | libcerror_error_set( |
577 | 0 | error, |
578 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
579 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
580 | 0 | "%s: unable to retrieve date time value string: 3.", |
581 | 0 | function ); |
582 | |
|
583 | 0 | goto on_error; |
584 | 0 | } |
585 | 461 | if( ( date_time_value_string_size != 2 ) |
586 | 461 | && ( date_time_value_string_size != 3 ) ) |
587 | 11 | { |
588 | 11 | libcerror_error_set( |
589 | 11 | error, |
590 | 11 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
591 | 11 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
592 | 11 | "%s: unsupported date time value string size: 3.", |
593 | 11 | function ); |
594 | | |
595 | 11 | goto on_error; |
596 | 11 | } |
597 | 450 | if( libewf_utf8_string_hours_copy_to_time_elements( |
598 | 450 | date_time_value_string, |
599 | 450 | date_time_value_string_size, |
600 | 450 | &time_elements, |
601 | 450 | error ) != 1 ) |
602 | 20 | { |
603 | 20 | libcerror_error_set( |
604 | 20 | error, |
605 | 20 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
606 | 20 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
607 | 20 | "%s: unable to copy hours value.", |
608 | 20 | function ); |
609 | | |
610 | 20 | goto on_error; |
611 | 20 | } |
612 | | /* Set the minutes |
613 | | */ |
614 | 430 | if( libfvalue_split_utf8_string_get_segment_by_index( |
615 | 430 | date_time_values, |
616 | 430 | 4, |
617 | 430 | &date_time_value_string, |
618 | 430 | &date_time_value_string_size, |
619 | 430 | error ) != 1 ) |
620 | 0 | { |
621 | 0 | libcerror_error_set( |
622 | 0 | error, |
623 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
624 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
625 | 0 | "%s: unable to retrieve date time value string: 4.", |
626 | 0 | function ); |
627 | |
|
628 | 0 | goto on_error; |
629 | 0 | } |
630 | 430 | if( ( date_time_value_string_size != 2 ) |
631 | 430 | && ( date_time_value_string_size != 3 ) ) |
632 | 11 | { |
633 | 11 | libcerror_error_set( |
634 | 11 | error, |
635 | 11 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
636 | 11 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
637 | 11 | "%s: unsupported date time value string size: 4.", |
638 | 11 | function ); |
639 | | |
640 | 11 | goto on_error; |
641 | 11 | } |
642 | 419 | if( libewf_utf8_string_minutes_copy_to_time_elements( |
643 | 419 | date_time_value_string, |
644 | 419 | date_time_value_string_size, |
645 | 419 | &time_elements, |
646 | 419 | error ) != 1 ) |
647 | 22 | { |
648 | 22 | libcerror_error_set( |
649 | 22 | error, |
650 | 22 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
651 | 22 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
652 | 22 | "%s: unable to copy minutes value.", |
653 | 22 | function ); |
654 | | |
655 | 22 | goto on_error; |
656 | 22 | } |
657 | | /* Set the seconds |
658 | | */ |
659 | 397 | if( libfvalue_split_utf8_string_get_segment_by_index( |
660 | 397 | date_time_values, |
661 | 397 | 5, |
662 | 397 | &date_time_value_string, |
663 | 397 | &date_time_value_string_size, |
664 | 397 | error ) != 1 ) |
665 | 0 | { |
666 | 0 | libcerror_error_set( |
667 | 0 | error, |
668 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
669 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
670 | 0 | "%s: unable to retrieve date time value string: 5.", |
671 | 0 | function ); |
672 | |
|
673 | 0 | goto on_error; |
674 | 0 | } |
675 | 397 | if( ( date_time_value_string_size != 2 ) |
676 | 397 | && ( date_time_value_string_size != 3 ) ) |
677 | 15 | { |
678 | 15 | libcerror_error_set( |
679 | 15 | error, |
680 | 15 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
681 | 15 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
682 | 15 | "%s: unsupported date time value string size: 5.", |
683 | 15 | function ); |
684 | | |
685 | 15 | goto on_error; |
686 | 15 | } |
687 | 382 | if( libewf_utf8_string_seconds_copy_to_time_elements( |
688 | 382 | date_time_value_string, |
689 | 382 | date_time_value_string_size, |
690 | 382 | &time_elements, |
691 | 382 | error ) != 1 ) |
692 | 16 | { |
693 | 16 | libcerror_error_set( |
694 | 16 | error, |
695 | 16 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
696 | 16 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
697 | 16 | "%s: unable to copy seconds value.", |
698 | 16 | function ); |
699 | | |
700 | 16 | goto on_error; |
701 | 16 | } |
702 | | /* Set to ignore the daylight saving time |
703 | | */ |
704 | 366 | time_elements.tm_isdst = -1; |
705 | | |
706 | 366 | if( libfvalue_split_utf8_string_free( |
707 | 366 | &date_time_values, |
708 | 366 | error ) != 1 ) |
709 | 0 | { |
710 | 0 | libcerror_error_set( |
711 | 0 | error, |
712 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
713 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
714 | 0 | "%s: unable to free split date time elements.", |
715 | 0 | function ); |
716 | |
|
717 | 0 | goto on_error; |
718 | 0 | } |
719 | | /* Create a timestamp |
720 | | */ |
721 | 366 | timestamp = libewf_date_time_mktime( |
722 | 366 | &time_elements ); |
723 | | |
724 | 366 | if( timestamp == (time_t) -1 ) |
725 | 0 | { |
726 | 0 | libcerror_error_set( |
727 | 0 | error, |
728 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
729 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
730 | 0 | "%s: unable to create timestamp.", |
731 | 0 | function ); |
732 | |
|
733 | 0 | goto on_error; |
734 | 0 | } |
735 | 366 | *date_time_values_string_size = 20; |
736 | | |
737 | 366 | *date_time_values_string = (uint8_t *) memory_allocate( |
738 | 366 | sizeof( uint8_t ) * *date_time_values_string_size ); |
739 | | |
740 | 366 | if( *date_time_values_string == NULL ) |
741 | 0 | { |
742 | 0 | libcerror_error_set( |
743 | 0 | error, |
744 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
745 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
746 | 0 | "%s: unable to create date time values string.", |
747 | 0 | function ); |
748 | |
|
749 | 0 | goto on_error; |
750 | 0 | } |
751 | 366 | if( libewf_date_time_values_copy_from_timestamp( |
752 | 366 | *date_time_values_string, |
753 | 366 | *date_time_values_string_size, |
754 | 366 | timestamp, |
755 | 366 | error ) != 1 ) |
756 | 12 | { |
757 | 12 | libcerror_error_set( |
758 | 12 | error, |
759 | 12 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
760 | 12 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
761 | 12 | "%s: unable to convert timestamp into date time values string.", |
762 | 12 | function ); |
763 | | |
764 | 12 | goto on_error; |
765 | 12 | } |
766 | 354 | return( 1 ); |
767 | | |
768 | 406 | on_error: |
769 | 406 | if( date_time_values != NULL ) |
770 | 394 | { |
771 | 394 | libfvalue_split_utf8_string_free( |
772 | 394 | &date_time_values, |
773 | 394 | NULL ); |
774 | 394 | } |
775 | 406 | if( *date_time_values_string != NULL ) |
776 | 12 | { |
777 | 12 | memory_free( |
778 | 12 | *date_time_values_string ); |
779 | | |
780 | 12 | *date_time_values_string = NULL; |
781 | 12 | } |
782 | 406 | *date_time_values_string_size = 0; |
783 | | |
784 | 406 | return( -1 ); |
785 | 366 | } |
786 | | |
787 | | /* Generates a date time values string within a header value |
788 | | * Sets date time values string and size |
789 | | * Returns 1 if successful or -1 on error |
790 | | */ |
791 | | int libewf_generate_date_header_value( |
792 | | time_t timestamp, |
793 | | uint8_t **date_time_values_string, |
794 | | size_t *date_time_values_string_size, |
795 | | libcerror_error_t **error ) |
796 | 0 | { |
797 | 0 | struct tm time_elements; |
798 | |
|
799 | 0 | static char *function = "libewf_generate_date_header_value"; |
800 | 0 | size_t date_time_values_string_index = 0; |
801 | |
|
802 | 0 | if( date_time_values_string == NULL ) |
803 | 0 | { |
804 | 0 | libcerror_error_set( |
805 | 0 | error, |
806 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
807 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
808 | 0 | "%s: invalid date time values string.", |
809 | 0 | function ); |
810 | |
|
811 | 0 | return( -1 ); |
812 | 0 | } |
813 | 0 | if( *date_time_values_string != NULL ) |
814 | 0 | { |
815 | 0 | libcerror_error_set( |
816 | 0 | error, |
817 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
818 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
819 | 0 | "%s: date time values string already created.", |
820 | 0 | function ); |
821 | |
|
822 | 0 | return( -1 ); |
823 | 0 | } |
824 | 0 | if( date_time_values_string_size == NULL ) |
825 | 0 | { |
826 | 0 | libcerror_error_set( |
827 | 0 | error, |
828 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
829 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
830 | 0 | "%s: invalid date time values string size.", |
831 | 0 | function ); |
832 | |
|
833 | 0 | return( -1 ); |
834 | 0 | } |
835 | 0 | if( libewf_date_time_localtime( |
836 | 0 | ×tamp, |
837 | 0 | &time_elements, |
838 | 0 | error ) != 1 ) |
839 | 0 | { |
840 | 0 | libcerror_error_set( |
841 | 0 | error, |
842 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
843 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
844 | 0 | "%s: unable to create time elements.", |
845 | 0 | function ); |
846 | |
|
847 | 0 | goto on_error; |
848 | 0 | } |
849 | 0 | if( ( time_elements.tm_year + 1900 ) > 10000 ) |
850 | 0 | { |
851 | 0 | libcerror_error_set( |
852 | 0 | error, |
853 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
854 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
855 | 0 | "%s: unsupported year value.", |
856 | 0 | function ); |
857 | |
|
858 | 0 | goto on_error; |
859 | 0 | } |
860 | 0 | *date_time_values_string_size = 20; |
861 | |
|
862 | 0 | *date_time_values_string = (uint8_t *) memory_allocate( |
863 | 0 | sizeof( uint8_t ) * *date_time_values_string_size ); |
864 | |
|
865 | 0 | if( *date_time_values_string == NULL ) |
866 | 0 | { |
867 | 0 | libcerror_error_set( |
868 | 0 | error, |
869 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
870 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
871 | 0 | "%s: unable to create date time values string.", |
872 | 0 | function ); |
873 | |
|
874 | 0 | goto on_error; |
875 | 0 | } |
876 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
877 | 0 | *date_time_values_string, |
878 | 0 | *date_time_values_string_size, |
879 | 0 | &date_time_values_string_index, |
880 | 0 | (uint64_t) time_elements.tm_year + 1900, |
881 | 0 | 16, |
882 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
883 | 0 | error ) != 1 ) |
884 | 0 | { |
885 | 0 | libcerror_error_set( |
886 | 0 | error, |
887 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
888 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
889 | 0 | "%s: unable to copy year to date time values string.", |
890 | 0 | function ); |
891 | |
|
892 | 0 | goto on_error; |
893 | 0 | } |
894 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
895 | |
|
896 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
897 | 0 | *date_time_values_string, |
898 | 0 | *date_time_values_string_size, |
899 | 0 | &date_time_values_string_index, |
900 | 0 | (uint64_t) time_elements.tm_mon + 1, |
901 | 0 | 8, |
902 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
903 | 0 | error ) != 1 ) |
904 | 0 | { |
905 | 0 | libcerror_error_set( |
906 | 0 | error, |
907 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
908 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
909 | 0 | "%s: unable to copy month to date time values string.", |
910 | 0 | function ); |
911 | |
|
912 | 0 | goto on_error; |
913 | 0 | } |
914 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
915 | |
|
916 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
917 | 0 | *date_time_values_string, |
918 | 0 | *date_time_values_string_size, |
919 | 0 | &date_time_values_string_index, |
920 | 0 | (uint64_t) time_elements.tm_mday, |
921 | 0 | 8, |
922 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
923 | 0 | error ) != 1 ) |
924 | 0 | { |
925 | 0 | libcerror_error_set( |
926 | 0 | error, |
927 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
928 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
929 | 0 | "%s: unable to copy day of month to date time values string.", |
930 | 0 | function ); |
931 | |
|
932 | 0 | goto on_error; |
933 | 0 | } |
934 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
935 | |
|
936 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
937 | 0 | *date_time_values_string, |
938 | 0 | *date_time_values_string_size, |
939 | 0 | &date_time_values_string_index, |
940 | 0 | (uint64_t) time_elements.tm_hour, |
941 | 0 | 8, |
942 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
943 | 0 | error ) != 1 ) |
944 | 0 | { |
945 | 0 | libcerror_error_set( |
946 | 0 | error, |
947 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
948 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
949 | 0 | "%s: unable to copy hours to date time values string.", |
950 | 0 | function ); |
951 | |
|
952 | 0 | goto on_error; |
953 | 0 | } |
954 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
955 | |
|
956 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
957 | 0 | *date_time_values_string, |
958 | 0 | *date_time_values_string_size, |
959 | 0 | &date_time_values_string_index, |
960 | 0 | (uint64_t) time_elements.tm_min, |
961 | 0 | 8, |
962 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
963 | 0 | error ) != 1 ) |
964 | 0 | { |
965 | 0 | libcerror_error_set( |
966 | 0 | error, |
967 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
968 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
969 | 0 | "%s: unable to copy minutes to date time values string.", |
970 | 0 | function ); |
971 | |
|
972 | 0 | goto on_error; |
973 | 0 | } |
974 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
975 | |
|
976 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
977 | 0 | *date_time_values_string, |
978 | 0 | *date_time_values_string_size, |
979 | 0 | &date_time_values_string_index, |
980 | 0 | (uint64_t) time_elements.tm_sec, |
981 | 0 | 8, |
982 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
983 | 0 | error ) != 1 ) |
984 | 0 | { |
985 | 0 | libcerror_error_set( |
986 | 0 | error, |
987 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
988 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
989 | 0 | "%s: unable to copy seconds to date time values string.", |
990 | 0 | function ); |
991 | |
|
992 | 0 | goto on_error; |
993 | 0 | } |
994 | | /* The end-of-string character is set by libfvalue_utf8_string_with_index_copy_from_integer |
995 | | */ |
996 | 0 | return( 1 ); |
997 | | |
998 | 0 | on_error: |
999 | 0 | if( *date_time_values_string != NULL ) |
1000 | 0 | { |
1001 | 0 | memory_free( |
1002 | 0 | *date_time_values_string ); |
1003 | |
|
1004 | 0 | *date_time_values_string = NULL; |
1005 | 0 | } |
1006 | 0 | *date_time_values_string_size = 0; |
1007 | |
|
1008 | 0 | return( -1 ); |
1009 | 0 | } |
1010 | | |
1011 | | /* Convert a header2 value into a date time values string |
1012 | | * Sets date time values string and size |
1013 | | * Returns 1 if successful or -1 on error |
1014 | | */ |
1015 | | int libewf_convert_date_header2_value( |
1016 | | const uint8_t *header_value, |
1017 | | size_t header_value_size, |
1018 | | uint8_t **date_time_values_string, |
1019 | | size_t *date_time_values_string_size, |
1020 | | libcerror_error_t **error ) |
1021 | 1.92k | { |
1022 | 1.92k | static char *function = "libewf_convert_date_header2_value"; |
1023 | 1.92k | uint64_t value_64bit = 0; |
1024 | | |
1025 | 1.92k | if( date_time_values_string == NULL ) |
1026 | 0 | { |
1027 | 0 | libcerror_error_set( |
1028 | 0 | error, |
1029 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1030 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1031 | 0 | "%s: invalid date time values string.", |
1032 | 0 | function ); |
1033 | |
|
1034 | 0 | return( -1 ); |
1035 | 0 | } |
1036 | 1.92k | if( date_time_values_string_size == NULL ) |
1037 | 0 | { |
1038 | 0 | libcerror_error_set( |
1039 | 0 | error, |
1040 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1041 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1042 | 0 | "%s: invalid date time values string size.", |
1043 | 0 | function ); |
1044 | |
|
1045 | 0 | return( -1 ); |
1046 | 0 | } |
1047 | 1.92k | if( libfvalue_utf8_string_copy_to_integer( |
1048 | 1.92k | header_value, |
1049 | 1.92k | header_value_size - 1, |
1050 | 1.92k | &value_64bit, |
1051 | 1.92k | 64, |
1052 | 1.92k | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
1053 | 1.92k | error ) != 1 ) |
1054 | 551 | { |
1055 | 551 | libcerror_error_set( |
1056 | 551 | error, |
1057 | 551 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1058 | 551 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1059 | 551 | "%s: unable to set timestamp.", |
1060 | 551 | function ); |
1061 | | |
1062 | 551 | goto on_error; |
1063 | 551 | } |
1064 | 1.36k | *date_time_values_string_size = 20; |
1065 | | |
1066 | 1.36k | *date_time_values_string = (uint8_t *) memory_allocate( |
1067 | 1.36k | sizeof( uint8_t ) * *date_time_values_string_size ); |
1068 | | |
1069 | 1.36k | if( *date_time_values_string == NULL ) |
1070 | 0 | { |
1071 | 0 | libcerror_error_set( |
1072 | 0 | error, |
1073 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1074 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1075 | 0 | "%s: unable to create date time values string.", |
1076 | 0 | function ); |
1077 | |
|
1078 | 0 | goto on_error; |
1079 | 0 | } |
1080 | 1.36k | if( libewf_date_time_values_copy_from_timestamp( |
1081 | 1.36k | *date_time_values_string, |
1082 | 1.36k | *date_time_values_string_size, |
1083 | 1.36k | (time_t) value_64bit, |
1084 | 1.36k | error ) != 1 ) |
1085 | 66 | { |
1086 | 66 | libcerror_error_set( |
1087 | 66 | error, |
1088 | 66 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1089 | 66 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1090 | 66 | "%s: unable to convert timestamp into date time values string.", |
1091 | 66 | function ); |
1092 | | |
1093 | 66 | goto on_error; |
1094 | 66 | } |
1095 | 1.30k | return( 1 ); |
1096 | | |
1097 | 617 | on_error: |
1098 | 617 | if( *date_time_values_string != NULL ) |
1099 | 66 | { |
1100 | 66 | memory_free( |
1101 | 66 | *date_time_values_string ); |
1102 | | |
1103 | 66 | *date_time_values_string = NULL; |
1104 | 66 | } |
1105 | 617 | *date_time_values_string_size = 0; |
1106 | | |
1107 | 617 | return( -1 ); |
1108 | 1.36k | } |
1109 | | |
1110 | | /* Generates a date time values string within a header2 value |
1111 | | * Sets date time values string and size |
1112 | | * Returns 1 if successful or -1 on error |
1113 | | */ |
1114 | | int libewf_generate_date_header2_value( |
1115 | | time_t timestamp, |
1116 | | uint8_t **date_time_values_string, |
1117 | | size_t *date_time_values_string_size, |
1118 | | libcerror_error_t **error ) |
1119 | 0 | { |
1120 | 0 | static char *function = "libewf_generate_date_header2_value"; |
1121 | 0 | size_t date_time_values_string_index = 0; |
1122 | |
|
1123 | 0 | if( date_time_values_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 date time values string.", |
1130 | 0 | function ); |
1131 | |
|
1132 | 0 | return( -1 ); |
1133 | 0 | } |
1134 | 0 | if( *date_time_values_string != NULL ) |
1135 | 0 | { |
1136 | 0 | libcerror_error_set( |
1137 | 0 | error, |
1138 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1139 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1140 | 0 | "%s: date time values string already created.", |
1141 | 0 | function ); |
1142 | |
|
1143 | 0 | return( -1 ); |
1144 | 0 | } |
1145 | 0 | if( date_time_values_string_size == 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 date time values string size.", |
1152 | 0 | function ); |
1153 | |
|
1154 | 0 | return( -1 ); |
1155 | 0 | } |
1156 | 0 | *date_time_values_string_size = 11; |
1157 | |
|
1158 | 0 | *date_time_values_string = (uint8_t *) memory_allocate( |
1159 | 0 | sizeof( uint8_t ) * *date_time_values_string_size ); |
1160 | |
|
1161 | 0 | if( *date_time_values_string == NULL ) |
1162 | 0 | { |
1163 | 0 | libcerror_error_set( |
1164 | 0 | error, |
1165 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1166 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1167 | 0 | "%s: unable to create date time values string.", |
1168 | 0 | function ); |
1169 | |
|
1170 | 0 | goto on_error; |
1171 | 0 | } |
1172 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
1173 | 0 | *date_time_values_string, |
1174 | 0 | *date_time_values_string_size, |
1175 | 0 | &date_time_values_string_index, |
1176 | 0 | (uint64_t) timestamp, |
1177 | 0 | 32, |
1178 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
1179 | 0 | error ) != 1 ) |
1180 | 0 | { |
1181 | 0 | libcerror_error_set( |
1182 | 0 | error, |
1183 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1184 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1185 | 0 | "%s: unable to copy timestamp to date time values string.", |
1186 | 0 | function ); |
1187 | |
|
1188 | 0 | goto on_error; |
1189 | 0 | } |
1190 | | /* The end-of-string character is set by libfvalue_utf8_string_with_index_copy_from_integer |
1191 | | */ |
1192 | 0 | return( 1 ); |
1193 | | |
1194 | 0 | on_error: |
1195 | 0 | if( *date_time_values_string != NULL ) |
1196 | 0 | { |
1197 | 0 | memory_free( |
1198 | 0 | *date_time_values_string ); |
1199 | |
|
1200 | 0 | *date_time_values_string = NULL; |
1201 | 0 | } |
1202 | 0 | *date_time_values_string_size = 0; |
1203 | |
|
1204 | 0 | return( -1 ); |
1205 | 0 | } |
1206 | | |
1207 | | /* Copies the header values from the source to the destination |
1208 | | * Returns 1 if successful -1 on error |
1209 | | */ |
1210 | | int libewf_header_values_copy( |
1211 | | libfvalue_table_t *destination_header_values, |
1212 | | libfvalue_table_t *source_header_values, |
1213 | | libcerror_error_t **error ) |
1214 | 0 | { |
1215 | 0 | libfvalue_value_t *destination_header_value = NULL; |
1216 | 0 | libfvalue_value_t *source_header_value = NULL; |
1217 | 0 | uint8_t *identifier = NULL; |
1218 | 0 | static char *function = "libewf_header_values_copy"; |
1219 | 0 | size_t identifier_size = 0; |
1220 | 0 | int header_value_index = 0; |
1221 | 0 | int number_of_header_values = 0; |
1222 | 0 | int result = 0; |
1223 | |
|
1224 | 0 | if( destination_header_values == NULL ) |
1225 | 0 | { |
1226 | 0 | libcerror_error_set( |
1227 | 0 | error, |
1228 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1229 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1230 | 0 | "%s: invalid destination header values.", |
1231 | 0 | function ); |
1232 | |
|
1233 | 0 | return( -1 ); |
1234 | 0 | } |
1235 | 0 | if( libfvalue_table_get_number_of_values( |
1236 | 0 | source_header_values, |
1237 | 0 | &number_of_header_values, |
1238 | 0 | error ) != 1 ) |
1239 | 0 | { |
1240 | 0 | libcerror_error_set( |
1241 | 0 | error, |
1242 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1243 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1244 | 0 | "%s: unable to retrieve number of header values.", |
1245 | 0 | function ); |
1246 | |
|
1247 | 0 | return( -1 ); |
1248 | 0 | } |
1249 | 0 | for( header_value_index = 0; |
1250 | 0 | header_value_index < number_of_header_values; |
1251 | 0 | header_value_index++ ) |
1252 | 0 | { |
1253 | 0 | if( libfvalue_table_get_value_by_index( |
1254 | 0 | source_header_values, |
1255 | 0 | header_value_index, |
1256 | 0 | &source_header_value, |
1257 | 0 | error ) != 1 ) |
1258 | 0 | { |
1259 | 0 | libcerror_error_set( |
1260 | 0 | error, |
1261 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1262 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1263 | 0 | "%s: unable to retrieve header value: %d.", |
1264 | 0 | function, |
1265 | 0 | header_value_index ); |
1266 | |
|
1267 | 0 | goto on_error; |
1268 | 0 | } |
1269 | 0 | if( libfvalue_value_get_identifier( |
1270 | 0 | source_header_value, |
1271 | 0 | &identifier, |
1272 | 0 | &identifier_size, |
1273 | 0 | error ) != 1 ) |
1274 | 0 | { |
1275 | 0 | libcerror_error_set( |
1276 | 0 | error, |
1277 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1278 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1279 | 0 | "%s: unable to retrieve identifier of header value: %d.", |
1280 | 0 | function, |
1281 | 0 | header_value_index ); |
1282 | |
|
1283 | 0 | goto on_error; |
1284 | 0 | } |
1285 | | /* Ignore header values without an identifier |
1286 | | */ |
1287 | 0 | if( ( identifier == NULL ) |
1288 | 0 | || ( identifier_size == 0 ) ) |
1289 | 0 | { |
1290 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1291 | | if( libcnotify_verbose != 0 ) |
1292 | | { |
1293 | | libcnotify_printf( |
1294 | | "%s: missing identifier for header value: %d.\n", |
1295 | | function, |
1296 | | header_value_index ); |
1297 | | } |
1298 | | #endif |
1299 | 0 | continue; |
1300 | 0 | } |
1301 | | /* Ignore the acquiry and system date |
1302 | | * They will be auto generated |
1303 | | */ |
1304 | 0 | else if( ( identifier_size == 13 ) |
1305 | 0 | && ( narrow_string_compare( |
1306 | 0 | (char *) identifier, |
1307 | 0 | "acquiry_date", |
1308 | 0 | 12 ) == 0 ) ) |
1309 | 0 | { |
1310 | 0 | continue; |
1311 | 0 | } |
1312 | 0 | else if( ( identifier_size == 12 ) |
1313 | 0 | && ( narrow_string_compare( |
1314 | 0 | (char *) identifier, |
1315 | 0 | "system_date", |
1316 | 0 | 11 ) == 0 ) ) |
1317 | 0 | { |
1318 | 0 | continue; |
1319 | 0 | } |
1320 | | /* Ignore empty values |
1321 | | */ |
1322 | 0 | result = libfvalue_value_has_data( |
1323 | 0 | source_header_value, |
1324 | 0 | error ); |
1325 | |
|
1326 | 0 | if( result == -1 ) |
1327 | 0 | { |
1328 | 0 | libcerror_error_set( |
1329 | 0 | error, |
1330 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1331 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1332 | 0 | "%s: unable to retrieve data of header value: %s.", |
1333 | 0 | function, |
1334 | 0 | (char *) identifier ); |
1335 | |
|
1336 | 0 | goto on_error; |
1337 | 0 | } |
1338 | 0 | else if( result == 0 ) |
1339 | 0 | { |
1340 | 0 | continue; |
1341 | 0 | } |
1342 | 0 | if( libfvalue_value_clone( |
1343 | 0 | &destination_header_value, |
1344 | 0 | source_header_value, |
1345 | 0 | error ) != 1 ) |
1346 | 0 | { |
1347 | 0 | libcerror_error_set( |
1348 | 0 | error, |
1349 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1350 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1351 | 0 | "%s: unable create destination header value.", |
1352 | 0 | function ); |
1353 | |
|
1354 | 0 | goto on_error; |
1355 | 0 | } |
1356 | 0 | if( libfvalue_table_set_value_by_index( |
1357 | 0 | destination_header_values, |
1358 | 0 | header_value_index, |
1359 | 0 | destination_header_value, |
1360 | 0 | error ) != 1 ) |
1361 | 0 | { |
1362 | 0 | libcerror_error_set( |
1363 | 0 | error, |
1364 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1365 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1366 | 0 | "%s: unable to set header value: %d.", |
1367 | 0 | function, |
1368 | 0 | header_value_index ); |
1369 | |
|
1370 | 0 | goto on_error; |
1371 | 0 | } |
1372 | 0 | destination_header_value = NULL; |
1373 | 0 | } |
1374 | 0 | return( 1 ); |
1375 | | |
1376 | 0 | on_error: |
1377 | 0 | if( destination_header_value != NULL ) |
1378 | 0 | { |
1379 | 0 | libfvalue_value_free( |
1380 | 0 | &destination_header_value, |
1381 | 0 | NULL ); |
1382 | 0 | } |
1383 | 0 | return( -1 ); |
1384 | 0 | } |
1385 | | |
1386 | | /* Parses an UTF-8 encoded header string |
1387 | | * Returns 1 if successful or -1 on error |
1388 | | */ |
1389 | | int libewf_header_values_parse_utf8_header_string( |
1390 | | libfvalue_table_t *header_values, |
1391 | | const uint8_t *header_string, |
1392 | | size_t header_string_size, |
1393 | | uint8_t header_section_number, |
1394 | | uint8_t *format, |
1395 | | libcerror_error_t **error ) |
1396 | 1.02k | { |
1397 | 1.02k | libfvalue_split_utf8_string_t *lines = NULL; |
1398 | 1.02k | libfvalue_split_utf8_string_t *types = NULL; |
1399 | 1.02k | libfvalue_split_utf8_string_t *values = NULL; |
1400 | 1.02k | uint8_t *line_string = NULL; |
1401 | 1.02k | uint8_t *type_string = NULL; |
1402 | 1.02k | uint8_t *value_string = NULL; |
1403 | 1.02k | static char *function = "libewf_header_values_parse_utf8_header_string"; |
1404 | 1.02k | size_t line_string_size = 0; |
1405 | 1.02k | size_t type_string_size = 0; |
1406 | 1.02k | size_t value_string_size = 0; |
1407 | 1.02k | uint8_t acquiry_software_version = 0; |
1408 | 1.02k | uint8_t number_of_sections = 0; |
1409 | 1.02k | int number_of_lines = 0; |
1410 | 1.02k | int number_of_types = 0; |
1411 | 1.02k | int number_of_values = 0; |
1412 | 1.02k | int value_index = 0; |
1413 | | |
1414 | 1.02k | if( header_string == NULL ) |
1415 | 0 | { |
1416 | 0 | libcerror_error_set( |
1417 | 0 | error, |
1418 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1419 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1420 | 0 | "%s: invalid header string.", |
1421 | 0 | function ); |
1422 | |
|
1423 | 0 | return( -1 ); |
1424 | 0 | } |
1425 | 1.02k | if( ( header_section_number != 1 ) |
1426 | 1.02k | && ( header_section_number != 2 ) ) |
1427 | 0 | { |
1428 | 0 | libcerror_error_set( |
1429 | 0 | error, |
1430 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1431 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
1432 | 0 | "%s: unsupported header section number.", |
1433 | 0 | function ); |
1434 | |
|
1435 | 0 | goto on_error; |
1436 | 0 | } |
1437 | 1.02k | if( format == NULL ) |
1438 | 0 | { |
1439 | 0 | libcerror_error_set( |
1440 | 0 | error, |
1441 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1442 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1443 | 0 | "%s: invalid format.", |
1444 | 0 | function ); |
1445 | |
|
1446 | 0 | return( -1 ); |
1447 | 0 | } |
1448 | 1.02k | if( libfvalue_utf8_string_split( |
1449 | 1.02k | header_string, |
1450 | 1.02k | header_string_size, |
1451 | 1.02k | (uint8_t) '\n', |
1452 | 1.02k | &lines, |
1453 | 1.02k | error ) != 1 ) |
1454 | 0 | { |
1455 | 0 | libcerror_error_set( |
1456 | 0 | error, |
1457 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1458 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1459 | 0 | "%s: unable to split header string into lines.", |
1460 | 0 | function ); |
1461 | |
|
1462 | 0 | goto on_error; |
1463 | 0 | } |
1464 | 1.02k | if( libfvalue_split_utf8_string_get_number_of_segments( |
1465 | 1.02k | lines, |
1466 | 1.02k | &number_of_lines, |
1467 | 1.02k | error ) != 1 ) |
1468 | 2 | { |
1469 | 2 | libcerror_error_set( |
1470 | 2 | error, |
1471 | 2 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1472 | 2 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1473 | 2 | "%s: unable to retrieve number of lines.", |
1474 | 2 | function ); |
1475 | | |
1476 | 2 | goto on_error; |
1477 | 2 | } |
1478 | 1.02k | if( number_of_lines > 0 ) |
1479 | 1.02k | { |
1480 | 1.02k | if( libfvalue_split_utf8_string_get_segment_by_index( |
1481 | 1.02k | lines, |
1482 | 1.02k | 0, |
1483 | 1.02k | &line_string, |
1484 | 1.02k | &line_string_size, |
1485 | 1.02k | error ) != 1 ) |
1486 | 0 | { |
1487 | 0 | libcerror_error_set( |
1488 | 0 | error, |
1489 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1490 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1491 | 0 | "%s: unable to retrieve line string: 0.", |
1492 | 0 | function ); |
1493 | |
|
1494 | 0 | goto on_error; |
1495 | 0 | } |
1496 | 1.02k | if( line_string == NULL ) |
1497 | 0 | { |
1498 | 0 | libcerror_error_set( |
1499 | 0 | error, |
1500 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1501 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1502 | 0 | "%s: missing line string: 0.", |
1503 | 0 | function ); |
1504 | |
|
1505 | 0 | goto on_error; |
1506 | 0 | } |
1507 | 1.02k | if( ( line_string == NULL ) |
1508 | 1.02k | || ( line_string_size < 2 ) |
1509 | 1.02k | || ( line_string[ 0 ] == 0 ) ) |
1510 | 1 | { |
1511 | 1 | libcerror_error_set( |
1512 | 1 | error, |
1513 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1514 | 1 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1515 | 1 | "%s: missing line string: 0.", |
1516 | 1 | function ); |
1517 | | |
1518 | 1 | goto on_error; |
1519 | 1 | } |
1520 | | /* Remove trailing carriage return |
1521 | | */ |
1522 | 1.02k | else if( line_string[ line_string_size - 2 ] == (uint8_t) '\r' ) |
1523 | 338 | { |
1524 | 338 | line_string[ line_string_size - 2 ] = 0; |
1525 | | |
1526 | 338 | line_string_size -= 1; |
1527 | 338 | } |
1528 | 1.02k | if( line_string_size != 2 ) |
1529 | 165 | { |
1530 | 165 | libcerror_error_set( |
1531 | 165 | error, |
1532 | 165 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1533 | 165 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1534 | 165 | "%s: unsupported line string: 0.", |
1535 | 165 | function ); |
1536 | | |
1537 | 165 | goto on_error; |
1538 | 165 | } |
1539 | 856 | if( ( line_string[ 0 ] != (uint8_t) '1' ) |
1540 | 856 | && ( line_string[ 0 ] != (uint8_t) '3' ) ) |
1541 | 17 | { |
1542 | 17 | libcerror_error_set( |
1543 | 17 | error, |
1544 | 17 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1545 | 17 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1546 | 17 | "%s: unsupported line string: 0.", |
1547 | 17 | function ); |
1548 | | |
1549 | 17 | goto on_error; |
1550 | 17 | } |
1551 | 839 | number_of_sections = line_string[ 0 ]; |
1552 | | |
1553 | 839 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1554 | 839 | lines, |
1555 | 839 | 1, |
1556 | 839 | &line_string, |
1557 | 839 | &line_string_size, |
1558 | 839 | error ) != 1 ) |
1559 | 2 | { |
1560 | 2 | libcerror_error_set( |
1561 | 2 | error, |
1562 | 2 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1563 | 2 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1564 | 2 | "%s: unable to retrieve line string: 1.", |
1565 | 2 | function ); |
1566 | | |
1567 | 2 | goto on_error; |
1568 | 2 | } |
1569 | 837 | if( line_string == NULL ) |
1570 | 0 | { |
1571 | 0 | libcerror_error_set( |
1572 | 0 | error, |
1573 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1574 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1575 | 0 | "%s: missing line string: 1.", |
1576 | 0 | function ); |
1577 | |
|
1578 | 0 | goto on_error; |
1579 | 0 | } |
1580 | 837 | if( ( line_string == NULL ) |
1581 | 837 | || ( line_string_size < 5 ) |
1582 | 837 | || ( line_string[ 0 ] == 0 ) ) |
1583 | 12 | { |
1584 | 12 | libcerror_error_set( |
1585 | 12 | error, |
1586 | 12 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1587 | 12 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1588 | 12 | "%s: missing line string: 1.", |
1589 | 12 | function ); |
1590 | | |
1591 | 12 | goto on_error; |
1592 | 12 | } |
1593 | | /* Remove trailing carriage return |
1594 | | */ |
1595 | 825 | else if( line_string[ line_string_size - 2 ] == (uint8_t) '\r' ) |
1596 | 331 | { |
1597 | 331 | line_string[ line_string_size - 2 ] = 0; |
1598 | | |
1599 | 331 | line_string_size -= 1; |
1600 | 331 | } |
1601 | 825 | if( line_string_size != 5 ) |
1602 | 11 | { |
1603 | 11 | libcerror_error_set( |
1604 | 11 | error, |
1605 | 11 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1606 | 11 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1607 | 11 | "%s: unsupported line string: 1.", |
1608 | 11 | function ); |
1609 | | |
1610 | 11 | goto on_error; |
1611 | 11 | } |
1612 | 814 | if( ( line_string[ 0 ] != (uint8_t) 'm' ) |
1613 | 814 | || ( line_string[ 1 ] != (uint8_t) 'a' ) |
1614 | 814 | || ( line_string[ 2 ] != (uint8_t) 'i' ) |
1615 | 814 | || ( line_string[ 3 ] != (uint8_t) 'n' ) ) |
1616 | 35 | { |
1617 | 35 | libcerror_error_set( |
1618 | 35 | error, |
1619 | 35 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1620 | 35 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1621 | 35 | "%s: unsupported line string: 1.", |
1622 | 35 | function ); |
1623 | | |
1624 | 35 | goto on_error; |
1625 | 35 | } |
1626 | 779 | if( header_section_number == 1 ) |
1627 | 329 | { |
1628 | | /* If the header string contains 3 object the version is at least linen5 |
1629 | | * otherwise the version is at least EnCase1 |
1630 | | */ |
1631 | 329 | if( number_of_sections == (uint8_t) '3' ) |
1632 | 1 | { |
1633 | 1 | *format = LIBEWF_FORMAT_LINEN5; |
1634 | 1 | } |
1635 | 328 | else |
1636 | 328 | { |
1637 | 328 | *format = LIBEWF_FORMAT_ENCASE1; |
1638 | 328 | } |
1639 | 329 | } |
1640 | 779 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1641 | 779 | lines, |
1642 | 779 | 2, |
1643 | 779 | &line_string, |
1644 | 779 | &line_string_size, |
1645 | 779 | error ) != 1 ) |
1646 | 1 | { |
1647 | 1 | libcerror_error_set( |
1648 | 1 | error, |
1649 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1650 | 1 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1651 | 1 | "%s: unable to retrieve line string: 2.", |
1652 | 1 | function ); |
1653 | | |
1654 | 1 | goto on_error; |
1655 | 1 | } |
1656 | 778 | if( libfvalue_utf8_string_split( |
1657 | 778 | line_string, |
1658 | 778 | line_string_size, |
1659 | 778 | (uint8_t) '\t', |
1660 | 778 | &types, |
1661 | 778 | error ) != 1 ) |
1662 | 0 | { |
1663 | 0 | libcerror_error_set( |
1664 | 0 | error, |
1665 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1666 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1667 | 0 | "%s: unable to split header values string into types.", |
1668 | 0 | function ); |
1669 | |
|
1670 | 0 | goto on_error; |
1671 | 0 | } |
1672 | 778 | if( libfvalue_split_utf8_string_get_number_of_segments( |
1673 | 778 | types, |
1674 | 778 | &number_of_types, |
1675 | 778 | error ) != 1 ) |
1676 | 3 | { |
1677 | 3 | libcerror_error_set( |
1678 | 3 | error, |
1679 | 3 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1680 | 3 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1681 | 3 | "%s: unable to retrieve number of types.", |
1682 | 3 | function ); |
1683 | | |
1684 | 3 | goto on_error; |
1685 | 3 | } |
1686 | 775 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1687 | 775 | lines, |
1688 | 775 | 3, |
1689 | 775 | &line_string, |
1690 | 775 | &line_string_size, |
1691 | 775 | error ) != 1 ) |
1692 | 8 | { |
1693 | 8 | libcerror_error_set( |
1694 | 8 | error, |
1695 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1696 | 8 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1697 | 8 | "%s: unable to retrieve line string: 3.", |
1698 | 8 | function ); |
1699 | | |
1700 | 8 | goto on_error; |
1701 | 8 | } |
1702 | 767 | if( libfvalue_utf8_string_split( |
1703 | 767 | line_string, |
1704 | 767 | line_string_size, |
1705 | 767 | (uint8_t) '\t', |
1706 | 767 | &values, |
1707 | 767 | error ) != 1 ) |
1708 | 0 | { |
1709 | 0 | libcerror_error_set( |
1710 | 0 | error, |
1711 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1712 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1713 | 0 | "%s: unable to split header values string into values.", |
1714 | 0 | function ); |
1715 | |
|
1716 | 0 | goto on_error; |
1717 | 0 | } |
1718 | 767 | if( libfvalue_split_utf8_string_get_number_of_segments( |
1719 | 767 | values, |
1720 | 767 | &number_of_values, |
1721 | 767 | error ) != 1 ) |
1722 | 4 | { |
1723 | 4 | libcerror_error_set( |
1724 | 4 | error, |
1725 | 4 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1726 | 4 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1727 | 4 | "%s: unable to retrieve number of values.", |
1728 | 4 | function ); |
1729 | | |
1730 | 4 | goto on_error; |
1731 | 4 | } |
1732 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1733 | | if( number_of_types != number_of_values ) |
1734 | | { |
1735 | | if( libcnotify_verbose != 0 ) |
1736 | | { |
1737 | | libcnotify_printf( |
1738 | | "%s: mismatch in number of types and values.\n", |
1739 | | function ); |
1740 | | } |
1741 | | } |
1742 | | #endif |
1743 | 763 | for( value_index = 0; |
1744 | 19.3k | value_index < number_of_types; |
1745 | 18.6k | value_index++ ) |
1746 | 18.7k | { |
1747 | 18.7k | if( libfvalue_split_utf8_string_get_segment_by_index( |
1748 | 18.7k | types, |
1749 | 18.7k | value_index, |
1750 | 18.7k | &type_string, |
1751 | 18.7k | &type_string_size, |
1752 | 18.7k | error ) != 1 ) |
1753 | 0 | { |
1754 | 0 | libcerror_error_set( |
1755 | 0 | error, |
1756 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1757 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1758 | 0 | "%s: unable to retrieve type string: %d.", |
1759 | 0 | function, |
1760 | 0 | value_index ); |
1761 | |
|
1762 | 0 | goto on_error; |
1763 | 0 | } |
1764 | 18.7k | if( value_index >= number_of_values ) |
1765 | 8.99k | { |
1766 | 8.99k | value_string = NULL; |
1767 | 8.99k | value_string_size = 0; |
1768 | 8.99k | } |
1769 | 9.71k | else if( libfvalue_split_utf8_string_get_segment_by_index( |
1770 | 9.71k | values, |
1771 | 9.71k | value_index, |
1772 | 9.71k | &value_string, |
1773 | 9.71k | &value_string_size, |
1774 | 9.71k | error ) != 1 ) |
1775 | 0 | { |
1776 | 0 | libcerror_error_set( |
1777 | 0 | error, |
1778 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1779 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1780 | 0 | "%s: unable to retrieve value string: %d.", |
1781 | 0 | function, |
1782 | 0 | value_index ); |
1783 | |
|
1784 | 0 | goto on_error; |
1785 | 0 | } |
1786 | 18.7k | if( libewf_header_values_parse_utf8_header_string_value( |
1787 | 18.7k | header_values, |
1788 | 18.7k | type_string, |
1789 | 18.7k | type_string_size, |
1790 | 18.7k | value_string, |
1791 | 18.7k | value_string_size, |
1792 | 18.7k | value_index, |
1793 | 18.7k | header_section_number, |
1794 | 18.7k | number_of_sections, |
1795 | 18.7k | format, |
1796 | 18.7k | &acquiry_software_version, |
1797 | 18.7k | error ) != 1 ) |
1798 | 109 | { |
1799 | 109 | libcerror_error_set( |
1800 | 109 | error, |
1801 | 109 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1802 | 109 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1803 | 109 | "%s: unable to parse UTF-8 string value: %d.", |
1804 | 109 | function, |
1805 | 109 | value_index ); |
1806 | | |
1807 | 109 | goto on_error; |
1808 | 109 | } |
1809 | 18.7k | } |
1810 | 654 | if( libfvalue_split_utf8_string_free( |
1811 | 654 | &values, |
1812 | 654 | error ) != 1 ) |
1813 | 0 | { |
1814 | 0 | libcerror_error_set( |
1815 | 0 | error, |
1816 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1817 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1818 | 0 | "%s: unable to free split values.", |
1819 | 0 | function ); |
1820 | |
|
1821 | 0 | goto on_error; |
1822 | 0 | } |
1823 | 654 | if( libfvalue_split_utf8_string_free( |
1824 | 654 | &types, |
1825 | 654 | error ) != 1 ) |
1826 | 0 | { |
1827 | 0 | libcerror_error_set( |
1828 | 0 | error, |
1829 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1830 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1831 | 0 | "%s: unable to free split types.", |
1832 | 0 | function ); |
1833 | |
|
1834 | 0 | goto on_error; |
1835 | 0 | } |
1836 | 654 | } |
1837 | 654 | if( libfvalue_split_utf8_string_free( |
1838 | 654 | &lines, |
1839 | 654 | error ) != 1 ) |
1840 | 0 | { |
1841 | 0 | libcerror_error_set( |
1842 | 0 | error, |
1843 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1844 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1845 | 0 | "%s: unable to free split lines.", |
1846 | 0 | function ); |
1847 | |
|
1848 | 0 | goto on_error; |
1849 | 0 | } |
1850 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1851 | | if( libcnotify_verbose != 0 ) |
1852 | | { |
1853 | | libcnotify_printf( |
1854 | | "\n" ); |
1855 | | } |
1856 | | #endif |
1857 | 654 | return( 1 ); |
1858 | | |
1859 | 370 | on_error: |
1860 | 370 | if( values != NULL ) |
1861 | 109 | { |
1862 | 109 | libfvalue_split_utf8_string_free( |
1863 | 109 | &values, |
1864 | 109 | NULL ); |
1865 | 109 | } |
1866 | 370 | if( types != NULL ) |
1867 | 121 | { |
1868 | 121 | libfvalue_split_utf8_string_free( |
1869 | 121 | &types, |
1870 | 121 | NULL ); |
1871 | 121 | } |
1872 | 370 | if( lines != NULL ) |
1873 | 368 | { |
1874 | 368 | libfvalue_split_utf8_string_free( |
1875 | 368 | &lines, |
1876 | 368 | NULL ); |
1877 | 368 | } |
1878 | 370 | return( -1 ); |
1879 | 654 | } |
1880 | | |
1881 | | /* Parses an UTF-8 encoded header string value |
1882 | | * Returns 1 if successful or -1 on error |
1883 | | */ |
1884 | | int libewf_header_values_parse_utf8_header_string_value( |
1885 | | libfvalue_table_t *header_values, |
1886 | | uint8_t *type_string, |
1887 | | size_t type_string_size, |
1888 | | uint8_t *value_string, |
1889 | | size_t value_string_size, |
1890 | | int value_index, |
1891 | | uint8_t header_section_number, |
1892 | | uint8_t number_of_sections, |
1893 | | uint8_t *format, |
1894 | | uint8_t *acquiry_software_version, |
1895 | | libcerror_error_t **error ) |
1896 | 18.7k | { |
1897 | 18.7k | uint8_t *date_time_values_string = NULL; |
1898 | 18.7k | uint8_t *identifier = NULL; |
1899 | 18.7k | static char *function = "libewf_header_values_parse_utf8_header_string_value"; |
1900 | 18.7k | size_t date_time_values_string_size = 0; |
1901 | 18.7k | size_t identifier_size = 0; |
1902 | 18.7k | uint8_t has_carriage_return = 0; |
1903 | 18.7k | int result = 0; |
1904 | | |
1905 | 18.7k | if( ( type_string == NULL ) |
1906 | 18.7k | || ( type_string_size < 2 ) |
1907 | 18.7k | || ( type_string[ 0 ] == 0 ) ) |
1908 | 109 | { |
1909 | 109 | libcerror_error_set( |
1910 | 109 | error, |
1911 | 109 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1912 | 109 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1913 | 109 | "%s: missing type string: %d.", |
1914 | 109 | function, |
1915 | 109 | value_index ); |
1916 | | |
1917 | 109 | goto on_error; |
1918 | 109 | } |
1919 | 18.6k | if( ( header_section_number != 1 ) |
1920 | 18.6k | && ( header_section_number != 2 ) ) |
1921 | 0 | { |
1922 | 0 | libcerror_error_set( |
1923 | 0 | error, |
1924 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1925 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
1926 | 0 | "%s: unsupported header section number.", |
1927 | 0 | function ); |
1928 | |
|
1929 | 0 | goto on_error; |
1930 | 0 | } |
1931 | 18.6k | if( format == NULL ) |
1932 | 0 | { |
1933 | 0 | libcerror_error_set( |
1934 | 0 | error, |
1935 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1936 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1937 | 0 | "%s: invalid format.", |
1938 | 0 | function ); |
1939 | |
|
1940 | 0 | return( -1 ); |
1941 | 0 | } |
1942 | 18.6k | if( acquiry_software_version == NULL ) |
1943 | 0 | { |
1944 | 0 | libcerror_error_set( |
1945 | 0 | error, |
1946 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1947 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1948 | 0 | "%s: invalid acquiry software version.", |
1949 | 0 | function ); |
1950 | |
|
1951 | 0 | return( -1 ); |
1952 | 0 | } |
1953 | | /* Remove trailing carriage return |
1954 | | */ |
1955 | 18.6k | if( type_string[ type_string_size - 2 ] == (uint8_t) '\r' ) |
1956 | 816 | { |
1957 | 816 | type_string[ type_string_size - 2 ] = 0; |
1958 | | |
1959 | 816 | type_string_size -= 1; |
1960 | | |
1961 | 816 | has_carriage_return = 1; |
1962 | 816 | } |
1963 | 18.6k | if( ( value_string == NULL ) |
1964 | 18.6k | || ( value_string_size < 2 ) |
1965 | 18.6k | || ( value_string[ 0 ] == 0 ) ) |
1966 | 10.2k | { |
1967 | 10.2k | value_string = NULL; |
1968 | 10.2k | value_string_size = 0; |
1969 | 10.2k | } |
1970 | | /* Remove trailing carriage return |
1971 | | */ |
1972 | 8.31k | else if( value_string[ value_string_size - 2 ] == (uint8_t) '\r' ) |
1973 | 359 | { |
1974 | 359 | value_string[ value_string_size - 2 ] = 0; |
1975 | | |
1976 | 359 | value_string_size -= 1; |
1977 | 359 | } |
1978 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1979 | | if( libcnotify_verbose != 0 ) |
1980 | | { |
1981 | | libcnotify_printf( |
1982 | | "%s: type: %3s with value\t:", |
1983 | | function, |
1984 | | (char *) type_string ); |
1985 | | |
1986 | | if( value_string != NULL ) |
1987 | | { |
1988 | | libcnotify_printf( |
1989 | | " %s", |
1990 | | (char *) value_string ); |
1991 | | } |
1992 | | libcnotify_printf( |
1993 | | "\n" ); |
1994 | | } |
1995 | | #endif |
1996 | 18.6k | identifier = NULL; |
1997 | 18.6k | identifier_size = 0; |
1998 | | |
1999 | 18.6k | if( type_string_size == 4 ) |
2000 | 1.32k | { |
2001 | 1.32k | if( ( type_string[ 0 ] == (uint8_t) 'e' ) |
2002 | 1.32k | && ( type_string[ 1 ] == (uint8_t) 'x' ) |
2003 | 1.32k | && ( type_string[ 2 ] == (uint8_t) 't' ) ) |
2004 | 82 | { |
2005 | 82 | identifier = (uint8_t *) "extents"; |
2006 | 82 | identifier_size = 8; |
2007 | 82 | } |
2008 | 1.24k | else if( ( type_string[ 0 ] == (uint8_t) 'p' ) |
2009 | 1.24k | && ( type_string[ 1 ] == (uint8_t) 'i' ) |
2010 | 1.24k | && ( type_string[ 2 ] == (uint8_t) 'd' ) ) |
2011 | 78 | { |
2012 | 78 | identifier = (uint8_t *) "process_identifier"; |
2013 | 78 | identifier_size = 19; |
2014 | 78 | } |
2015 | 1.32k | } |
2016 | 17.2k | else if( type_string_size == 3 ) |
2017 | 3.87k | { |
2018 | 3.87k | if( ( type_string[ 0 ] == (uint8_t) 'a' ) |
2019 | 3.87k | && ( type_string[ 1 ] == (uint8_t) 'v' ) ) |
2020 | 770 | { |
2021 | 770 | identifier = (uint8_t *) "acquiry_software_version"; |
2022 | 770 | identifier_size = 25; |
2023 | | |
2024 | 770 | if( value_index == 5 ) |
2025 | 250 | { |
2026 | | /* The linen5 header contains av on the 6th position |
2027 | | */ |
2028 | 250 | if( header_section_number == 1 ) |
2029 | 248 | { |
2030 | 248 | *format = LIBEWF_FORMAT_LINEN5; |
2031 | 248 | } |
2032 | 2 | else if( header_section_number == 2 ) |
2033 | 2 | { |
2034 | | /* The EnCase4 header2 contains av on the 6th position |
2035 | | * and the header2 consist of 1 sections |
2036 | | */ |
2037 | 2 | if( number_of_sections == (uint8_t) '1' ) |
2038 | 1 | { |
2039 | 1 | *format = LIBEWF_FORMAT_ENCASE4; |
2040 | 1 | } |
2041 | | /* The EnCase5 header2 contains av on the 6th position |
2042 | | * and the header2 consist of 3 sections |
2043 | | */ |
2044 | 1 | else if( number_of_sections == (uint8_t) '3' ) |
2045 | 1 | { |
2046 | 1 | *format = LIBEWF_FORMAT_ENCASE5; |
2047 | 1 | } |
2048 | 2 | } |
2049 | 250 | } |
2050 | 770 | if( ( value_string != NULL ) |
2051 | 770 | && ( value_string_size > 1 ) ) |
2052 | 619 | { |
2053 | 619 | *acquiry_software_version = value_string[ 0 ]; |
2054 | 619 | } |
2055 | 770 | } |
2056 | 3.10k | else if( ( type_string[ 0 ] == (uint8_t) 'd' ) |
2057 | 3.10k | && ( type_string[ 1 ] == (uint8_t) 'c' ) ) |
2058 | 343 | { |
2059 | 343 | identifier = (uint8_t *) "unknown_dc"; |
2060 | 343 | identifier_size = 11; |
2061 | 343 | } |
2062 | 2.76k | else if( ( type_string[ 0 ] == (uint8_t) 'm' ) |
2063 | 2.76k | && ( type_string[ 1 ] == (uint8_t) 'd' ) ) |
2064 | 415 | { |
2065 | 415 | identifier = (uint8_t *) "model"; |
2066 | 415 | identifier_size = 6; |
2067 | | |
2068 | 415 | if( value_index == 5 ) |
2069 | 293 | { |
2070 | | /* The linen6 header contains md on the 6th position |
2071 | | */ |
2072 | 293 | if( header_section_number == 1 ) |
2073 | 1 | { |
2074 | 1 | *format = LIBEWF_FORMAT_LINEN6; |
2075 | 1 | } |
2076 | | /* The EnCase6 header2 contains md on the 6th position |
2077 | | */ |
2078 | 292 | else if( header_section_number == 2 ) |
2079 | 292 | { |
2080 | 292 | *format = LIBEWF_FORMAT_ENCASE6; |
2081 | 292 | } |
2082 | 293 | } |
2083 | 415 | } |
2084 | 2.34k | else if( ( type_string[ 0 ] == (uint8_t) 'o' ) |
2085 | 2.34k | && ( type_string[ 1 ] == (uint8_t) 'v' ) ) |
2086 | 589 | { |
2087 | 589 | identifier = (uint8_t *) "acquiry_operating_system"; |
2088 | 589 | identifier_size = 25; |
2089 | 589 | } |
2090 | 1.75k | else if( ( type_string[ 0 ] == (uint8_t) 's' ) |
2091 | 1.75k | && ( type_string[ 1 ] == (uint8_t) 'n' ) ) |
2092 | 365 | { |
2093 | 365 | identifier = (uint8_t *) "serial_number"; |
2094 | 365 | identifier_size = 14; |
2095 | 365 | } |
2096 | 3.87k | } |
2097 | 13.4k | else if( type_string_size == 2 ) |
2098 | 11.9k | { |
2099 | 11.9k | if( type_string[ 0 ] == (uint8_t) 'a' ) |
2100 | 1.06k | { |
2101 | 1.06k | identifier = (uint8_t *) "description"; |
2102 | 1.06k | identifier_size = 12; |
2103 | 1.06k | } |
2104 | 10.8k | else if( type_string[ 0 ] == (uint8_t) 'c' ) |
2105 | 937 | { |
2106 | 937 | identifier = (uint8_t *) "case_number"; |
2107 | 937 | identifier_size = 12; |
2108 | 937 | } |
2109 | 9.90k | else if( type_string[ 0 ] == (uint8_t) 'e' ) |
2110 | 1.10k | { |
2111 | 1.10k | identifier = (uint8_t *) "examiner_name"; |
2112 | 1.10k | identifier_size = 14; |
2113 | 1.10k | } |
2114 | 8.80k | else if( type_string[ 0 ] == (uint8_t) 'l' ) |
2115 | 243 | { |
2116 | 243 | identifier = (uint8_t *) "device_label"; |
2117 | 243 | identifier_size = 13; |
2118 | | |
2119 | | /* The linen7 header contains l |
2120 | | */ |
2121 | 243 | if( header_section_number == 1 ) |
2122 | 0 | { |
2123 | 0 | *format = LIBEWF_FORMAT_LINEN7; |
2124 | 0 | } |
2125 | | /* The EnCase7 header2 contains l |
2126 | | */ |
2127 | 243 | else if( header_section_number == 2 ) |
2128 | 243 | { |
2129 | 243 | *format = LIBEWF_FORMAT_ENCASE7; |
2130 | 243 | } |
2131 | 243 | } |
2132 | 8.55k | else if( ( type_string[ 0 ] == (uint8_t) 'm' ) |
2133 | 8.55k | || ( type_string[ 0 ] == (uint8_t) 'u' ) ) |
2134 | 3.94k | { |
2135 | 3.94k | if( ( value_string == NULL ) |
2136 | 3.94k | || ( value_string_size == 0 ) |
2137 | 3.94k | || ( value_string[ 0 ] == 0 ) ) |
2138 | 1.26k | { |
2139 | 1.26k | date_time_values_string = NULL; |
2140 | 1.26k | result = 0; |
2141 | 1.26k | } |
2142 | | /* If the date time values string contains spaces it is in the old header |
2143 | | * format otherwise is in new header2 format |
2144 | | */ |
2145 | 2.68k | else if( narrow_string_search_character( |
2146 | 2.68k | (char *) value_string, |
2147 | 2.68k | ' ', |
2148 | 2.68k | value_string_size - 1 ) != NULL ) |
2149 | 760 | { |
2150 | 760 | result = libewf_convert_date_header_value( |
2151 | 760 | value_string, |
2152 | 760 | value_string_size, |
2153 | 760 | &date_time_values_string, |
2154 | 760 | &date_time_values_string_size, |
2155 | 760 | error ); |
2156 | 760 | } |
2157 | 1.92k | else |
2158 | 1.92k | { |
2159 | 1.92k | result = libewf_convert_date_header2_value( |
2160 | 1.92k | value_string, |
2161 | 1.92k | value_string_size, |
2162 | 1.92k | &date_time_values_string, |
2163 | 1.92k | &date_time_values_string_size, |
2164 | 1.92k | error ); |
2165 | 1.92k | } |
2166 | 3.94k | if( result == -1 ) |
2167 | 1.02k | { |
2168 | 1.02k | libcerror_error_set( |
2169 | 1.02k | error, |
2170 | 1.02k | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2171 | 1.02k | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2172 | 1.02k | "%s: unable to create date time values string.", |
2173 | 1.02k | function ); |
2174 | | |
2175 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2176 | | if( libcnotify_verbose != 0 ) |
2177 | | { |
2178 | | if( ( error != NULL ) |
2179 | | && ( *error != NULL ) ) |
2180 | | { |
2181 | | libcnotify_print_error_backtrace( |
2182 | | *error ); |
2183 | | } |
2184 | | } |
2185 | | #endif |
2186 | 1.02k | libcerror_error_free( |
2187 | 1.02k | error ); |
2188 | 1.02k | } |
2189 | | /* The effective size of the date time values string is needed |
2190 | | */ |
2191 | 3.94k | if( date_time_values_string != NULL ) |
2192 | 1.65k | { |
2193 | 1.65k | value_string = date_time_values_string; |
2194 | 1.65k | value_string_size = 1 + narrow_string_length( |
2195 | 1.65k | (char *) date_time_values_string ); |
2196 | | |
2197 | 1.65k | if( type_string[ 0 ] == (uint8_t) 'm' ) |
2198 | 578 | { |
2199 | 578 | identifier = (uint8_t *) "acquiry_date"; |
2200 | 578 | identifier_size = 13; |
2201 | 578 | } |
2202 | 1.07k | else if( type_string[ 0 ] == (uint8_t) 'u' ) |
2203 | 1.07k | { |
2204 | 1.07k | identifier = (uint8_t *) "system_date"; |
2205 | 1.07k | identifier_size = 12; |
2206 | 1.07k | } |
2207 | 1.65k | } |
2208 | 3.94k | } |
2209 | 4.61k | else if( type_string[ 0 ] == (uint8_t) 'n' ) |
2210 | 895 | { |
2211 | 895 | identifier = (uint8_t *) "evidence_number"; |
2212 | 895 | identifier_size = 16; |
2213 | 895 | } |
2214 | 3.71k | else if( type_string[ 0 ] == (uint8_t) 'p' ) |
2215 | 1.46k | { |
2216 | 1.46k | if( ( value_string == NULL ) |
2217 | 1.46k | || ( value_string_size == 0 ) |
2218 | 1.46k | || ( value_string[ 0 ] == 0 ) ) |
2219 | 653 | { |
2220 | | /* Empty hash do nothing |
2221 | | */ |
2222 | 653 | } |
2223 | 815 | else if( ( value_string_size == 2 ) |
2224 | 815 | && ( value_string[ 0 ] == (uint8_t) '0' ) ) |
2225 | 518 | { |
2226 | | /* Empty hash do nothing |
2227 | | */ |
2228 | 518 | } |
2229 | 297 | else |
2230 | 297 | { |
2231 | 297 | identifier = (uint8_t *) "password"; |
2232 | 297 | identifier_size = 9; |
2233 | 297 | } |
2234 | 1.46k | } |
2235 | 2.24k | else if( type_string[ 0 ] == (uint8_t) 'r' ) |
2236 | 495 | { |
2237 | 495 | identifier = (uint8_t *) "compression_level"; |
2238 | 495 | identifier_size = 18; |
2239 | | |
2240 | 495 | if( header_section_number == 1 ) |
2241 | 141 | { |
2242 | | /* The EnCase1 header contains r on the 9th position |
2243 | | */ |
2244 | 141 | if( value_index == 8 ) |
2245 | 4 | { |
2246 | 4 | *format = LIBEWF_FORMAT_ENCASE1; |
2247 | 4 | } |
2248 | 137 | else if( value_index == 10 ) |
2249 | 14 | { |
2250 | | /* The EnCase2 and EnCase3 header contains r on the 11th position |
2251 | | * and uses \r\n as line ends. The only way to tell both version |
2252 | | * apart is to look at the acquiry software version |
2253 | | */ |
2254 | 14 | if( has_carriage_return != 0 ) |
2255 | 9 | { |
2256 | 9 | if( *acquiry_software_version == (uint8_t) '2' ) |
2257 | 1 | { |
2258 | 1 | *format = LIBEWF_FORMAT_ENCASE2; |
2259 | 1 | } |
2260 | 8 | else if( *acquiry_software_version == (uint8_t) '3' ) |
2261 | 1 | { |
2262 | 1 | *format = LIBEWF_FORMAT_ENCASE3; |
2263 | 1 | } |
2264 | 9 | } |
2265 | | /* The FTK imager header contains r on the 11th position |
2266 | | * and uses \n as line ends |
2267 | | */ |
2268 | 5 | else |
2269 | 5 | { |
2270 | 5 | *format = LIBEWF_FORMAT_FTK_IMAGER; |
2271 | 5 | } |
2272 | 14 | } |
2273 | 141 | } |
2274 | 495 | } |
2275 | 1.75k | else if( type_string[ 0 ] == (uint8_t) 't' ) |
2276 | 856 | { |
2277 | 856 | identifier = (uint8_t *) "notes"; |
2278 | 856 | identifier_size = 6; |
2279 | 856 | } |
2280 | 11.9k | } |
2281 | | /* Ignore empty values |
2282 | | */ |
2283 | 18.6k | if( value_string == NULL ) |
2284 | 10.2k | { |
2285 | 10.2k | return( 1 ); |
2286 | 10.2k | } |
2287 | 8.31k | if( identifier != NULL ) |
2288 | 6.12k | { |
2289 | 6.12k | if( libewf_value_table_set_value_by_identifier( |
2290 | 6.12k | header_values, |
2291 | 6.12k | identifier, |
2292 | 6.12k | identifier_size, |
2293 | 6.12k | value_string, |
2294 | 6.12k | value_string_size, |
2295 | 6.12k | error ) != 1 ) |
2296 | 0 | { |
2297 | 0 | libcerror_error_set( |
2298 | 0 | error, |
2299 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2300 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2301 | 0 | "%s: unable to set header value: %s.", |
2302 | 0 | function, |
2303 | 0 | (char *) identifier ); |
2304 | |
|
2305 | 0 | goto on_error; |
2306 | 0 | } |
2307 | 6.12k | } |
2308 | 8.31k | if( date_time_values_string != NULL ) |
2309 | 1.65k | { |
2310 | 1.65k | memory_free( |
2311 | 1.65k | date_time_values_string ); |
2312 | | |
2313 | 1.65k | date_time_values_string = NULL; |
2314 | 1.65k | } |
2315 | 8.31k | return( 1 ); |
2316 | | |
2317 | 109 | on_error: |
2318 | 109 | if( date_time_values_string != NULL ) |
2319 | 0 | { |
2320 | 0 | memory_free( |
2321 | 0 | date_time_values_string ); |
2322 | 0 | } |
2323 | 109 | return( -1 ); |
2324 | 8.31k | } |
2325 | | |
2326 | | /* Parses EWF version 1 header for values |
2327 | | * Returns 1 if successful or -1 on error |
2328 | | */ |
2329 | | int libewf_header_values_parse_header( |
2330 | | libfvalue_table_t *header_values, |
2331 | | uint8_t *header, |
2332 | | size_t header_size, |
2333 | | int codepage, |
2334 | | uint8_t *format, |
2335 | | libcerror_error_t **error ) |
2336 | 397 | { |
2337 | 397 | uint8_t *header_string = NULL; |
2338 | 397 | static char *function = "libewf_header_values_parse_header"; |
2339 | 397 | size_t header_string_size = 0; |
2340 | | |
2341 | 397 | if( libuna_utf8_string_size_from_byte_stream( |
2342 | 397 | header, |
2343 | 397 | header_size, |
2344 | 397 | codepage, |
2345 | 397 | &header_string_size, |
2346 | 397 | error ) != 1 ) |
2347 | 0 | { |
2348 | 0 | libcerror_error_set( |
2349 | 0 | error, |
2350 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2351 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2352 | 0 | "%s: unable to determine header string size.", |
2353 | 0 | function ); |
2354 | |
|
2355 | 0 | goto on_error; |
2356 | 0 | } |
2357 | 397 | if( ( header_string_size == 0 ) |
2358 | 397 | || ( header_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
2359 | 1 | { |
2360 | 1 | libcerror_error_set( |
2361 | 1 | error, |
2362 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2363 | 1 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2364 | 1 | "%s: invalid header string size value out of bounds.", |
2365 | 1 | function ); |
2366 | | |
2367 | 1 | goto on_error; |
2368 | 1 | } |
2369 | 396 | header_string = (uint8_t *) memory_allocate( |
2370 | 396 | sizeof( uint8_t ) * header_string_size ); |
2371 | | |
2372 | 396 | if( header_string == NULL ) |
2373 | 0 | { |
2374 | 0 | libcerror_error_set( |
2375 | 0 | error, |
2376 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2377 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
2378 | 0 | "%s: unable to create header string.", |
2379 | 0 | function ); |
2380 | |
|
2381 | 0 | goto on_error; |
2382 | 0 | } |
2383 | 396 | if( libuna_utf8_string_copy_from_byte_stream( |
2384 | 396 | header_string, |
2385 | 396 | header_string_size, |
2386 | 396 | header, |
2387 | 396 | header_size, |
2388 | 396 | codepage, |
2389 | 396 | error ) != 1 ) |
2390 | 0 | { |
2391 | 0 | libcerror_error_set( |
2392 | 0 | error, |
2393 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2394 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
2395 | 0 | "%s: unable to set header string.", |
2396 | 0 | function ); |
2397 | |
|
2398 | 0 | goto on_error; |
2399 | 0 | } |
2400 | 396 | if( libewf_header_values_parse_utf8_header_string( |
2401 | 396 | header_values, |
2402 | 396 | header_string, |
2403 | 396 | header_string_size, |
2404 | 396 | 1, |
2405 | 396 | format, |
2406 | 396 | error ) != 1 ) |
2407 | 122 | { |
2408 | 122 | libcerror_error_set( |
2409 | 122 | error, |
2410 | 122 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2411 | 122 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2412 | 122 | "%s: unable to parse header string.", |
2413 | 122 | function ); |
2414 | | |
2415 | 122 | goto on_error; |
2416 | 122 | } |
2417 | 274 | memory_free( |
2418 | 274 | header_string ); |
2419 | | |
2420 | 274 | return( 1 ); |
2421 | | |
2422 | 123 | on_error: |
2423 | 123 | if( header_string != NULL ) |
2424 | 122 | { |
2425 | 122 | memory_free( |
2426 | 122 | header_string ); |
2427 | 122 | } |
2428 | 123 | return( -1 ); |
2429 | 396 | } |
2430 | | |
2431 | | /* Parses EWF version 1 header2 for values |
2432 | | * Returns 1 if successful or -1 on error |
2433 | | */ |
2434 | | int libewf_header_values_parse_header2( |
2435 | | libfvalue_table_t *header_values, |
2436 | | uint8_t *header2, |
2437 | | size_t header2_size, |
2438 | | uint8_t *format, |
2439 | | libcerror_error_t **error ) |
2440 | 682 | { |
2441 | 682 | uint8_t *header_string = NULL; |
2442 | 682 | static char *function = "libewf_header_values_parse_header2"; |
2443 | 682 | size_t header_string_size = 0; |
2444 | | |
2445 | 682 | if( libuna_utf8_string_size_from_utf16_stream( |
2446 | 682 | header2, |
2447 | 682 | header2_size, |
2448 | 682 | LIBUNA_ENDIAN_LITTLE, |
2449 | 682 | &header_string_size, |
2450 | 682 | error ) != 1 ) |
2451 | 50 | { |
2452 | 50 | libcerror_error_set( |
2453 | 50 | error, |
2454 | 50 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2455 | 50 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2456 | 50 | "%s: unable to determine header string size.", |
2457 | 50 | function ); |
2458 | | |
2459 | 50 | goto on_error; |
2460 | 50 | } |
2461 | 632 | if( ( header_string_size == 0 ) |
2462 | 632 | || ( header_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
2463 | 4 | { |
2464 | 4 | libcerror_error_set( |
2465 | 4 | error, |
2466 | 4 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2467 | 4 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2468 | 4 | "%s: invalid header string size value out of bounds.", |
2469 | 4 | function ); |
2470 | | |
2471 | 4 | goto on_error; |
2472 | 4 | } |
2473 | 628 | header_string = (uint8_t *) memory_allocate( |
2474 | 628 | sizeof( uint8_t ) * header_string_size ); |
2475 | | |
2476 | 628 | if( header_string == NULL ) |
2477 | 0 | { |
2478 | 0 | libcerror_error_set( |
2479 | 0 | error, |
2480 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2481 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
2482 | 0 | "%s: unable to create header string.", |
2483 | 0 | function ); |
2484 | |
|
2485 | 0 | goto on_error; |
2486 | 0 | } |
2487 | 628 | if( libuna_utf8_string_copy_from_utf16_stream( |
2488 | 628 | header_string, |
2489 | 628 | header_string_size, |
2490 | 628 | header2, |
2491 | 628 | header2_size, |
2492 | 628 | LIBUNA_ENDIAN_LITTLE, |
2493 | 628 | error ) != 1 ) |
2494 | 0 | { |
2495 | 0 | libcerror_error_set( |
2496 | 0 | error, |
2497 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2498 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
2499 | 0 | "%s: unable to set header string.", |
2500 | 0 | function ); |
2501 | |
|
2502 | 0 | goto on_error; |
2503 | 0 | } |
2504 | 628 | if( libewf_header_values_parse_utf8_header_string( |
2505 | 628 | header_values, |
2506 | 628 | header_string, |
2507 | 628 | header_string_size, |
2508 | 628 | 2, |
2509 | 628 | format, |
2510 | 628 | error ) != 1 ) |
2511 | 248 | { |
2512 | 248 | libcerror_error_set( |
2513 | 248 | error, |
2514 | 248 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2515 | 248 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2516 | 248 | "%s: unable to parse header string.", |
2517 | 248 | function ); |
2518 | | |
2519 | 248 | goto on_error; |
2520 | 248 | } |
2521 | 380 | memory_free( |
2522 | 380 | header_string ); |
2523 | | |
2524 | 380 | return( 1 ); |
2525 | | |
2526 | 302 | on_error: |
2527 | 302 | if( header_string != NULL ) |
2528 | 248 | { |
2529 | 248 | memory_free( |
2530 | 248 | header_string ); |
2531 | 248 | } |
2532 | 302 | return( -1 ); |
2533 | 628 | } |
2534 | | |
2535 | | /* Converts an UTF-8 encoded header string into a header |
2536 | | * Sets the header and header size |
2537 | | * Returns 1 if successful or -1 on error |
2538 | | */ |
2539 | | int libewf_header_values_convert_utf8_header_string_to_header( |
2540 | | const uint8_t *header_string, |
2541 | | size_t header_string_size, |
2542 | | uint8_t **header, |
2543 | | size_t *header_size, |
2544 | | int codepage, |
2545 | | libcerror_error_t **error ) |
2546 | 0 | { |
2547 | 0 | static char *function = "libewf_header_values_convert_utf8_header_string_to_header"; |
2548 | |
|
2549 | 0 | if( header_string == NULL ) |
2550 | 0 | { |
2551 | 0 | libcerror_error_set( |
2552 | 0 | error, |
2553 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2554 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2555 | 0 | "%s: invalid header string.", |
2556 | 0 | function ); |
2557 | |
|
2558 | 0 | return( -1 ); |
2559 | 0 | } |
2560 | 0 | if( header == NULL ) |
2561 | 0 | { |
2562 | 0 | libcerror_error_set( |
2563 | 0 | error, |
2564 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2565 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2566 | 0 | "%s: invalid header.", |
2567 | 0 | function ); |
2568 | |
|
2569 | 0 | return( -1 ); |
2570 | 0 | } |
2571 | 0 | if( *header != NULL ) |
2572 | 0 | { |
2573 | 0 | libcerror_error_set( |
2574 | 0 | error, |
2575 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2576 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
2577 | 0 | "%s: header already set.", |
2578 | 0 | function ); |
2579 | |
|
2580 | 0 | return( -1 ); |
2581 | 0 | } |
2582 | 0 | if( header_size == NULL ) |
2583 | 0 | { |
2584 | 0 | libcerror_error_set( |
2585 | 0 | error, |
2586 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2587 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2588 | 0 | "%s: invalid header size.", |
2589 | 0 | function ); |
2590 | |
|
2591 | 0 | return( -1 ); |
2592 | 0 | } |
2593 | 0 | if( libuna_byte_stream_size_from_utf8( |
2594 | 0 | header_string, |
2595 | 0 | header_string_size, |
2596 | 0 | codepage, |
2597 | 0 | header_size, |
2598 | 0 | error ) != 1 ) |
2599 | 0 | { |
2600 | 0 | libcerror_error_set( |
2601 | 0 | error, |
2602 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2603 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2604 | 0 | "%s: unable to determine header size.", |
2605 | 0 | function ); |
2606 | |
|
2607 | 0 | goto on_error; |
2608 | 0 | } |
2609 | 0 | if( ( *header_size == 0 ) |
2610 | 0 | || ( *header_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
2611 | 0 | { |
2612 | 0 | libcerror_error_set( |
2613 | 0 | error, |
2614 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2615 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2616 | 0 | "%s: invalid header size value out of bounds.", |
2617 | 0 | function ); |
2618 | |
|
2619 | 0 | goto on_error; |
2620 | 0 | } |
2621 | 0 | *header = (uint8_t *) memory_allocate( |
2622 | 0 | sizeof( uint8_t ) * *header_size ); |
2623 | |
|
2624 | 0 | if( *header == NULL ) |
2625 | 0 | { |
2626 | 0 | libcerror_error_set( |
2627 | 0 | error, |
2628 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2629 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
2630 | 0 | "%s: unable to create header.", |
2631 | 0 | function ); |
2632 | |
|
2633 | 0 | goto on_error; |
2634 | 0 | } |
2635 | 0 | if( libuna_byte_stream_copy_from_utf8( |
2636 | 0 | *header, |
2637 | 0 | *header_size, |
2638 | 0 | codepage, |
2639 | 0 | header_string, |
2640 | 0 | header_string_size, |
2641 | 0 | error ) != 1 ) |
2642 | 0 | { |
2643 | 0 | libcerror_error_set( |
2644 | 0 | error, |
2645 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2646 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2647 | 0 | "%s: unable to set header.", |
2648 | 0 | function ); |
2649 | |
|
2650 | 0 | goto on_error; |
2651 | 0 | } |
2652 | 0 | return( 1 ); |
2653 | | |
2654 | 0 | on_error: |
2655 | 0 | if( *header != NULL ) |
2656 | 0 | { |
2657 | 0 | memory_free( |
2658 | 0 | *header ); |
2659 | |
|
2660 | 0 | *header = NULL; |
2661 | 0 | } |
2662 | 0 | *header_size = 0; |
2663 | |
|
2664 | 0 | return( -1 ); |
2665 | 0 | } |
2666 | | |
2667 | | /* Generate an UTF-8 encoded header string |
2668 | | * Sets header string and header string size |
2669 | | * Returns 1 if successful or -1 on error |
2670 | | */ |
2671 | | int libewf_header_values_generate_utf8_header_string( |
2672 | | libfvalue_table_t *header_values, |
2673 | | uint8_t header_type, |
2674 | | uint8_t header_string_type, |
2675 | | uint8_t *newline_string, |
2676 | | size_t newline_string_length, |
2677 | | time_t timestamp, |
2678 | | int8_t compression_level, |
2679 | | uint8_t **utf8_string, |
2680 | | size_t *utf8_string_size, |
2681 | | libcerror_error_t **error ) |
2682 | 0 | { |
2683 | 0 | uint8_t *generated_acquiry_date = NULL; |
2684 | 0 | uint8_t *generated_system_date = NULL; |
2685 | 0 | uint8_t *safe_utf8_string = NULL; |
2686 | 0 | static char *function = "libewf_header_values_generate_utf8_header_string"; |
2687 | 0 | char *generated_compression_level = NULL; |
2688 | 0 | char *generated_extents = NULL; |
2689 | 0 | char *generated_password = NULL; |
2690 | 0 | char *generated_srce_section = NULL; |
2691 | 0 | char *generated_sub_section = NULL; |
2692 | 0 | size_t acquiry_date_string_length = 0; |
2693 | 0 | size_t acquiry_operating_system_string_length = 0; |
2694 | 0 | size_t acquiry_software_version_string_length = 0; |
2695 | 0 | size_t case_number_string_length = 0; |
2696 | 0 | size_t compression_level_string_length = 0; |
2697 | 0 | size_t description_string_length = 0; |
2698 | 0 | size_t device_label_string_length = 0; |
2699 | 0 | size_t evidence_number_string_length = 0; |
2700 | 0 | size_t examiner_name_string_length = 0; |
2701 | 0 | size_t extents_string_length = 0; |
2702 | 0 | size_t generated_acquiry_date_size = 0; |
2703 | 0 | size_t generated_system_date_size = 0; |
2704 | 0 | size_t model_string_length = 0; |
2705 | 0 | size_t notes_string_length = 0; |
2706 | 0 | size_t password_string_length = 0; |
2707 | 0 | size_t process_identifier_string_length = 0; |
2708 | 0 | size_t safe_utf8_string_size = 0; |
2709 | 0 | size_t serial_number_string_length = 0; |
2710 | 0 | size_t srce_section_string_length = 0; |
2711 | 0 | size_t sub_section_string_length = 0; |
2712 | 0 | size_t system_date_string_length = 0; |
2713 | 0 | size_t unknown_dc_string_length = 0; |
2714 | 0 | size_t utf8_string_index = 0; |
2715 | 0 | int number_of_characters = 0; |
2716 | 0 | int number_of_tabs = 0; |
2717 | 0 | int result = 0; |
2718 | |
|
2719 | 0 | if( ( header_type != 1 ) |
2720 | 0 | && ( header_type != 2 ) ) |
2721 | 0 | { |
2722 | 0 | libcerror_error_set( |
2723 | 0 | error, |
2724 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2725 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
2726 | 0 | "%s: unsupported header type.", |
2727 | 0 | function ); |
2728 | |
|
2729 | 0 | return( -1 ); |
2730 | 0 | } |
2731 | 0 | if( ( header_string_type != LIBEWF_HEADER_STRING_TYPE_1 ) |
2732 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_2 ) |
2733 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_3 ) |
2734 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_4 ) |
2735 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_5 ) |
2736 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_6 ) |
2737 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_7 ) |
2738 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_8 ) |
2739 | 0 | && ( header_string_type != LIBEWF_HEADER_STRING_TYPE_9 ) ) |
2740 | 0 | { |
2741 | 0 | libcerror_error_set( |
2742 | 0 | error, |
2743 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2744 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
2745 | 0 | "%s: unsupported header string type.", |
2746 | 0 | function ); |
2747 | |
|
2748 | 0 | return( -1 ); |
2749 | 0 | } |
2750 | 0 | if( newline_string == NULL ) |
2751 | 0 | { |
2752 | 0 | libcerror_error_set( |
2753 | 0 | error, |
2754 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2755 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2756 | 0 | "%s: invalid newline string.", |
2757 | 0 | function ); |
2758 | |
|
2759 | 0 | return( -1 ); |
2760 | 0 | } |
2761 | 0 | if( ( newline_string_length != 1 ) |
2762 | 0 | && ( newline_string_length != 2 ) ) |
2763 | 0 | { |
2764 | 0 | libcerror_error_set( |
2765 | 0 | error, |
2766 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2767 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
2768 | 0 | "%s: unsupported newline string length.", |
2769 | 0 | function ); |
2770 | |
|
2771 | 0 | return( -1 ); |
2772 | 0 | } |
2773 | 0 | if( ( compression_level != LIBEWF_COMPRESSION_LEVEL_DEFAULT ) |
2774 | 0 | && ( compression_level != LIBEWF_COMPRESSION_LEVEL_NONE ) |
2775 | 0 | && ( compression_level != LIBEWF_COMPRESSION_LEVEL_FAST ) |
2776 | 0 | && ( compression_level != LIBEWF_COMPRESSION_LEVEL_BEST ) ) |
2777 | 0 | { |
2778 | 0 | libcerror_error_set( |
2779 | 0 | error, |
2780 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2781 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
2782 | 0 | "%s: unsupported compression level.", |
2783 | 0 | function ); |
2784 | |
|
2785 | 0 | return( -1 ); |
2786 | 0 | } |
2787 | 0 | if( utf8_string == NULL ) |
2788 | 0 | { |
2789 | 0 | libcerror_error_set( |
2790 | 0 | error, |
2791 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2792 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2793 | 0 | "%s: invalid UTF-8 string.", |
2794 | 0 | function ); |
2795 | |
|
2796 | 0 | return( -1 ); |
2797 | 0 | } |
2798 | 0 | if( *utf8_string != NULL ) |
2799 | 0 | { |
2800 | 0 | libcerror_error_set( |
2801 | 0 | error, |
2802 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2803 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
2804 | 0 | "%s: UTF-8 string already set.", |
2805 | 0 | function ); |
2806 | |
|
2807 | 0 | return( -1 ); |
2808 | 0 | } |
2809 | 0 | if( utf8_string_size == NULL ) |
2810 | 0 | { |
2811 | 0 | libcerror_error_set( |
2812 | 0 | error, |
2813 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2814 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2815 | 0 | "%s: invalid UTF-8 string size.", |
2816 | 0 | function ); |
2817 | |
|
2818 | 0 | return( -1 ); |
2819 | 0 | } |
2820 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2821 | 0 | header_values, |
2822 | 0 | (uint8_t *) "case_number", |
2823 | 0 | 12, |
2824 | 0 | &case_number_string_length, |
2825 | 0 | error ) == -1 ) |
2826 | 0 | { |
2827 | 0 | libcerror_error_set( |
2828 | 0 | error, |
2829 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2830 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2831 | 0 | "%s: unable to retrieve header value: case_number length.", |
2832 | 0 | function ); |
2833 | |
|
2834 | 0 | goto on_error; |
2835 | 0 | } |
2836 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2837 | 0 | header_values, |
2838 | 0 | (uint8_t *) "description", |
2839 | 0 | 12, |
2840 | 0 | &description_string_length, |
2841 | 0 | error ) == -1 ) |
2842 | 0 | { |
2843 | 0 | libcerror_error_set( |
2844 | 0 | error, |
2845 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2846 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2847 | 0 | "%s: unable to retrieve header value: description length.", |
2848 | 0 | function ); |
2849 | |
|
2850 | 0 | goto on_error; |
2851 | 0 | } |
2852 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2853 | 0 | header_values, |
2854 | 0 | (uint8_t *) "examiner_name", |
2855 | 0 | 14, |
2856 | 0 | &examiner_name_string_length, |
2857 | 0 | error ) == -1 ) |
2858 | 0 | { |
2859 | 0 | libcerror_error_set( |
2860 | 0 | error, |
2861 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2862 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2863 | 0 | "%s: unable to retrieve header value: examiner_name length.", |
2864 | 0 | function ); |
2865 | |
|
2866 | 0 | goto on_error; |
2867 | 0 | } |
2868 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2869 | 0 | header_values, |
2870 | 0 | (uint8_t *) "evidence_number", |
2871 | 0 | 16, |
2872 | 0 | &evidence_number_string_length, |
2873 | 0 | error ) == -1 ) |
2874 | 0 | { |
2875 | 0 | libcerror_error_set( |
2876 | 0 | error, |
2877 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2878 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2879 | 0 | "%s: unable to retrieve header value: evidence_number length.", |
2880 | 0 | function ); |
2881 | |
|
2882 | 0 | goto on_error; |
2883 | 0 | } |
2884 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2885 | 0 | header_values, |
2886 | 0 | (uint8_t *) "notes", |
2887 | 0 | 6, |
2888 | 0 | ¬es_string_length, |
2889 | 0 | error ) == -1 ) |
2890 | 0 | { |
2891 | 0 | libcerror_error_set( |
2892 | 0 | error, |
2893 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2894 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2895 | 0 | "%s: unable to retrieve header value: notes length.", |
2896 | 0 | function ); |
2897 | |
|
2898 | 0 | goto on_error; |
2899 | 0 | } |
2900 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2901 | 0 | header_values, |
2902 | 0 | (uint8_t *) "acquiry_date", |
2903 | 0 | 13, |
2904 | 0 | &acquiry_date_string_length, |
2905 | 0 | error ) == -1 ) |
2906 | 0 | { |
2907 | 0 | libcerror_error_set( |
2908 | 0 | error, |
2909 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2910 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2911 | 0 | "%s: unable to retrieve header value: acquiry_date length.", |
2912 | 0 | function ); |
2913 | |
|
2914 | 0 | goto on_error; |
2915 | 0 | } |
2916 | 0 | if( acquiry_date_string_length == 0 ) |
2917 | 0 | { |
2918 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
2919 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
2920 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) ) |
2921 | 0 | { |
2922 | 0 | result = libewf_generate_date_header_value( |
2923 | 0 | timestamp, |
2924 | 0 | &generated_acquiry_date, |
2925 | 0 | &generated_acquiry_date_size, |
2926 | 0 | error ); |
2927 | 0 | } |
2928 | 0 | else |
2929 | 0 | { |
2930 | 0 | result = libewf_generate_date_header2_value( |
2931 | 0 | timestamp, |
2932 | 0 | &generated_acquiry_date, |
2933 | 0 | &generated_acquiry_date_size, |
2934 | 0 | error ); |
2935 | 0 | } |
2936 | 0 | if( result != 1 ) |
2937 | 0 | { |
2938 | 0 | libcerror_error_set( |
2939 | 0 | error, |
2940 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2941 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2942 | 0 | "%s: unable to generate acquiry date header value.", |
2943 | 0 | function ); |
2944 | |
|
2945 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2946 | | if( libcnotify_verbose != 0 ) |
2947 | | { |
2948 | | if( ( error != NULL ) |
2949 | | && ( *error != NULL ) ) |
2950 | | { |
2951 | | libcnotify_print_error_backtrace( |
2952 | | *error ); |
2953 | | } |
2954 | | } |
2955 | | #endif |
2956 | 0 | libcerror_error_free( |
2957 | 0 | error ); |
2958 | 0 | } |
2959 | 0 | else |
2960 | 0 | { |
2961 | | /* Make sure to determine the actual length of the date time values string |
2962 | | */ |
2963 | 0 | acquiry_date_string_length = narrow_string_length( |
2964 | 0 | (char *) generated_acquiry_date ); |
2965 | 0 | } |
2966 | 0 | } |
2967 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
2968 | 0 | header_values, |
2969 | 0 | (uint8_t *) "system_date", |
2970 | 0 | 12, |
2971 | 0 | &system_date_string_length, |
2972 | 0 | error ) == -1 ) |
2973 | 0 | { |
2974 | 0 | libcerror_error_set( |
2975 | 0 | error, |
2976 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2977 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2978 | 0 | "%s: unable to retrieve header value: system_date length.", |
2979 | 0 | function ); |
2980 | |
|
2981 | 0 | goto on_error; |
2982 | 0 | } |
2983 | 0 | if( system_date_string_length == 0 ) |
2984 | 0 | { |
2985 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
2986 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
2987 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) ) |
2988 | 0 | { |
2989 | 0 | result = libewf_generate_date_header_value( |
2990 | 0 | timestamp, |
2991 | 0 | &generated_system_date, |
2992 | 0 | &generated_system_date_size, |
2993 | 0 | error ); |
2994 | 0 | } |
2995 | 0 | else |
2996 | 0 | { |
2997 | 0 | result = libewf_generate_date_header2_value( |
2998 | 0 | timestamp, |
2999 | 0 | &generated_system_date, |
3000 | 0 | &generated_system_date_size, |
3001 | 0 | error ); |
3002 | 0 | } |
3003 | 0 | if( result != 1 ) |
3004 | 0 | { |
3005 | 0 | libcerror_error_set( |
3006 | 0 | error, |
3007 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3008 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3009 | 0 | "%s: unable to generate system date header value.", |
3010 | 0 | function ); |
3011 | |
|
3012 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
3013 | | if( libcnotify_verbose != 0 ) |
3014 | | { |
3015 | | if( ( error != NULL ) |
3016 | | && ( *error != NULL ) ) |
3017 | | { |
3018 | | libcnotify_print_error_backtrace( |
3019 | | *error ); |
3020 | | } |
3021 | | } |
3022 | | #endif |
3023 | 0 | libcerror_error_free( |
3024 | 0 | error ); |
3025 | 0 | } |
3026 | 0 | else |
3027 | 0 | { |
3028 | | /* Make sure to determine the actual length of the date time values string |
3029 | | */ |
3030 | 0 | system_date_string_length = narrow_string_length( |
3031 | 0 | (char *) generated_system_date ); |
3032 | 0 | } |
3033 | 0 | } |
3034 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3035 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) |
3036 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) |
3037 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3038 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3039 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3040 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3041 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3042 | 0 | { |
3043 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3044 | 0 | header_values, |
3045 | 0 | (uint8_t *) "acquiry_software_version", |
3046 | 0 | 25, |
3047 | 0 | &acquiry_software_version_string_length, |
3048 | 0 | error ) == -1 ) |
3049 | 0 | { |
3050 | 0 | libcerror_error_set( |
3051 | 0 | error, |
3052 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3053 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3054 | 0 | "%s: unable to retrieve header value: acquiry_software_version length.", |
3055 | 0 | function ); |
3056 | |
|
3057 | 0 | goto on_error; |
3058 | 0 | } |
3059 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3060 | 0 | header_values, |
3061 | 0 | (uint8_t *) "acquiry_operating_system", |
3062 | 0 | 25, |
3063 | 0 | &acquiry_operating_system_string_length, |
3064 | 0 | error ) == -1 ) |
3065 | 0 | { |
3066 | 0 | libcerror_error_set( |
3067 | 0 | error, |
3068 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3069 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3070 | 0 | "%s: unable to retrieve header value: acquiry_operating_system length.", |
3071 | 0 | function ); |
3072 | |
|
3073 | 0 | goto on_error; |
3074 | 0 | } |
3075 | 0 | } |
3076 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3077 | 0 | header_values, |
3078 | 0 | (uint8_t *) "password", |
3079 | 0 | 9, |
3080 | 0 | &password_string_length, |
3081 | 0 | error ) == -1 ) |
3082 | 0 | { |
3083 | 0 | libcerror_error_set( |
3084 | 0 | error, |
3085 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3086 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3087 | 0 | "%s: unable to retrieve header value: password length.", |
3088 | 0 | function ); |
3089 | |
|
3090 | 0 | goto on_error; |
3091 | 0 | } |
3092 | 0 | if( ( password_string_length == 0 ) |
3093 | 0 | && ( header_type == 1 ) ) |
3094 | 0 | { |
3095 | 0 | generated_password = "0"; |
3096 | |
|
3097 | 0 | password_string_length = 1; |
3098 | 0 | } |
3099 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
3100 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) ) |
3101 | 0 | { |
3102 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3103 | 0 | header_values, |
3104 | 0 | (uint8_t *) "compression_level", |
3105 | 0 | 18, |
3106 | 0 | &compression_level_string_length, |
3107 | 0 | error ) == -1 ) |
3108 | 0 | { |
3109 | 0 | libcerror_error_set( |
3110 | 0 | error, |
3111 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3112 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3113 | 0 | "%s: unable to retrieve header value: compression_level length.", |
3114 | 0 | function ); |
3115 | |
|
3116 | 0 | goto on_error; |
3117 | 0 | } |
3118 | 0 | if( compression_level_string_length == 0 ) |
3119 | 0 | { |
3120 | 0 | if( ( compression_level == LIBEWF_COMPRESSION_LEVEL_DEFAULT ) |
3121 | 0 | || ( compression_level == LIBEWF_COMPRESSION_LEVEL_NONE ) ) |
3122 | 0 | { |
3123 | 0 | generated_compression_level = LIBEWF_HEADER_VALUE_COMPRESSION_LEVEL_NONE; |
3124 | 0 | } |
3125 | 0 | else if( compression_level == LIBEWF_COMPRESSION_LEVEL_FAST ) |
3126 | 0 | { |
3127 | 0 | generated_compression_level = LIBEWF_HEADER_VALUE_COMPRESSION_LEVEL_FAST; |
3128 | 0 | } |
3129 | 0 | else if( compression_level == LIBEWF_COMPRESSION_LEVEL_BEST ) |
3130 | 0 | { |
3131 | 0 | generated_compression_level = LIBEWF_HEADER_VALUE_COMPRESSION_LEVEL_BEST; |
3132 | 0 | } |
3133 | 0 | compression_level_string_length = narrow_string_length( |
3134 | 0 | generated_compression_level ); |
3135 | 0 | } |
3136 | 0 | } |
3137 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3138 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3139 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3140 | 0 | { |
3141 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3142 | 0 | header_values, |
3143 | 0 | (uint8_t *) "model", |
3144 | 0 | 6, |
3145 | 0 | &model_string_length, |
3146 | 0 | error ) == -1 ) |
3147 | 0 | { |
3148 | 0 | libcerror_error_set( |
3149 | 0 | error, |
3150 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3151 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3152 | 0 | "%s: unable to retrieve header value: model length.", |
3153 | 0 | function ); |
3154 | |
|
3155 | 0 | goto on_error; |
3156 | 0 | } |
3157 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3158 | 0 | header_values, |
3159 | 0 | (uint8_t *) "serial_number", |
3160 | 0 | 14, |
3161 | 0 | &serial_number_string_length, |
3162 | 0 | error ) == -1 ) |
3163 | 0 | { |
3164 | 0 | libcerror_error_set( |
3165 | 0 | error, |
3166 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3167 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3168 | 0 | "%s: unable to retrieve header value: serial_number length.", |
3169 | 0 | function ); |
3170 | |
|
3171 | 0 | goto on_error; |
3172 | 0 | } |
3173 | 0 | } |
3174 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3175 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3176 | 0 | { |
3177 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3178 | 0 | header_values, |
3179 | 0 | (uint8_t *) "device_label", |
3180 | 0 | 13, |
3181 | 0 | &device_label_string_length, |
3182 | 0 | error ) == -1 ) |
3183 | 0 | { |
3184 | 0 | libcerror_error_set( |
3185 | 0 | error, |
3186 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3187 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3188 | 0 | "%s: unable to retrieve header value: device_label length.", |
3189 | 0 | function ); |
3190 | |
|
3191 | 0 | goto on_error; |
3192 | 0 | } |
3193 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3194 | 0 | header_values, |
3195 | 0 | (uint8_t *) "process_identifier", |
3196 | 0 | 19, |
3197 | 0 | &process_identifier_string_length, |
3198 | 0 | error ) == -1 ) |
3199 | 0 | { |
3200 | 0 | libcerror_error_set( |
3201 | 0 | error, |
3202 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3203 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3204 | 0 | "%s: unable to retrieve header value: process_identifier length.", |
3205 | 0 | function ); |
3206 | |
|
3207 | 0 | goto on_error; |
3208 | 0 | } |
3209 | 0 | } |
3210 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3211 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3212 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3213 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3214 | 0 | { |
3215 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3216 | 0 | header_values, |
3217 | 0 | (uint8_t *) "unknown_dc", |
3218 | 0 | 11, |
3219 | 0 | &unknown_dc_string_length, |
3220 | 0 | error ) == -1 ) |
3221 | 0 | { |
3222 | 0 | libcerror_error_set( |
3223 | 0 | error, |
3224 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3225 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3226 | 0 | "%s: unable to retrieve header value: unknown_dc length.", |
3227 | 0 | function ); |
3228 | |
|
3229 | 0 | goto on_error; |
3230 | 0 | } |
3231 | 0 | } |
3232 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3233 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3234 | 0 | { |
3235 | 0 | if( libewf_value_table_get_value_utf8_string_length( |
3236 | 0 | header_values, |
3237 | 0 | (uint8_t *) "extents", |
3238 | 0 | 8, |
3239 | 0 | &extents_string_length, |
3240 | 0 | error ) == -1 ) |
3241 | 0 | { |
3242 | 0 | libcerror_error_set( |
3243 | 0 | error, |
3244 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3245 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3246 | 0 | "%s: unable to retrieve header value: extents length.", |
3247 | 0 | function ); |
3248 | |
|
3249 | 0 | goto on_error; |
3250 | 0 | } |
3251 | 0 | if( extents_string_length == 0 ) |
3252 | 0 | { |
3253 | 0 | generated_extents = "0"; |
3254 | |
|
3255 | 0 | extents_string_length = 1; |
3256 | 0 | } |
3257 | 0 | } |
3258 | | /* Determine the string size |
3259 | | * Reserve space for: |
3260 | | * # <newline> |
3261 | | * main <newline> |
3262 | | */ |
3263 | 0 | safe_utf8_string_size = 5 + ( 2 * newline_string_length ); |
3264 | |
|
3265 | 0 | switch( header_string_type ) |
3266 | 0 | { |
3267 | 0 | case LIBEWF_HEADER_STRING_TYPE_1: |
3268 | | /* Reserve space for: |
3269 | | * c <tab> n <tab> a <tab> e <tab> t <tab> m <tab> u <tab> p <tab> r <newline> |
3270 | | */ |
3271 | 0 | number_of_characters = 9; |
3272 | 0 | number_of_tabs = 8; |
3273 | 0 | break; |
3274 | | |
3275 | 0 | case LIBEWF_HEADER_STRING_TYPE_2: |
3276 | | /* Reserve space for: |
3277 | | * c <tab> n <tab> a <tab> e <tab> t <tab> av <tab> ov <tab> m <tab> u <tab> p <tab> r <newline> |
3278 | | */ |
3279 | 0 | number_of_characters = 13; |
3280 | 0 | number_of_tabs = 10; |
3281 | 0 | break; |
3282 | | |
3283 | 0 | case LIBEWF_HEADER_STRING_TYPE_3: |
3284 | | /* Reserve space for: |
3285 | | * c <tab> n <tab> a <tab> e <tab> t <tab> av <tab> ov <tab> m <tab> u <tab> p <newline> |
3286 | | */ |
3287 | 0 | number_of_characters = 12; |
3288 | 0 | number_of_tabs = 9; |
3289 | 0 | break; |
3290 | | |
3291 | 0 | case LIBEWF_HEADER_STRING_TYPE_4: |
3292 | 0 | case LIBEWF_HEADER_STRING_TYPE_7: |
3293 | | /* Reserve space for: |
3294 | | * a <tab> c <tab> n <tab> e <tab> t <tab> av <tab> ov <tab> m <tab> u <tab> p <newline> |
3295 | | */ |
3296 | 0 | number_of_characters = 12; |
3297 | 0 | number_of_tabs = 9; |
3298 | 0 | break; |
3299 | | |
3300 | 0 | case LIBEWF_HEADER_STRING_TYPE_5: |
3301 | | /* Reserve space for: |
3302 | | * a <tab> c <tab> n <tab> e <tab> t <tab> av <tab> ov <tab> m <tab> u <tab> p <tab> dc <newline> |
3303 | | */ |
3304 | 0 | number_of_characters = 14; |
3305 | 0 | number_of_tabs = 10; |
3306 | 0 | break; |
3307 | | |
3308 | 0 | case LIBEWF_HEADER_STRING_TYPE_6: |
3309 | | /* Reserve space for: |
3310 | | * a <tab> c <tab> n <tab> e <tab> t <tab> md <tab> sn <tab> av <tab> ov <tab> m <tab> u <tab> p <tab> dc <newline> |
3311 | | */ |
3312 | 0 | number_of_characters = 18; |
3313 | 0 | number_of_tabs = 12; |
3314 | 0 | break; |
3315 | | |
3316 | 0 | case LIBEWF_HEADER_STRING_TYPE_8: |
3317 | 0 | case LIBEWF_HEADER_STRING_TYPE_9: |
3318 | | /* Reserve space for: |
3319 | | * a <tab> c <tab> n <tab> e <tab> t <tab> md <tab> sn <tab> l <tab> av <tab> ov <tab> m <tab> u <tab> p <tab> pid <tab> dc <tab> ext <newline> |
3320 | | */ |
3321 | 0 | number_of_characters = 25; |
3322 | 0 | number_of_tabs = 15; |
3323 | 0 | break; |
3324 | 0 | } |
3325 | 0 | safe_utf8_string_size += number_of_characters + number_of_tabs + newline_string_length; |
3326 | | |
3327 | | /* Reserve space for the values |
3328 | | */ |
3329 | 0 | safe_utf8_string_size += case_number_string_length |
3330 | 0 | + description_string_length |
3331 | 0 | + examiner_name_string_length |
3332 | 0 | + evidence_number_string_length |
3333 | 0 | + notes_string_length |
3334 | 0 | + acquiry_date_string_length |
3335 | 0 | + system_date_string_length; |
3336 | |
|
3337 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3338 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) |
3339 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) |
3340 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3341 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3342 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3343 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3344 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3345 | 0 | { |
3346 | 0 | safe_utf8_string_size += acquiry_software_version_string_length |
3347 | 0 | + acquiry_operating_system_string_length; |
3348 | 0 | } |
3349 | 0 | safe_utf8_string_size += password_string_length; |
3350 | |
|
3351 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
3352 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) ) |
3353 | 0 | { |
3354 | 0 | safe_utf8_string_size += compression_level_string_length; |
3355 | 0 | } |
3356 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3357 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3358 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3359 | 0 | { |
3360 | 0 | safe_utf8_string_size += model_string_length |
3361 | 0 | + serial_number_string_length; |
3362 | 0 | } |
3363 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3364 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3365 | 0 | { |
3366 | 0 | safe_utf8_string_size += device_label_string_length |
3367 | 0 | + process_identifier_string_length; |
3368 | 0 | } |
3369 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3370 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3371 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3372 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3373 | 0 | { |
3374 | 0 | safe_utf8_string_size += unknown_dc_string_length; |
3375 | 0 | } |
3376 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3377 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3378 | 0 | { |
3379 | 0 | safe_utf8_string_size += extents_string_length; |
3380 | 0 | } |
3381 | | /* Reserve space for the tabs and 2 newlines |
3382 | | */ |
3383 | 0 | safe_utf8_string_size += number_of_tabs + ( 2 * newline_string_length ); |
3384 | | |
3385 | | /* Reserve space for additional sections |
3386 | | */ |
3387 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3388 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3389 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) ) |
3390 | 0 | { |
3391 | 0 | generated_srce_section = "srce\n" |
3392 | 0 | "0\t1\n" |
3393 | 0 | "p\tn\tid\tev\ttb\tlo\tpo\tah\tgu\taq\n" |
3394 | 0 | "0\t0\n" |
3395 | 0 | "\t\t\t\t\t-1\t-1\t\t\t\n" |
3396 | 0 | "\n"; |
3397 | |
|
3398 | 0 | srce_section_string_length = narrow_string_length( |
3399 | 0 | generated_srce_section ); |
3400 | |
|
3401 | 0 | safe_utf8_string_size += srce_section_string_length; |
3402 | 0 | } |
3403 | 0 | else if( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3404 | 0 | { |
3405 | 0 | generated_srce_section = "srce\n" |
3406 | 0 | "0\t1\n" |
3407 | 0 | "p\tn\tid\tev\ttb\tlo\tpo\tah\tsh\tgu\taq\n" |
3408 | 0 | "0\t0\n" |
3409 | 0 | "\t\t\t\t\t-1\t-1\t00000000000000000000000000000000\t0000000000000000000000000000000000000000\t00000000000000000000000000000000\t\n" |
3410 | 0 | "\n"; |
3411 | |
|
3412 | 0 | srce_section_string_length = narrow_string_length( |
3413 | 0 | generated_srce_section ); |
3414 | |
|
3415 | 0 | safe_utf8_string_size += srce_section_string_length; |
3416 | 0 | } |
3417 | 0 | else if( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) |
3418 | 0 | { |
3419 | 0 | generated_srce_section = "srce\n" |
3420 | 0 | "0\t1\n" |
3421 | 0 | "p\tn\tid\tev\ttb\tlo\tpo\tah\tsh\tgu\tpgu\taq\n" |
3422 | 0 | "0\t0\n" |
3423 | 0 | "\t\t\t\t\t-1\t-1\t00000000000000000000000000000000\t0000000000000000000000000000000000000000\t00000000000000000000000000000000\t00000000000000000000000000000000\t\n" |
3424 | 0 | "\n"; |
3425 | |
|
3426 | 0 | srce_section_string_length = narrow_string_length( |
3427 | 0 | generated_srce_section ); |
3428 | |
|
3429 | 0 | safe_utf8_string_size += srce_section_string_length; |
3430 | 0 | } |
3431 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3432 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3433 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) ) |
3434 | 0 | { |
3435 | | /* Note that the trailing after the co value is intentional |
3436 | | */ |
3437 | 0 | generated_sub_section = "sub\n" |
3438 | 0 | "0\t1\n" |
3439 | 0 | "p\tn\tid\tnu\tco\tgu\n" |
3440 | 0 | "0\t0\n" |
3441 | 0 | "\t\t\t\t1 \t\n" |
3442 | 0 | "\n"; |
3443 | |
|
3444 | 0 | sub_section_string_length = narrow_string_length( |
3445 | 0 | generated_sub_section ); |
3446 | |
|
3447 | 0 | safe_utf8_string_size += sub_section_string_length; |
3448 | 0 | } |
3449 | 0 | else if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3450 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3451 | 0 | { |
3452 | | /* Note that the trailing after the co value is intentional |
3453 | | */ |
3454 | 0 | generated_sub_section = "sub\n" |
3455 | 0 | "0\t1\n" |
3456 | 0 | "p\tn\tid\tnu\tco\tgu\n" |
3457 | 0 | "0\t0\n" |
3458 | 0 | "\t\t\t\t1 \t00000000000000000000000000000000\n" |
3459 | 0 | "\n"; |
3460 | |
|
3461 | 0 | sub_section_string_length = narrow_string_length( |
3462 | 0 | generated_sub_section ); |
3463 | |
|
3464 | 0 | safe_utf8_string_size += sub_section_string_length; |
3465 | 0 | } |
3466 | | /* Reserve space for the end-of-string character |
3467 | | */ |
3468 | 0 | safe_utf8_string_size += 1; |
3469 | |
|
3470 | 0 | if( safe_utf8_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) |
3471 | 0 | { |
3472 | 0 | libcerror_error_set( |
3473 | 0 | error, |
3474 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3475 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3476 | 0 | "%s: invalid UTF-8 string size value out of bounds.", |
3477 | 0 | function ); |
3478 | |
|
3479 | 0 | goto on_error; |
3480 | 0 | } |
3481 | | /* Determine the string |
3482 | | */ |
3483 | 0 | safe_utf8_string = (uint8_t *) memory_allocate( |
3484 | 0 | sizeof( uint8_t ) * safe_utf8_string_size ); |
3485 | |
|
3486 | 0 | if( safe_utf8_string == NULL ) |
3487 | 0 | { |
3488 | 0 | libcerror_error_set( |
3489 | 0 | error, |
3490 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
3491 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
3492 | 0 | "%s: unable to create UTF-8 string.", |
3493 | 0 | function ); |
3494 | |
|
3495 | 0 | goto on_error; |
3496 | 0 | } |
3497 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
3498 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3499 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) |
3500 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) ) |
3501 | 0 | { |
3502 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '1'; |
3503 | 0 | } |
3504 | 0 | else if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3505 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3506 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3507 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3508 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3509 | 0 | { |
3510 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '3'; |
3511 | 0 | } |
3512 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ]; |
3513 | |
|
3514 | 0 | if( newline_string_length == 2 ) |
3515 | 0 | { |
3516 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ]; |
3517 | 0 | } |
3518 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'm'; |
3519 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a'; |
3520 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'i'; |
3521 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n'; |
3522 | |
|
3523 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ]; |
3524 | |
|
3525 | 0 | if( newline_string_length == 2 ) |
3526 | 0 | { |
3527 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ]; |
3528 | 0 | } |
3529 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) |
3530 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3531 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3532 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3533 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3534 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3535 | 0 | { |
3536 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a'; |
3537 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3538 | 0 | } |
3539 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'c'; |
3540 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3541 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n'; |
3542 | |
|
3543 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
3544 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3545 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) ) |
3546 | 0 | { |
3547 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3548 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a'; |
3549 | 0 | } |
3550 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3551 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'e'; |
3552 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3553 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't'; |
3554 | |
|
3555 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3556 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3557 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3558 | 0 | { |
3559 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3560 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'm'; |
3561 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'd'; |
3562 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3563 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 's'; |
3564 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n'; |
3565 | 0 | } |
3566 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3567 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3568 | 0 | { |
3569 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3570 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'l'; |
3571 | 0 | } |
3572 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3573 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) |
3574 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) |
3575 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3576 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3577 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3578 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3579 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3580 | 0 | { |
3581 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3582 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a'; |
3583 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'v'; |
3584 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3585 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'o'; |
3586 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'v'; |
3587 | 0 | } |
3588 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3589 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'm'; |
3590 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3591 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'u'; |
3592 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3593 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'p'; |
3594 | |
|
3595 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
3596 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) ) |
3597 | 0 | { |
3598 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3599 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'r'; |
3600 | 0 | } |
3601 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3602 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3603 | 0 | { |
3604 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3605 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'p'; |
3606 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'i'; |
3607 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'd'; |
3608 | 0 | } |
3609 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3610 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3611 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3612 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3613 | 0 | { |
3614 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3615 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'd'; |
3616 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'c'; |
3617 | 0 | } |
3618 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3619 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3620 | 0 | { |
3621 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3622 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'e'; |
3623 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'x'; |
3624 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't'; |
3625 | 0 | } |
3626 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ]; |
3627 | |
|
3628 | 0 | if( newline_string_length == 2 ) |
3629 | 0 | { |
3630 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ]; |
3631 | 0 | } |
3632 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) |
3633 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3634 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3635 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3636 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3637 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3638 | 0 | { |
3639 | 0 | if( description_string_length > 0 ) |
3640 | 0 | { |
3641 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3642 | 0 | header_values, |
3643 | 0 | (uint8_t *) "description", |
3644 | 0 | 12, |
3645 | 0 | safe_utf8_string, |
3646 | 0 | safe_utf8_string_size, |
3647 | 0 | &utf8_string_index, |
3648 | 0 | error ) != 1 ) |
3649 | 0 | { |
3650 | 0 | libcerror_error_set( |
3651 | 0 | error, |
3652 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3653 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3654 | 0 | "%s: unable to copy header value: case_number to string.", |
3655 | 0 | function ); |
3656 | |
|
3657 | 0 | goto on_error; |
3658 | 0 | } |
3659 | 0 | } |
3660 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3661 | 0 | } |
3662 | 0 | if( case_number_string_length > 0 ) |
3663 | 0 | { |
3664 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3665 | 0 | header_values, |
3666 | 0 | (uint8_t *) "case_number", |
3667 | 0 | 12, |
3668 | 0 | safe_utf8_string, |
3669 | 0 | safe_utf8_string_size, |
3670 | 0 | &utf8_string_index, |
3671 | 0 | error ) != 1 ) |
3672 | 0 | { |
3673 | 0 | libcerror_error_set( |
3674 | 0 | error, |
3675 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3676 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3677 | 0 | "%s: unable to copy header value: case_number to string.", |
3678 | 0 | function ); |
3679 | |
|
3680 | 0 | goto on_error; |
3681 | 0 | } |
3682 | 0 | } |
3683 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3684 | |
|
3685 | 0 | if( evidence_number_string_length > 0 ) |
3686 | 0 | { |
3687 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3688 | 0 | header_values, |
3689 | 0 | (uint8_t *) "evidence_number", |
3690 | 0 | 16, |
3691 | 0 | safe_utf8_string, |
3692 | 0 | safe_utf8_string_size, |
3693 | 0 | &utf8_string_index, |
3694 | 0 | error ) != 1 ) |
3695 | 0 | { |
3696 | 0 | libcerror_error_set( |
3697 | 0 | error, |
3698 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3699 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3700 | 0 | "%s: unable to copy header value: evidence_number to string.", |
3701 | 0 | function ); |
3702 | |
|
3703 | 0 | goto on_error; |
3704 | 0 | } |
3705 | 0 | } |
3706 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
3707 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3708 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) ) |
3709 | 0 | { |
3710 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3711 | |
|
3712 | 0 | if( description_string_length > 0 ) |
3713 | 0 | { |
3714 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3715 | 0 | header_values, |
3716 | 0 | (uint8_t *) "description", |
3717 | 0 | 12, |
3718 | 0 | safe_utf8_string, |
3719 | 0 | safe_utf8_string_size, |
3720 | 0 | &utf8_string_index, |
3721 | 0 | error ) != 1 ) |
3722 | 0 | { |
3723 | 0 | libcerror_error_set( |
3724 | 0 | error, |
3725 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3726 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3727 | 0 | "%s: unable to copy header value: case_number to string.", |
3728 | 0 | function ); |
3729 | |
|
3730 | 0 | goto on_error; |
3731 | 0 | } |
3732 | 0 | } |
3733 | 0 | } |
3734 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3735 | |
|
3736 | 0 | if( examiner_name_string_length > 0 ) |
3737 | 0 | { |
3738 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3739 | 0 | header_values, |
3740 | 0 | (uint8_t *) "examiner_name", |
3741 | 0 | 14, |
3742 | 0 | safe_utf8_string, |
3743 | 0 | safe_utf8_string_size, |
3744 | 0 | &utf8_string_index, |
3745 | 0 | error ) != 1 ) |
3746 | 0 | { |
3747 | 0 | libcerror_error_set( |
3748 | 0 | error, |
3749 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3750 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3751 | 0 | "%s: unable to copy header value: examiner_name to string.", |
3752 | 0 | function ); |
3753 | |
|
3754 | 0 | goto on_error; |
3755 | 0 | } |
3756 | 0 | } |
3757 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3758 | |
|
3759 | 0 | if( notes_string_length > 0 ) |
3760 | 0 | { |
3761 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3762 | 0 | header_values, |
3763 | 0 | (uint8_t *) "notes", |
3764 | 0 | 6, |
3765 | 0 | safe_utf8_string, |
3766 | 0 | safe_utf8_string_size, |
3767 | 0 | &utf8_string_index, |
3768 | 0 | error ) != 1 ) |
3769 | 0 | { |
3770 | 0 | libcerror_error_set( |
3771 | 0 | error, |
3772 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3773 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3774 | 0 | "%s: unable to copy header value: notes to string.", |
3775 | 0 | function ); |
3776 | |
|
3777 | 0 | goto on_error; |
3778 | 0 | } |
3779 | 0 | } |
3780 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3781 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3782 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3783 | 0 | { |
3784 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3785 | |
|
3786 | 0 | if( model_string_length > 0 ) |
3787 | 0 | { |
3788 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3789 | 0 | header_values, |
3790 | 0 | (uint8_t *) "model", |
3791 | 0 | 6, |
3792 | 0 | safe_utf8_string, |
3793 | 0 | safe_utf8_string_size, |
3794 | 0 | &utf8_string_index, |
3795 | 0 | error ) != 1 ) |
3796 | 0 | { |
3797 | 0 | libcerror_error_set( |
3798 | 0 | error, |
3799 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3800 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3801 | 0 | "%s: unable to copy header value: model to string.", |
3802 | 0 | function ); |
3803 | |
|
3804 | 0 | goto on_error; |
3805 | 0 | } |
3806 | 0 | } |
3807 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3808 | |
|
3809 | 0 | if( serial_number_string_length > 0 ) |
3810 | 0 | { |
3811 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3812 | 0 | header_values, |
3813 | 0 | (uint8_t *) "serial_number", |
3814 | 0 | 14, |
3815 | 0 | safe_utf8_string, |
3816 | 0 | safe_utf8_string_size, |
3817 | 0 | &utf8_string_index, |
3818 | 0 | error ) != 1 ) |
3819 | 0 | { |
3820 | 0 | libcerror_error_set( |
3821 | 0 | error, |
3822 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3823 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3824 | 0 | "%s: unable to copy header value: serial_number to string.", |
3825 | 0 | function ); |
3826 | |
|
3827 | 0 | goto on_error; |
3828 | 0 | } |
3829 | 0 | } |
3830 | 0 | } |
3831 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3832 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3833 | 0 | { |
3834 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3835 | |
|
3836 | 0 | if( device_label_string_length > 0 ) |
3837 | 0 | { |
3838 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3839 | 0 | header_values, |
3840 | 0 | (uint8_t *) "device_label", |
3841 | 0 | 13, |
3842 | 0 | safe_utf8_string, |
3843 | 0 | safe_utf8_string_size, |
3844 | 0 | &utf8_string_index, |
3845 | 0 | error ) != 1 ) |
3846 | 0 | { |
3847 | 0 | libcerror_error_set( |
3848 | 0 | error, |
3849 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3850 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3851 | 0 | "%s: unable to copy header value: device_label to string.", |
3852 | 0 | function ); |
3853 | |
|
3854 | 0 | goto on_error; |
3855 | 0 | } |
3856 | 0 | } |
3857 | 0 | } |
3858 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) |
3859 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_3 ) |
3860 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_4 ) |
3861 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
3862 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
3863 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
3864 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
3865 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
3866 | 0 | { |
3867 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3868 | |
|
3869 | 0 | if( acquiry_software_version_string_length > 0 ) |
3870 | 0 | { |
3871 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3872 | 0 | header_values, |
3873 | 0 | (uint8_t *) "acquiry_software_version", |
3874 | 0 | 25, |
3875 | 0 | safe_utf8_string, |
3876 | 0 | safe_utf8_string_size, |
3877 | 0 | &utf8_string_index, |
3878 | 0 | error ) != 1 ) |
3879 | 0 | { |
3880 | 0 | libcerror_error_set( |
3881 | 0 | error, |
3882 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3883 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3884 | 0 | "%s: unable to copy header value: acquiry_software_version to string.", |
3885 | 0 | function ); |
3886 | |
|
3887 | 0 | goto on_error; |
3888 | 0 | } |
3889 | 0 | } |
3890 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3891 | |
|
3892 | 0 | if( acquiry_operating_system_string_length > 0 ) |
3893 | 0 | { |
3894 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3895 | 0 | header_values, |
3896 | 0 | (uint8_t *) "acquiry_operating_system", |
3897 | 0 | 25, |
3898 | 0 | safe_utf8_string, |
3899 | 0 | safe_utf8_string_size, |
3900 | 0 | &utf8_string_index, |
3901 | 0 | error ) != 1 ) |
3902 | 0 | { |
3903 | 0 | libcerror_error_set( |
3904 | 0 | error, |
3905 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3906 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3907 | 0 | "%s: unable to copy header value: acquiry_operating_system to string.", |
3908 | 0 | function ); |
3909 | |
|
3910 | 0 | goto on_error; |
3911 | 0 | } |
3912 | 0 | } |
3913 | 0 | } |
3914 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3915 | |
|
3916 | 0 | if( generated_acquiry_date == NULL ) |
3917 | 0 | { |
3918 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3919 | 0 | header_values, |
3920 | 0 | (uint8_t *) "acquiry_date", |
3921 | 0 | 13, |
3922 | 0 | safe_utf8_string, |
3923 | 0 | safe_utf8_string_size, |
3924 | 0 | &utf8_string_index, |
3925 | 0 | error ) != 1 ) |
3926 | 0 | { |
3927 | 0 | libcerror_error_set( |
3928 | 0 | error, |
3929 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3930 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3931 | 0 | "%s: unable to copy header value: acquiry_date to string.", |
3932 | 0 | function ); |
3933 | |
|
3934 | 0 | goto on_error; |
3935 | 0 | } |
3936 | 0 | } |
3937 | 0 | else |
3938 | 0 | { |
3939 | 0 | if( narrow_string_copy( |
3940 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
3941 | 0 | (char *) generated_acquiry_date, |
3942 | 0 | acquiry_date_string_length ) == NULL ) |
3943 | 0 | { |
3944 | 0 | libcerror_error_set( |
3945 | 0 | error, |
3946 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3947 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3948 | 0 | "%s: unable to copy acquiry date string.", |
3949 | 0 | function ); |
3950 | |
|
3951 | 0 | goto on_error; |
3952 | 0 | } |
3953 | 0 | utf8_string_index += acquiry_date_string_length; |
3954 | |
|
3955 | 0 | memory_free( |
3956 | 0 | generated_acquiry_date ); |
3957 | |
|
3958 | 0 | generated_acquiry_date = NULL; |
3959 | 0 | } |
3960 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
3961 | |
|
3962 | 0 | if( generated_system_date == NULL ) |
3963 | 0 | { |
3964 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
3965 | 0 | header_values, |
3966 | 0 | (uint8_t *) "system_date", |
3967 | 0 | 12, |
3968 | 0 | safe_utf8_string, |
3969 | 0 | safe_utf8_string_size, |
3970 | 0 | &utf8_string_index, |
3971 | 0 | error ) != 1 ) |
3972 | 0 | { |
3973 | 0 | libcerror_error_set( |
3974 | 0 | error, |
3975 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3976 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3977 | 0 | "%s: unable to copy header value: system_date to string.", |
3978 | 0 | function ); |
3979 | |
|
3980 | 0 | goto on_error; |
3981 | 0 | } |
3982 | 0 | } |
3983 | 0 | else |
3984 | 0 | { |
3985 | 0 | if( narrow_string_copy( |
3986 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
3987 | 0 | (char *) generated_system_date, |
3988 | 0 | system_date_string_length ) == NULL ) |
3989 | 0 | { |
3990 | 0 | libcerror_error_set( |
3991 | 0 | error, |
3992 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3993 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3994 | 0 | "%s: unable to copy system date string.", |
3995 | 0 | function ); |
3996 | |
|
3997 | 0 | goto on_error; |
3998 | 0 | } |
3999 | 0 | utf8_string_index += system_date_string_length; |
4000 | |
|
4001 | 0 | memory_free( |
4002 | 0 | generated_system_date ); |
4003 | |
|
4004 | 0 | generated_system_date = NULL; |
4005 | 0 | } |
4006 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
4007 | |
|
4008 | 0 | if( generated_password == NULL ) |
4009 | 0 | { |
4010 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
4011 | 0 | header_values, |
4012 | 0 | (uint8_t *) "password", |
4013 | 0 | 9, |
4014 | 0 | safe_utf8_string, |
4015 | 0 | safe_utf8_string_size, |
4016 | 0 | &utf8_string_index, |
4017 | 0 | error ) != 1 ) |
4018 | 0 | { |
4019 | 0 | libcerror_error_set( |
4020 | 0 | error, |
4021 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4022 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4023 | 0 | "%s: unable to copy header value: password to string.", |
4024 | 0 | function ); |
4025 | |
|
4026 | 0 | goto on_error; |
4027 | 0 | } |
4028 | 0 | } |
4029 | 0 | else |
4030 | 0 | { |
4031 | 0 | if( narrow_string_copy( |
4032 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
4033 | 0 | generated_password, |
4034 | 0 | password_string_length ) == NULL ) |
4035 | 0 | { |
4036 | 0 | libcerror_error_set( |
4037 | 0 | error, |
4038 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4039 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4040 | 0 | "%s: unable to copy password string.", |
4041 | 0 | function ); |
4042 | |
|
4043 | 0 | goto on_error; |
4044 | 0 | } |
4045 | 0 | utf8_string_index += password_string_length; |
4046 | 0 | } |
4047 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_1 ) |
4048 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_2 ) ) |
4049 | 0 | { |
4050 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
4051 | |
|
4052 | 0 | if( generated_compression_level == NULL ) |
4053 | 0 | { |
4054 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
4055 | 0 | header_values, |
4056 | 0 | (uint8_t *) "compression_level", |
4057 | 0 | 18, |
4058 | 0 | safe_utf8_string, |
4059 | 0 | safe_utf8_string_size, |
4060 | 0 | &utf8_string_index, |
4061 | 0 | error ) != 1 ) |
4062 | 0 | { |
4063 | 0 | libcerror_error_set( |
4064 | 0 | error, |
4065 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4066 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4067 | 0 | "%s: unable to copy header value: compression_level to string.", |
4068 | 0 | function ); |
4069 | |
|
4070 | 0 | goto on_error; |
4071 | 0 | } |
4072 | 0 | } |
4073 | 0 | else |
4074 | 0 | { |
4075 | 0 | if( narrow_string_copy( |
4076 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
4077 | 0 | generated_compression_level, |
4078 | 0 | compression_level_string_length ) == NULL ) |
4079 | 0 | { |
4080 | 0 | libcerror_error_set( |
4081 | 0 | error, |
4082 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4083 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4084 | 0 | "%s: unable to copy compression level string.", |
4085 | 0 | function ); |
4086 | |
|
4087 | 0 | goto on_error; |
4088 | 0 | } |
4089 | 0 | utf8_string_index += compression_level_string_length; |
4090 | 0 | } |
4091 | 0 | } |
4092 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
4093 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
4094 | 0 | { |
4095 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
4096 | |
|
4097 | 0 | if( process_identifier_string_length > 0 ) |
4098 | 0 | { |
4099 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
4100 | 0 | header_values, |
4101 | 0 | (uint8_t *) "process_identifier", |
4102 | 0 | 19, |
4103 | 0 | safe_utf8_string, |
4104 | 0 | safe_utf8_string_size, |
4105 | 0 | &utf8_string_index, |
4106 | 0 | error ) != 1 ) |
4107 | 0 | { |
4108 | 0 | libcerror_error_set( |
4109 | 0 | error, |
4110 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4111 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4112 | 0 | "%s: unable to copy header value: process_identifier to string.", |
4113 | 0 | function ); |
4114 | |
|
4115 | 0 | goto on_error; |
4116 | 0 | } |
4117 | 0 | } |
4118 | 0 | } |
4119 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
4120 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
4121 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
4122 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
4123 | 0 | { |
4124 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
4125 | |
|
4126 | 0 | if( unknown_dc_string_length > 0 ) |
4127 | 0 | { |
4128 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
4129 | 0 | header_values, |
4130 | 0 | (uint8_t *) "unknown_dc", |
4131 | 0 | 11, |
4132 | 0 | safe_utf8_string, |
4133 | 0 | safe_utf8_string_size, |
4134 | 0 | &utf8_string_index, |
4135 | 0 | error ) != 1 ) |
4136 | 0 | { |
4137 | 0 | libcerror_error_set( |
4138 | 0 | error, |
4139 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4140 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4141 | 0 | "%s: unable to copy header value: unknown_dc to string.", |
4142 | 0 | function ); |
4143 | |
|
4144 | 0 | goto on_error; |
4145 | 0 | } |
4146 | 0 | } |
4147 | 0 | } |
4148 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
4149 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
4150 | 0 | { |
4151 | 0 | safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t'; |
4152 | |
|
4153 | 0 | if( generated_extents == NULL ) |
4154 | 0 | { |
4155 | 0 | if( libewf_value_table_get_value_copy_to_utf8_string_with_index( |
4156 | 0 | header_values, |
4157 | 0 | (uint8_t *) "extents", |
4158 | 0 | 8, |
4159 | 0 | safe_utf8_string, |
4160 | 0 | safe_utf8_string_size, |
4161 | 0 | &utf8_string_index, |
4162 | 0 | error ) != 1 ) |
4163 | 0 | { |
4164 | 0 | libcerror_error_set( |
4165 | 0 | error, |
4166 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4167 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4168 | 0 | "%s: unable to copy header value: extents to string.", |
4169 | 0 | function ); |
4170 | |
|
4171 | 0 | goto on_error; |
4172 | 0 | } |
4173 | 0 | } |
4174 | 0 | else |
4175 | 0 | { |
4176 | 0 | if( narrow_string_copy( |
4177 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
4178 | 0 | generated_extents, |
4179 | 0 | extents_string_length ) == NULL ) |
4180 | 0 | { |
4181 | 0 | libcerror_error_set( |
4182 | 0 | error, |
4183 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4184 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4185 | 0 | "%s: unable to copy extents string.", |
4186 | 0 | function ); |
4187 | |
|
4188 | 0 | goto on_error; |
4189 | 0 | } |
4190 | 0 | utf8_string_index += extents_string_length; |
4191 | 0 | } |
4192 | 0 | } |
4193 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ]; |
4194 | |
|
4195 | 0 | if( newline_string_length == 2 ) |
4196 | 0 | { |
4197 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ]; |
4198 | 0 | } |
4199 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ]; |
4200 | |
|
4201 | 0 | if( newline_string_length == 2 ) |
4202 | 0 | { |
4203 | 0 | safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ]; |
4204 | 0 | } |
4205 | 0 | if( ( header_string_type == LIBEWF_HEADER_STRING_TYPE_5 ) |
4206 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_6 ) |
4207 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_7 ) |
4208 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_8 ) |
4209 | 0 | || ( header_string_type == LIBEWF_HEADER_STRING_TYPE_9 ) ) |
4210 | 0 | { |
4211 | 0 | if( srce_section_string_length > 0 ) |
4212 | 0 | { |
4213 | 0 | if( narrow_string_copy( |
4214 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
4215 | 0 | generated_srce_section, |
4216 | 0 | srce_section_string_length ) == NULL ) |
4217 | 0 | { |
4218 | 0 | libcerror_error_set( |
4219 | 0 | error, |
4220 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4221 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4222 | 0 | "%s: unable to copy srce section string.", |
4223 | 0 | function ); |
4224 | |
|
4225 | 0 | goto on_error; |
4226 | 0 | } |
4227 | 0 | utf8_string_index += srce_section_string_length; |
4228 | 0 | } |
4229 | 0 | if( sub_section_string_length > 0 ) |
4230 | 0 | { |
4231 | 0 | if( narrow_string_copy( |
4232 | 0 | (char *) &( safe_utf8_string[ utf8_string_index ] ), |
4233 | 0 | generated_sub_section, |
4234 | 0 | sub_section_string_length ) == NULL ) |
4235 | 0 | { |
4236 | 0 | libcerror_error_set( |
4237 | 0 | error, |
4238 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4239 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4240 | 0 | "%s: unable to copy sub section string.", |
4241 | 0 | function ); |
4242 | |
|
4243 | 0 | goto on_error; |
4244 | 0 | } |
4245 | 0 | utf8_string_index += sub_section_string_length; |
4246 | 0 | } |
4247 | 0 | } |
4248 | 0 | safe_utf8_string[ utf8_string_index++ ] = 0; |
4249 | |
|
4250 | 0 | *utf8_string = safe_utf8_string; |
4251 | 0 | *utf8_string_size = safe_utf8_string_size; |
4252 | |
|
4253 | 0 | return( 1 ); |
4254 | | |
4255 | 0 | on_error: |
4256 | 0 | if( generated_acquiry_date != NULL ) |
4257 | 0 | { |
4258 | 0 | memory_free( |
4259 | 0 | generated_acquiry_date ); |
4260 | 0 | } |
4261 | 0 | if( generated_system_date != NULL ) |
4262 | 0 | { |
4263 | 0 | memory_free( |
4264 | 0 | generated_system_date ); |
4265 | 0 | } |
4266 | 0 | if( safe_utf8_string != NULL ) |
4267 | 0 | { |
4268 | 0 | memory_free( |
4269 | 0 | safe_utf8_string ); |
4270 | 0 | } |
4271 | 0 | return( -1 ); |
4272 | 0 | } |
4273 | | |
4274 | | /* Generate an EWF header |
4275 | | * Sets header and header length |
4276 | | * Returns 1 if successful or -1 on error |
4277 | | */ |
4278 | | int libewf_header_values_generate_header_ewf( |
4279 | | libfvalue_table_t *header_values, |
4280 | | time_t timestamp, |
4281 | | int8_t compression_level, |
4282 | | uint8_t **header, |
4283 | | size_t *header_size, |
4284 | | int codepage, |
4285 | | libcerror_error_t **error ) |
4286 | 0 | { |
4287 | 0 | uint8_t *header_string = NULL; |
4288 | 0 | static char *function = "libewf_header_values_generate_header_ewf"; |
4289 | 0 | size_t header_string_size = 0; |
4290 | |
|
4291 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4292 | 0 | header_values, |
4293 | 0 | 1, |
4294 | 0 | LIBEWF_HEADER_STRING_TYPE_1, |
4295 | 0 | (uint8_t *) "\n", |
4296 | 0 | 1, |
4297 | 0 | timestamp, |
4298 | 0 | compression_level, |
4299 | 0 | &header_string, |
4300 | 0 | &header_string_size, |
4301 | 0 | error ) != 1 ) |
4302 | 0 | { |
4303 | 0 | libcerror_error_set( |
4304 | 0 | error, |
4305 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4306 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4307 | 0 | "%s: unable to create header string.", |
4308 | 0 | function ); |
4309 | |
|
4310 | 0 | goto on_error; |
4311 | 0 | } |
4312 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
4313 | 0 | header_string, |
4314 | 0 | header_string_size, |
4315 | 0 | header, |
4316 | 0 | header_size, |
4317 | 0 | codepage, |
4318 | 0 | error ) != 1 ) |
4319 | 0 | { |
4320 | 0 | libcerror_error_set( |
4321 | 0 | error, |
4322 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4323 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4324 | 0 | "%s: unable to create header.", |
4325 | 0 | function ); |
4326 | |
|
4327 | 0 | goto on_error; |
4328 | 0 | } |
4329 | 0 | memory_free( |
4330 | 0 | header_string ); |
4331 | |
|
4332 | 0 | return( 1 ); |
4333 | | |
4334 | 0 | on_error: |
4335 | 0 | if( header_string != NULL ) |
4336 | 0 | { |
4337 | 0 | memory_free( |
4338 | 0 | header_string ); |
4339 | 0 | } |
4340 | 0 | return( -1 ); |
4341 | 0 | } |
4342 | | |
4343 | | /* Generate an EnCase1 header |
4344 | | * Sets header and header length |
4345 | | * Returns 1 if successful or -1 on error |
4346 | | */ |
4347 | | int libewf_header_values_generate_header_encase1( |
4348 | | libfvalue_table_t *header_values, |
4349 | | time_t timestamp, |
4350 | | int8_t compression_level, |
4351 | | uint8_t **header, |
4352 | | size_t *header_size, |
4353 | | int codepage, |
4354 | | libcerror_error_t **error ) |
4355 | 0 | { |
4356 | 0 | uint8_t *header_string = NULL; |
4357 | 0 | static char *function = "libewf_header_values_generate_header_encase1"; |
4358 | 0 | size_t header_string_size = 0; |
4359 | |
|
4360 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4361 | 0 | header_values, |
4362 | 0 | 1, |
4363 | 0 | LIBEWF_HEADER_STRING_TYPE_1, |
4364 | 0 | (uint8_t *) "\r\n", |
4365 | 0 | 2, |
4366 | 0 | timestamp, |
4367 | 0 | compression_level, |
4368 | 0 | &header_string, |
4369 | 0 | &header_string_size, |
4370 | 0 | error ) != 1 ) |
4371 | 0 | { |
4372 | 0 | libcerror_error_set( |
4373 | 0 | error, |
4374 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4375 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4376 | 0 | "%s: unable to create header string.", |
4377 | 0 | function ); |
4378 | |
|
4379 | 0 | goto on_error; |
4380 | 0 | } |
4381 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
4382 | 0 | header_string, |
4383 | 0 | header_string_size, |
4384 | 0 | header, |
4385 | 0 | header_size, |
4386 | 0 | codepage, |
4387 | 0 | error ) != 1 ) |
4388 | 0 | { |
4389 | 0 | libcerror_error_set( |
4390 | 0 | error, |
4391 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4392 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4393 | 0 | "%s: unable to create header.", |
4394 | 0 | function ); |
4395 | |
|
4396 | 0 | goto on_error; |
4397 | 0 | } |
4398 | 0 | memory_free( |
4399 | 0 | header_string ); |
4400 | |
|
4401 | 0 | return( 1 ); |
4402 | | |
4403 | 0 | on_error: |
4404 | 0 | if( header_string != NULL ) |
4405 | 0 | { |
4406 | 0 | memory_free( |
4407 | 0 | header_string ); |
4408 | 0 | } |
4409 | 0 | return( -1 ); |
4410 | 0 | } |
4411 | | |
4412 | | /* Generate an FTK Imager header |
4413 | | * Sets header and header length |
4414 | | * Returns 1 if successful or -1 on error |
4415 | | */ |
4416 | | int libewf_header_values_generate_header_ftk( |
4417 | | libfvalue_table_t *header_values, |
4418 | | time_t timestamp, |
4419 | | int8_t compression_level, |
4420 | | uint8_t **header, |
4421 | | size_t *header_size, |
4422 | | int codepage, |
4423 | | libcerror_error_t **error ) |
4424 | 0 | { |
4425 | 0 | uint8_t *header_string = NULL; |
4426 | 0 | static char *function = "libewf_header_values_generate_header_ftk"; |
4427 | 0 | size_t header_string_size = 0; |
4428 | |
|
4429 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4430 | 0 | header_values, |
4431 | 0 | 1, |
4432 | 0 | LIBEWF_HEADER_STRING_TYPE_2, |
4433 | 0 | (uint8_t *) "\n", |
4434 | 0 | 1, |
4435 | 0 | timestamp, |
4436 | 0 | compression_level, |
4437 | 0 | &header_string, |
4438 | 0 | &header_string_size, |
4439 | 0 | error ) != 1 ) |
4440 | 0 | { |
4441 | 0 | libcerror_error_set( |
4442 | 0 | error, |
4443 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4444 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4445 | 0 | "%s: unable to create header string.", |
4446 | 0 | function ); |
4447 | |
|
4448 | 0 | goto on_error; |
4449 | 0 | } |
4450 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
4451 | 0 | header_string, |
4452 | 0 | header_string_size, |
4453 | 0 | header, |
4454 | 0 | header_size, |
4455 | 0 | codepage, |
4456 | 0 | error ) != 1 ) |
4457 | 0 | { |
4458 | 0 | libcerror_error_set( |
4459 | 0 | error, |
4460 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4461 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4462 | 0 | "%s: unable to create header.", |
4463 | 0 | function ); |
4464 | |
|
4465 | 0 | goto on_error; |
4466 | 0 | } |
4467 | 0 | memory_free( |
4468 | 0 | header_string ); |
4469 | |
|
4470 | 0 | return( 1 ); |
4471 | | |
4472 | 0 | on_error: |
4473 | 0 | if( header_string != NULL ) |
4474 | 0 | { |
4475 | 0 | memory_free( |
4476 | 0 | header_string ); |
4477 | 0 | } |
4478 | 0 | return( -1 ); |
4479 | 0 | } |
4480 | | |
4481 | | /* Generate an EnCase2 and EnCase3 header |
4482 | | * Sets header and header length |
4483 | | * Returns 1 if successful or -1 on error |
4484 | | */ |
4485 | | int libewf_header_values_generate_header_encase2( |
4486 | | libfvalue_table_t *header_values, |
4487 | | time_t timestamp, |
4488 | | int8_t compression_level, |
4489 | | uint8_t **header, |
4490 | | size_t *header_size, |
4491 | | int codepage, |
4492 | | libcerror_error_t **error ) |
4493 | 0 | { |
4494 | 0 | uint8_t *header_string = NULL; |
4495 | 0 | static char *function = "libewf_header_values_generate_header_encase2"; |
4496 | 0 | size_t header_string_size = 0; |
4497 | |
|
4498 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4499 | 0 | header_values, |
4500 | 0 | 1, |
4501 | 0 | LIBEWF_HEADER_STRING_TYPE_2, |
4502 | 0 | (uint8_t *) "\r\n", |
4503 | 0 | 2, |
4504 | 0 | timestamp, |
4505 | 0 | compression_level, |
4506 | 0 | &header_string, |
4507 | 0 | &header_string_size, |
4508 | 0 | error ) != 1 ) |
4509 | 0 | { |
4510 | 0 | libcerror_error_set( |
4511 | 0 | error, |
4512 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4513 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4514 | 0 | "%s: unable to create header string.", |
4515 | 0 | function ); |
4516 | |
|
4517 | 0 | goto on_error; |
4518 | 0 | } |
4519 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
4520 | 0 | header_string, |
4521 | 0 | header_string_size, |
4522 | 0 | header, |
4523 | 0 | header_size, |
4524 | 0 | codepage, |
4525 | 0 | error ) != 1 ) |
4526 | 0 | { |
4527 | 0 | libcerror_error_set( |
4528 | 0 | error, |
4529 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4530 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4531 | 0 | "%s: unable to create header.", |
4532 | 0 | function ); |
4533 | |
|
4534 | 0 | goto on_error; |
4535 | 0 | } |
4536 | 0 | memory_free( |
4537 | 0 | header_string ); |
4538 | |
|
4539 | 0 | return( 1 ); |
4540 | | |
4541 | 0 | on_error: |
4542 | 0 | if( header_string != NULL ) |
4543 | 0 | { |
4544 | 0 | memory_free( |
4545 | 0 | header_string ); |
4546 | 0 | } |
4547 | 0 | return( -1 ); |
4548 | 0 | } |
4549 | | |
4550 | | /* Generate an EnCase4 header |
4551 | | * Sets header and header length |
4552 | | * Returns 1 if successful or -1 on error |
4553 | | */ |
4554 | | int libewf_header_values_generate_header_encase4( |
4555 | | libfvalue_table_t *header_values, |
4556 | | time_t timestamp, |
4557 | | int8_t compression_level, |
4558 | | uint8_t **header, |
4559 | | size_t *header_size, |
4560 | | int codepage, |
4561 | | libcerror_error_t **error ) |
4562 | 0 | { |
4563 | 0 | uint8_t *header_string = NULL; |
4564 | 0 | static char *function = "libewf_header_values_generate_header_encase4"; |
4565 | 0 | size_t header_string_size = 0; |
4566 | |
|
4567 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4568 | 0 | header_values, |
4569 | 0 | 1, |
4570 | 0 | LIBEWF_HEADER_STRING_TYPE_3, |
4571 | 0 | (uint8_t *) "\r\n", |
4572 | 0 | 2, |
4573 | 0 | timestamp, |
4574 | 0 | compression_level, |
4575 | 0 | &header_string, |
4576 | 0 | &header_string_size, |
4577 | 0 | error ) != 1 ) |
4578 | 0 | { |
4579 | 0 | libcerror_error_set( |
4580 | 0 | error, |
4581 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4582 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4583 | 0 | "%s: unable to create header string.", |
4584 | 0 | function ); |
4585 | |
|
4586 | 0 | goto on_error; |
4587 | 0 | } |
4588 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
4589 | 0 | header_string, |
4590 | 0 | header_string_size, |
4591 | 0 | header, |
4592 | 0 | header_size, |
4593 | 0 | codepage, |
4594 | 0 | error ) != 1 ) |
4595 | 0 | { |
4596 | 0 | libcerror_error_set( |
4597 | 0 | error, |
4598 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4599 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4600 | 0 | "%s: unable to create header.", |
4601 | 0 | function ); |
4602 | |
|
4603 | 0 | goto on_error; |
4604 | 0 | } |
4605 | 0 | memory_free( |
4606 | 0 | header_string ); |
4607 | |
|
4608 | 0 | return( 1 ); |
4609 | | |
4610 | 0 | on_error: |
4611 | 0 | if( header_string != NULL ) |
4612 | 0 | { |
4613 | 0 | memory_free( |
4614 | 0 | header_string ); |
4615 | 0 | } |
4616 | 0 | return( -1 ); |
4617 | 0 | } |
4618 | | |
4619 | | /* Generate a linen header |
4620 | | * Sets header and header length |
4621 | | * Returns 1 if successful or -1 on error |
4622 | | */ |
4623 | | int libewf_header_values_generate_header_linen( |
4624 | | libfvalue_table_t *header_values, |
4625 | | uint8_t format, |
4626 | | time_t timestamp, |
4627 | | int8_t compression_level, |
4628 | | uint8_t **header, |
4629 | | size_t *header_size, |
4630 | | int codepage, |
4631 | | libcerror_error_t **error ) |
4632 | 0 | { |
4633 | 0 | uint8_t *header_string = NULL; |
4634 | 0 | static char *function = "libewf_header_values_generate_header_linen"; |
4635 | 0 | size_t header_string_size = 0; |
4636 | 0 | uint8_t header_string_type = 0; |
4637 | |
|
4638 | 0 | switch( format ) |
4639 | 0 | { |
4640 | 0 | case LIBEWF_FORMAT_LINEN5: |
4641 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_7; |
4642 | 0 | break; |
4643 | | |
4644 | 0 | case LIBEWF_FORMAT_LINEN6: |
4645 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_6; |
4646 | 0 | break; |
4647 | | |
4648 | 0 | case LIBEWF_FORMAT_LINEN7: |
4649 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_8; |
4650 | 0 | break; |
4651 | | |
4652 | 0 | default: |
4653 | 0 | libcerror_error_set( |
4654 | 0 | error, |
4655 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4656 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
4657 | 0 | "%s: unsupported format.", |
4658 | 0 | function ); |
4659 | |
|
4660 | 0 | break; |
4661 | 0 | } |
4662 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4663 | 0 | header_values, |
4664 | 0 | 1, |
4665 | 0 | header_string_type, |
4666 | 0 | (uint8_t *) "\n", |
4667 | 0 | 1, |
4668 | 0 | timestamp, |
4669 | 0 | compression_level, |
4670 | 0 | &header_string, |
4671 | 0 | &header_string_size, |
4672 | 0 | error ) != 1 ) |
4673 | 0 | { |
4674 | 0 | libcerror_error_set( |
4675 | 0 | error, |
4676 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4677 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4678 | 0 | "%s: unable to create header string.", |
4679 | 0 | function ); |
4680 | |
|
4681 | 0 | goto on_error; |
4682 | 0 | } |
4683 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
4684 | 0 | header_string, |
4685 | 0 | header_string_size, |
4686 | 0 | header, |
4687 | 0 | header_size, |
4688 | 0 | codepage, |
4689 | 0 | error ) != 1 ) |
4690 | 0 | { |
4691 | 0 | libcerror_error_set( |
4692 | 0 | error, |
4693 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4694 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4695 | 0 | "%s: unable to create header.", |
4696 | 0 | function ); |
4697 | |
|
4698 | 0 | goto on_error; |
4699 | 0 | } |
4700 | 0 | memory_free( |
4701 | 0 | header_string ); |
4702 | |
|
4703 | 0 | return( 1 ); |
4704 | | |
4705 | 0 | on_error: |
4706 | 0 | if( header_string != NULL ) |
4707 | 0 | { |
4708 | 0 | memory_free( |
4709 | 0 | header_string ); |
4710 | 0 | } |
4711 | 0 | return( -1 ); |
4712 | 0 | } |
4713 | | |
4714 | | /* Generate a header2 |
4715 | | * Sets header2 and header2 size |
4716 | | * Returns 1 if successful or -1 on error |
4717 | | */ |
4718 | | int libewf_header_values_generate_header2( |
4719 | | libfvalue_table_t *header_values, |
4720 | | uint8_t format, |
4721 | | time_t timestamp, |
4722 | | int8_t compression_level, |
4723 | | uint8_t **header2, |
4724 | | size_t *header2_size, |
4725 | | libcerror_error_t **error ) |
4726 | 0 | { |
4727 | 0 | uint8_t *header_string = NULL; |
4728 | 0 | uint8_t *safe_header2 = NULL; |
4729 | 0 | static char *function = "libewf_header_values_generate_header2"; |
4730 | 0 | size_t header_string_size = 0; |
4731 | 0 | size_t safe_header2_size = 0; |
4732 | 0 | uint8_t header_string_type = 0; |
4733 | |
|
4734 | 0 | switch( format ) |
4735 | 0 | { |
4736 | 0 | case LIBEWF_FORMAT_ENCASE4: |
4737 | 0 | case LIBEWF_FORMAT_EWFX: |
4738 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_4; |
4739 | 0 | break; |
4740 | | |
4741 | 0 | case LIBEWF_FORMAT_ENCASE5: |
4742 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_5; |
4743 | 0 | break; |
4744 | | |
4745 | 0 | case LIBEWF_FORMAT_ENCASE6: |
4746 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_6; |
4747 | 0 | break; |
4748 | | |
4749 | 0 | case LIBEWF_FORMAT_ENCASE7: |
4750 | 0 | header_string_type = LIBEWF_HEADER_STRING_TYPE_9; |
4751 | 0 | break; |
4752 | | |
4753 | 0 | default: |
4754 | 0 | libcerror_error_set( |
4755 | 0 | error, |
4756 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4757 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
4758 | 0 | "%s: unsupported format.", |
4759 | 0 | function ); |
4760 | |
|
4761 | 0 | break; |
4762 | 0 | } |
4763 | 0 | if( header2 == NULL ) |
4764 | 0 | { |
4765 | 0 | libcerror_error_set( |
4766 | 0 | error, |
4767 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4768 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4769 | 0 | "%s: invalid header2.", |
4770 | 0 | function ); |
4771 | |
|
4772 | 0 | return( -1 ); |
4773 | 0 | } |
4774 | 0 | if( *header2 != NULL ) |
4775 | 0 | { |
4776 | 0 | libcerror_error_set( |
4777 | 0 | error, |
4778 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4779 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4780 | 0 | "%s: header2 already created.", |
4781 | 0 | function ); |
4782 | |
|
4783 | 0 | return( -1 ); |
4784 | 0 | } |
4785 | 0 | if( header2_size == NULL ) |
4786 | 0 | { |
4787 | 0 | libcerror_error_set( |
4788 | 0 | error, |
4789 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4790 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4791 | 0 | "%s: invalid header2 size.", |
4792 | 0 | function ); |
4793 | |
|
4794 | 0 | return( -1 ); |
4795 | 0 | } |
4796 | 0 | if( libewf_header_values_generate_utf8_header_string( |
4797 | 0 | header_values, |
4798 | 0 | 2, |
4799 | 0 | header_string_type, |
4800 | 0 | (uint8_t *) "\n", |
4801 | 0 | 1, |
4802 | 0 | timestamp, |
4803 | 0 | compression_level, |
4804 | 0 | &header_string, |
4805 | 0 | &header_string_size, |
4806 | 0 | error ) != 1 ) |
4807 | 0 | { |
4808 | 0 | libcerror_error_set( |
4809 | 0 | error, |
4810 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4811 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4812 | 0 | "%s: unable to create header string.", |
4813 | 0 | function ); |
4814 | |
|
4815 | 0 | goto on_error; |
4816 | 0 | } |
4817 | 0 | if( libuna_utf16_stream_size_from_utf8( |
4818 | 0 | header_string, |
4819 | 0 | header_string_size, |
4820 | 0 | &safe_header2_size, |
4821 | 0 | error ) != 1 ) |
4822 | 0 | { |
4823 | 0 | libcerror_error_set( |
4824 | 0 | error, |
4825 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
4826 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
4827 | 0 | "%s: unable to determine header2 size.", |
4828 | 0 | function ); |
4829 | |
|
4830 | 0 | goto on_error; |
4831 | 0 | } |
4832 | 0 | if( ( safe_header2_size == 0 ) |
4833 | 0 | || ( safe_header2_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
4834 | 0 | { |
4835 | 0 | libcerror_error_set( |
4836 | 0 | error, |
4837 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4838 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
4839 | 0 | "%s: invalid header2 size value out of bounds.", |
4840 | 0 | function ); |
4841 | |
|
4842 | 0 | goto on_error; |
4843 | 0 | } |
4844 | 0 | safe_header2 = (uint8_t *) memory_allocate( |
4845 | 0 | sizeof( uint8_t ) * safe_header2_size ); |
4846 | |
|
4847 | 0 | if( safe_header2 == NULL ) |
4848 | 0 | { |
4849 | 0 | libcerror_error_set( |
4850 | 0 | error, |
4851 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
4852 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
4853 | 0 | "%s: unable to create header2.", |
4854 | 0 | function ); |
4855 | |
|
4856 | 0 | goto on_error; |
4857 | 0 | } |
4858 | 0 | if( libuna_utf16_stream_copy_from_utf8( |
4859 | 0 | safe_header2, |
4860 | 0 | safe_header2_size, |
4861 | 0 | LIBUNA_ENDIAN_LITTLE, |
4862 | 0 | header_string, |
4863 | 0 | header_string_size, |
4864 | 0 | error ) != 1 ) |
4865 | 0 | { |
4866 | 0 | libcerror_error_set( |
4867 | 0 | error, |
4868 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
4869 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
4870 | 0 | "%s: unable to set header2.", |
4871 | 0 | function ); |
4872 | |
|
4873 | 0 | goto on_error; |
4874 | 0 | } |
4875 | 0 | memory_free( |
4876 | 0 | header_string ); |
4877 | |
|
4878 | 0 | *header2 = safe_header2; |
4879 | 0 | *header2_size = safe_header2_size; |
4880 | |
|
4881 | 0 | return( 1 ); |
4882 | | |
4883 | 0 | on_error: |
4884 | 0 | if( header_string != NULL ) |
4885 | 0 | { |
4886 | 0 | memory_free( |
4887 | 0 | header_string ); |
4888 | 0 | } |
4889 | 0 | if( safe_header2 != NULL ) |
4890 | 0 | { |
4891 | 0 | memory_free( |
4892 | 0 | safe_header2 ); |
4893 | 0 | } |
4894 | 0 | return( -1 ); |
4895 | 0 | } |
4896 | | |
4897 | | /* Convert date time values string within an xheader value |
4898 | | * Sets date time values string and length |
4899 | | * Returns 1 if successful, 0 if not an xheader value or -1 on error |
4900 | | */ |
4901 | | int libewf_convert_date_xheader_value( |
4902 | | const uint8_t *header_value, |
4903 | | size_t header_value_length, |
4904 | | uint8_t **date_time_values_string, |
4905 | | size_t *date_time_values_string_size, |
4906 | | libcerror_error_t **error ) |
4907 | 0 | { |
4908 | 0 | struct tm time_elements; |
4909 | |
|
4910 | 0 | libfvalue_split_utf8_string_t *date_time_values = NULL; |
4911 | 0 | uint8_t *date_time_value_string = NULL; |
4912 | 0 | uint8_t *timezone_name = NULL; |
4913 | 0 | uint8_t *timezone_string = NULL; |
4914 | 0 | static char *function = "libewf_convert_date_xheader_value"; |
4915 | 0 | size_t date_time_value_string_size = 0; |
4916 | 0 | size_t date_time_values_string_index = 0; |
4917 | 0 | size_t timezone_name_size = 0; |
4918 | 0 | size_t timezone_string_size = 0; |
4919 | 0 | time_t timestamp = 0; |
4920 | 0 | int empty_date_element_correction = 0; |
4921 | 0 | int number_of_date_time_values = 0; |
4922 | |
|
4923 | 0 | if( header_value == NULL ) |
4924 | 0 | { |
4925 | 0 | libcerror_error_set( |
4926 | 0 | error, |
4927 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4928 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4929 | 0 | "%s: invalid header value.", |
4930 | 0 | function ); |
4931 | |
|
4932 | 0 | return( -1 ); |
4933 | 0 | } |
4934 | 0 | if( date_time_values_string == NULL ) |
4935 | 0 | { |
4936 | 0 | libcerror_error_set( |
4937 | 0 | error, |
4938 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4939 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4940 | 0 | "%s: invalid date time values string.", |
4941 | 0 | function ); |
4942 | |
|
4943 | 0 | return( -1 ); |
4944 | 0 | } |
4945 | 0 | if( *date_time_values_string != NULL ) |
4946 | 0 | { |
4947 | 0 | libcerror_error_set( |
4948 | 0 | error, |
4949 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4950 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4951 | 0 | "%s: date time values string already created.", |
4952 | 0 | function ); |
4953 | |
|
4954 | 0 | return( -1 ); |
4955 | 0 | } |
4956 | 0 | if( date_time_values_string_size == NULL ) |
4957 | 0 | { |
4958 | 0 | libcerror_error_set( |
4959 | 0 | error, |
4960 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4961 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4962 | 0 | "%s: invalid date time values string size.", |
4963 | 0 | function ); |
4964 | |
|
4965 | 0 | return( -1 ); |
4966 | 0 | } |
4967 | 0 | if( libfvalue_utf8_string_split( |
4968 | 0 | header_value, |
4969 | 0 | header_value_length, |
4970 | 0 | (uint8_t) ' ', |
4971 | 0 | &date_time_values, |
4972 | 0 | error ) != 1 ) |
4973 | 0 | { |
4974 | 0 | libcerror_error_set( |
4975 | 0 | error, |
4976 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4977 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4978 | 0 | "%s: unable to split header value.", |
4979 | 0 | function ); |
4980 | |
|
4981 | 0 | goto on_error; |
4982 | 0 | } |
4983 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
4984 | 0 | date_time_values, |
4985 | 0 | &number_of_date_time_values, |
4986 | 0 | error ) != 1 ) |
4987 | 0 | { |
4988 | 0 | libcerror_error_set( |
4989 | 0 | error, |
4990 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4991 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4992 | 0 | "%s: unable to retrieve number of date time values.", |
4993 | 0 | function ); |
4994 | |
|
4995 | 0 | goto on_error; |
4996 | 0 | } |
4997 | | /* The ctime formatted string use an additional space |
4998 | | * when the day is less than 10 |
4999 | | */ |
5000 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5001 | 0 | date_time_values, |
5002 | 0 | 2, |
5003 | 0 | &date_time_value_string, |
5004 | 0 | &date_time_value_string_size, |
5005 | 0 | error ) != 1 ) |
5006 | 0 | { |
5007 | 0 | libcerror_error_set( |
5008 | 0 | error, |
5009 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5010 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5011 | 0 | "%s: unable to retrieve date time value string: 2.", |
5012 | 0 | function ); |
5013 | |
|
5014 | 0 | goto on_error; |
5015 | 0 | } |
5016 | 0 | if( ( date_time_value_string != NULL ) |
5017 | 0 | && ( date_time_value_string[ 0 ] == 0 ) ) |
5018 | 0 | { |
5019 | 0 | empty_date_element_correction = 1; |
5020 | 0 | } |
5021 | 0 | if( number_of_date_time_values < ( 5 + empty_date_element_correction ) ) |
5022 | 0 | { |
5023 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
5024 | | if( libcnotify_verbose != 0 ) |
5025 | | { |
5026 | | libcnotify_printf( |
5027 | | "%s: unsupported number of date time element values: %d.\n", |
5028 | | function, |
5029 | | number_of_date_time_values ); |
5030 | | } |
5031 | | #endif |
5032 | 0 | if( libfvalue_split_utf8_string_free( |
5033 | 0 | &date_time_values, |
5034 | 0 | error ) != 1 ) |
5035 | 0 | { |
5036 | 0 | libcerror_error_set( |
5037 | 0 | error, |
5038 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5039 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
5040 | 0 | "%s: unable to free split date time elements.", |
5041 | 0 | function ); |
5042 | |
|
5043 | 0 | goto on_error; |
5044 | 0 | } |
5045 | 0 | return( 0 ); |
5046 | 0 | } |
5047 | | /* Check the day of the week |
5048 | | */ |
5049 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5050 | 0 | date_time_values, |
5051 | 0 | 0, |
5052 | 0 | &date_time_value_string, |
5053 | 0 | &date_time_value_string_size, |
5054 | 0 | error ) != 1 ) |
5055 | 0 | { |
5056 | 0 | libcerror_error_set( |
5057 | 0 | error, |
5058 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5059 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5060 | 0 | "%s: unable to retrieve date time value string: 0.", |
5061 | 0 | function ); |
5062 | |
|
5063 | 0 | goto on_error; |
5064 | 0 | } |
5065 | 0 | if( libewf_utf8_string_day_of_week_copy_to_time_elements( |
5066 | 0 | date_time_value_string, |
5067 | 0 | date_time_value_string_size, |
5068 | 0 | &time_elements, |
5069 | 0 | error ) != 1 ) |
5070 | 0 | { |
5071 | 0 | libcerror_error_set( |
5072 | 0 | error, |
5073 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5074 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5075 | 0 | "%s: unable to copy day of week string.", |
5076 | 0 | function ); |
5077 | |
|
5078 | 0 | goto on_error; |
5079 | 0 | } |
5080 | | /* Set the year |
5081 | | */ |
5082 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5083 | 0 | date_time_values, |
5084 | 0 | 4 + empty_date_element_correction, |
5085 | 0 | &date_time_value_string, |
5086 | 0 | &date_time_value_string_size, |
5087 | 0 | error ) != 1 ) |
5088 | 0 | { |
5089 | 0 | libcerror_error_set( |
5090 | 0 | error, |
5091 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5092 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5093 | 0 | "%s: unable to retrieve date time value string: %d.", |
5094 | 0 | function, |
5095 | 0 | 4 + empty_date_element_correction ); |
5096 | |
|
5097 | 0 | goto on_error; |
5098 | 0 | } |
5099 | 0 | if( libewf_utf8_string_year_copy_to_time_elements( |
5100 | 0 | date_time_value_string, |
5101 | 0 | date_time_value_string_size, |
5102 | 0 | &time_elements, |
5103 | 0 | error ) != 1 ) |
5104 | 0 | { |
5105 | 0 | libcerror_error_set( |
5106 | 0 | error, |
5107 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5108 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5109 | 0 | "%s: unable to copy year value.", |
5110 | 0 | function ); |
5111 | |
|
5112 | 0 | goto on_error; |
5113 | 0 | } |
5114 | | /* Set the month |
5115 | | */ |
5116 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5117 | 0 | date_time_values, |
5118 | 0 | 1, |
5119 | 0 | &date_time_value_string, |
5120 | 0 | &date_time_value_string_size, |
5121 | 0 | error ) != 1 ) |
5122 | 0 | { |
5123 | 0 | libcerror_error_set( |
5124 | 0 | error, |
5125 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5126 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5127 | 0 | "%s: unable to retrieve date time value string: 1.", |
5128 | 0 | function ); |
5129 | |
|
5130 | 0 | goto on_error; |
5131 | 0 | } |
5132 | 0 | if( date_time_value_string_size != 4 ) |
5133 | 0 | { |
5134 | 0 | libcerror_error_set( |
5135 | 0 | error, |
5136 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5137 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
5138 | 0 | "%s: unsupported date time value string size: 1.", |
5139 | 0 | function ); |
5140 | |
|
5141 | 0 | goto on_error; |
5142 | 0 | } |
5143 | 0 | if( libewf_utf8_string_month_copy_to_time_elements( |
5144 | 0 | date_time_value_string, |
5145 | 0 | date_time_value_string_size, |
5146 | 0 | &time_elements, |
5147 | 0 | error ) != 1 ) |
5148 | 0 | { |
5149 | 0 | libcerror_error_set( |
5150 | 0 | error, |
5151 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5152 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5153 | 0 | "%s: unable to copy month value.", |
5154 | 0 | function ); |
5155 | |
|
5156 | 0 | goto on_error; |
5157 | 0 | } |
5158 | | /* Set the day of the month |
5159 | | */ |
5160 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5161 | 0 | date_time_values, |
5162 | 0 | 2 + empty_date_element_correction, |
5163 | 0 | &date_time_value_string, |
5164 | 0 | &date_time_value_string_size, |
5165 | 0 | error ) != 1 ) |
5166 | 0 | { |
5167 | 0 | libcerror_error_set( |
5168 | 0 | error, |
5169 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5170 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5171 | 0 | "%s: unable to retrieve date time value string: %d.", |
5172 | 0 | function, |
5173 | 0 | empty_date_element_correction ); |
5174 | |
|
5175 | 0 | goto on_error; |
5176 | 0 | } |
5177 | 0 | if( ( date_time_value_string_size != 2 ) |
5178 | 0 | && ( date_time_value_string_size != 3 ) ) |
5179 | 0 | { |
5180 | 0 | libcerror_error_set( |
5181 | 0 | error, |
5182 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5183 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
5184 | 0 | "%s: unsupported date time value string size: %d.", |
5185 | 0 | function, |
5186 | 0 | empty_date_element_correction ); |
5187 | |
|
5188 | 0 | goto on_error; |
5189 | 0 | } |
5190 | 0 | if( libewf_utf8_string_day_of_month_copy_to_time_elements( |
5191 | 0 | date_time_value_string, |
5192 | 0 | date_time_value_string_size, |
5193 | 0 | &time_elements, |
5194 | 0 | error ) != 1 ) |
5195 | 0 | { |
5196 | 0 | libcerror_error_set( |
5197 | 0 | error, |
5198 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5199 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5200 | 0 | "%s: unable to copy day of month value.", |
5201 | 0 | function ); |
5202 | |
|
5203 | 0 | goto on_error; |
5204 | 0 | } |
5205 | | /* Set the hours, minutes and seconds |
5206 | | */ |
5207 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5208 | 0 | date_time_values, |
5209 | 0 | 3 + empty_date_element_correction, |
5210 | 0 | &date_time_value_string, |
5211 | 0 | &date_time_value_string_size, |
5212 | 0 | error ) != 1 ) |
5213 | 0 | { |
5214 | 0 | libcerror_error_set( |
5215 | 0 | error, |
5216 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5217 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5218 | 0 | "%s: unable to retrieve date time value string: %d.", |
5219 | 0 | function, |
5220 | 0 | 3 + empty_date_element_correction ); |
5221 | |
|
5222 | 0 | goto on_error; |
5223 | 0 | } |
5224 | 0 | if( date_time_value_string_size != 9 ) |
5225 | 0 | { |
5226 | 0 | libcerror_error_set( |
5227 | 0 | error, |
5228 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5229 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
5230 | 0 | "%s: unsupported date time value string size: %d.", |
5231 | 0 | function, |
5232 | 0 | 3 + empty_date_element_correction ); |
5233 | |
|
5234 | 0 | goto on_error; |
5235 | 0 | } |
5236 | 0 | if( libewf_utf8_string_hours_copy_to_time_elements( |
5237 | 0 | &( date_time_value_string[ 0 ] ), |
5238 | 0 | 2, |
5239 | 0 | &time_elements, |
5240 | 0 | error ) != 1 ) |
5241 | 0 | { |
5242 | 0 | libcerror_error_set( |
5243 | 0 | error, |
5244 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5245 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5246 | 0 | "%s: unable to copy hours value.", |
5247 | 0 | function ); |
5248 | |
|
5249 | 0 | goto on_error; |
5250 | 0 | } |
5251 | 0 | if( libewf_utf8_string_minutes_copy_to_time_elements( |
5252 | 0 | &( date_time_value_string[ 3 ] ), |
5253 | 0 | 2, |
5254 | 0 | &time_elements, |
5255 | 0 | error ) != 1 ) |
5256 | 0 | { |
5257 | 0 | libcerror_error_set( |
5258 | 0 | error, |
5259 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5260 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5261 | 0 | "%s: unable to copy minutes value.", |
5262 | 0 | function ); |
5263 | |
|
5264 | 0 | goto on_error; |
5265 | 0 | } |
5266 | 0 | if( libewf_utf8_string_seconds_copy_to_time_elements( |
5267 | 0 | &( date_time_value_string[ 6 ] ), |
5268 | 0 | 2, |
5269 | 0 | &time_elements, |
5270 | 0 | error ) != 1 ) |
5271 | 0 | { |
5272 | 0 | libcerror_error_set( |
5273 | 0 | error, |
5274 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5275 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5276 | 0 | "%s: unable to copy seconds value.", |
5277 | 0 | function ); |
5278 | |
|
5279 | 0 | goto on_error; |
5280 | 0 | } |
5281 | | /* Set to ignore the daylight saving time |
5282 | | */ |
5283 | 0 | time_elements.tm_isdst = -1; |
5284 | | |
5285 | | /* Create a timestamp |
5286 | | */ |
5287 | 0 | timestamp = libewf_date_time_mktime( |
5288 | 0 | &time_elements ); |
5289 | |
|
5290 | 0 | if( timestamp == (time_t) -1 ) |
5291 | 0 | { |
5292 | 0 | libcerror_error_set( |
5293 | 0 | error, |
5294 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5295 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5296 | 0 | "%s: unable to create timestamp.", |
5297 | 0 | function ); |
5298 | |
|
5299 | 0 | goto on_error; |
5300 | 0 | } |
5301 | 0 | *date_time_values_string_size = 20; |
5302 | |
|
5303 | 0 | if( ( number_of_date_time_values - empty_date_element_correction ) > 5 ) |
5304 | 0 | { |
5305 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5306 | 0 | date_time_values, |
5307 | 0 | 5 + empty_date_element_correction, |
5308 | 0 | &timezone_string, |
5309 | 0 | &timezone_string_size, |
5310 | 0 | error ) != 1 ) |
5311 | 0 | { |
5312 | 0 | libcerror_error_set( |
5313 | 0 | error, |
5314 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5315 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5316 | 0 | "%s: unable to retrieve date time value string: %d.", |
5317 | 0 | function, |
5318 | 0 | 5 + empty_date_element_correction ); |
5319 | |
|
5320 | 0 | goto on_error; |
5321 | 0 | } |
5322 | 0 | *date_time_values_string_size += timezone_string_size; |
5323 | 0 | } |
5324 | 0 | if( ( number_of_date_time_values - empty_date_element_correction ) > 6 ) |
5325 | 0 | { |
5326 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
5327 | 0 | date_time_values, |
5328 | 0 | 6 + empty_date_element_correction, |
5329 | 0 | &timezone_name, |
5330 | 0 | &timezone_name_size, |
5331 | 0 | error ) != 1 ) |
5332 | 0 | { |
5333 | 0 | libcerror_error_set( |
5334 | 0 | error, |
5335 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5336 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5337 | 0 | "%s: unable to retrieve date time value string: %d.", |
5338 | 0 | function, |
5339 | 0 | 6 + empty_date_element_correction ); |
5340 | |
|
5341 | 0 | goto on_error; |
5342 | 0 | } |
5343 | 0 | *date_time_values_string_size += timezone_name_size; |
5344 | 0 | } |
5345 | 0 | if( ( *date_time_values_string_size == 0 ) |
5346 | 0 | | ( *date_time_values_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
5347 | 0 | { |
5348 | 0 | libcerror_error_set( |
5349 | 0 | error, |
5350 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5351 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
5352 | 0 | "%s: invalid date time values string size value out of bounds.", |
5353 | 0 | function ); |
5354 | |
|
5355 | 0 | goto on_error; |
5356 | 0 | } |
5357 | 0 | *date_time_values_string = (uint8_t *) memory_allocate( |
5358 | 0 | sizeof( uint8_t ) * *date_time_values_string_size ); |
5359 | |
|
5360 | 0 | if( *date_time_values_string == NULL ) |
5361 | 0 | { |
5362 | 0 | libcerror_error_set( |
5363 | 0 | error, |
5364 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
5365 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
5366 | 0 | "%s: unable to create date time values string.", |
5367 | 0 | function ); |
5368 | |
|
5369 | 0 | goto on_error; |
5370 | 0 | } |
5371 | 0 | if( libewf_date_time_values_copy_from_timestamp( |
5372 | 0 | *date_time_values_string, |
5373 | 0 | *date_time_values_string_size, |
5374 | 0 | timestamp, |
5375 | 0 | error ) != 1 ) |
5376 | 0 | { |
5377 | 0 | libcerror_error_set( |
5378 | 0 | error, |
5379 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
5380 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
5381 | 0 | "%s: unable to convert timestamp into date time values string.", |
5382 | 0 | function ); |
5383 | |
|
5384 | 0 | goto on_error; |
5385 | 0 | } |
5386 | 0 | date_time_values_string_index = 19; |
5387 | |
|
5388 | 0 | if( number_of_date_time_values > ( 5 + empty_date_element_correction ) ) |
5389 | 0 | { |
5390 | 0 | ( *date_time_values_string )[ date_time_values_string_index++ ] = (uint8_t) ' '; |
5391 | |
|
5392 | 0 | if( narrow_string_copy( |
5393 | 0 | (char *) &( ( *date_time_values_string )[ date_time_values_string_index ] ), |
5394 | 0 | (char *) timezone_string, |
5395 | 0 | timezone_string_size - 1 ) == NULL ) |
5396 | 0 | { |
5397 | 0 | libcerror_error_set( |
5398 | 0 | error, |
5399 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5400 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5401 | 0 | "%s: unable to set timezone string in data time values string.", |
5402 | 0 | function ); |
5403 | |
|
5404 | 0 | goto on_error; |
5405 | 0 | } |
5406 | 0 | date_time_values_string_index += timezone_string_size - 1; |
5407 | 0 | } |
5408 | 0 | if( number_of_date_time_values > ( 6 + empty_date_element_correction ) ) |
5409 | 0 | { |
5410 | 0 | ( *date_time_values_string )[ date_time_values_string_index++ ] = (uint8_t) ' '; |
5411 | |
|
5412 | 0 | if( narrow_string_copy( |
5413 | 0 | (char *) &( ( *date_time_values_string )[ date_time_values_string_index ] ), |
5414 | 0 | (char *) timezone_name, |
5415 | 0 | timezone_name_size - 1 ) == NULL ) |
5416 | 0 | { |
5417 | 0 | libcerror_error_set( |
5418 | 0 | error, |
5419 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5420 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5421 | 0 | "%s: unable to set timezone name in data time values string.", |
5422 | 0 | function ); |
5423 | |
|
5424 | 0 | goto on_error; |
5425 | 0 | } |
5426 | 0 | date_time_values_string_index += timezone_name_size - 1; |
5427 | |
|
5428 | 0 | } |
5429 | 0 | ( *date_time_values_string )[ date_time_values_string_index ] = 0; |
5430 | |
|
5431 | 0 | if( libfvalue_split_utf8_string_free( |
5432 | 0 | &date_time_values, |
5433 | 0 | error ) != 1 ) |
5434 | 0 | { |
5435 | 0 | libcerror_error_set( |
5436 | 0 | error, |
5437 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5438 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
5439 | 0 | "%s: unable to free split date time elements.", |
5440 | 0 | function ); |
5441 | |
|
5442 | 0 | goto on_error; |
5443 | 0 | } |
5444 | 0 | return( 1 ); |
5445 | | |
5446 | 0 | on_error: |
5447 | 0 | if( date_time_values != NULL ) |
5448 | 0 | { |
5449 | 0 | libfvalue_split_utf8_string_free( |
5450 | 0 | &date_time_values, |
5451 | 0 | NULL ); |
5452 | 0 | } |
5453 | 0 | if( *date_time_values_string != NULL ) |
5454 | 0 | { |
5455 | 0 | memory_free( |
5456 | 0 | *date_time_values_string ); |
5457 | |
|
5458 | 0 | *date_time_values_string = NULL; |
5459 | 0 | } |
5460 | 0 | *date_time_values_string_size = 0; |
5461 | |
|
5462 | 0 | return( -1 ); |
5463 | 0 | } |
5464 | | |
5465 | | /* Generate date time values string within a xheader value |
5466 | | * Sets date time values string and size |
5467 | | * Returns 1 if successful or -1 on error |
5468 | | */ |
5469 | | int libewf_generate_date_xheader_value( |
5470 | | time_t timestamp, |
5471 | | uint8_t **date_time_values_string, |
5472 | | size_t *date_time_values_string_size, |
5473 | | libcerror_error_t **error ) |
5474 | 0 | { |
5475 | 0 | struct tm time_elements; |
5476 | |
|
5477 | 0 | static char *function = "libewf_generate_date_xheader_value"; |
5478 | 0 | size_t date_time_values_string_index = 0; |
5479 | 0 | int print_count = 0; |
5480 | |
|
5481 | | #if defined( WINAPI ) |
5482 | | size_t tzname_length = 0; |
5483 | | #endif |
5484 | |
|
5485 | 0 | if( date_time_values_string == NULL ) |
5486 | 0 | { |
5487 | 0 | libcerror_error_set( |
5488 | 0 | error, |
5489 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5490 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5491 | 0 | "%s: invalid date time values string.", |
5492 | 0 | function ); |
5493 | |
|
5494 | 0 | return( -1 ); |
5495 | 0 | } |
5496 | 0 | if( *date_time_values_string != NULL ) |
5497 | 0 | { |
5498 | 0 | libcerror_error_set( |
5499 | 0 | error, |
5500 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5501 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5502 | 0 | "%s: date time values string already created.", |
5503 | 0 | function ); |
5504 | |
|
5505 | 0 | return( -1 ); |
5506 | 0 | } |
5507 | 0 | if( date_time_values_string_size == NULL ) |
5508 | 0 | { |
5509 | 0 | libcerror_error_set( |
5510 | 0 | error, |
5511 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5512 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5513 | 0 | "%s: invalid date time values string size.", |
5514 | 0 | function ); |
5515 | |
|
5516 | 0 | return( -1 ); |
5517 | 0 | } |
5518 | 0 | if( libewf_date_time_localtime( |
5519 | 0 | ×tamp, |
5520 | 0 | &time_elements, |
5521 | 0 | error ) != 1 ) |
5522 | 0 | { |
5523 | 0 | libcerror_error_set( |
5524 | 0 | error, |
5525 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5526 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
5527 | 0 | "%s: unable to create time elements.", |
5528 | 0 | function ); |
5529 | |
|
5530 | 0 | goto on_error; |
5531 | 0 | } |
5532 | 0 | if( ( time_elements.tm_year + 1900 ) > 10000 ) |
5533 | 0 | { |
5534 | 0 | libcerror_error_set( |
5535 | 0 | error, |
5536 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5537 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
5538 | 0 | "%s: unsupported year value.", |
5539 | 0 | function ); |
5540 | |
|
5541 | 0 | goto on_error; |
5542 | 0 | } |
5543 | 0 | *date_time_values_string_size = 64; |
5544 | |
|
5545 | 0 | *date_time_values_string = (uint8_t *) memory_allocate( |
5546 | 0 | sizeof( uint8_t ) * *date_time_values_string_size ); |
5547 | |
|
5548 | 0 | if( *date_time_values_string == NULL ) |
5549 | 0 | { |
5550 | 0 | libcerror_error_set( |
5551 | 0 | error, |
5552 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
5553 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
5554 | 0 | "%s: unable to create date time values string.", |
5555 | 0 | function ); |
5556 | |
|
5557 | 0 | goto on_error; |
5558 | 0 | } |
5559 | 0 | if( libewf_utf8_string_day_of_week_copy_from_time_elements( |
5560 | 0 | *date_time_values_string, |
5561 | 0 | *date_time_values_string_size, |
5562 | 0 | &date_time_values_string_index, |
5563 | 0 | &time_elements, |
5564 | 0 | error ) != 1 ) |
5565 | 0 | { |
5566 | 0 | libcerror_error_set( |
5567 | 0 | error, |
5568 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5569 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5570 | 0 | "%s: unable to copy day of week to date time values string.", |
5571 | 0 | function ); |
5572 | |
|
5573 | 0 | goto on_error; |
5574 | 0 | } |
5575 | 0 | ( *date_time_values_string )[ date_time_values_string_index++ ] = (uint8_t) ' '; |
5576 | |
|
5577 | 0 | if( libewf_utf8_string_month_copy_from_time_elements( |
5578 | 0 | *date_time_values_string, |
5579 | 0 | *date_time_values_string_size, |
5580 | 0 | &date_time_values_string_index, |
5581 | 0 | &time_elements, |
5582 | 0 | error ) != 1 ) |
5583 | 0 | { |
5584 | 0 | libcerror_error_set( |
5585 | 0 | error, |
5586 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5587 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5588 | 0 | "%s: unable to copy month to date time values string.", |
5589 | 0 | function ); |
5590 | |
|
5591 | 0 | goto on_error; |
5592 | 0 | } |
5593 | 0 | ( *date_time_values_string )[ date_time_values_string_index++ ] = (uint8_t) ' '; |
5594 | |
|
5595 | 0 | if( time_elements.tm_mday < 10 ) |
5596 | 0 | { |
5597 | 0 | ( *date_time_values_string )[ date_time_values_string_index++ ] = (uint8_t) ' '; |
5598 | 0 | } |
5599 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
5600 | 0 | *date_time_values_string, |
5601 | 0 | *date_time_values_string_size, |
5602 | 0 | &date_time_values_string_index, |
5603 | 0 | (uint64_t) time_elements.tm_mday, |
5604 | 0 | 8, |
5605 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
5606 | 0 | error ) != 1 ) |
5607 | 0 | { |
5608 | 0 | libcerror_error_set( |
5609 | 0 | error, |
5610 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5611 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5612 | 0 | "%s: unable to copy day of month to date time values string.", |
5613 | 0 | function ); |
5614 | |
|
5615 | 0 | goto on_error; |
5616 | 0 | } |
5617 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
5618 | |
|
5619 | 0 | if( libewf_utf8_string_time_copy_from_time_elements( |
5620 | 0 | *date_time_values_string, |
5621 | 0 | *date_time_values_string_size, |
5622 | 0 | &date_time_values_string_index, |
5623 | 0 | &time_elements, |
5624 | 0 | error ) != 1 ) |
5625 | 0 | { |
5626 | 0 | libcerror_error_set( |
5627 | 0 | error, |
5628 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5629 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5630 | 0 | "%s: unable to copy time to date time values string.", |
5631 | 0 | function ); |
5632 | |
|
5633 | 0 | goto on_error; |
5634 | 0 | } |
5635 | 0 | ( *date_time_values_string )[ date_time_values_string_index++ ] = (uint8_t) ' '; |
5636 | |
|
5637 | 0 | if( libfvalue_utf8_string_with_index_copy_from_integer( |
5638 | 0 | *date_time_values_string, |
5639 | 0 | *date_time_values_string_size, |
5640 | 0 | &date_time_values_string_index, |
5641 | 0 | (uint64_t) time_elements.tm_year + 1900, |
5642 | 0 | 16, |
5643 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
5644 | 0 | error ) != 1 ) |
5645 | 0 | { |
5646 | 0 | libcerror_error_set( |
5647 | 0 | error, |
5648 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5649 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5650 | 0 | "%s: unable to copy year to date time values string.", |
5651 | 0 | function ); |
5652 | |
|
5653 | 0 | goto on_error; |
5654 | 0 | } |
5655 | 0 | ( *date_time_values_string )[ date_time_values_string_index - 1 ] = (uint8_t) ' '; |
5656 | |
|
5657 | | #if defined( _BSD_SOURCE ) |
5658 | | time_elements.tm_gmtoff /= 60; |
5659 | | |
5660 | | print_count = narrow_string_snprintf( |
5661 | | (char *) &( ( ( *date_time_values_string )[ date_time_values_string_index ] ) ), |
5662 | | *date_time_values_string_size - date_time_values_string_index, |
5663 | | "%+03ld:%02ld (%s)", |
5664 | | time_elements.tm_gmtoff / 60, |
5665 | | time_elements.tm_gmtoff % 60, |
5666 | | time_elements.tm_zone ); |
5667 | | |
5668 | | #elif defined( WINAPI ) |
5669 | | /* WINAPI sometimes uses long timezone names |
5670 | | */ |
5671 | | tzname_length = narrow_string_length( |
5672 | | _tzname[ time_elements.tm_isdst ] ); |
5673 | | |
5674 | | if( tzname_length <= 4 ) |
5675 | | { |
5676 | | print_count = narrow_string_snprintf( |
5677 | | (char *) &( ( ( *date_time_values_string )[ date_time_values_string_index ] ) ), |
5678 | | *date_time_values_string_size - date_time_values_string_index, |
5679 | | "%s", |
5680 | | _tzname[ time_elements.tm_isdst ] ); |
5681 | | } |
5682 | | else |
5683 | | { |
5684 | | print_count = 0; |
5685 | | } |
5686 | | #else |
5687 | 0 | print_count = narrow_string_snprintf( |
5688 | 0 | (char *) &( ( ( *date_time_values_string )[ date_time_values_string_index ] ) ), |
5689 | 0 | *date_time_values_string_size - date_time_values_string_index, |
5690 | 0 | "%s", |
5691 | 0 | tzname[ time_elements.tm_isdst ] ); |
5692 | 0 | #endif |
5693 | |
|
5694 | 0 | if( ( print_count <= -1 ) |
5695 | 0 | || ( (size_t) print_count > ( *date_time_values_string_size - date_time_values_string_index ) ) ) |
5696 | 0 | { |
5697 | 0 | libcerror_error_set( |
5698 | 0 | error, |
5699 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5700 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5701 | 0 | "%s: unable to set date time values string.", |
5702 | 0 | function ); |
5703 | |
|
5704 | 0 | goto on_error; |
5705 | 0 | } |
5706 | 0 | date_time_values_string_index += print_count; |
5707 | |
|
5708 | 0 | ( *date_time_values_string )[ date_time_values_string_index ] = 0; |
5709 | |
|
5710 | 0 | return( 1 ); |
5711 | | |
5712 | 0 | on_error: |
5713 | 0 | if( *date_time_values_string != NULL ) |
5714 | 0 | { |
5715 | 0 | memory_free( |
5716 | 0 | *date_time_values_string ); |
5717 | |
|
5718 | 0 | *date_time_values_string = NULL; |
5719 | 0 | } |
5720 | 0 | *date_time_values_string_size = 0; |
5721 | |
|
5722 | 0 | return( -1 ); |
5723 | 0 | } |
5724 | | |
5725 | | /* Parses a xheader for the values |
5726 | | * Returns 1 if successful or -1 on error |
5727 | | */ |
5728 | | int libewf_header_values_parse_xheader( |
5729 | | libfvalue_table_t *header_values, |
5730 | | const uint8_t *xheader, |
5731 | | size_t xheader_size, |
5732 | | libcerror_error_t **error ) |
5733 | 47 | { |
5734 | 47 | static char *function = "libewf_header_values_parse_xheader"; |
5735 | | |
5736 | 47 | if( libfvalue_table_copy_from_utf8_xml_string( |
5737 | 47 | header_values, |
5738 | 47 | xheader, |
5739 | 47 | xheader_size, |
5740 | 47 | (uint8_t *) "xheader", |
5741 | 47 | 7, |
5742 | 47 | error ) != 1 ) |
5743 | 47 | { |
5744 | 47 | libcerror_error_set( |
5745 | 47 | error, |
5746 | 47 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5747 | 47 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5748 | 47 | "%s: unable to copy UTF-8 string to header values table.", |
5749 | 47 | function ); |
5750 | | |
5751 | 47 | return( -1 ); |
5752 | 47 | } |
5753 | 0 | if( libewf_header_values_parse_xheader_date_value( |
5754 | 0 | header_values, |
5755 | 0 | (uint8_t *) "acquiry_date", |
5756 | 0 | 13, |
5757 | 0 | error ) != 1 ) |
5758 | 0 | { |
5759 | 0 | libcerror_error_set( |
5760 | 0 | error, |
5761 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
5762 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
5763 | 0 | "%s: unable to parse xheader date value: acquiry_date.", |
5764 | 0 | function ); |
5765 | |
|
5766 | 0 | return( -1 ); |
5767 | 0 | } |
5768 | 0 | return( 1 ); |
5769 | 0 | } |
5770 | | |
5771 | | /* Parses a xheader date value |
5772 | | * Returns 1 if successful or -1 on error |
5773 | | */ |
5774 | | int libewf_header_values_parse_xheader_date_value( |
5775 | | libfvalue_table_t *header_values, |
5776 | | const uint8_t *identifier, |
5777 | | size_t identifier_size, |
5778 | | libcerror_error_t **error ) |
5779 | 0 | { |
5780 | 0 | libfvalue_value_t *header_value = NULL; |
5781 | 0 | uint8_t *date_time_values_string = NULL; |
5782 | 0 | uint8_t *value_data = NULL; |
5783 | 0 | static char *function = "libewf_header_values_parse_xheader_date_value"; |
5784 | 0 | size_t date_time_values_string_size = 0; |
5785 | 0 | size_t value_data_size = 0; |
5786 | 0 | int encoding = 0; |
5787 | 0 | int result = 0; |
5788 | |
|
5789 | 0 | result = libfvalue_table_get_value_by_identifier( |
5790 | 0 | header_values, |
5791 | 0 | identifier, |
5792 | 0 | identifier_size, |
5793 | 0 | &header_value, |
5794 | 0 | 0, |
5795 | 0 | error ); |
5796 | |
|
5797 | 0 | if( result == -1 ) |
5798 | 0 | { |
5799 | 0 | libcerror_error_set( |
5800 | 0 | error, |
5801 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5802 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5803 | 0 | "%s: unable to retrieve header value: %s.", |
5804 | 0 | function, |
5805 | 0 | (char *) identifier ); |
5806 | |
|
5807 | 0 | goto on_error; |
5808 | 0 | } |
5809 | 0 | else if( result == 1 ) |
5810 | 0 | { |
5811 | 0 | if( libfvalue_value_get_data( |
5812 | 0 | header_value, |
5813 | 0 | &value_data, |
5814 | 0 | &value_data_size, |
5815 | 0 | &encoding, |
5816 | 0 | error ) != 1 ) |
5817 | 0 | { |
5818 | 0 | libcerror_error_set( |
5819 | 0 | error, |
5820 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5821 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5822 | 0 | "%s: unable to retrieve header value: %s data.", |
5823 | 0 | function, |
5824 | 0 | (char *) identifier ); |
5825 | |
|
5826 | 0 | goto on_error; |
5827 | 0 | } |
5828 | 0 | result = libewf_convert_date_xheader_value( |
5829 | 0 | value_data, |
5830 | 0 | value_data_size, |
5831 | 0 | &date_time_values_string, |
5832 | 0 | &date_time_values_string_size, |
5833 | 0 | error ); |
5834 | |
|
5835 | 0 | if( result == -1 ) |
5836 | 0 | { |
5837 | 0 | libcerror_error_set( |
5838 | 0 | error, |
5839 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
5840 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
5841 | 0 | "%s: unable to create date time values string.", |
5842 | 0 | function ); |
5843 | |
|
5844 | | #if defined( HAVE_DEBUG_OUTPUT ) |
5845 | | if( libcnotify_verbose != 0 ) |
5846 | | { |
5847 | | if( ( error != NULL ) |
5848 | | && ( *error != NULL ) ) |
5849 | | { |
5850 | | libcnotify_print_error_backtrace( |
5851 | | *error ); |
5852 | | } |
5853 | | } |
5854 | | #endif |
5855 | 0 | libcerror_error_free( |
5856 | 0 | error ); |
5857 | 0 | } |
5858 | 0 | else if( result != 0 ) |
5859 | 0 | { |
5860 | | /* Make sure to determine the actual length of the date time values string |
5861 | | */ |
5862 | 0 | date_time_values_string_size = 1 + narrow_string_length( |
5863 | 0 | (char *) date_time_values_string ); |
5864 | |
|
5865 | 0 | if( libfvalue_value_set_data( |
5866 | 0 | header_value, |
5867 | 0 | date_time_values_string, |
5868 | 0 | date_time_values_string_size, |
5869 | 0 | LIBFVALUE_CODEPAGE_UTF8, |
5870 | 0 | LIBFVALUE_VALUE_DATA_FLAG_MANAGED, |
5871 | 0 | error ) != 1 ) |
5872 | 0 | { |
5873 | 0 | libcerror_error_set( |
5874 | 0 | error, |
5875 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5876 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5877 | 0 | "%s: unable to set header value: %s data.", |
5878 | 0 | function, |
5879 | 0 | (char *) identifier ); |
5880 | |
|
5881 | 0 | goto on_error; |
5882 | 0 | } |
5883 | 0 | memory_free( |
5884 | 0 | date_time_values_string ); |
5885 | |
|
5886 | 0 | date_time_values_string = NULL; |
5887 | 0 | } |
5888 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
5889 | | else if( libcnotify_verbose != 0 ) |
5890 | | { |
5891 | | libcnotify_printf( |
5892 | | "%s: unsupported xheader date value: %s.\n", |
5893 | | function, |
5894 | | (char *) identifier ); |
5895 | | } |
5896 | | #endif |
5897 | 0 | } |
5898 | 0 | return( 1 ); |
5899 | | |
5900 | 0 | on_error: |
5901 | 0 | if( date_time_values_string != NULL ) |
5902 | 0 | { |
5903 | 0 | memory_free( |
5904 | 0 | date_time_values_string ); |
5905 | 0 | } |
5906 | 0 | return( -1 ); |
5907 | 0 | } |
5908 | | |
5909 | | /* Generate an xheader |
5910 | | * Sets xheader and the xheader size |
5911 | | * Returns 1 if successful or -1 on error |
5912 | | */ |
5913 | | int libewf_header_values_generate_xheader( |
5914 | | libfvalue_table_t *header_values, |
5915 | | time_t timestamp, |
5916 | | uint8_t **xheader, |
5917 | | size_t *xheader_size, |
5918 | | libcerror_error_t **error ) |
5919 | 0 | { |
5920 | 0 | libfvalue_value_t *header_value = NULL; |
5921 | 0 | uint8_t *generated_acquiry_date = NULL; |
5922 | 0 | uint8_t *identifier = NULL; |
5923 | 0 | char *xml_head = NULL; |
5924 | 0 | char *xml_xheader_close_tag = NULL; |
5925 | 0 | char *xml_xheader_open_tag = NULL; |
5926 | 0 | static char *function = "libewf_header_values_generate_xheader"; |
5927 | 0 | size_t acquiry_date_string_length = 0; |
5928 | 0 | size_t generated_acquiry_date_size = 0; |
5929 | 0 | size_t identifier_size = 0; |
5930 | 0 | size_t value_string_size = 0; |
5931 | 0 | size_t xheader_index = 0; |
5932 | 0 | size_t xml_head_length = 0; |
5933 | 0 | size_t xml_xheader_close_tag_length = 0; |
5934 | 0 | size_t xml_xheader_open_tag_length = 0; |
5935 | 0 | int header_value_index = 0; |
5936 | 0 | int number_of_header_values = 0; |
5937 | 0 | int result = 0; |
5938 | |
|
5939 | 0 | if( xheader == NULL ) |
5940 | 0 | { |
5941 | 0 | libcerror_error_set( |
5942 | 0 | error, |
5943 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5944 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5945 | 0 | "%s: invalid xheader.", |
5946 | 0 | function ); |
5947 | |
|
5948 | 0 | return( -1 ); |
5949 | 0 | } |
5950 | 0 | if( *xheader != NULL ) |
5951 | 0 | { |
5952 | 0 | libcerror_error_set( |
5953 | 0 | error, |
5954 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5955 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5956 | 0 | "%s: xheader already created.", |
5957 | 0 | function ); |
5958 | |
|
5959 | 0 | return( -1 ); |
5960 | 0 | } |
5961 | 0 | if( xheader_size == NULL ) |
5962 | 0 | { |
5963 | 0 | libcerror_error_set( |
5964 | 0 | error, |
5965 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5966 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5967 | 0 | "%s: invalid string size.", |
5968 | 0 | function ); |
5969 | |
|
5970 | 0 | return( -1 ); |
5971 | 0 | } |
5972 | 0 | if( libfvalue_table_get_number_of_values( |
5973 | 0 | header_values, |
5974 | 0 | &number_of_header_values, |
5975 | 0 | error ) != 1 ) |
5976 | 0 | { |
5977 | 0 | libcerror_error_set( |
5978 | 0 | error, |
5979 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5980 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5981 | 0 | "%s: unable to retrieve number of header values.", |
5982 | 0 | function ); |
5983 | |
|
5984 | 0 | goto on_error; |
5985 | 0 | } |
5986 | 0 | xml_head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
5987 | |
|
5988 | 0 | xml_head_length = narrow_string_length( |
5989 | 0 | xml_head ); |
5990 | |
|
5991 | 0 | xml_xheader_open_tag = "<xheader>\n"; |
5992 | |
|
5993 | 0 | xml_xheader_open_tag_length = narrow_string_length( |
5994 | 0 | xml_xheader_open_tag ); |
5995 | |
|
5996 | 0 | xml_xheader_close_tag = "</xheader>\n\n"; |
5997 | |
|
5998 | 0 | xml_xheader_close_tag_length = narrow_string_length( |
5999 | 0 | xml_xheader_close_tag ); |
6000 | | |
6001 | | /* Reserve space for the UTF-8 byte order mark and the XML skeleton data |
6002 | | */ |
6003 | 0 | *xheader_size = 3 + xml_head_length + xml_xheader_open_tag_length + xml_xheader_close_tag_length; |
6004 | |
|
6005 | 0 | for( header_value_index = 0; |
6006 | 0 | header_value_index < number_of_header_values; |
6007 | 0 | header_value_index++ ) |
6008 | 0 | { |
6009 | 0 | if( libfvalue_table_get_value_by_index( |
6010 | 0 | header_values, |
6011 | 0 | header_value_index, |
6012 | 0 | &header_value, |
6013 | 0 | error ) != 1 ) |
6014 | 0 | { |
6015 | 0 | libcerror_error_set( |
6016 | 0 | error, |
6017 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6018 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6019 | 0 | "%s: unable to retrieve header value: %d.", |
6020 | 0 | function, |
6021 | 0 | header_value_index ); |
6022 | |
|
6023 | 0 | goto on_error; |
6024 | 0 | } |
6025 | 0 | if( libfvalue_value_get_identifier( |
6026 | 0 | header_value, |
6027 | 0 | &identifier, |
6028 | 0 | &identifier_size, |
6029 | 0 | error ) != 1 ) |
6030 | 0 | { |
6031 | 0 | libcerror_error_set( |
6032 | 0 | error, |
6033 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6034 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6035 | 0 | "%s: unable to retrieve identifier of header value: %d.", |
6036 | 0 | function, |
6037 | 0 | header_value_index ); |
6038 | |
|
6039 | 0 | goto on_error; |
6040 | 0 | } |
6041 | 0 | if( ( identifier == NULL ) |
6042 | 0 | || ( identifier_size == 0 ) ) |
6043 | 0 | { |
6044 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
6045 | | if( libcnotify_verbose != 0 ) |
6046 | | { |
6047 | | libcnotify_printf( |
6048 | | "%s: missing identifier for header value: %d.\n", |
6049 | | function, |
6050 | | header_value_index ); |
6051 | | } |
6052 | | #endif |
6053 | 0 | continue; |
6054 | 0 | } |
6055 | 0 | result = libfvalue_value_has_data( |
6056 | 0 | header_value, |
6057 | 0 | error ); |
6058 | |
|
6059 | 0 | if( result == -1 ) |
6060 | 0 | { |
6061 | 0 | libcerror_error_set( |
6062 | 0 | error, |
6063 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6064 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6065 | 0 | "%s: unable to retrieve data of header value: %s.", |
6066 | 0 | function, |
6067 | 0 | (char *) identifier ); |
6068 | |
|
6069 | 0 | goto on_error; |
6070 | 0 | } |
6071 | 0 | else if( result == 0 ) |
6072 | 0 | { |
6073 | 0 | if( ( generated_acquiry_date == NULL ) |
6074 | 0 | && ( identifier_size == 13 ) |
6075 | 0 | && ( narrow_string_compare( |
6076 | 0 | (char *) identifier, |
6077 | 0 | "acquiry_date", |
6078 | 0 | 12 ) == 0 ) ) |
6079 | 0 | { |
6080 | 0 | if( libewf_generate_date_xheader_value( |
6081 | 0 | timestamp, |
6082 | 0 | &generated_acquiry_date, |
6083 | 0 | &generated_acquiry_date_size, |
6084 | 0 | error ) != 1 ) |
6085 | 0 | { |
6086 | 0 | libcerror_error_set( |
6087 | 0 | error, |
6088 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6089 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
6090 | 0 | "%s: unable to generate acquiry date header value.", |
6091 | 0 | function ); |
6092 | |
|
6093 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
6094 | | if( libcnotify_verbose != 0 ) |
6095 | | { |
6096 | | if( ( error != NULL ) |
6097 | | && ( *error != NULL ) ) |
6098 | | { |
6099 | | libcnotify_print_error_backtrace( |
6100 | | *error ); |
6101 | | } |
6102 | | } |
6103 | | #endif |
6104 | 0 | libcerror_error_free( |
6105 | 0 | error ); |
6106 | 0 | } |
6107 | 0 | else |
6108 | 0 | { |
6109 | 0 | acquiry_date_string_length = narrow_string_length( |
6110 | 0 | (char *) generated_acquiry_date ); |
6111 | | |
6112 | | /* Reserve space for a leading tab, <acquiry_date>, header value, </acquiry_date> and a newline |
6113 | | * Make sure to determine the effective length of the acquiry date time values string |
6114 | | */ |
6115 | 0 | *xheader_size += 7 + ( 2 * ( identifier_size - 1 ) ) + acquiry_date_string_length; |
6116 | 0 | } |
6117 | 0 | } |
6118 | 0 | continue; |
6119 | 0 | } |
6120 | 0 | result = libfvalue_value_get_utf8_string_size( |
6121 | 0 | header_value, |
6122 | 0 | 0, |
6123 | 0 | &value_string_size, |
6124 | 0 | error ); |
6125 | |
|
6126 | 0 | if( result == -1 ) |
6127 | 0 | { |
6128 | 0 | libcerror_error_set( |
6129 | 0 | error, |
6130 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6131 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6132 | 0 | "%s: unable to retrieve string size of header value: %s.", |
6133 | 0 | function, |
6134 | 0 | (char *) identifier ); |
6135 | |
|
6136 | 0 | goto on_error; |
6137 | 0 | } |
6138 | 0 | if( value_string_size > 1 ) |
6139 | 0 | { |
6140 | | /* Reserve space for a leading tab, <identifier>value</identifier> and a newline |
6141 | | */ |
6142 | 0 | *xheader_size += 7 + ( 2 * ( identifier_size - 1 ) ) + ( value_string_size - 1 ); |
6143 | 0 | } |
6144 | 0 | } |
6145 | | /* Reserve space for the end-of-string character |
6146 | | */ |
6147 | 0 | *xheader_size += 1; |
6148 | |
|
6149 | 0 | if( *xheader_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) |
6150 | 0 | { |
6151 | 0 | libcerror_error_set( |
6152 | 0 | error, |
6153 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6154 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
6155 | 0 | "%s: invalid xheader size value out of bounds.", |
6156 | 0 | function ); |
6157 | |
|
6158 | 0 | goto on_error; |
6159 | 0 | } |
6160 | 0 | *xheader = (uint8_t *) memory_allocate( |
6161 | 0 | sizeof( uint8_t ) * *xheader_size ); |
6162 | |
|
6163 | 0 | if( *xheader == NULL ) |
6164 | 0 | { |
6165 | 0 | libcerror_error_set( |
6166 | 0 | error, |
6167 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
6168 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
6169 | 0 | "%s: unable to create xheader.", |
6170 | 0 | function ); |
6171 | |
|
6172 | 0 | goto on_error; |
6173 | 0 | } |
6174 | 0 | ( *xheader )[ xheader_index++ ] = 0xef; |
6175 | 0 | ( *xheader )[ xheader_index++ ] = 0xbb; |
6176 | 0 | ( *xheader )[ xheader_index++ ] = 0xbf; |
6177 | |
|
6178 | 0 | if( narrow_string_copy( |
6179 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6180 | 0 | xml_head, |
6181 | 0 | xml_head_length ) == NULL ) |
6182 | 0 | { |
6183 | 0 | libcerror_error_set( |
6184 | 0 | error, |
6185 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6186 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6187 | 0 | "%s: unable to copy XML head string.", |
6188 | 0 | function ); |
6189 | |
|
6190 | 0 | goto on_error; |
6191 | 0 | } |
6192 | 0 | xheader_index += xml_head_length; |
6193 | |
|
6194 | 0 | if( narrow_string_copy( |
6195 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6196 | 0 | xml_xheader_open_tag, |
6197 | 0 | xml_xheader_open_tag_length ) == NULL ) |
6198 | 0 | { |
6199 | 0 | libcerror_error_set( |
6200 | 0 | error, |
6201 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6202 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6203 | 0 | "%s: unable to copy xheader open tag string.", |
6204 | 0 | function ); |
6205 | |
|
6206 | 0 | goto on_error; |
6207 | 0 | } |
6208 | 0 | xheader_index += xml_xheader_open_tag_length; |
6209 | |
|
6210 | 0 | for( header_value_index = 0; |
6211 | 0 | header_value_index < number_of_header_values; |
6212 | 0 | header_value_index++ ) |
6213 | 0 | { |
6214 | 0 | if( libfvalue_table_get_value_by_index( |
6215 | 0 | header_values, |
6216 | 0 | header_value_index, |
6217 | 0 | &header_value, |
6218 | 0 | error ) != 1 ) |
6219 | 0 | { |
6220 | 0 | libcerror_error_set( |
6221 | 0 | error, |
6222 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6223 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6224 | 0 | "%s: unable to retrieve header value: %d.", |
6225 | 0 | function, |
6226 | 0 | header_value_index ); |
6227 | |
|
6228 | 0 | goto on_error; |
6229 | 0 | } |
6230 | 0 | if( libfvalue_value_get_identifier( |
6231 | 0 | header_value, |
6232 | 0 | &identifier, |
6233 | 0 | &identifier_size, |
6234 | 0 | error ) != 1 ) |
6235 | 0 | { |
6236 | 0 | libcerror_error_set( |
6237 | 0 | error, |
6238 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6239 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6240 | 0 | "%s: unable to retrieve identifier of header value: %d.", |
6241 | 0 | function, |
6242 | 0 | header_value_index ); |
6243 | |
|
6244 | 0 | goto on_error; |
6245 | 0 | } |
6246 | 0 | if( ( identifier == NULL ) |
6247 | 0 | || ( identifier_size == 0 ) ) |
6248 | 0 | { |
6249 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
6250 | | if( libcnotify_verbose != 0 ) |
6251 | | { |
6252 | | libcnotify_printf( |
6253 | | "%s: missing identifier for header value: %d.\n", |
6254 | | function, |
6255 | | header_value_index ); |
6256 | | } |
6257 | | #endif |
6258 | 0 | continue; |
6259 | 0 | } |
6260 | 0 | result = libfvalue_value_has_data( |
6261 | 0 | header_value, |
6262 | 0 | error ); |
6263 | |
|
6264 | 0 | if( result == -1 ) |
6265 | 0 | { |
6266 | 0 | libcerror_error_set( |
6267 | 0 | error, |
6268 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6269 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6270 | 0 | "%s: unable to retrieve data of header value: %s.", |
6271 | 0 | function, |
6272 | 0 | (char *) identifier ); |
6273 | |
|
6274 | 0 | goto on_error; |
6275 | 0 | } |
6276 | 0 | else if( result == 0 ) |
6277 | 0 | { |
6278 | 0 | continue; |
6279 | 0 | } |
6280 | 0 | result = libfvalue_value_get_utf8_string_size( |
6281 | 0 | header_value, |
6282 | 0 | 0, |
6283 | 0 | &value_string_size, |
6284 | 0 | error ); |
6285 | |
|
6286 | 0 | if( result == -1 ) |
6287 | 0 | { |
6288 | 0 | libcerror_error_set( |
6289 | 0 | error, |
6290 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6291 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6292 | 0 | "%s: unable to retrieve string size of header value: %s.", |
6293 | 0 | function, |
6294 | 0 | (char *) identifier ); |
6295 | |
|
6296 | 0 | goto on_error; |
6297 | 0 | } |
6298 | 0 | if( value_string_size > 1 ) |
6299 | 0 | { |
6300 | 0 | ( *xheader )[ xheader_index++ ] = (uint8_t) '\t'; |
6301 | 0 | ( *xheader )[ xheader_index++ ] = (uint8_t) '<'; |
6302 | |
|
6303 | 0 | if( narrow_string_copy( |
6304 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6305 | 0 | (char *) identifier, |
6306 | 0 | identifier_size - 1 ) == NULL ) |
6307 | 0 | { |
6308 | 0 | libcerror_error_set( |
6309 | 0 | error, |
6310 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6311 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6312 | 0 | "%s: unable to copy %s open tag string.", |
6313 | 0 | function, |
6314 | 0 | (char *) identifier ); |
6315 | |
|
6316 | 0 | goto on_error; |
6317 | 0 | } |
6318 | 0 | xheader_index += identifier_size - 1; |
6319 | |
|
6320 | 0 | ( *xheader )[ xheader_index++ ] = (uint8_t) '>'; |
6321 | |
|
6322 | 0 | result = libfvalue_value_copy_to_utf8_string_with_index( |
6323 | 0 | header_value, |
6324 | 0 | 0, |
6325 | 0 | *xheader, |
6326 | 0 | *xheader_size, |
6327 | 0 | &xheader_index, |
6328 | 0 | error ); |
6329 | |
|
6330 | 0 | if( result == -1 ) |
6331 | 0 | { |
6332 | 0 | libcerror_error_set( |
6333 | 0 | error, |
6334 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6335 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6336 | 0 | "%s: unable to copy header value: %s to string.", |
6337 | 0 | function, |
6338 | 0 | (char *) identifier ); |
6339 | |
|
6340 | 0 | goto on_error; |
6341 | 0 | } |
6342 | 0 | ( *xheader )[ xheader_index - 1 ] = (uint8_t) '<'; |
6343 | 0 | ( *xheader )[ xheader_index++ ] = (uint8_t) '/'; |
6344 | |
|
6345 | 0 | if( narrow_string_copy( |
6346 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6347 | 0 | (char *) identifier, |
6348 | 0 | identifier_size - 1 ) == NULL ) |
6349 | 0 | { |
6350 | 0 | libcerror_error_set( |
6351 | 0 | error, |
6352 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6353 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6354 | 0 | "%s: unable to copy %s close tag string.", |
6355 | 0 | function, |
6356 | 0 | (char *) identifier ); |
6357 | |
|
6358 | 0 | goto on_error; |
6359 | 0 | } |
6360 | 0 | xheader_index += identifier_size - 1; |
6361 | |
|
6362 | 0 | ( *xheader )[ xheader_index++ ] = (uint8_t) '>'; |
6363 | 0 | ( *xheader )[ xheader_index++ ] = (uint8_t) '\n'; |
6364 | 0 | } |
6365 | 0 | } |
6366 | 0 | if( generated_acquiry_date != NULL ) |
6367 | 0 | { |
6368 | 0 | if( narrow_string_copy( |
6369 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6370 | 0 | "\t<acquiry_date>", |
6371 | 0 | 15 ) == NULL ) |
6372 | 0 | { |
6373 | 0 | libcerror_error_set( |
6374 | 0 | error, |
6375 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6376 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6377 | 0 | "%s: unable to copy acquiry_date open tag string.", |
6378 | 0 | function ); |
6379 | |
|
6380 | 0 | goto on_error; |
6381 | 0 | } |
6382 | 0 | xheader_index += 15; |
6383 | |
|
6384 | 0 | if( narrow_string_copy( |
6385 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6386 | 0 | (char *) generated_acquiry_date, |
6387 | 0 | acquiry_date_string_length ) == NULL ) |
6388 | 0 | { |
6389 | 0 | libcerror_error_set( |
6390 | 0 | error, |
6391 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6392 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6393 | 0 | "%s: unable to copy generated acquiry date string.", |
6394 | 0 | function ); |
6395 | |
|
6396 | 0 | goto on_error; |
6397 | 0 | } |
6398 | 0 | xheader_index += acquiry_date_string_length; |
6399 | |
|
6400 | 0 | memory_free( |
6401 | 0 | generated_acquiry_date ); |
6402 | |
|
6403 | 0 | generated_acquiry_date = NULL; |
6404 | |
|
6405 | 0 | if( narrow_string_copy( |
6406 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6407 | 0 | "</acquiry_date>\n", |
6408 | 0 | 16 ) == NULL ) |
6409 | 0 | { |
6410 | 0 | libcerror_error_set( |
6411 | 0 | error, |
6412 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6413 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6414 | 0 | "%s: unable to copy acquiry_date close tag string.", |
6415 | 0 | function ); |
6416 | |
|
6417 | 0 | goto on_error; |
6418 | 0 | } |
6419 | 0 | xheader_index += 16; |
6420 | 0 | } |
6421 | 0 | if( narrow_string_copy( |
6422 | 0 | (char *) &( ( *xheader )[ xheader_index ] ), |
6423 | 0 | xml_xheader_close_tag, |
6424 | 0 | xml_xheader_close_tag_length ) == NULL ) |
6425 | 0 | { |
6426 | 0 | libcerror_error_set( |
6427 | 0 | error, |
6428 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6429 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6430 | 0 | "%s: unable to copy xheader close tag string.", |
6431 | 0 | function ); |
6432 | |
|
6433 | 0 | goto on_error; |
6434 | 0 | } |
6435 | 0 | xheader_index += xml_xheader_close_tag_length; |
6436 | | |
6437 | | /* Make sure the string is terminated |
6438 | | */ |
6439 | 0 | ( *xheader )[ xheader_index ] = 0; |
6440 | |
|
6441 | 0 | return( 1 ); |
6442 | | |
6443 | 0 | on_error: |
6444 | 0 | if( generated_acquiry_date != NULL ) |
6445 | 0 | { |
6446 | 0 | memory_free( |
6447 | 0 | generated_acquiry_date ); |
6448 | 0 | } |
6449 | 0 | if( *xheader != NULL ) |
6450 | 0 | { |
6451 | 0 | memory_free( |
6452 | 0 | *xheader ); |
6453 | |
|
6454 | 0 | *xheader = NULL; |
6455 | 0 | } |
6456 | 0 | *xheader_size = 0; |
6457 | |
|
6458 | 0 | return( -1 ); |
6459 | 0 | } |
6460 | | |
6461 | | /* Generate an EWFX header |
6462 | | * Sets header and the header size |
6463 | | * Returns 1 if successful or -1 on error |
6464 | | */ |
6465 | | int libewf_header_values_generate_header_ewfx( |
6466 | | libfvalue_table_t *header_values, |
6467 | | time_t timestamp, |
6468 | | int8_t compression_level, |
6469 | | uint8_t **header, |
6470 | | size_t *header_size, |
6471 | | int codepage, |
6472 | | libcerror_error_t **error ) |
6473 | 0 | { |
6474 | 0 | uint8_t *header_string = NULL; |
6475 | 0 | static char *function = "libewf_header_values_generate_header_ewfx"; |
6476 | 0 | size_t header_string_size = 0; |
6477 | |
|
6478 | 0 | if( libewf_header_values_generate_utf8_header_string( |
6479 | 0 | header_values, |
6480 | 0 | 1, |
6481 | 0 | LIBEWF_HEADER_STRING_TYPE_3, |
6482 | 0 | (uint8_t *) "\n", |
6483 | 0 | 1, |
6484 | 0 | timestamp, |
6485 | 0 | compression_level, |
6486 | 0 | &header_string, |
6487 | 0 | &header_string_size, |
6488 | 0 | error ) != 1 ) |
6489 | 0 | { |
6490 | 0 | libcerror_error_set( |
6491 | 0 | error, |
6492 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6493 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
6494 | 0 | "%s: unable to create header string.", |
6495 | 0 | function ); |
6496 | |
|
6497 | 0 | goto on_error; |
6498 | 0 | } |
6499 | 0 | if( libewf_header_values_convert_utf8_header_string_to_header( |
6500 | 0 | header_string, |
6501 | 0 | header_string_size, |
6502 | 0 | header, |
6503 | 0 | header_size, |
6504 | 0 | codepage, |
6505 | 0 | error ) != 1 ) |
6506 | 0 | { |
6507 | 0 | libcerror_error_set( |
6508 | 0 | error, |
6509 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6510 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
6511 | 0 | "%s: unable to create header.", |
6512 | 0 | function ); |
6513 | |
|
6514 | 0 | goto on_error; |
6515 | 0 | } |
6516 | 0 | memory_free( |
6517 | 0 | header_string ); |
6518 | |
|
6519 | 0 | return( 1 ); |
6520 | | |
6521 | 0 | on_error: |
6522 | 0 | if( header_string != NULL ) |
6523 | 0 | { |
6524 | 0 | memory_free( |
6525 | 0 | header_string ); |
6526 | 0 | } |
6527 | 0 | return( -1 ); |
6528 | 0 | } |
6529 | | |
6530 | | /* Retrieves the size of the value identifier of a specific index |
6531 | | * The identifier size includes the end of string character |
6532 | | * Returns 1 if successful, 0 if no header values are present or -1 on error |
6533 | | */ |
6534 | | int libewf_header_values_get_identifier_size( |
6535 | | libfvalue_table_t *header_values, |
6536 | | uint32_t index, |
6537 | | size_t *identifier_size, |
6538 | | libcerror_error_t **error ) |
6539 | 0 | { |
6540 | 0 | libfvalue_value_t *header_value = NULL; |
6541 | 0 | uint8_t *header_value_identifier = NULL; |
6542 | 0 | static char *function = "libewf_header_values_get_identifier_size"; |
6543 | |
|
6544 | 0 | if( header_values == NULL ) |
6545 | 0 | { |
6546 | 0 | libcerror_error_set( |
6547 | 0 | error, |
6548 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6549 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6550 | 0 | "%s: invalid header values.", |
6551 | 0 | function ); |
6552 | |
|
6553 | 0 | return( -1 ); |
6554 | 0 | } |
6555 | 0 | if( libfvalue_table_get_value_by_index( |
6556 | 0 | header_values, |
6557 | 0 | (int) index, |
6558 | 0 | &header_value, |
6559 | 0 | error ) != 1 ) |
6560 | 0 | { |
6561 | 0 | libcerror_error_set( |
6562 | 0 | error, |
6563 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6564 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6565 | 0 | "%s: unable to retrieve header value: %" PRIu32 ".", |
6566 | 0 | function, |
6567 | 0 | index ); |
6568 | |
|
6569 | 0 | return( -1 ); |
6570 | 0 | } |
6571 | 0 | if( libfvalue_value_get_identifier( |
6572 | 0 | header_value, |
6573 | 0 | &header_value_identifier, |
6574 | 0 | identifier_size, |
6575 | 0 | error ) != 1 ) |
6576 | 0 | { |
6577 | 0 | libcerror_error_set( |
6578 | 0 | error, |
6579 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6580 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6581 | 0 | "%s: unable to retrieve header value identifier size.", |
6582 | 0 | function ); |
6583 | |
|
6584 | 0 | return( -1 ); |
6585 | 0 | } |
6586 | 0 | return( 1 ); |
6587 | 0 | } |
6588 | | |
6589 | | /* Retrieves the header value identifier of a specific index |
6590 | | * The identifier size should include the end of string character |
6591 | | * Returns 1 if successful, 0 if no header values are present or -1 on error |
6592 | | */ |
6593 | | int libewf_header_values_get_identifier( |
6594 | | libfvalue_table_t *header_values, |
6595 | | uint32_t index, |
6596 | | uint8_t *identifier, |
6597 | | size_t identifier_size, |
6598 | | libcerror_error_t **error ) |
6599 | 0 | { |
6600 | 0 | libfvalue_value_t *header_value = NULL; |
6601 | 0 | uint8_t *header_value_identifier = NULL; |
6602 | 0 | static char *function = "libewf_header_values_get_identifier"; |
6603 | 0 | size_t header_value_identifier_size = 0; |
6604 | |
|
6605 | 0 | if( header_values == NULL ) |
6606 | 0 | { |
6607 | 0 | libcerror_error_set( |
6608 | 0 | error, |
6609 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6610 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6611 | 0 | "%s: invalid header values.", |
6612 | 0 | function ); |
6613 | |
|
6614 | 0 | return( -1 ); |
6615 | 0 | } |
6616 | 0 | if( identifier == NULL ) |
6617 | 0 | { |
6618 | 0 | libcerror_error_set( |
6619 | 0 | error, |
6620 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6621 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6622 | 0 | "%s: invalid identifier.", |
6623 | 0 | function ); |
6624 | |
|
6625 | 0 | return( -1 ); |
6626 | 0 | } |
6627 | 0 | if( identifier_size > (size_t) SSIZE_MAX ) |
6628 | 0 | { |
6629 | 0 | libcerror_error_set( |
6630 | 0 | error, |
6631 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6632 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
6633 | 0 | "%s: invalid identifier size value exceeds maximum.", |
6634 | 0 | function ); |
6635 | |
|
6636 | 0 | return( -1 ); |
6637 | 0 | } |
6638 | 0 | if( libfvalue_table_get_value_by_index( |
6639 | 0 | header_values, |
6640 | 0 | (int) index, |
6641 | 0 | &header_value, |
6642 | 0 | error ) != 1 ) |
6643 | 0 | { |
6644 | 0 | libcerror_error_set( |
6645 | 0 | error, |
6646 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6647 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6648 | 0 | "%s: unable to retrieve header value: %" PRIu32 ".", |
6649 | 0 | function, |
6650 | 0 | index ); |
6651 | |
|
6652 | 0 | return( -1 ); |
6653 | 0 | } |
6654 | 0 | if( libfvalue_value_get_identifier( |
6655 | 0 | header_value, |
6656 | 0 | &header_value_identifier, |
6657 | 0 | &header_value_identifier_size, |
6658 | 0 | error ) != 1 ) |
6659 | 0 | { |
6660 | 0 | libcerror_error_set( |
6661 | 0 | error, |
6662 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6663 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6664 | 0 | "%s: unable to retrieve header value: %" PRIu32 " identifier size.", |
6665 | 0 | function, |
6666 | 0 | index ); |
6667 | |
|
6668 | 0 | return( -1 ); |
6669 | 0 | } |
6670 | 0 | if( identifier_size < header_value_identifier_size ) |
6671 | 0 | { |
6672 | 0 | libcerror_error_set( |
6673 | 0 | error, |
6674 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6675 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
6676 | 0 | "%s: header value: %" PRIu32 " identifier size too small.", |
6677 | 0 | function, |
6678 | 0 | index ); |
6679 | |
|
6680 | 0 | return( -1 ); |
6681 | 0 | } |
6682 | 0 | if( memory_copy( |
6683 | 0 | identifier, |
6684 | 0 | header_value_identifier, |
6685 | 0 | header_value_identifier_size ) == NULL ) |
6686 | 0 | { |
6687 | 0 | libcerror_error_set( |
6688 | 0 | error, |
6689 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
6690 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
6691 | 0 | "%s: unable to copy header value: %" PRIu32 " identifier.", |
6692 | 0 | function, |
6693 | 0 | index ); |
6694 | |
|
6695 | 0 | return( -1 ); |
6696 | 0 | } |
6697 | 0 | return( 1 ); |
6698 | 0 | } |
6699 | | |
6700 | | /* Retrieves the size of the UTF-8 encoded header value of an identifier |
6701 | | * The string size includes the end of string character |
6702 | | * Returns 1 if successful, 0 if not set or -1 on error |
6703 | | */ |
6704 | | int libewf_header_values_get_utf8_value_size( |
6705 | | libfvalue_table_t *header_values, |
6706 | | const uint8_t *identifier, |
6707 | | size_t identifier_length, |
6708 | | int date_format, |
6709 | | size_t *utf8_string_size, |
6710 | | libcerror_error_t **error ) |
6711 | 0 | { |
6712 | 0 | uint8_t date_time_string[ 64 ]; |
6713 | |
|
6714 | 0 | libfvalue_value_t *header_value = NULL; |
6715 | 0 | uint8_t *header_value_data = NULL; |
6716 | 0 | static char *function = "libewf_header_values_get_utf8_value_size"; |
6717 | 0 | size_t date_time_string_size = 64; |
6718 | 0 | size_t header_value_data_size = 0; |
6719 | 0 | size_t string_index = 0; |
6720 | 0 | int encoding = 0; |
6721 | 0 | int result = 0; |
6722 | |
|
6723 | 0 | if( header_values == NULL ) |
6724 | 0 | { |
6725 | 0 | libcerror_error_set( |
6726 | 0 | error, |
6727 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6728 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6729 | 0 | "%s: invalid header values.", |
6730 | 0 | function ); |
6731 | |
|
6732 | 0 | return( -1 ); |
6733 | 0 | } |
6734 | 0 | if( identifier == NULL ) |
6735 | 0 | { |
6736 | 0 | libcerror_error_set( |
6737 | 0 | error, |
6738 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6739 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6740 | 0 | "%s: invalid indentifier.", |
6741 | 0 | function ); |
6742 | |
|
6743 | 0 | return( -1 ); |
6744 | 0 | } |
6745 | 0 | if( identifier_length > (size_t) ( SSIZE_MAX - 1 ) ) |
6746 | 0 | { |
6747 | 0 | libcerror_error_set( |
6748 | 0 | error, |
6749 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6750 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
6751 | 0 | "%s: invalid identifier length value exceeds maximum.", |
6752 | 0 | function ); |
6753 | |
|
6754 | 0 | return( -1 ); |
6755 | 0 | } |
6756 | 0 | if( ( identifier_length == 16 ) |
6757 | 0 | && ( narrow_string_compare( |
6758 | 0 | (char *) identifier, |
6759 | 0 | "compression_type", |
6760 | 0 | 16 ) == 0 ) ) |
6761 | 0 | { |
6762 | 0 | result = libfvalue_table_get_value_by_identifier( |
6763 | 0 | header_values, |
6764 | 0 | (uint8_t *) "compression_level", |
6765 | 0 | 18, |
6766 | 0 | &header_value, |
6767 | 0 | 0, |
6768 | 0 | error ); |
6769 | 0 | } |
6770 | 0 | else |
6771 | 0 | { |
6772 | 0 | result = libfvalue_table_get_value_by_identifier( |
6773 | 0 | header_values, |
6774 | 0 | identifier, |
6775 | 0 | identifier_length + 1, |
6776 | 0 | &header_value, |
6777 | 0 | 0, |
6778 | 0 | error ); |
6779 | 0 | } |
6780 | 0 | if( result == -1 ) |
6781 | 0 | { |
6782 | 0 | libcerror_error_set( |
6783 | 0 | error, |
6784 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6785 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6786 | 0 | "%s: unable to retrieve header value: %s.", |
6787 | 0 | function, |
6788 | 0 | (char *) identifier ); |
6789 | |
|
6790 | 0 | return( -1 ); |
6791 | 0 | } |
6792 | 0 | else if( result == 0 ) |
6793 | 0 | { |
6794 | 0 | return( 0 ); |
6795 | 0 | } |
6796 | 0 | result = libfvalue_value_has_data( |
6797 | 0 | header_value, |
6798 | 0 | error ); |
6799 | |
|
6800 | 0 | if( result == -1 ) |
6801 | 0 | { |
6802 | 0 | libcerror_error_set( |
6803 | 0 | error, |
6804 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6805 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6806 | 0 | "%s: unable to determine if header value has data.", |
6807 | 0 | function ); |
6808 | |
|
6809 | 0 | return( -1 ); |
6810 | 0 | } |
6811 | 0 | else if( result == 0 ) |
6812 | 0 | { |
6813 | 0 | return( 0 ); |
6814 | 0 | } |
6815 | 0 | if( ( ( identifier_length == 11 ) |
6816 | 0 | && ( narrow_string_compare( |
6817 | 0 | (char *) identifier, |
6818 | 0 | "system_date", |
6819 | 0 | 11 ) == 0 ) ) |
6820 | 0 | || ( ( identifier_length == 12 ) |
6821 | 0 | && ( narrow_string_compare( |
6822 | 0 | (char *) identifier, |
6823 | 0 | "acquiry_date", |
6824 | 0 | 12 ) == 0 ) ) ) |
6825 | 0 | { |
6826 | 0 | if( libfvalue_value_get_data( |
6827 | 0 | header_value, |
6828 | 0 | &header_value_data, |
6829 | 0 | &header_value_data_size, |
6830 | 0 | &encoding, |
6831 | 0 | error ) != 1 ) |
6832 | 0 | { |
6833 | 0 | libcerror_error_set( |
6834 | 0 | error, |
6835 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6836 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6837 | 0 | "%s: unable to retrieve header value data.", |
6838 | 0 | function ); |
6839 | |
|
6840 | 0 | return( -1 ); |
6841 | 0 | } |
6842 | 0 | if( libewf_date_time_values_copy_to_utf8_string( |
6843 | 0 | header_value_data, |
6844 | 0 | header_value_data_size, |
6845 | 0 | date_format, |
6846 | 0 | date_time_string, |
6847 | 0 | date_time_string_size, |
6848 | 0 | error ) != 1 ) |
6849 | 0 | { |
6850 | 0 | libcerror_error_set( |
6851 | 0 | error, |
6852 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6853 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
6854 | 0 | "%s: unable to copy header value data to date time string.", |
6855 | 0 | function ); |
6856 | |
|
6857 | 0 | return( -1 ); |
6858 | 0 | } |
6859 | 0 | if( utf8_string_size == NULL ) |
6860 | 0 | { |
6861 | 0 | libcerror_error_set( |
6862 | 0 | error, |
6863 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6864 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6865 | 0 | "%s: invalid UTF-8 string size.", |
6866 | 0 | function ); |
6867 | |
|
6868 | 0 | return( -1 ); |
6869 | 0 | } |
6870 | 0 | for( string_index = 0; |
6871 | 0 | string_index < date_time_string_size; |
6872 | 0 | string_index++ ) |
6873 | 0 | { |
6874 | 0 | if( date_time_string[ string_index ] == 0 ) |
6875 | 0 | { |
6876 | 0 | break; |
6877 | 0 | } |
6878 | 0 | } |
6879 | 0 | *utf8_string_size = 1 + string_index; |
6880 | 0 | } |
6881 | 0 | else |
6882 | 0 | { |
6883 | 0 | if( libfvalue_value_get_utf8_string_size( |
6884 | 0 | header_value, |
6885 | 0 | 0, |
6886 | 0 | utf8_string_size, |
6887 | 0 | error ) != 1 ) |
6888 | 0 | { |
6889 | 0 | libcerror_error_set( |
6890 | 0 | error, |
6891 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6892 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6893 | 0 | "%s: unable to retrieve UTF-8 string size of header value.", |
6894 | 0 | function ); |
6895 | |
|
6896 | 0 | return( -1 ); |
6897 | 0 | } |
6898 | 0 | } |
6899 | 0 | return( 1 ); |
6900 | 0 | } |
6901 | | |
6902 | | /* Retrieves the UTF-8 encoded header value of an identifier |
6903 | | * The string size should include the end of string character |
6904 | | * Returns 1 if successful, 0 if not set or -1 on error |
6905 | | */ |
6906 | | int libewf_header_values_get_utf8_value( |
6907 | | libfvalue_table_t *header_values, |
6908 | | const uint8_t *identifier, |
6909 | | size_t identifier_length, |
6910 | | int date_format, |
6911 | | uint8_t *utf8_string, |
6912 | | size_t utf8_string_size, |
6913 | | libcerror_error_t **error ) |
6914 | 0 | { |
6915 | 0 | libfvalue_value_t *header_value = NULL; |
6916 | 0 | uint8_t *header_value_data = NULL; |
6917 | 0 | static char *function = "libewf_header_values_get_utf8_value"; |
6918 | 0 | size_t header_value_data_size = 0; |
6919 | 0 | int encoding = 0; |
6920 | 0 | int result = 0; |
6921 | |
|
6922 | 0 | if( header_values == NULL ) |
6923 | 0 | { |
6924 | 0 | libcerror_error_set( |
6925 | 0 | error, |
6926 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6927 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6928 | 0 | "%s: invalid header values.", |
6929 | 0 | function ); |
6930 | |
|
6931 | 0 | return( -1 ); |
6932 | 0 | } |
6933 | 0 | if( identifier == NULL ) |
6934 | 0 | { |
6935 | 0 | libcerror_error_set( |
6936 | 0 | error, |
6937 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6938 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6939 | 0 | "%s: invalid indentifier.", |
6940 | 0 | function ); |
6941 | |
|
6942 | 0 | return( -1 ); |
6943 | 0 | } |
6944 | 0 | if( identifier_length > (size_t) ( SSIZE_MAX - 1 ) ) |
6945 | 0 | { |
6946 | 0 | libcerror_error_set( |
6947 | 0 | error, |
6948 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6949 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
6950 | 0 | "%s: invalid identifier length value exceeds maximum.", |
6951 | 0 | function ); |
6952 | |
|
6953 | 0 | return( -1 ); |
6954 | 0 | } |
6955 | 0 | if( ( identifier_length == 16 ) |
6956 | 0 | && ( narrow_string_compare( |
6957 | 0 | (char *) identifier, |
6958 | 0 | "compression_type", |
6959 | 0 | 16 ) == 0 ) ) |
6960 | 0 | { |
6961 | 0 | result = libfvalue_table_get_value_by_identifier( |
6962 | 0 | header_values, |
6963 | 0 | (uint8_t *) "compression_level", |
6964 | 0 | 18, |
6965 | 0 | &header_value, |
6966 | 0 | 0, |
6967 | 0 | error ); |
6968 | 0 | } |
6969 | 0 | else |
6970 | 0 | { |
6971 | 0 | result = libfvalue_table_get_value_by_identifier( |
6972 | 0 | header_values, |
6973 | 0 | identifier, |
6974 | 0 | identifier_length + 1, |
6975 | 0 | &header_value, |
6976 | 0 | 0, |
6977 | 0 | error ); |
6978 | 0 | } |
6979 | 0 | if( result == -1 ) |
6980 | 0 | { |
6981 | 0 | libcerror_error_set( |
6982 | 0 | error, |
6983 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6984 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6985 | 0 | "%s: unable to retrieve header value: %s.", |
6986 | 0 | function, |
6987 | 0 | (char *) identifier ); |
6988 | |
|
6989 | 0 | return( -1 ); |
6990 | 0 | } |
6991 | 0 | else if( result == 0 ) |
6992 | 0 | { |
6993 | 0 | return( 0 ); |
6994 | 0 | } |
6995 | 0 | result = libfvalue_value_has_data( |
6996 | 0 | header_value, |
6997 | 0 | error ); |
6998 | |
|
6999 | 0 | if( result == -1 ) |
7000 | 0 | { |
7001 | 0 | libcerror_error_set( |
7002 | 0 | error, |
7003 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7004 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7005 | 0 | "%s: unable to determine if header value has data.", |
7006 | 0 | function ); |
7007 | |
|
7008 | 0 | return( -1 ); |
7009 | 0 | } |
7010 | 0 | else if( result == 0 ) |
7011 | 0 | { |
7012 | 0 | return( 0 ); |
7013 | 0 | } |
7014 | 0 | if( ( ( identifier_length == 11 ) |
7015 | 0 | && ( narrow_string_compare( |
7016 | 0 | (char *) identifier, |
7017 | 0 | "system_date", |
7018 | 0 | 11 ) == 0 ) ) |
7019 | 0 | || ( ( identifier_length == 12 ) |
7020 | 0 | && ( narrow_string_compare( |
7021 | 0 | (char *) identifier, |
7022 | 0 | "acquiry_date", |
7023 | 0 | 12 ) == 0 ) ) ) |
7024 | 0 | { |
7025 | 0 | if( libfvalue_value_get_data( |
7026 | 0 | header_value, |
7027 | 0 | &header_value_data, |
7028 | 0 | &header_value_data_size, |
7029 | 0 | &encoding, |
7030 | 0 | error ) != 1 ) |
7031 | 0 | { |
7032 | 0 | libcerror_error_set( |
7033 | 0 | error, |
7034 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7035 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7036 | 0 | "%s: unable to retrieve header value data.", |
7037 | 0 | function ); |
7038 | |
|
7039 | 0 | return( -1 ); |
7040 | 0 | } |
7041 | 0 | if( libewf_date_time_values_copy_to_utf8_string( |
7042 | 0 | header_value_data, |
7043 | 0 | header_value_data_size, |
7044 | 0 | date_format, |
7045 | 0 | utf8_string, |
7046 | 0 | utf8_string_size, |
7047 | 0 | error ) != 1 ) |
7048 | 0 | { |
7049 | 0 | libcerror_error_set( |
7050 | 0 | error, |
7051 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7052 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
7053 | 0 | "%s: unable to copy header value data to UTF-8 string.", |
7054 | 0 | function ); |
7055 | |
|
7056 | 0 | return( -1 ); |
7057 | 0 | } |
7058 | 0 | } |
7059 | 0 | else |
7060 | 0 | { |
7061 | 0 | if( libfvalue_value_copy_to_utf8_string( |
7062 | 0 | header_value, |
7063 | 0 | 0, |
7064 | 0 | utf8_string, |
7065 | 0 | utf8_string_size, |
7066 | 0 | error ) != 1 ) |
7067 | 0 | { |
7068 | 0 | libcerror_error_set( |
7069 | 0 | error, |
7070 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7071 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
7072 | 0 | "%s: unable to copy header value to UTF-8 string.", |
7073 | 0 | function ); |
7074 | |
|
7075 | 0 | return( -1 ); |
7076 | 0 | } |
7077 | 0 | } |
7078 | 0 | return( 1 ); |
7079 | 0 | } |
7080 | | |
7081 | | /* Retrieves the size of the UTF-16 encoded header value of an identifier |
7082 | | * The string size includes the end of string character |
7083 | | * Returns 1 if successful, 0 if not set or -1 on error |
7084 | | */ |
7085 | | int libewf_header_values_get_utf16_value_size( |
7086 | | libfvalue_table_t *header_values, |
7087 | | const uint8_t *identifier, |
7088 | | size_t identifier_length, |
7089 | | int date_format, |
7090 | | size_t *utf16_string_size, |
7091 | | libcerror_error_t **error ) |
7092 | 0 | { |
7093 | 0 | uint16_t date_time_string[ 64 ]; |
7094 | |
|
7095 | 0 | libfvalue_value_t *header_value = NULL; |
7096 | 0 | uint8_t *header_value_data = NULL; |
7097 | 0 | static char *function = "libewf_header_values_get_utf16_value_size"; |
7098 | 0 | size_t date_time_string_size = 64; |
7099 | 0 | size_t header_value_data_size = 0; |
7100 | 0 | size_t string_index = 0; |
7101 | 0 | int encoding = 0; |
7102 | 0 | int result = 0; |
7103 | |
|
7104 | 0 | if( header_values == NULL ) |
7105 | 0 | { |
7106 | 0 | libcerror_error_set( |
7107 | 0 | error, |
7108 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7109 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7110 | 0 | "%s: invalid header values.", |
7111 | 0 | function ); |
7112 | |
|
7113 | 0 | return( -1 ); |
7114 | 0 | } |
7115 | 0 | if( identifier == NULL ) |
7116 | 0 | { |
7117 | 0 | libcerror_error_set( |
7118 | 0 | error, |
7119 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7120 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7121 | 0 | "%s: invalid indentifier.", |
7122 | 0 | function ); |
7123 | |
|
7124 | 0 | return( -1 ); |
7125 | 0 | } |
7126 | 0 | if( identifier_length > (size_t) ( SSIZE_MAX - 1 ) ) |
7127 | 0 | { |
7128 | 0 | libcerror_error_set( |
7129 | 0 | error, |
7130 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7131 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
7132 | 0 | "%s: invalid identifier length value exceeds maximum.", |
7133 | 0 | function ); |
7134 | |
|
7135 | 0 | return( -1 ); |
7136 | 0 | } |
7137 | 0 | if( ( identifier_length == 16 ) |
7138 | 0 | && ( narrow_string_compare( |
7139 | 0 | (char *) identifier, |
7140 | 0 | "compression_type", |
7141 | 0 | 16 ) == 0 ) ) |
7142 | 0 | { |
7143 | 0 | result = libfvalue_table_get_value_by_identifier( |
7144 | 0 | header_values, |
7145 | 0 | (uint8_t *) "compression_level", |
7146 | 0 | 18, |
7147 | 0 | &header_value, |
7148 | 0 | 0, |
7149 | 0 | error ); |
7150 | 0 | } |
7151 | 0 | else |
7152 | 0 | { |
7153 | 0 | result = libfvalue_table_get_value_by_identifier( |
7154 | 0 | header_values, |
7155 | 0 | identifier, |
7156 | 0 | identifier_length + 1, |
7157 | 0 | &header_value, |
7158 | 0 | 0, |
7159 | 0 | error ); |
7160 | 0 | } |
7161 | 0 | if( result == -1 ) |
7162 | 0 | { |
7163 | 0 | libcerror_error_set( |
7164 | 0 | error, |
7165 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7166 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7167 | 0 | "%s: unable to retrieve header value: %s.", |
7168 | 0 | function, |
7169 | 0 | (char *) identifier ); |
7170 | |
|
7171 | 0 | return( -1 ); |
7172 | 0 | } |
7173 | 0 | else if( result == 0 ) |
7174 | 0 | { |
7175 | 0 | return( 0 ); |
7176 | 0 | } |
7177 | 0 | result = libfvalue_value_has_data( |
7178 | 0 | header_value, |
7179 | 0 | error ); |
7180 | |
|
7181 | 0 | if( result == -1 ) |
7182 | 0 | { |
7183 | 0 | libcerror_error_set( |
7184 | 0 | error, |
7185 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7186 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7187 | 0 | "%s: unable to determine if header value has data.", |
7188 | 0 | function ); |
7189 | |
|
7190 | 0 | return( -1 ); |
7191 | 0 | } |
7192 | 0 | else if( result == 0 ) |
7193 | 0 | { |
7194 | 0 | return( 0 ); |
7195 | 0 | } |
7196 | 0 | if( ( ( identifier_length == 11 ) |
7197 | 0 | && ( narrow_string_compare( |
7198 | 0 | (char *) identifier, |
7199 | 0 | "system_date", |
7200 | 0 | 11 ) == 0 ) ) |
7201 | 0 | || ( ( identifier_length == 12 ) |
7202 | 0 | && ( narrow_string_compare( |
7203 | 0 | (char *) identifier, |
7204 | 0 | "acquiry_date", |
7205 | 0 | 12 ) == 0 ) ) ) |
7206 | 0 | { |
7207 | 0 | if( libfvalue_value_get_data( |
7208 | 0 | header_value, |
7209 | 0 | &header_value_data, |
7210 | 0 | &header_value_data_size, |
7211 | 0 | &encoding, |
7212 | 0 | error ) != 1 ) |
7213 | 0 | { |
7214 | 0 | libcerror_error_set( |
7215 | 0 | error, |
7216 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7217 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7218 | 0 | "%s: unable to retrieve header value data.", |
7219 | 0 | function ); |
7220 | |
|
7221 | 0 | return( -1 ); |
7222 | 0 | } |
7223 | 0 | if( libewf_date_time_values_copy_to_utf16_string( |
7224 | 0 | header_value_data, |
7225 | 0 | header_value_data_size, |
7226 | 0 | date_format, |
7227 | 0 | date_time_string, |
7228 | 0 | date_time_string_size, |
7229 | 0 | error ) != 1 ) |
7230 | 0 | { |
7231 | 0 | libcerror_error_set( |
7232 | 0 | error, |
7233 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7234 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
7235 | 0 | "%s: unable to copy header value data to date time string.", |
7236 | 0 | function ); |
7237 | |
|
7238 | 0 | return( -1 ); |
7239 | 0 | } |
7240 | 0 | if( utf16_string_size == NULL ) |
7241 | 0 | { |
7242 | 0 | libcerror_error_set( |
7243 | 0 | error, |
7244 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7245 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7246 | 0 | "%s: invalid UTF-16 string size.", |
7247 | 0 | function ); |
7248 | |
|
7249 | 0 | return( -1 ); |
7250 | 0 | } |
7251 | 0 | for( string_index = 0; |
7252 | 0 | string_index < date_time_string_size; |
7253 | 0 | string_index++ ) |
7254 | 0 | { |
7255 | 0 | if( date_time_string[ string_index ] == 0 ) |
7256 | 0 | { |
7257 | 0 | break; |
7258 | 0 | } |
7259 | 0 | } |
7260 | 0 | *utf16_string_size = 1 + string_index; |
7261 | 0 | } |
7262 | 0 | else |
7263 | 0 | { |
7264 | 0 | if( libfvalue_value_get_utf16_string_size( |
7265 | 0 | header_value, |
7266 | 0 | 0, |
7267 | 0 | utf16_string_size, |
7268 | 0 | error ) != 1 ) |
7269 | 0 | { |
7270 | 0 | libcerror_error_set( |
7271 | 0 | error, |
7272 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7273 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7274 | 0 | "%s: unable to retrieve UTF-16 string size of header value.", |
7275 | 0 | function ); |
7276 | |
|
7277 | 0 | return( -1 ); |
7278 | 0 | } |
7279 | 0 | } |
7280 | 0 | return( 1 ); |
7281 | 0 | } |
7282 | | |
7283 | | /* Retrieves the UTF-16 encoded header value of an identifier |
7284 | | * The string size should include the end of string character |
7285 | | * Returns 1 if successful, 0 if not set or -1 on error |
7286 | | */ |
7287 | | int libewf_header_values_get_utf16_value( |
7288 | | libfvalue_table_t *header_values, |
7289 | | const uint8_t *identifier, |
7290 | | size_t identifier_length, |
7291 | | int date_format, |
7292 | | uint16_t *utf16_string, |
7293 | | size_t utf16_string_size, |
7294 | | libcerror_error_t **error ) |
7295 | 0 | { |
7296 | 0 | libfvalue_value_t *header_value = NULL; |
7297 | 0 | uint8_t *header_value_data = NULL; |
7298 | 0 | static char *function = "libewf_header_values_get_utf16_value"; |
7299 | 0 | size_t header_value_data_size = 0; |
7300 | 0 | int encoding = 0; |
7301 | 0 | int result = 0; |
7302 | |
|
7303 | 0 | if( header_values == NULL ) |
7304 | 0 | { |
7305 | 0 | libcerror_error_set( |
7306 | 0 | error, |
7307 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7308 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7309 | 0 | "%s: invalid header values.", |
7310 | 0 | function ); |
7311 | |
|
7312 | 0 | return( -1 ); |
7313 | 0 | } |
7314 | 0 | if( identifier == NULL ) |
7315 | 0 | { |
7316 | 0 | libcerror_error_set( |
7317 | 0 | error, |
7318 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7319 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7320 | 0 | "%s: invalid indentifier.", |
7321 | 0 | function ); |
7322 | |
|
7323 | 0 | return( -1 ); |
7324 | 0 | } |
7325 | 0 | if( identifier_length > (size_t) ( SSIZE_MAX - 1 ) ) |
7326 | 0 | { |
7327 | 0 | libcerror_error_set( |
7328 | 0 | error, |
7329 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7330 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
7331 | 0 | "%s: invalid identifier length value exceeds maximum.", |
7332 | 0 | function ); |
7333 | |
|
7334 | 0 | return( -1 ); |
7335 | 0 | } |
7336 | 0 | if( ( identifier_length == 16 ) |
7337 | 0 | && ( narrow_string_compare( |
7338 | 0 | (char *) identifier, |
7339 | 0 | "compression_type", |
7340 | 0 | 16 ) == 0 ) ) |
7341 | 0 | { |
7342 | 0 | result = libfvalue_table_get_value_by_identifier( |
7343 | 0 | header_values, |
7344 | 0 | (uint8_t *) "compression_level", |
7345 | 0 | 18, |
7346 | 0 | &header_value, |
7347 | 0 | 0, |
7348 | 0 | error ); |
7349 | 0 | } |
7350 | 0 | else |
7351 | 0 | { |
7352 | 0 | result = libfvalue_table_get_value_by_identifier( |
7353 | 0 | header_values, |
7354 | 0 | identifier, |
7355 | 0 | identifier_length + 1, |
7356 | 0 | &header_value, |
7357 | 0 | 0, |
7358 | 0 | error ); |
7359 | 0 | } |
7360 | 0 | if( result == -1 ) |
7361 | 0 | { |
7362 | 0 | libcerror_error_set( |
7363 | 0 | error, |
7364 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7365 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7366 | 0 | "%s: unable to retrieve header value: %s.", |
7367 | 0 | function, |
7368 | 0 | (char *) identifier ); |
7369 | |
|
7370 | 0 | return( -1 ); |
7371 | 0 | } |
7372 | 0 | else if( result == 0 ) |
7373 | 0 | { |
7374 | 0 | return( 0 ); |
7375 | 0 | } |
7376 | 0 | result = libfvalue_value_has_data( |
7377 | 0 | header_value, |
7378 | 0 | error ); |
7379 | |
|
7380 | 0 | if( result == -1 ) |
7381 | 0 | { |
7382 | 0 | libcerror_error_set( |
7383 | 0 | error, |
7384 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7385 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7386 | 0 | "%s: unable to determine if header value has data.", |
7387 | 0 | function ); |
7388 | |
|
7389 | 0 | return( -1 ); |
7390 | 0 | } |
7391 | 0 | else if( result == 0 ) |
7392 | 0 | { |
7393 | 0 | return( 0 ); |
7394 | 0 | } |
7395 | 0 | if( ( ( identifier_length == 11 ) |
7396 | 0 | && ( narrow_string_compare( |
7397 | 0 | (char *) identifier, |
7398 | 0 | "system_date", |
7399 | 0 | 11 ) == 0 ) ) |
7400 | 0 | || ( ( identifier_length == 12 ) |
7401 | 0 | && ( narrow_string_compare( |
7402 | 0 | (char *) identifier, |
7403 | 0 | "acquiry_date", |
7404 | 0 | 12 ) == 0 ) ) ) |
7405 | 0 | { |
7406 | 0 | if( libfvalue_value_get_data( |
7407 | 0 | header_value, |
7408 | 0 | &header_value_data, |
7409 | 0 | &header_value_data_size, |
7410 | 0 | &encoding, |
7411 | 0 | error ) != 1 ) |
7412 | 0 | { |
7413 | 0 | libcerror_error_set( |
7414 | 0 | error, |
7415 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7416 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7417 | 0 | "%s: unable to retrieve header value data.", |
7418 | 0 | function ); |
7419 | |
|
7420 | 0 | return( -1 ); |
7421 | 0 | } |
7422 | 0 | if( libewf_date_time_values_copy_to_utf16_string( |
7423 | 0 | header_value_data, |
7424 | 0 | header_value_data_size, |
7425 | 0 | date_format, |
7426 | 0 | utf16_string, |
7427 | 0 | utf16_string_size, |
7428 | 0 | error ) != 1 ) |
7429 | 0 | { |
7430 | 0 | libcerror_error_set( |
7431 | 0 | error, |
7432 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7433 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
7434 | 0 | "%s: unable to copy header value data to UTF-16 string.", |
7435 | 0 | function ); |
7436 | |
|
7437 | 0 | return( -1 ); |
7438 | 0 | } |
7439 | 0 | } |
7440 | 0 | else |
7441 | 0 | { |
7442 | 0 | if( libfvalue_value_copy_to_utf16_string( |
7443 | 0 | header_value, |
7444 | 0 | 0, |
7445 | 0 | utf16_string, |
7446 | 0 | utf16_string_size, |
7447 | 0 | error ) != 1 ) |
7448 | 0 | { |
7449 | 0 | libcerror_error_set( |
7450 | 0 | error, |
7451 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7452 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
7453 | 0 | "%s: unable to copy header value to UTF-16 string.", |
7454 | 0 | function ); |
7455 | |
|
7456 | 0 | return( -1 ); |
7457 | 0 | } |
7458 | 0 | } |
7459 | 0 | return( 1 ); |
7460 | 0 | } |
7461 | | |