/src/libewf/libewf/libewf_header_sections.c
Line | Count | Source |
1 | | /* |
2 | | * Header sections 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 <types.h> |
25 | | |
26 | | #include "libewf_definitions.h" |
27 | | #include "libewf_io_handle.h" |
28 | | #include "libewf_header_sections.h" |
29 | | #include "libewf_header_values.h" |
30 | | #include "libewf_libcerror.h" |
31 | | #include "libewf_libcnotify.h" |
32 | | #include "libewf_libfvalue.h" |
33 | | |
34 | | /* Creates header sections |
35 | | * Make sure the value header_sections is referencing, is set to NULL |
36 | | * Returns 1 if successful or -1 on error |
37 | | */ |
38 | | int libewf_header_sections_initialize( |
39 | | libewf_header_sections_t **header_sections, |
40 | | libcerror_error_t **error ) |
41 | 2.77k | { |
42 | 2.77k | static char *function = "libewf_header_sections_initialize"; |
43 | | |
44 | 2.77k | if( header_sections == NULL ) |
45 | 0 | { |
46 | 0 | libcerror_error_set( |
47 | 0 | error, |
48 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
49 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
50 | 0 | "%s: invalid header sections.", |
51 | 0 | function ); |
52 | |
|
53 | 0 | return( -1 ); |
54 | 0 | } |
55 | 2.77k | if( *header_sections != NULL ) |
56 | 0 | { |
57 | 0 | libcerror_error_set( |
58 | 0 | error, |
59 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
60 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
61 | 0 | "%s: invalid header sections value already set.", |
62 | 0 | function ); |
63 | |
|
64 | 0 | return( -1 ); |
65 | 0 | } |
66 | 2.77k | *header_sections = memory_allocate_structure( |
67 | 2.77k | libewf_header_sections_t ); |
68 | | |
69 | 2.77k | if( *header_sections == NULL ) |
70 | 0 | { |
71 | 0 | libcerror_error_set( |
72 | 0 | error, |
73 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
74 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
75 | 0 | "%s: unable to create header sections.", |
76 | 0 | function ); |
77 | |
|
78 | 0 | goto on_error; |
79 | 0 | } |
80 | 2.77k | if( memory_set( |
81 | 2.77k | *header_sections, |
82 | 2.77k | 0, |
83 | 2.77k | sizeof( libewf_header_sections_t ) ) == NULL ) |
84 | 0 | { |
85 | 0 | libcerror_error_set( |
86 | 0 | error, |
87 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
88 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
89 | 0 | "%s: unable to clear header sections.", |
90 | 0 | function ); |
91 | |
|
92 | 0 | goto on_error; |
93 | 0 | } |
94 | 2.77k | return( 1 ); |
95 | | |
96 | 0 | on_error: |
97 | 0 | if( *header_sections != NULL ) |
98 | 0 | { |
99 | 0 | memory_free( |
100 | 0 | *header_sections ); |
101 | |
|
102 | 0 | *header_sections = NULL; |
103 | 0 | } |
104 | 0 | return( -1 ); |
105 | 2.77k | } |
106 | | |
107 | | /* Frees header sections |
108 | | * Returns 1 if successful or -1 on error |
109 | | */ |
110 | | int libewf_header_sections_free( |
111 | | libewf_header_sections_t **header_sections, |
112 | | libcerror_error_t **error ) |
113 | 2.77k | { |
114 | 2.77k | static char *function = "libewf_header_sections_free"; |
115 | | |
116 | 2.77k | if( header_sections == NULL ) |
117 | 0 | { |
118 | 0 | libcerror_error_set( |
119 | 0 | error, |
120 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
121 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
122 | 0 | "%s: invalid header sections.", |
123 | 0 | function ); |
124 | |
|
125 | 0 | return( -1 ); |
126 | 0 | } |
127 | 2.77k | if( *header_sections != NULL ) |
128 | 2.77k | { |
129 | 2.77k | if( ( *header_sections )->header != NULL ) |
130 | 1.01k | { |
131 | 1.01k | memory_free( |
132 | 1.01k | ( *header_sections )->header ); |
133 | 1.01k | } |
134 | 2.77k | if( ( *header_sections )->header2 != NULL ) |
135 | 1.25k | { |
136 | 1.25k | memory_free( |
137 | 1.25k | ( *header_sections )->header2 ); |
138 | 1.25k | } |
139 | 2.77k | if( ( *header_sections )->xheader != NULL ) |
140 | 48 | { |
141 | 48 | memory_free( |
142 | 48 | ( *header_sections )->xheader ); |
143 | 48 | } |
144 | 2.77k | memory_free( |
145 | 2.77k | *header_sections ); |
146 | | |
147 | 2.77k | *header_sections = NULL; |
148 | 2.77k | } |
149 | 2.77k | return( 1 ); |
150 | 2.77k | } |
151 | | |
152 | | /* Clones the header sections |
153 | | * Returns 1 if successful or -1 on error |
154 | | */ |
155 | | int libewf_header_sections_clone( |
156 | | libewf_header_sections_t **destination_header_sections, |
157 | | libewf_header_sections_t *source_header_sections, |
158 | | libcerror_error_t **error ) |
159 | 0 | { |
160 | 0 | static char *function = "libewf_header_sections_clone"; |
161 | |
|
162 | 0 | if( destination_header_sections == NULL ) |
163 | 0 | { |
164 | 0 | libcerror_error_set( |
165 | 0 | error, |
166 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
167 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
168 | 0 | "%s: invalid destination header sections.", |
169 | 0 | function ); |
170 | |
|
171 | 0 | return( -1 ); |
172 | 0 | } |
173 | 0 | if( *destination_header_sections != NULL ) |
174 | 0 | { |
175 | 0 | libcerror_error_set( |
176 | 0 | error, |
177 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
178 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
179 | 0 | "%s: invalid destination header sections already set.", |
180 | 0 | function ); |
181 | |
|
182 | 0 | return( -1 ); |
183 | 0 | } |
184 | 0 | if( source_header_sections == NULL ) |
185 | 0 | { |
186 | 0 | *destination_header_sections = NULL; |
187 | |
|
188 | 0 | return( 1 ); |
189 | 0 | } |
190 | 0 | if( libewf_header_sections_initialize( |
191 | 0 | destination_header_sections, |
192 | 0 | error ) != 1 ) |
193 | 0 | { |
194 | 0 | libcerror_error_set( |
195 | 0 | error, |
196 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
197 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
198 | 0 | "%s: unable to create destination header sections.", |
199 | 0 | function ); |
200 | |
|
201 | 0 | goto on_error; |
202 | 0 | } |
203 | 0 | if( *destination_header_sections == NULL ) |
204 | 0 | { |
205 | 0 | libcerror_error_set( |
206 | 0 | error, |
207 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
208 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
209 | 0 | "%s: missing destination header sections.", |
210 | 0 | function ); |
211 | |
|
212 | 0 | goto on_error; |
213 | 0 | } |
214 | 0 | if( source_header_sections->header != NULL ) |
215 | 0 | { |
216 | 0 | ( *destination_header_sections )->header = (uint8_t *) memory_allocate( |
217 | 0 | sizeof( uint8_t ) * source_header_sections->header_size ); |
218 | |
|
219 | 0 | if( ( *destination_header_sections )->header == NULL ) |
220 | 0 | { |
221 | 0 | libcerror_error_set( |
222 | 0 | error, |
223 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
224 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
225 | 0 | "%s: unable to create destination header.", |
226 | 0 | function ); |
227 | |
|
228 | 0 | goto on_error; |
229 | 0 | } |
230 | 0 | if( memory_copy( |
231 | 0 | ( *destination_header_sections )->header, |
232 | 0 | source_header_sections->header, |
233 | 0 | sizeof( uint8_t ) * source_header_sections->header_size ) == NULL ) |
234 | 0 | { |
235 | 0 | libcerror_error_set( |
236 | 0 | error, |
237 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
238 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
239 | 0 | "%s: unable to copy source to destination header.", |
240 | 0 | function ); |
241 | |
|
242 | 0 | goto on_error; |
243 | 0 | } |
244 | 0 | ( *destination_header_sections )->header_size = source_header_sections->header_size; |
245 | 0 | } |
246 | 0 | if( source_header_sections->header2 != NULL ) |
247 | 0 | { |
248 | 0 | ( *destination_header_sections )->header2 = (uint8_t *) memory_allocate( |
249 | 0 | sizeof( uint8_t ) * source_header_sections->header2_size ); |
250 | |
|
251 | 0 | if( ( *destination_header_sections )->header2 == NULL ) |
252 | 0 | { |
253 | 0 | libcerror_error_set( |
254 | 0 | error, |
255 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
256 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
257 | 0 | "%s: unable to create destination header2.", |
258 | 0 | function ); |
259 | |
|
260 | 0 | goto on_error; |
261 | 0 | } |
262 | 0 | if( memory_copy( |
263 | 0 | ( *destination_header_sections )->header2, |
264 | 0 | source_header_sections->header2, |
265 | 0 | sizeof( uint8_t ) * source_header_sections->header2_size ) == NULL ) |
266 | 0 | { |
267 | 0 | libcerror_error_set( |
268 | 0 | error, |
269 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
270 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
271 | 0 | "%s: unable to copy source to destination header2.", |
272 | 0 | function ); |
273 | |
|
274 | 0 | goto on_error; |
275 | 0 | } |
276 | 0 | ( *destination_header_sections )->header2_size = source_header_sections->header2_size; |
277 | 0 | } |
278 | 0 | if( source_header_sections->xheader != NULL ) |
279 | 0 | { |
280 | 0 | ( *destination_header_sections )->xheader = (uint8_t *) memory_allocate( |
281 | 0 | sizeof( uint8_t ) * source_header_sections->xheader_size ); |
282 | |
|
283 | 0 | if( ( *destination_header_sections )->xheader == NULL ) |
284 | 0 | { |
285 | 0 | libcerror_error_set( |
286 | 0 | error, |
287 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
288 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
289 | 0 | "%s: unable to create destination xheader.", |
290 | 0 | function ); |
291 | |
|
292 | 0 | goto on_error; |
293 | 0 | } |
294 | 0 | if( memory_copy( |
295 | 0 | ( *destination_header_sections )->xheader, |
296 | 0 | source_header_sections->xheader, |
297 | 0 | sizeof( uint8_t ) * source_header_sections->xheader_size ) == NULL ) |
298 | 0 | { |
299 | 0 | libcerror_error_set( |
300 | 0 | error, |
301 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
302 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
303 | 0 | "%s: unable to copy source to destination xheader.", |
304 | 0 | function ); |
305 | |
|
306 | 0 | goto on_error; |
307 | 0 | } |
308 | 0 | ( *destination_header_sections )->xheader_size = source_header_sections->xheader_size; |
309 | 0 | } |
310 | 0 | ( *destination_header_sections )->number_of_header_sections = source_header_sections->number_of_header_sections; |
311 | |
|
312 | 0 | return( 1 ); |
313 | | |
314 | 0 | on_error: |
315 | 0 | if( *destination_header_sections != NULL ) |
316 | 0 | { |
317 | 0 | if( ( *destination_header_sections )->xheader != NULL ) |
318 | 0 | { |
319 | 0 | memory_free( |
320 | 0 | ( *destination_header_sections )->xheader ); |
321 | 0 | } |
322 | 0 | if( ( *destination_header_sections )->header2 != NULL ) |
323 | 0 | { |
324 | 0 | memory_free( |
325 | 0 | ( *destination_header_sections )->header2 ); |
326 | 0 | } |
327 | 0 | if( ( *destination_header_sections )->header != NULL ) |
328 | 0 | { |
329 | 0 | memory_free( |
330 | 0 | ( *destination_header_sections )->header ); |
331 | 0 | } |
332 | 0 | memory_free( |
333 | 0 | *destination_header_sections ); |
334 | |
|
335 | 0 | *destination_header_sections = NULL; |
336 | 0 | } |
337 | 0 | return( -1 ); |
338 | 0 | } |
339 | | |
340 | | /* Create the header sections from the header values |
341 | | * Returns 1 on success or -1 on error |
342 | | */ |
343 | | int libewf_header_sections_generate( |
344 | | libewf_header_sections_t *header_sections, |
345 | | libfvalue_table_t *header_values, |
346 | | time_t timestamp, |
347 | | int8_t compression_level, |
348 | | uint8_t format, |
349 | | int header_codepage, |
350 | | libcerror_error_t **error ) |
351 | 0 | { |
352 | 0 | static char *function = "libewf_header_sections_generate"; |
353 | |
|
354 | 0 | if( header_sections == NULL ) |
355 | 0 | { |
356 | 0 | libcerror_error_set( |
357 | 0 | error, |
358 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
359 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
360 | 0 | "%s: invalid header sections.", |
361 | 0 | function ); |
362 | |
|
363 | 0 | return( -1 ); |
364 | 0 | } |
365 | 0 | if( format == LIBEWF_FORMAT_EWF ) |
366 | 0 | { |
367 | 0 | if( libewf_header_values_generate_header_ewf( |
368 | 0 | header_values, |
369 | 0 | timestamp, |
370 | 0 | compression_level, |
371 | 0 | &( header_sections->header ), |
372 | 0 | &( header_sections->header_size ), |
373 | 0 | header_codepage, |
374 | 0 | error ) != 1 ) |
375 | 0 | { |
376 | 0 | libcerror_error_set( |
377 | 0 | error, |
378 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
379 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
380 | 0 | "%s: unable to create header section.", |
381 | 0 | function ); |
382 | |
|
383 | 0 | goto on_error; |
384 | 0 | } |
385 | 0 | } |
386 | 0 | else if( format == LIBEWF_FORMAT_ENCASE1 ) |
387 | 0 | { |
388 | 0 | if( libewf_header_values_generate_header_encase1( |
389 | 0 | header_values, |
390 | 0 | timestamp, |
391 | 0 | compression_level, |
392 | 0 | &( header_sections->header ), |
393 | 0 | &( header_sections->header_size ), |
394 | 0 | header_codepage, |
395 | 0 | error ) != 1 ) |
396 | 0 | { |
397 | 0 | libcerror_error_set( |
398 | 0 | error, |
399 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
400 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
401 | 0 | "%s: unable to create header section.", |
402 | 0 | function ); |
403 | |
|
404 | 0 | goto on_error; |
405 | 0 | } |
406 | 0 | } |
407 | 0 | else if( ( format == LIBEWF_FORMAT_ENCASE2 ) |
408 | 0 | || ( format == LIBEWF_FORMAT_ENCASE3 ) ) |
409 | 0 | { |
410 | 0 | if( libewf_header_values_generate_header_encase2( |
411 | 0 | header_values, |
412 | 0 | timestamp, |
413 | 0 | compression_level, |
414 | 0 | &( header_sections->header ), |
415 | 0 | &( header_sections->header_size ), |
416 | 0 | header_codepage, |
417 | 0 | error ) != 1 ) |
418 | 0 | { |
419 | 0 | libcerror_error_set( |
420 | 0 | error, |
421 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
422 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
423 | 0 | "%s: unable to create header section.", |
424 | 0 | function ); |
425 | |
|
426 | 0 | goto on_error; |
427 | 0 | } |
428 | 0 | } |
429 | 0 | else if( ( format == LIBEWF_FORMAT_FTK_IMAGER ) |
430 | 0 | || ( format == LIBEWF_FORMAT_SMART ) ) |
431 | 0 | { |
432 | 0 | if( libewf_header_values_generate_header_ftk( |
433 | 0 | header_values, |
434 | 0 | timestamp, |
435 | 0 | compression_level, |
436 | 0 | &( header_sections->header ), |
437 | 0 | &( header_sections->header_size ), |
438 | 0 | header_codepage, |
439 | 0 | error ) != 1 ) |
440 | 0 | { |
441 | 0 | libcerror_error_set( |
442 | 0 | error, |
443 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
444 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
445 | 0 | "%s: unable to create header section.", |
446 | 0 | function ); |
447 | |
|
448 | 0 | goto on_error; |
449 | 0 | } |
450 | 0 | } |
451 | 0 | else if( ( format == LIBEWF_FORMAT_ENCASE4 ) |
452 | 0 | || ( format == LIBEWF_FORMAT_ENCASE5 ) |
453 | 0 | || ( format == LIBEWF_FORMAT_ENCASE6 ) |
454 | 0 | || ( format == LIBEWF_FORMAT_ENCASE7 ) ) |
455 | 0 | { |
456 | 0 | if( libewf_header_values_generate_header_encase4( |
457 | 0 | header_values, |
458 | 0 | timestamp, |
459 | 0 | compression_level, |
460 | 0 | &( header_sections->header ), |
461 | 0 | &( header_sections->header_size ), |
462 | 0 | header_codepage, |
463 | 0 | error ) != 1 ) |
464 | 0 | { |
465 | 0 | libcerror_error_set( |
466 | 0 | error, |
467 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
468 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
469 | 0 | "%s: unable to create header section.", |
470 | 0 | function ); |
471 | |
|
472 | 0 | goto on_error; |
473 | 0 | } |
474 | 0 | if( libewf_header_values_generate_header2( |
475 | 0 | header_values, |
476 | 0 | format, |
477 | 0 | timestamp, |
478 | 0 | compression_level, |
479 | 0 | &( header_sections->header2 ), |
480 | 0 | &( header_sections->header2_size ), |
481 | 0 | error ) != 1 ) |
482 | 0 | { |
483 | 0 | libcerror_error_set( |
484 | 0 | error, |
485 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
486 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
487 | 0 | "%s: unable to create header2 section.", |
488 | 0 | function ); |
489 | |
|
490 | 0 | goto on_error; |
491 | 0 | } |
492 | 0 | } |
493 | 0 | else if( ( format == LIBEWF_FORMAT_LINEN5 ) |
494 | 0 | || ( format == LIBEWF_FORMAT_LINEN6 ) |
495 | 0 | || ( format == LIBEWF_FORMAT_LINEN7 ) ) |
496 | 0 | { |
497 | 0 | if( libewf_header_values_generate_header_linen( |
498 | 0 | header_values, |
499 | 0 | format, |
500 | 0 | timestamp, |
501 | 0 | compression_level, |
502 | 0 | &( header_sections->header ), |
503 | 0 | &( header_sections->header_size ), |
504 | 0 | header_codepage, |
505 | 0 | error ) != 1 ) |
506 | 0 | { |
507 | 0 | libcerror_error_set( |
508 | 0 | error, |
509 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
510 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
511 | 0 | "%s: unable to create header section.", |
512 | 0 | function ); |
513 | |
|
514 | 0 | goto on_error; |
515 | 0 | } |
516 | 0 | } |
517 | 0 | else if( format == LIBEWF_FORMAT_EWFX ) |
518 | 0 | { |
519 | 0 | if( libewf_header_values_generate_header_ewfx( |
520 | 0 | header_values, |
521 | 0 | timestamp, |
522 | 0 | compression_level, |
523 | 0 | &( header_sections->header ), |
524 | 0 | &( header_sections->header_size ), |
525 | 0 | header_codepage, |
526 | 0 | error ) != 1 ) |
527 | 0 | { |
528 | 0 | libcerror_error_set( |
529 | 0 | error, |
530 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
531 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
532 | 0 | "%s: unable to create header section.", |
533 | 0 | function ); |
534 | |
|
535 | 0 | goto on_error; |
536 | 0 | } |
537 | 0 | if( libewf_header_values_generate_header2( |
538 | 0 | header_values, |
539 | 0 | format, |
540 | 0 | timestamp, |
541 | 0 | compression_level, |
542 | 0 | &( header_sections->header2 ), |
543 | 0 | &( header_sections->header2_size ), |
544 | 0 | error ) != 1 ) |
545 | 0 | { |
546 | 0 | libcerror_error_set( |
547 | 0 | error, |
548 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
549 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
550 | 0 | "%s: unable to create header2 section.", |
551 | 0 | function ); |
552 | |
|
553 | 0 | goto on_error; |
554 | 0 | } |
555 | 0 | if( libewf_header_values_generate_xheader( |
556 | 0 | header_values, |
557 | 0 | timestamp, |
558 | 0 | &( header_sections->xheader ), |
559 | 0 | &( header_sections->xheader_size ), |
560 | 0 | error ) != 1 ) |
561 | 0 | { |
562 | 0 | libcerror_error_set( |
563 | 0 | error, |
564 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
565 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
566 | 0 | "%s: unable to create xheader section.", |
567 | 0 | function ); |
568 | |
|
569 | 0 | goto on_error; |
570 | 0 | } |
571 | 0 | } |
572 | 0 | return( 1 ); |
573 | | |
574 | 0 | on_error: |
575 | 0 | if( header_sections->header2 != NULL ) |
576 | 0 | { |
577 | 0 | memory_free( |
578 | 0 | header_sections->header2 ); |
579 | |
|
580 | 0 | header_sections->header2 = NULL; |
581 | 0 | header_sections->header2_size = 0; |
582 | 0 | } |
583 | 0 | if( header_sections->header != NULL ) |
584 | 0 | { |
585 | 0 | memory_free( |
586 | 0 | header_sections->header ); |
587 | |
|
588 | 0 | header_sections->header = NULL; |
589 | 0 | header_sections->header_size = 0; |
590 | 0 | } |
591 | 0 | return( -1 ); |
592 | 0 | } |
593 | | |
594 | | /* Parses the header, header2 and/or xheader section for header values |
595 | | * Returns 1 if successful or -1 on error |
596 | | */ |
597 | | int libewf_header_sections_parse( |
598 | | libewf_header_sections_t *header_sections, |
599 | | libewf_io_handle_t *io_handle, |
600 | | libfvalue_table_t *header_values, |
601 | | uint8_t *format, |
602 | | libcerror_error_t **error ) |
603 | 829 | { |
604 | 829 | static char *function = "libewf_header_sections_parse"; |
605 | 829 | int result_header = 1; |
606 | 829 | int result_header2 = 1; |
607 | 829 | int result_xheader = 1; |
608 | | |
609 | 829 | if( header_sections == NULL ) |
610 | 0 | { |
611 | 0 | libcerror_error_set( |
612 | 0 | error, |
613 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
614 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
615 | 0 | "%s: invalid header sections.", |
616 | 0 | function ); |
617 | |
|
618 | 0 | return( -1 ); |
619 | 0 | } |
620 | 829 | if( io_handle == NULL ) |
621 | 0 | { |
622 | 0 | libcerror_error_set( |
623 | 0 | error, |
624 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
625 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
626 | 0 | "%s: invalid IO handle.", |
627 | 0 | function ); |
628 | |
|
629 | 0 | return( -1 ); |
630 | 0 | } |
631 | 829 | if( format == NULL ) |
632 | 0 | { |
633 | 0 | libcerror_error_set( |
634 | 0 | error, |
635 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
636 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
637 | 0 | "%s: invalid format.", |
638 | 0 | function ); |
639 | |
|
640 | 0 | return( -1 ); |
641 | 0 | } |
642 | | /* For EWF version 1 format read all the header sections |
643 | | * and overwrite values by the most specific data |
644 | | * This also applied to the format |
645 | | */ |
646 | 829 | if( header_sections->header != NULL ) |
647 | 388 | { |
648 | 388 | if( libewf_header_values_parse_header( |
649 | 388 | header_values, |
650 | 388 | header_sections->header, |
651 | 388 | header_sections->header_size, |
652 | 388 | io_handle->header_codepage, |
653 | 388 | format, |
654 | 388 | error ) != 1 ) |
655 | 122 | { |
656 | 122 | libcerror_error_set( |
657 | 122 | error, |
658 | 122 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
659 | 122 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
660 | 122 | "%s: unable to parse header.", |
661 | 122 | function ); |
662 | | |
663 | 122 | result_header = -1; |
664 | 122 | } |
665 | 388 | } |
666 | 829 | if( header_sections->header2 != NULL ) |
667 | 686 | { |
668 | 686 | if( libewf_header_values_parse_header2( |
669 | 686 | header_values, |
670 | 686 | header_sections->header2, |
671 | 686 | header_sections->header2_size, |
672 | 686 | format, |
673 | 686 | error ) != 1 ) |
674 | 302 | { |
675 | 302 | libcerror_error_set( |
676 | 302 | error, |
677 | 302 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
678 | 302 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
679 | 302 | "%s: unable to parse header2.", |
680 | 302 | function ); |
681 | | |
682 | 302 | result_header2 = -1; |
683 | 302 | } |
684 | 686 | } |
685 | 829 | if( header_sections->xheader != NULL ) |
686 | 48 | { |
687 | 48 | if( libewf_header_values_parse_xheader( |
688 | 48 | header_values, |
689 | 48 | header_sections->xheader, |
690 | 48 | header_sections->xheader_size, |
691 | 48 | error ) != 1 ) |
692 | 48 | { |
693 | 48 | libcerror_error_set( |
694 | 48 | error, |
695 | 48 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
696 | 48 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
697 | 48 | "%s: unable to parse xheader.", |
698 | 48 | function ); |
699 | | |
700 | 48 | result_xheader = -1; |
701 | 48 | } |
702 | 48 | *format = LIBEWF_FORMAT_EWFX; |
703 | 48 | } |
704 | 829 | if( ( result_header != 1 ) |
705 | 122 | && ( result_header2 != 1 ) |
706 | 27 | && ( result_xheader != 1 ) ) |
707 | 1 | { |
708 | 1 | return( -1 ); |
709 | 1 | } |
710 | 828 | if( ( result_header != 1 ) |
711 | 707 | || ( result_header2 != 1 ) |
712 | 432 | || ( result_xheader != 1 ) ) |
713 | 443 | { |
714 | | #if defined( HAVE_DEBUG_OUTPUT ) |
715 | | if( libcnotify_verbose != 0 ) |
716 | | { |
717 | | if( ( error != NULL ) |
718 | | && ( *error != NULL ) ) |
719 | | { |
720 | | libcnotify_print_error_backtrace( |
721 | | *error ); |
722 | | } |
723 | | } |
724 | | #endif |
725 | 443 | libcerror_error_free( |
726 | 443 | error ); |
727 | 443 | } |
728 | 828 | return( 1 ); |
729 | 829 | } |
730 | | |