/src/libolecf/libolecf/libolecf_file_header.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * File header functions |
3 | | * |
4 | | * Copyright (C) 2008-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libolecf_allocation_table.h" |
28 | | #include "libolecf_debug.h" |
29 | | #include "libolecf_definitions.h" |
30 | | #include "libolecf_file_header.h" |
31 | | #include "libolecf_io_handle.h" |
32 | | #include "libolecf_libcerror.h" |
33 | | #include "libolecf_libcnotify.h" |
34 | | #include "libolecf_libfguid.h" |
35 | | |
36 | | #include "olecf_file_header.h" |
37 | | |
38 | | /* Creates file header |
39 | | * Make sure the value file_header is referencing, is set to NULL |
40 | | * Returns 1 if successful or -1 on error |
41 | | */ |
42 | | int libolecf_file_header_initialize( |
43 | | libolecf_file_header_t **file_header, |
44 | | libcerror_error_t **error ) |
45 | 1.93k | { |
46 | 1.93k | static char *function = "libolecf_file_header_initialize"; |
47 | | |
48 | 1.93k | if( file_header == NULL ) |
49 | 0 | { |
50 | 0 | libcerror_error_set( |
51 | 0 | error, |
52 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
53 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
54 | 0 | "%s: invalid file header.", |
55 | 0 | function ); |
56 | |
|
57 | 0 | return( -1 ); |
58 | 0 | } |
59 | 1.93k | if( *file_header != NULL ) |
60 | 0 | { |
61 | 0 | libcerror_error_set( |
62 | 0 | error, |
63 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
64 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
65 | 0 | "%s: invalid file header value already set.", |
66 | 0 | function ); |
67 | |
|
68 | 0 | return( -1 ); |
69 | 0 | } |
70 | 1.93k | *file_header = memory_allocate_structure( |
71 | 1.93k | libolecf_file_header_t ); |
72 | | |
73 | 1.93k | if( *file_header == NULL ) |
74 | 0 | { |
75 | 0 | libcerror_error_set( |
76 | 0 | error, |
77 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
78 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
79 | 0 | "%s: unable to create file header.", |
80 | 0 | function ); |
81 | |
|
82 | 0 | goto on_error; |
83 | 0 | } |
84 | 1.93k | if( memory_set( |
85 | 1.93k | *file_header, |
86 | 1.93k | 0, |
87 | 1.93k | sizeof( libolecf_file_header_t ) ) == NULL ) |
88 | 0 | { |
89 | 0 | libcerror_error_set( |
90 | 0 | error, |
91 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
92 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
93 | 0 | "%s: unable to clear file header.", |
94 | 0 | function ); |
95 | |
|
96 | 0 | goto on_error; |
97 | 0 | } |
98 | 1.93k | return( 1 ); |
99 | | |
100 | 0 | on_error: |
101 | 0 | if( *file_header != NULL ) |
102 | 0 | { |
103 | 0 | memory_free( |
104 | 0 | *file_header ); |
105 | |
|
106 | 0 | *file_header = NULL; |
107 | 0 | } |
108 | 0 | return( -1 ); |
109 | 1.93k | } |
110 | | |
111 | | /* Frees file header |
112 | | * Returns 1 if successful or -1 on error |
113 | | */ |
114 | | int libolecf_file_header_free( |
115 | | libolecf_file_header_t **file_header, |
116 | | libcerror_error_t **error ) |
117 | 1.93k | { |
118 | 1.93k | static char *function = "libolecf_file_header_free"; |
119 | | |
120 | 1.93k | if( file_header == NULL ) |
121 | 0 | { |
122 | 0 | libcerror_error_set( |
123 | 0 | error, |
124 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
125 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
126 | 0 | "%s: invalid file header.", |
127 | 0 | function ); |
128 | |
|
129 | 0 | return( -1 ); |
130 | 0 | } |
131 | 1.93k | if( *file_header != NULL ) |
132 | 1.93k | { |
133 | 1.93k | memory_free( |
134 | 1.93k | *file_header ); |
135 | | |
136 | 1.93k | *file_header = NULL; |
137 | 1.93k | } |
138 | 1.93k | return( 1 ); |
139 | 1.93k | } |
140 | | |
141 | | /* Reads the file header data |
142 | | * Returns 1 if successful or -1 on error |
143 | | */ |
144 | | int libolecf_file_header_read_data( |
145 | | libolecf_file_header_t *file_header, |
146 | | const uint8_t *data, |
147 | | size_t data_size, |
148 | | libolecf_allocation_table_t *msat, |
149 | | libcerror_error_t **error ) |
150 | 1.89k | { |
151 | 1.89k | const uint8_t *msat_entry = NULL; |
152 | 1.89k | static char *function = "libolecf_file_header_read_data"; |
153 | 1.89k | uint16_t sector_size = 0; |
154 | 1.89k | uint16_t short_sector_size = 0; |
155 | 1.89k | int msat_index = 0; |
156 | | |
157 | 1.89k | if( file_header == NULL ) |
158 | 0 | { |
159 | 0 | libcerror_error_set( |
160 | 0 | error, |
161 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
162 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
163 | 0 | "%s: invalid file header.", |
164 | 0 | function ); |
165 | |
|
166 | 0 | return( -1 ); |
167 | 0 | } |
168 | 1.89k | if( data == NULL ) |
169 | 0 | { |
170 | 0 | libcerror_error_set( |
171 | 0 | error, |
172 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
173 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
174 | 0 | "%s: invalid data.", |
175 | 0 | function ); |
176 | |
|
177 | 0 | return( -1 ); |
178 | 0 | } |
179 | 1.89k | if( data_size < sizeof( olecf_file_header_t ) ) |
180 | 0 | { |
181 | 0 | libcerror_error_set( |
182 | 0 | error, |
183 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
184 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
185 | 0 | "%s: invalid data size value too small.", |
186 | 0 | function ); |
187 | |
|
188 | 0 | return( -1 ); |
189 | 0 | } |
190 | 1.89k | if( data_size > (size_t) SSIZE_MAX ) |
191 | 0 | { |
192 | 0 | libcerror_error_set( |
193 | 0 | error, |
194 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
195 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
196 | 0 | "%s: invalid data size value exceeds maximum.", |
197 | 0 | function ); |
198 | |
|
199 | 0 | return( -1 ); |
200 | 0 | } |
201 | 1.89k | if( msat == NULL ) |
202 | 0 | { |
203 | 0 | libcerror_error_set( |
204 | 0 | error, |
205 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
206 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
207 | 0 | "%s: invalid MSAT.", |
208 | 0 | function ); |
209 | |
|
210 | 0 | return( -1 ); |
211 | 0 | } |
212 | | #if defined( HAVE_DEBUG_OUTPUT ) |
213 | | if( libcnotify_verbose != 0 ) |
214 | | { |
215 | | libcnotify_printf( |
216 | | "%s: file header:\n", |
217 | | function ); |
218 | | libcnotify_print_data( |
219 | | (uint8_t *) data, |
220 | | sizeof( olecf_file_header_t ), |
221 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
222 | | } |
223 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
224 | | |
225 | 1.89k | if( ( memory_compare( |
226 | 1.89k | ( (olecf_file_header_t *) data )->signature, |
227 | 1.89k | olecf_file_signature, |
228 | 1.89k | 8 ) != 0 ) |
229 | 1.89k | && ( memory_compare( |
230 | 217 | ( (olecf_file_header_t *) data )->signature, |
231 | 217 | olecf_beta_file_signature, |
232 | 217 | 8 ) != 0 ) ) |
233 | 114 | { |
234 | 114 | libcerror_error_set( |
235 | 114 | error, |
236 | 114 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
237 | 114 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
238 | 114 | "%s: invalid file signature.", |
239 | 114 | function ); |
240 | | |
241 | 114 | return( -1 ); |
242 | 114 | } |
243 | 1.78k | if( ( ( (olecf_file_header_t *) data )->byte_order[ 0 ] == 0xfe ) |
244 | 1.78k | && ( ( (olecf_file_header_t *) data )->byte_order[ 1 ] == 0xff ) ) |
245 | 1.05k | { |
246 | 1.05k | file_header->byte_order = LIBOLECF_ENDIAN_LITTLE; |
247 | 1.05k | } |
248 | 727 | else if( ( ( (olecf_file_header_t *) data )->byte_order[ 0 ] == 0xff ) |
249 | 727 | && ( ( (olecf_file_header_t *) data )->byte_order[ 1 ] == 0xfe ) ) |
250 | 665 | { |
251 | 665 | file_header->byte_order = LIBOLECF_ENDIAN_BIG; |
252 | 665 | } |
253 | 62 | else |
254 | 62 | { |
255 | 62 | libcerror_error_set( |
256 | 62 | error, |
257 | 62 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
258 | 62 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
259 | 62 | "%s: unsupported byte order: 0x%02" PRIx8 " 0x%02" PRIx8 ".", |
260 | 62 | function, |
261 | 62 | ( (olecf_file_header_t *) data )->byte_order[ 0 ], |
262 | 62 | ( (olecf_file_header_t *) data )->byte_order[ 1 ] ); |
263 | | |
264 | 62 | return( -1 ); |
265 | 62 | } |
266 | 1.72k | if( file_header->byte_order == LIBOLECF_ENDIAN_LITTLE ) |
267 | 1.05k | { |
268 | 1.05k | byte_stream_copy_to_uint16_little_endian( |
269 | 1.05k | ( (olecf_file_header_t *) data )->minor_format_version, |
270 | 1.05k | file_header->minor_format_version ); |
271 | | |
272 | 1.05k | byte_stream_copy_to_uint16_little_endian( |
273 | 1.05k | ( (olecf_file_header_t *) data )->major_format_version, |
274 | 1.05k | file_header->major_format_version ); |
275 | | |
276 | 1.05k | byte_stream_copy_to_uint16_little_endian( |
277 | 1.05k | ( (olecf_file_header_t *) data )->sector_size, |
278 | 1.05k | sector_size ); |
279 | | |
280 | 1.05k | byte_stream_copy_to_uint16_little_endian( |
281 | 1.05k | ( (olecf_file_header_t *) data )->short_sector_size, |
282 | 1.05k | short_sector_size ); |
283 | | |
284 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
285 | 1.05k | ( (olecf_file_header_t *) data )->number_of_sat_sectors, |
286 | 1.05k | file_header->number_of_sat_sectors ); |
287 | | |
288 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
289 | 1.05k | ( (olecf_file_header_t *) data )->root_directory_sector_identifier, |
290 | 1.05k | file_header->root_directory_sector_identifier ); |
291 | | |
292 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
293 | 1.05k | ( (olecf_file_header_t *) data )->sector_stream_minimum_data_size, |
294 | 1.05k | file_header->sector_stream_minimum_data_size ); |
295 | | |
296 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
297 | 1.05k | ( (olecf_file_header_t *) data )->ssat_sector_identifier, |
298 | 1.05k | file_header->ssat_sector_identifier ); |
299 | | |
300 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
301 | 1.05k | ( (olecf_file_header_t *) data )->number_of_ssat_sectors, |
302 | 1.05k | file_header->number_of_ssat_sectors ); |
303 | | |
304 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
305 | 1.05k | ( (olecf_file_header_t *) data )->msat_sector_identifier, |
306 | 1.05k | file_header->msat_sector_identifier ); |
307 | | |
308 | 1.05k | byte_stream_copy_to_uint32_little_endian( |
309 | 1.05k | ( (olecf_file_header_t *) data )->number_of_msat_sectors, |
310 | 1.05k | file_header->number_of_msat_sectors ); |
311 | 1.05k | } |
312 | 665 | else if( file_header->byte_order == LIBOLECF_ENDIAN_BIG ) |
313 | 665 | { |
314 | 665 | byte_stream_copy_to_uint16_big_endian( |
315 | 665 | ( (olecf_file_header_t *) data )->minor_format_version, |
316 | 665 | file_header->minor_format_version ); |
317 | | |
318 | 665 | byte_stream_copy_to_uint16_big_endian( |
319 | 665 | ( (olecf_file_header_t *) data )->major_format_version, |
320 | 665 | file_header->major_format_version ); |
321 | | |
322 | 665 | byte_stream_copy_to_uint16_big_endian( |
323 | 665 | ( (olecf_file_header_t *) data )->sector_size, |
324 | 665 | sector_size ); |
325 | | |
326 | 665 | byte_stream_copy_to_uint16_big_endian( |
327 | 665 | ( (olecf_file_header_t *) data )->short_sector_size, |
328 | 665 | short_sector_size ); |
329 | | |
330 | 665 | byte_stream_copy_to_uint32_big_endian( |
331 | 665 | ( (olecf_file_header_t *) data )->number_of_sat_sectors, |
332 | 665 | file_header->number_of_sat_sectors ); |
333 | | |
334 | 665 | byte_stream_copy_to_uint32_big_endian( |
335 | 665 | ( (olecf_file_header_t *) data )->root_directory_sector_identifier, |
336 | 665 | file_header->root_directory_sector_identifier ); |
337 | | |
338 | 665 | byte_stream_copy_to_uint32_big_endian( |
339 | 665 | ( (olecf_file_header_t *) data )->sector_stream_minimum_data_size, |
340 | 665 | file_header->sector_stream_minimum_data_size ); |
341 | | |
342 | 665 | byte_stream_copy_to_uint32_big_endian( |
343 | 665 | ( (olecf_file_header_t *) data )->ssat_sector_identifier, |
344 | 665 | file_header->ssat_sector_identifier ); |
345 | | |
346 | 665 | byte_stream_copy_to_uint32_big_endian( |
347 | 665 | ( (olecf_file_header_t *) data )->number_of_ssat_sectors, |
348 | 665 | file_header->number_of_ssat_sectors ); |
349 | | |
350 | 665 | byte_stream_copy_to_uint32_big_endian( |
351 | 665 | ( (olecf_file_header_t *) data )->msat_sector_identifier, |
352 | 665 | file_header->msat_sector_identifier ); |
353 | | |
354 | 665 | byte_stream_copy_to_uint32_big_endian( |
355 | 665 | ( (olecf_file_header_t *) data )->number_of_msat_sectors, |
356 | 665 | file_header->number_of_msat_sectors ); |
357 | 665 | } |
358 | | #if defined( HAVE_DEBUG_OUTPUT ) |
359 | | if( libcnotify_verbose != 0 ) |
360 | | { |
361 | | libcnotify_printf( |
362 | | "%s: signature:\n", |
363 | | function ); |
364 | | libcnotify_print_data( |
365 | | ( (olecf_file_header_t *) data )->signature, |
366 | | 8, |
367 | | 0 ); |
368 | | |
369 | | if( libolecf_debug_print_guid_value( |
370 | | function, |
371 | | "class identifier\t\t\t", |
372 | | ( (olecf_file_header_t *) data )->class_identifier, |
373 | | 16, |
374 | | file_header->byte_order, |
375 | | LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, |
376 | | error ) != 1 ) |
377 | | { |
378 | | libcerror_error_set( |
379 | | error, |
380 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
381 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
382 | | "%s: unable to print GUID value.", |
383 | | function ); |
384 | | |
385 | | return( -1 ); |
386 | | } |
387 | | libcnotify_printf( |
388 | | "%s: minor format version\t\t\t: %" PRIu16 "\n", |
389 | | function, |
390 | | file_header->minor_format_version ); |
391 | | |
392 | | libcnotify_printf( |
393 | | "%s: major format version\t\t\t: %" PRIu16 "\n", |
394 | | function, |
395 | | file_header->major_format_version ); |
396 | | |
397 | | libcnotify_printf( |
398 | | "%s: byte order\t\t\t\t: 0x%02" PRIx8 " 0x%02" PRIx8 "\n", |
399 | | function, |
400 | | ( (olecf_file_header_t *) data )->byte_order[ 0 ], |
401 | | ( (olecf_file_header_t *) data )->byte_order[ 1 ] ); |
402 | | |
403 | | libcnotify_printf( |
404 | | "%s: sector size\t\t\t\t: %" PRIu16 " (%" PRIzd ")\n", |
405 | | function, |
406 | | sector_size, |
407 | | 1 << sector_size ); |
408 | | |
409 | | libcnotify_printf( |
410 | | "%s: short sector size\t\t\t: %" PRIu16 " (%" PRIzd ")\n", |
411 | | function, |
412 | | short_sector_size, |
413 | | 1 << short_sector_size ); |
414 | | |
415 | | libcnotify_printf( |
416 | | "%s: unknown:\n", |
417 | | function ); |
418 | | libcnotify_print_data( |
419 | | ( (olecf_file_header_t *) data )->unknown1, |
420 | | 10, |
421 | | 0 ); |
422 | | |
423 | | libcnotify_printf( |
424 | | "%s: number of SAT sectors\t\t\t: %" PRIu32 "\n", |
425 | | function, |
426 | | file_header->number_of_sat_sectors ); |
427 | | |
428 | | libcnotify_printf( |
429 | | "%s: root directory sector identifier\t: 0x%08" PRIx32 "\n", |
430 | | function, |
431 | | file_header->root_directory_sector_identifier ); |
432 | | |
433 | | libcnotify_printf( |
434 | | "%s: transactioning signature:\n", |
435 | | function ); |
436 | | libcnotify_print_data( |
437 | | ( (olecf_file_header_t *) data )->transactioning_signature, |
438 | | 4, |
439 | | 0 ); |
440 | | |
441 | | libcnotify_printf( |
442 | | "%s: sector stream minimum data size\t\t: %" PRIu32 "\n", |
443 | | function, |
444 | | file_header->sector_stream_minimum_data_size ); |
445 | | |
446 | | libcnotify_printf( |
447 | | "%s: SSAT sector identifier\t\t\t: 0x%08" PRIx32 "\n", |
448 | | function, |
449 | | file_header->ssat_sector_identifier ); |
450 | | |
451 | | libcnotify_printf( |
452 | | "%s: number of SSAT sectors\t\t\t: %" PRIu32 "\n", |
453 | | function, |
454 | | file_header->number_of_ssat_sectors ); |
455 | | |
456 | | libcnotify_printf( |
457 | | "%s: MSAT sector identifier\t\t\t: 0x%08" PRIx32 "\n", |
458 | | function, |
459 | | file_header->msat_sector_identifier ); |
460 | | |
461 | | libcnotify_printf( |
462 | | "%s: number of MSAT sectors\t\t\t: %" PRIu32 "\n", |
463 | | function, |
464 | | file_header->number_of_msat_sectors ); |
465 | | } |
466 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
467 | | |
468 | 1.72k | if( sector_size > 15 ) |
469 | 24 | { |
470 | 24 | libcerror_error_set( |
471 | 24 | error, |
472 | 24 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
473 | 24 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
474 | 24 | "%s: invalid sector size value exceeds maximum.", |
475 | 24 | function ); |
476 | | |
477 | 24 | return( -1 ); |
478 | 24 | } |
479 | 1.69k | if( short_sector_size > 15 ) |
480 | 24 | { |
481 | 24 | libcerror_error_set( |
482 | 24 | error, |
483 | 24 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
484 | 24 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
485 | 24 | "%s: invalid short sector size value exceeds maximum.", |
486 | 24 | function ); |
487 | | |
488 | 24 | return( -1 ); |
489 | 24 | } |
490 | 1.67k | file_header->sector_size = 1 << sector_size; |
491 | 1.67k | file_header->short_sector_size = 1 << short_sector_size; |
492 | | |
493 | | #if SIZEOF_SIZE_T <= 4 |
494 | | if( file_header->sector_stream_minimum_data_size > (uint32_t) SSIZE_MAX ) |
495 | | { |
496 | | libcerror_error_set( |
497 | | error, |
498 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
499 | | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
500 | | "%s: invalid sector stream minimum size value exceeds maximum.", |
501 | | function ); |
502 | | |
503 | | return( -1 ); |
504 | | } |
505 | | #endif |
506 | 1.67k | if( msat->number_of_sector_identifiers < 109 ) |
507 | 0 | { |
508 | 0 | if( libolecf_allocation_table_resize( |
509 | 0 | msat, |
510 | 0 | 109, |
511 | 0 | error ) != 1 ) |
512 | 0 | { |
513 | 0 | libcerror_error_set( |
514 | 0 | error, |
515 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
516 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
517 | 0 | "%s: unable to resize MSAT.", |
518 | 0 | function ); |
519 | |
|
520 | 0 | return( -1 ); |
521 | 0 | } |
522 | 0 | } |
523 | 1.67k | msat_entry = ( (olecf_file_header_t *) data )->msat; |
524 | | |
525 | 1.67k | for( msat_index = 0; |
526 | 184k | msat_index < 109; |
527 | 182k | msat_index++ ) |
528 | 182k | { |
529 | 182k | if( file_header->byte_order == LIBOLECF_ENDIAN_LITTLE ) |
530 | 111k | { |
531 | 111k | byte_stream_copy_to_uint32_little_endian( |
532 | 111k | msat_entry, |
533 | 111k | msat->sector_identifiers[ msat_index ] ); |
534 | 111k | } |
535 | 70.8k | else if( file_header->byte_order == LIBOLECF_ENDIAN_BIG ) |
536 | 70.8k | { |
537 | 70.8k | byte_stream_copy_to_uint32_big_endian( |
538 | 70.8k | msat_entry, |
539 | 70.8k | msat->sector_identifiers[ msat_index ] ); |
540 | 70.8k | } |
541 | | #if defined( HAVE_DEBUG_OUTPUT ) |
542 | | if( libcnotify_verbose != 0 ) |
543 | | { |
544 | | libcnotify_printf( |
545 | | "%s: MSAT entry: %03d sector identifier\t: 0x%08" PRIx32 "\n", |
546 | | function, |
547 | | msat_index, |
548 | | msat->sector_identifiers[ msat_index ] ); |
549 | | } |
550 | | #endif |
551 | 182k | msat_entry += 4; |
552 | 182k | } |
553 | | #if defined( HAVE_DEBUG_OUTPUT ) |
554 | | if( libcnotify_verbose != 0 ) |
555 | | { |
556 | | libcnotify_printf( |
557 | | "\n" ); |
558 | | } |
559 | | #endif |
560 | 1.67k | return( 1 ); |
561 | 1.67k | } |
562 | | |
563 | | /* Reads the file header |
564 | | * Returns 1 if successful or -1 on error |
565 | | */ |
566 | | int libolecf_file_header_read_file_io_handle( |
567 | | libolecf_file_header_t *file_header, |
568 | | libbfio_handle_t *file_io_handle, |
569 | | libolecf_allocation_table_t *msat, |
570 | | libcerror_error_t **error ) |
571 | 1.93k | { |
572 | 1.93k | uint8_t file_header_data[ sizeof( olecf_file_header_t ) ]; |
573 | | |
574 | 1.93k | static char *function = "libolecf_file_header_read_file_io_handle"; |
575 | 1.93k | ssize_t read_count = 0; |
576 | | |
577 | 1.93k | if( file_header == NULL ) |
578 | 0 | { |
579 | 0 | libcerror_error_set( |
580 | 0 | error, |
581 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
582 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
583 | 0 | "%s: invalid file header.", |
584 | 0 | function ); |
585 | |
|
586 | 0 | return( -1 ); |
587 | 0 | } |
588 | | #if defined( HAVE_DEBUG_OUTPUT ) |
589 | | if( libcnotify_verbose != 0 ) |
590 | | { |
591 | | libcnotify_printf( |
592 | | "%s: reading file header at offset: 0 (0x00000000)\n", |
593 | | function ); |
594 | | } |
595 | | #endif |
596 | 1.93k | read_count = libbfio_handle_read_buffer_at_offset( |
597 | 1.93k | file_io_handle, |
598 | 1.93k | file_header_data, |
599 | 1.93k | sizeof( olecf_file_header_t ), |
600 | 1.93k | 0, |
601 | 1.93k | error ); |
602 | | |
603 | 1.93k | if( read_count != (ssize_t) sizeof( olecf_file_header_t ) ) |
604 | 32 | { |
605 | 32 | libcerror_error_set( |
606 | 32 | error, |
607 | 32 | LIBCERROR_ERROR_DOMAIN_IO, |
608 | 32 | LIBCERROR_IO_ERROR_READ_FAILED, |
609 | 32 | "%s: unable to read file header data at offset: 0 (0x00000000).", |
610 | 32 | function ); |
611 | | |
612 | 32 | return( -1 ); |
613 | 32 | } |
614 | 1.89k | if( libolecf_file_header_read_data( |
615 | 1.89k | file_header, |
616 | 1.89k | file_header_data, |
617 | 1.89k | sizeof( olecf_file_header_t ), |
618 | 1.89k | msat, |
619 | 1.89k | error ) != 1 ) |
620 | 224 | { |
621 | 224 | libcerror_error_set( |
622 | 224 | error, |
623 | 224 | LIBCERROR_ERROR_DOMAIN_IO, |
624 | 224 | LIBCERROR_IO_ERROR_READ_FAILED, |
625 | 224 | "%s: unable to read file header.", |
626 | 224 | function ); |
627 | | |
628 | 224 | return( -1 ); |
629 | 224 | } |
630 | 1.67k | return( 1 ); |
631 | 1.89k | } |
632 | | |