/src/libewf/libewf/libewf_single_files.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Single file entries 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 | | #include "libewf_definitions.h" |
28 | | #include "libewf_lef_file_entry.h" |
29 | | #include "libewf_lef_permission.h" |
30 | | #include "libewf_lef_source.h" |
31 | | #include "libewf_lef_subject.h" |
32 | | #include "libewf_libbfio.h" |
33 | | #include "libewf_libcdata.h" |
34 | | #include "libewf_libcerror.h" |
35 | | #include "libewf_libcnotify.h" |
36 | | #include "libewf_libfdata.h" |
37 | | #include "libewf_libfvalue.h" |
38 | | #include "libewf_libuna.h" |
39 | | #include "libewf_line_reader.h" |
40 | | #include "libewf_permission_group.h" |
41 | | #include "libewf_single_files.h" |
42 | | |
43 | | /* Creates single files |
44 | | * Make sure the value single_files is referencing, is set to NULL |
45 | | * Returns 1 if successful or -1 on error |
46 | | */ |
47 | | int libewf_single_files_initialize( |
48 | | libewf_single_files_t **single_files, |
49 | | libcerror_error_t **error ) |
50 | 89 | { |
51 | 89 | static char *function = "libewf_single_files_initialize"; |
52 | | |
53 | 89 | if( single_files == NULL ) |
54 | 0 | { |
55 | 0 | libcerror_error_set( |
56 | 0 | error, |
57 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
58 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
59 | 0 | "%s: invalid single files.", |
60 | 0 | function ); |
61 | |
|
62 | 0 | return( -1 ); |
63 | 0 | } |
64 | 89 | if( *single_files != NULL ) |
65 | 0 | { |
66 | 0 | libcerror_error_set( |
67 | 0 | error, |
68 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
69 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
70 | 0 | "%s: invalid single files value already set.", |
71 | 0 | function ); |
72 | |
|
73 | 0 | return( -1 ); |
74 | 0 | } |
75 | 89 | *single_files = memory_allocate_structure( |
76 | 89 | libewf_single_files_t ); |
77 | | |
78 | 89 | if( *single_files == NULL ) |
79 | 0 | { |
80 | 0 | libcerror_error_set( |
81 | 0 | error, |
82 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
83 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
84 | 0 | "%s: unable to create single files.", |
85 | 0 | function ); |
86 | |
|
87 | 0 | goto on_error; |
88 | 0 | } |
89 | 89 | if( memory_set( |
90 | 89 | *single_files, |
91 | 89 | 0, |
92 | 89 | sizeof( libewf_single_files_t ) ) == NULL ) |
93 | 0 | { |
94 | 0 | libcerror_error_set( |
95 | 0 | error, |
96 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
97 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
98 | 0 | "%s: unable to clear single files.", |
99 | 0 | function ); |
100 | |
|
101 | 0 | memory_free( |
102 | 0 | *single_files ); |
103 | |
|
104 | 0 | *single_files = NULL; |
105 | |
|
106 | 0 | return( -1 ); |
107 | 0 | } |
108 | 89 | if( libcdata_array_initialize( |
109 | 89 | &( ( *single_files )->permission_groups ), |
110 | 89 | 0, |
111 | 89 | error ) != 1 ) |
112 | 0 | { |
113 | 0 | libcerror_error_set( |
114 | 0 | error, |
115 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
116 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
117 | 0 | "%s: unable to create permission groups array.", |
118 | 0 | function ); |
119 | |
|
120 | 0 | goto on_error; |
121 | 0 | } |
122 | 89 | if( libcdata_array_initialize( |
123 | 89 | &( ( *single_files )->sources ), |
124 | 89 | 0, |
125 | 89 | error ) != 1 ) |
126 | 0 | { |
127 | 0 | libcerror_error_set( |
128 | 0 | error, |
129 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
130 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
131 | 0 | "%s: unable to create sources array.", |
132 | 0 | function ); |
133 | |
|
134 | 0 | goto on_error; |
135 | 0 | } |
136 | 89 | return( 1 ); |
137 | | |
138 | 0 | on_error: |
139 | 0 | if( *single_files != NULL ) |
140 | 0 | { |
141 | 0 | if( ( *single_files )->permission_groups != NULL ) |
142 | 0 | { |
143 | 0 | libcdata_array_free( |
144 | 0 | &( ( *single_files )->permission_groups ), |
145 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, |
146 | 0 | NULL ); |
147 | 0 | } |
148 | 0 | memory_free( |
149 | 0 | *single_files ); |
150 | |
|
151 | 0 | *single_files = NULL; |
152 | 0 | } |
153 | 0 | return( -1 ); |
154 | 89 | } |
155 | | |
156 | | /* Frees single files |
157 | | * Returns 1 if successful or -1 on error |
158 | | */ |
159 | | int libewf_single_files_free( |
160 | | libewf_single_files_t **single_files, |
161 | | libcerror_error_t **error ) |
162 | 89 | { |
163 | 89 | static char *function = "libewf_single_files_free"; |
164 | 89 | int result = 1; |
165 | | |
166 | 89 | if( single_files == NULL ) |
167 | 0 | { |
168 | 0 | libcerror_error_set( |
169 | 0 | error, |
170 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
171 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
172 | 0 | "%s: invalid single files.", |
173 | 0 | function ); |
174 | |
|
175 | 0 | return( -1 ); |
176 | 0 | } |
177 | 89 | if( *single_files != NULL ) |
178 | 89 | { |
179 | 89 | if( ( *single_files )->file_entry_tree_root_node != NULL ) |
180 | 0 | { |
181 | 0 | if( libcdata_tree_node_free( |
182 | 0 | &( ( *single_files )->file_entry_tree_root_node ), |
183 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
184 | 0 | error ) != 1 ) |
185 | 0 | { |
186 | 0 | libcerror_error_set( |
187 | 0 | error, |
188 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
189 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
190 | 0 | "%s: unable to free file entry tree root node.", |
191 | 0 | function ); |
192 | |
|
193 | 0 | result = -1; |
194 | 0 | } |
195 | 0 | } |
196 | 89 | if( libcdata_array_free( |
197 | 89 | &( ( *single_files )->sources ), |
198 | 89 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_source_free, |
199 | 89 | error ) != 1 ) |
200 | 0 | { |
201 | 0 | libcerror_error_set( |
202 | 0 | error, |
203 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
204 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
205 | 0 | "%s: unable to free sources array.", |
206 | 0 | function ); |
207 | |
|
208 | 0 | result = -1; |
209 | 0 | } |
210 | 89 | if( libcdata_array_free( |
211 | 89 | &( ( *single_files )->permission_groups ), |
212 | 89 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, |
213 | 89 | error ) != 1 ) |
214 | 0 | { |
215 | 0 | libcerror_error_set( |
216 | 0 | error, |
217 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
218 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
219 | 0 | "%s: unable to free permission groups array.", |
220 | 0 | function ); |
221 | |
|
222 | 0 | result = -1; |
223 | 0 | } |
224 | 89 | memory_free( |
225 | 89 | *single_files ); |
226 | | |
227 | 89 | *single_files = NULL; |
228 | 89 | } |
229 | 89 | return( result ); |
230 | 89 | } |
231 | | |
232 | | /* Clones the single files |
233 | | * Returns 1 if successful or -1 on error |
234 | | */ |
235 | | int libewf_single_files_clone( |
236 | | libewf_single_files_t **destination_single_files, |
237 | | libewf_single_files_t *source_single_files, |
238 | | libcerror_error_t **error ) |
239 | 0 | { |
240 | 0 | static char *function = "libewf_single_files_clone"; |
241 | |
|
242 | 0 | if( destination_single_files == NULL ) |
243 | 0 | { |
244 | 0 | libcerror_error_set( |
245 | 0 | error, |
246 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
247 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
248 | 0 | "%s: invalid destination single files.", |
249 | 0 | function ); |
250 | |
|
251 | 0 | return( -1 ); |
252 | 0 | } |
253 | 0 | if( *destination_single_files != NULL ) |
254 | 0 | { |
255 | 0 | libcerror_error_set( |
256 | 0 | error, |
257 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
258 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
259 | 0 | "%s: invalid destination single files value already set.", |
260 | 0 | function ); |
261 | |
|
262 | 0 | return( -1 ); |
263 | 0 | } |
264 | 0 | if( source_single_files == NULL ) |
265 | 0 | { |
266 | 0 | *destination_single_files = NULL; |
267 | |
|
268 | 0 | return( 1 ); |
269 | 0 | } |
270 | 0 | *destination_single_files = memory_allocate_structure( |
271 | 0 | libewf_single_files_t ); |
272 | |
|
273 | 0 | if( *destination_single_files == NULL ) |
274 | 0 | { |
275 | 0 | libcerror_error_set( |
276 | 0 | error, |
277 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
278 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
279 | 0 | "%s: unable to create destination single files.", |
280 | 0 | function ); |
281 | |
|
282 | 0 | goto on_error; |
283 | 0 | } |
284 | 0 | ( *destination_single_files )->permission_groups = NULL; |
285 | 0 | ( *destination_single_files )->sources = NULL; |
286 | 0 | ( *destination_single_files )->file_entry_tree_root_node = NULL; |
287 | |
|
288 | 0 | if( libcdata_array_clone( |
289 | 0 | &( ( *destination_single_files )->permission_groups ), |
290 | 0 | source_single_files->permission_groups, |
291 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_permission_group_free, |
292 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_permission_group_clone, |
293 | 0 | error ) != 1 ) |
294 | 0 | { |
295 | 0 | libcerror_error_set( |
296 | 0 | error, |
297 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
298 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
299 | 0 | "%s: unable to create destination permission groups array.", |
300 | 0 | function ); |
301 | |
|
302 | 0 | goto on_error; |
303 | 0 | } |
304 | 0 | if( libcdata_array_clone( |
305 | 0 | &( ( *destination_single_files )->sources ), |
306 | 0 | source_single_files->sources, |
307 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_source_free, |
308 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_lef_source_clone, |
309 | 0 | error ) != 1 ) |
310 | 0 | { |
311 | 0 | libcerror_error_set( |
312 | 0 | error, |
313 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
314 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
315 | 0 | "%s: unable to create destination sources array.", |
316 | 0 | function ); |
317 | |
|
318 | 0 | goto on_error; |
319 | 0 | } |
320 | 0 | if( libcdata_tree_node_clone( |
321 | 0 | &( ( *destination_single_files )->file_entry_tree_root_node ), |
322 | 0 | source_single_files->file_entry_tree_root_node, |
323 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
324 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_lef_file_entry_clone, |
325 | 0 | error ) != 1 ) |
326 | 0 | { |
327 | 0 | libcerror_error_set( |
328 | 0 | error, |
329 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
330 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
331 | 0 | "%s: unable to create destination file entry tree root node.", |
332 | 0 | function ); |
333 | |
|
334 | 0 | goto on_error; |
335 | 0 | } |
336 | 0 | return( 1 ); |
337 | | |
338 | 0 | on_error: |
339 | 0 | if( *destination_single_files != NULL ) |
340 | 0 | { |
341 | 0 | libewf_single_files_free( |
342 | 0 | destination_single_files, |
343 | 0 | NULL ); |
344 | 0 | } |
345 | 0 | return( -1 ); |
346 | 0 | } |
347 | | |
348 | | /* Parses the number of entries in a category |
349 | | * Returns 1 if successful or -1 on error |
350 | | */ |
351 | | int libewf_single_files_parse_category_number_of_entries( |
352 | | libewf_single_files_t *single_files, |
353 | | libewf_line_reader_t *line_reader, |
354 | | int *number_of_entries, |
355 | | libcerror_error_t **error ) |
356 | 0 | { |
357 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
358 | 0 | uint8_t *line_string = NULL; |
359 | 0 | uint8_t *value_string = NULL; |
360 | 0 | static char *function = "libewf_single_files_parse_category_number_of_entries"; |
361 | 0 | size_t line_string_size = 0; |
362 | 0 | size_t value_string_size = 0; |
363 | 0 | uint64_t value_64bit = 0; |
364 | 0 | int number_of_values = 0; |
365 | |
|
366 | 0 | if( single_files == NULL ) |
367 | 0 | { |
368 | 0 | libcerror_error_set( |
369 | 0 | error, |
370 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
371 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
372 | 0 | "%s: invalid single files.", |
373 | 0 | function ); |
374 | |
|
375 | 0 | return( -1 ); |
376 | 0 | } |
377 | 0 | if( line_reader == NULL ) |
378 | 0 | { |
379 | 0 | libcerror_error_set( |
380 | 0 | error, |
381 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
382 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
383 | 0 | "%s: invalid line reader.", |
384 | 0 | function ); |
385 | |
|
386 | 0 | return( -1 ); |
387 | 0 | } |
388 | 0 | if( number_of_entries == NULL ) |
389 | 0 | { |
390 | 0 | libcerror_error_set( |
391 | 0 | error, |
392 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
393 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
394 | 0 | "%s: invalid number of entries.", |
395 | 0 | function ); |
396 | |
|
397 | 0 | return( -1 ); |
398 | 0 | } |
399 | 0 | if( libewf_line_reader_read_utf8_string( |
400 | 0 | line_reader, |
401 | 0 | &line_string, |
402 | 0 | &line_string_size, |
403 | 0 | error ) != 1 ) |
404 | 0 | { |
405 | 0 | libcerror_error_set( |
406 | 0 | error, |
407 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
408 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
409 | 0 | "%s: unable to read line: %d.", |
410 | 0 | function, |
411 | 0 | line_reader->line_index ); |
412 | |
|
413 | 0 | goto on_error; |
414 | 0 | } |
415 | 0 | if( libfvalue_utf8_string_split( |
416 | 0 | line_string, |
417 | 0 | line_string_size, |
418 | 0 | (uint8_t) '\t', |
419 | 0 | &values, |
420 | 0 | error ) != 1 ) |
421 | 0 | { |
422 | 0 | libcerror_error_set( |
423 | 0 | error, |
424 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
425 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
426 | 0 | "%s: unable to split line: %d string into values.", |
427 | 0 | function, |
428 | 0 | line_reader->line_index - 1 ); |
429 | |
|
430 | 0 | goto on_error; |
431 | 0 | } |
432 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
433 | 0 | values, |
434 | 0 | &number_of_values, |
435 | 0 | error ) != 1 ) |
436 | 0 | { |
437 | 0 | libcerror_error_set( |
438 | 0 | error, |
439 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
440 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
441 | 0 | "%s: unable to retrieve number of values", |
442 | 0 | function ); |
443 | |
|
444 | 0 | goto on_error; |
445 | 0 | } |
446 | 0 | if( number_of_values != 2 ) |
447 | 0 | { |
448 | 0 | libcerror_error_set( |
449 | 0 | error, |
450 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
451 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
452 | 0 | "%s: unsupported number of values.", |
453 | 0 | function ); |
454 | |
|
455 | 0 | goto on_error; |
456 | 0 | } |
457 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
458 | 0 | values, |
459 | 0 | 1, |
460 | 0 | &value_string, |
461 | 0 | &value_string_size, |
462 | 0 | error ) != 1 ) |
463 | 0 | { |
464 | 0 | libcerror_error_set( |
465 | 0 | error, |
466 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
467 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
468 | 0 | "%s: unable to retrieve value string: 1.", |
469 | 0 | function ); |
470 | |
|
471 | 0 | goto on_error; |
472 | 0 | } |
473 | 0 | if( ( value_string_size != 2 ) |
474 | 0 | || ( value_string[ 0 ] != (uint8_t) '1' ) ) |
475 | 0 | { |
476 | 0 | libcerror_error_set( |
477 | 0 | error, |
478 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
479 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
480 | 0 | "%s: unsupported second value: %s.", |
481 | 0 | function, |
482 | 0 | value_string ); |
483 | |
|
484 | 0 | goto on_error; |
485 | 0 | } |
486 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
487 | 0 | values, |
488 | 0 | 0, |
489 | 0 | &value_string, |
490 | 0 | &value_string_size, |
491 | 0 | error ) != 1 ) |
492 | 0 | { |
493 | 0 | libcerror_error_set( |
494 | 0 | error, |
495 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
496 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
497 | 0 | "%s: unable to retrieve value string: 0.", |
498 | 0 | function ); |
499 | |
|
500 | 0 | goto on_error; |
501 | 0 | } |
502 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
503 | 0 | value_string, |
504 | 0 | value_string_size, |
505 | 0 | &value_64bit, |
506 | 0 | 64, |
507 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
508 | 0 | error ) != 1 ) |
509 | 0 | { |
510 | 0 | libcerror_error_set( |
511 | 0 | error, |
512 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
513 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
514 | 0 | "%s: unable to set number of entries.", |
515 | 0 | function ); |
516 | |
|
517 | 0 | goto on_error; |
518 | 0 | } |
519 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
520 | 0 | { |
521 | 0 | libcerror_error_set( |
522 | 0 | error, |
523 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
524 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
525 | 0 | "%s: invalid number of entries value out of bounds.", |
526 | 0 | function ); |
527 | |
|
528 | 0 | goto on_error; |
529 | 0 | } |
530 | 0 | if( libfvalue_split_utf8_string_free( |
531 | 0 | &values, |
532 | 0 | error ) != 1 ) |
533 | 0 | { |
534 | 0 | libcerror_error_set( |
535 | 0 | error, |
536 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
537 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
538 | 0 | "%s: unable to free split values.", |
539 | 0 | function ); |
540 | |
|
541 | 0 | goto on_error; |
542 | 0 | } |
543 | 0 | *number_of_entries = (int) value_64bit; |
544 | |
|
545 | 0 | return( 1 ); |
546 | | |
547 | 0 | on_error: |
548 | 0 | if( values != NULL ) |
549 | 0 | { |
550 | 0 | libfvalue_split_utf8_string_free( |
551 | 0 | &values, |
552 | 0 | NULL ); |
553 | 0 | } |
554 | 0 | return( -1 ); |
555 | 0 | } |
556 | | |
557 | | /* Parses the types of a category |
558 | | * Returns 1 if successful or -1 on error |
559 | | */ |
560 | | int libewf_single_files_parse_category_types( |
561 | | libewf_single_files_t *single_files, |
562 | | libewf_line_reader_t *line_reader, |
563 | | libfvalue_split_utf8_string_t **types, |
564 | | libcerror_error_t **error ) |
565 | 0 | { |
566 | 0 | uint8_t *line_string = NULL; |
567 | 0 | static char *function = "libewf_single_files_parse_category_types"; |
568 | 0 | size_t line_string_size = 0; |
569 | |
|
570 | 0 | if( single_files == NULL ) |
571 | 0 | { |
572 | 0 | libcerror_error_set( |
573 | 0 | error, |
574 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
575 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
576 | 0 | "%s: invalid single files.", |
577 | 0 | function ); |
578 | |
|
579 | 0 | return( -1 ); |
580 | 0 | } |
581 | 0 | if( line_reader == NULL ) |
582 | 0 | { |
583 | 0 | libcerror_error_set( |
584 | 0 | error, |
585 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
586 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
587 | 0 | "%s: invalid line reader.", |
588 | 0 | function ); |
589 | |
|
590 | 0 | return( -1 ); |
591 | 0 | } |
592 | 0 | if( libewf_line_reader_read_utf8_string( |
593 | 0 | line_reader, |
594 | 0 | &line_string, |
595 | 0 | &line_string_size, |
596 | 0 | error ) != 1 ) |
597 | 0 | { |
598 | 0 | libcerror_error_set( |
599 | 0 | error, |
600 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
601 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
602 | 0 | "%s: unable to read line: %d.", |
603 | 0 | function, |
604 | 0 | line_reader->line_index ); |
605 | |
|
606 | 0 | return( -1 ); |
607 | 0 | } |
608 | 0 | if( libfvalue_utf8_string_split( |
609 | 0 | line_string, |
610 | 0 | line_string_size, |
611 | 0 | (uint8_t) '\t', |
612 | 0 | types, |
613 | 0 | error ) != 1 ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
619 | 0 | "%s: unable to split line: %d into types.", |
620 | 0 | function, |
621 | 0 | line_reader->line_index - 1 ); |
622 | |
|
623 | 0 | return( -1 ); |
624 | 0 | } |
625 | 0 | return( 1 ); |
626 | 0 | } |
627 | | |
628 | | /* Parses the number of entries |
629 | | * Returns 1 if successful or -1 on error |
630 | | */ |
631 | | int libewf_single_files_parse_number_of_entries( |
632 | | libewf_single_files_t *single_files, |
633 | | libewf_line_reader_t *line_reader, |
634 | | int *number_of_entries, |
635 | | libcerror_error_t **error ) |
636 | 0 | { |
637 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
638 | 0 | uint8_t *line_string = NULL; |
639 | 0 | uint8_t *value_string = NULL; |
640 | 0 | static char *function = "libewf_single_files_parse_number_of_entries"; |
641 | 0 | size_t line_string_size = 0; |
642 | 0 | size_t value_string_size = 0; |
643 | 0 | uint64_t value_64bit = 0; |
644 | 0 | int number_of_values = 0; |
645 | |
|
646 | 0 | if( single_files == NULL ) |
647 | 0 | { |
648 | 0 | libcerror_error_set( |
649 | 0 | error, |
650 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
651 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
652 | 0 | "%s: invalid single files.", |
653 | 0 | function ); |
654 | |
|
655 | 0 | return( -1 ); |
656 | 0 | } |
657 | 0 | if( line_reader == NULL ) |
658 | 0 | { |
659 | 0 | libcerror_error_set( |
660 | 0 | error, |
661 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
662 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
663 | 0 | "%s: invalid line reader.", |
664 | 0 | function ); |
665 | |
|
666 | 0 | return( -1 ); |
667 | 0 | } |
668 | 0 | if( number_of_entries == NULL ) |
669 | 0 | { |
670 | 0 | libcerror_error_set( |
671 | 0 | error, |
672 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
673 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
674 | 0 | "%s: invalid number of entries.", |
675 | 0 | function ); |
676 | |
|
677 | 0 | return( -1 ); |
678 | 0 | } |
679 | 0 | if( libewf_line_reader_read_utf8_string( |
680 | 0 | line_reader, |
681 | 0 | &line_string, |
682 | 0 | &line_string_size, |
683 | 0 | error ) != 1 ) |
684 | 0 | { |
685 | 0 | libcerror_error_set( |
686 | 0 | error, |
687 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
688 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
689 | 0 | "%s: unable to read line: %d.", |
690 | 0 | function, |
691 | 0 | line_reader->line_index ); |
692 | |
|
693 | 0 | return( -1 ); |
694 | 0 | } |
695 | 0 | if( libfvalue_utf8_string_split( |
696 | 0 | line_string, |
697 | 0 | line_string_size, |
698 | 0 | (uint8_t) '\t', |
699 | 0 | &values, |
700 | 0 | error ) != 1 ) |
701 | 0 | { |
702 | 0 | libcerror_error_set( |
703 | 0 | error, |
704 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
705 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
706 | 0 | "%s: unable to split line: %d string into values.", |
707 | 0 | function, |
708 | 0 | line_reader->line_index - 1 ); |
709 | |
|
710 | 0 | goto on_error; |
711 | 0 | } |
712 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
713 | 0 | values, |
714 | 0 | &number_of_values, |
715 | 0 | error ) != 1 ) |
716 | 0 | { |
717 | 0 | libcerror_error_set( |
718 | 0 | error, |
719 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
720 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
721 | 0 | "%s: unable to retrieve number of values", |
722 | 0 | function ); |
723 | |
|
724 | 0 | goto on_error; |
725 | 0 | } |
726 | 0 | if( number_of_values != 2 ) |
727 | 0 | { |
728 | 0 | libcerror_error_set( |
729 | 0 | error, |
730 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
731 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
732 | 0 | "%s: unsupported number of values.", |
733 | 0 | function ); |
734 | |
|
735 | 0 | goto on_error; |
736 | 0 | } |
737 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
738 | 0 | values, |
739 | 0 | 0, |
740 | 0 | &value_string, |
741 | 0 | &value_string_size, |
742 | 0 | error ) != 1 ) |
743 | 0 | { |
744 | 0 | libcerror_error_set( |
745 | 0 | error, |
746 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
747 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
748 | 0 | "%s: unable to retrieve value string: 0.", |
749 | 0 | function ); |
750 | |
|
751 | 0 | goto on_error; |
752 | 0 | } |
753 | 0 | if( ( value_string_size != 2 ) |
754 | 0 | || ( value_string[ 0 ] != (uint8_t) '0' ) ) |
755 | 0 | { |
756 | 0 | libcerror_error_set( |
757 | 0 | error, |
758 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
759 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
760 | 0 | "%s: unsupported first value: %s.", |
761 | 0 | function, |
762 | 0 | value_string ); |
763 | |
|
764 | 0 | goto on_error; |
765 | 0 | } |
766 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
767 | 0 | values, |
768 | 0 | 1, |
769 | 0 | &value_string, |
770 | 0 | &value_string_size, |
771 | 0 | error ) != 1 ) |
772 | 0 | { |
773 | 0 | libcerror_error_set( |
774 | 0 | error, |
775 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
776 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
777 | 0 | "%s: unable to retrieve value string: 1.", |
778 | 0 | function ); |
779 | |
|
780 | 0 | goto on_error; |
781 | 0 | } |
782 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
783 | 0 | value_string, |
784 | 0 | value_string_size, |
785 | 0 | &value_64bit, |
786 | 0 | 64, |
787 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
788 | 0 | error ) != 1 ) |
789 | 0 | { |
790 | 0 | libcerror_error_set( |
791 | 0 | error, |
792 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
793 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
794 | 0 | "%s: unable to set number of entries.", |
795 | 0 | function ); |
796 | |
|
797 | 0 | goto on_error; |
798 | 0 | } |
799 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
800 | 0 | { |
801 | 0 | libcerror_error_set( |
802 | 0 | error, |
803 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
804 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
805 | 0 | "%s: invalid number of entries value out of bounds.", |
806 | 0 | function ); |
807 | |
|
808 | 0 | goto on_error; |
809 | 0 | } |
810 | 0 | if( libfvalue_split_utf8_string_free( |
811 | 0 | &values, |
812 | 0 | error ) != 1 ) |
813 | 0 | { |
814 | 0 | libcerror_error_set( |
815 | 0 | error, |
816 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
817 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
818 | 0 | "%s: unable to free split values.", |
819 | 0 | function ); |
820 | |
|
821 | 0 | goto on_error; |
822 | 0 | } |
823 | 0 | *number_of_entries = (int) value_64bit; |
824 | |
|
825 | 0 | return( 1 ); |
826 | | |
827 | 0 | on_error: |
828 | 0 | if( values != NULL ) |
829 | 0 | { |
830 | 0 | libfvalue_split_utf8_string_free( |
831 | 0 | &values, |
832 | 0 | NULL ); |
833 | 0 | } |
834 | 0 | return( -1 ); |
835 | 0 | } |
836 | | |
837 | | /* Determines the EWF format based on the entry types |
838 | | * Returns 1 if successful or -1 on error |
839 | | */ |
840 | | int libewf_single_files_parse_format( |
841 | | libfvalue_split_utf8_string_t *types, |
842 | | uint8_t *format, |
843 | | libcerror_error_t **error ) |
844 | 0 | { |
845 | 0 | uint8_t *type_string = NULL; |
846 | 0 | static char *function = "libewf_single_files_parse_format"; |
847 | 0 | size_t type_string_size = 0; |
848 | 0 | int number_of_types = 0; |
849 | 0 | int value_index = 0; |
850 | |
|
851 | 0 | if( format == NULL ) |
852 | 0 | { |
853 | 0 | libcerror_error_set( |
854 | 0 | error, |
855 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
856 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
857 | 0 | "%s: invalid format.", |
858 | 0 | function ); |
859 | |
|
860 | 0 | return( -1 ); |
861 | 0 | } |
862 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
863 | 0 | types, |
864 | 0 | &number_of_types, |
865 | 0 | error ) != 1 ) |
866 | 0 | { |
867 | 0 | libcerror_error_set( |
868 | 0 | error, |
869 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
870 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
871 | 0 | "%s: unable to retrieve number of types", |
872 | 0 | function ); |
873 | |
|
874 | 0 | return( -1 ); |
875 | 0 | } |
876 | 0 | for( value_index = 0; |
877 | 0 | value_index < number_of_types; |
878 | 0 | value_index++ ) |
879 | 0 | { |
880 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
881 | 0 | types, |
882 | 0 | value_index, |
883 | 0 | &type_string, |
884 | 0 | &type_string_size, |
885 | 0 | error ) != 1 ) |
886 | 0 | { |
887 | 0 | libcerror_error_set( |
888 | 0 | error, |
889 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
890 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
891 | 0 | "%s: unable to retrieve type string: %d.", |
892 | 0 | function, |
893 | 0 | value_index ); |
894 | |
|
895 | 0 | return( -1 ); |
896 | 0 | } |
897 | 0 | if( ( type_string == NULL ) |
898 | 0 | || ( type_string_size < 2 ) |
899 | 0 | || ( type_string[ 0 ] == 0 ) ) |
900 | 0 | { |
901 | 0 | libcerror_error_set( |
902 | 0 | error, |
903 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
904 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
905 | 0 | "%s: missing type string: %d.", |
906 | 0 | function, |
907 | 0 | value_index ); |
908 | |
|
909 | 0 | return( -1 ); |
910 | 0 | } |
911 | 0 | if( type_string_size == 3 ) |
912 | 0 | { |
913 | | /* Data offset |
914 | | * consist of: unknown, offset and size |
915 | | */ |
916 | 0 | if( ( type_string[ 0 ] == (uint8_t) 'b' ) |
917 | 0 | && ( type_string[ 1 ] == (uint8_t) 'e' ) ) |
918 | 0 | { |
919 | 0 | if( value_index == 19 ) |
920 | 0 | { |
921 | 0 | *format = LIBEWF_FORMAT_LOGICAL_ENCASE5; |
922 | 0 | } |
923 | 0 | else if( ( value_index == 20 ) |
924 | 0 | || ( value_index == 21 ) ) |
925 | 0 | { |
926 | 0 | *format = LIBEWF_FORMAT_LOGICAL_ENCASE6; |
927 | 0 | } |
928 | 0 | else if( value_index == 2 ) |
929 | 0 | { |
930 | 0 | *format = LIBEWF_FORMAT_LOGICAL_ENCASE7; |
931 | 0 | } |
932 | 0 | } |
933 | 0 | } |
934 | 0 | } |
935 | 0 | return( 1 ); |
936 | 0 | } |
937 | | |
938 | | /* Parses the "rec" category |
939 | | * Returns 1 if successful or -1 on error |
940 | | */ |
941 | | int libewf_single_files_parse_rec_category( |
942 | | libewf_single_files_t *single_files, |
943 | | libewf_line_reader_t *line_reader, |
944 | | size64_t *media_size, |
945 | | libcerror_error_t **error ) |
946 | 19 | { |
947 | 19 | uint8_t *line_string = NULL; |
948 | 19 | static char *function = "libewf_single_files_parse_rec_category"; |
949 | 19 | size_t line_string_size = 0; |
950 | | |
951 | 19 | if( single_files == NULL ) |
952 | 0 | { |
953 | 0 | libcerror_error_set( |
954 | 0 | error, |
955 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
956 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
957 | 0 | "%s: invalid single files.", |
958 | 0 | function ); |
959 | |
|
960 | 0 | return( -1 ); |
961 | 0 | } |
962 | 19 | if( line_reader == NULL ) |
963 | 0 | { |
964 | 0 | libcerror_error_set( |
965 | 0 | error, |
966 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
967 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
968 | 0 | "%s: invalid line reader.", |
969 | 0 | function ); |
970 | |
|
971 | 0 | return( -1 ); |
972 | 0 | } |
973 | 19 | if( libewf_line_reader_read_utf8_string( |
974 | 19 | line_reader, |
975 | 19 | &line_string, |
976 | 19 | &line_string_size, |
977 | 19 | error ) != 1 ) |
978 | 0 | { |
979 | 0 | libcerror_error_set( |
980 | 0 | error, |
981 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
982 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
983 | 0 | "%s: unable to read line: %d.", |
984 | 0 | function, |
985 | 0 | line_reader->line_index ); |
986 | |
|
987 | 0 | return( -1 ); |
988 | 0 | } |
989 | 19 | if( ( line_string_size != 4 ) |
990 | 19 | || ( line_string[ 0 ] != (uint8_t) 'r' ) |
991 | 19 | || ( line_string[ 1 ] != (uint8_t) 'e' ) |
992 | 19 | || ( line_string[ 2 ] != (uint8_t) 'c' ) ) |
993 | 19 | { |
994 | 19 | libcerror_error_set( |
995 | 19 | error, |
996 | 19 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
997 | 19 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
998 | 19 | "%s: unsupported category header.", |
999 | 19 | function ); |
1000 | | |
1001 | 19 | return( -1 ); |
1002 | 19 | } |
1003 | 0 | if( libewf_single_files_parse_record_values( |
1004 | 0 | single_files, |
1005 | 0 | line_reader, |
1006 | 0 | media_size, |
1007 | 0 | error ) != 1 ) |
1008 | 0 | { |
1009 | 0 | libcerror_error_set( |
1010 | 0 | error, |
1011 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1012 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1013 | 0 | "%s: unable to parse record values.", |
1014 | 0 | function ); |
1015 | |
|
1016 | 0 | return( -1 ); |
1017 | 0 | } |
1018 | | /* The category should be followed by an empty line |
1019 | | */ |
1020 | 0 | if( libewf_line_reader_read_utf8_string( |
1021 | 0 | line_reader, |
1022 | 0 | &line_string, |
1023 | 0 | &line_string_size, |
1024 | 0 | error ) != 1 ) |
1025 | 0 | { |
1026 | 0 | libcerror_error_set( |
1027 | 0 | error, |
1028 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1029 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1030 | 0 | "%s: unable to read line: %d.", |
1031 | 0 | function, |
1032 | 0 | line_reader->line_index ); |
1033 | |
|
1034 | 0 | return( -1 ); |
1035 | 0 | } |
1036 | 0 | if( ( line_string_size != 1 ) |
1037 | 0 | || ( line_string[ 0 ] != 0 ) ) |
1038 | 0 | { |
1039 | 0 | libcerror_error_set( |
1040 | 0 | error, |
1041 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1042 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1043 | 0 | "%s: unsupported empty line string: %d - not empty.", |
1044 | 0 | function, |
1045 | 0 | line_reader->line_index ); |
1046 | |
|
1047 | 0 | return( -1 ); |
1048 | 0 | } |
1049 | 0 | return( 1 ); |
1050 | 0 | } |
1051 | | |
1052 | | /* Parses a record string for the values |
1053 | | * Returns 1 if successful or -1 on error |
1054 | | */ |
1055 | | int libewf_single_files_parse_record_values( |
1056 | | libewf_single_files_t *single_files, |
1057 | | libewf_line_reader_t *line_reader, |
1058 | | size64_t *media_size, |
1059 | | libcerror_error_t **error ) |
1060 | 0 | { |
1061 | 0 | libfvalue_split_utf8_string_t *types = NULL; |
1062 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
1063 | 0 | uint8_t *line_string = NULL; |
1064 | 0 | uint8_t *type_string = NULL; |
1065 | 0 | uint8_t *value_string = NULL; |
1066 | 0 | static char *function = "libewf_single_files_parse_record_values"; |
1067 | 0 | size_t line_string_size = 0; |
1068 | 0 | size_t type_string_size = 0; |
1069 | 0 | size_t value_string_size = 0; |
1070 | 0 | uint64_t value_64bit = 0; |
1071 | 0 | int number_of_types = 0; |
1072 | 0 | int number_of_values = 0; |
1073 | 0 | int value_index = 0; |
1074 | |
|
1075 | 0 | if( single_files == NULL ) |
1076 | 0 | { |
1077 | 0 | libcerror_error_set( |
1078 | 0 | error, |
1079 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1080 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1081 | 0 | "%s: invalid single files.", |
1082 | 0 | function ); |
1083 | |
|
1084 | 0 | return( -1 ); |
1085 | 0 | } |
1086 | 0 | if( line_reader == NULL ) |
1087 | 0 | { |
1088 | 0 | libcerror_error_set( |
1089 | 0 | error, |
1090 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1091 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1092 | 0 | "%s: invalid line reader.", |
1093 | 0 | function ); |
1094 | |
|
1095 | 0 | return( -1 ); |
1096 | 0 | } |
1097 | 0 | if( media_size == NULL ) |
1098 | 0 | { |
1099 | 0 | libcerror_error_set( |
1100 | 0 | error, |
1101 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1102 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1103 | 0 | "%s: invalid media size.", |
1104 | 0 | function ); |
1105 | |
|
1106 | 0 | return( -1 ); |
1107 | 0 | } |
1108 | 0 | if( libewf_line_reader_read_utf8_string( |
1109 | 0 | line_reader, |
1110 | 0 | &line_string, |
1111 | 0 | &line_string_size, |
1112 | 0 | error ) != 1 ) |
1113 | 0 | { |
1114 | 0 | libcerror_error_set( |
1115 | 0 | error, |
1116 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1117 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1118 | 0 | "%s: unable to read line: %d.", |
1119 | 0 | function, |
1120 | 0 | line_reader->line_index ); |
1121 | |
|
1122 | 0 | goto on_error; |
1123 | 0 | } |
1124 | 0 | if( libfvalue_utf8_string_split( |
1125 | 0 | line_string, |
1126 | 0 | line_string_size, |
1127 | 0 | (uint8_t) '\t', |
1128 | 0 | &types, |
1129 | 0 | error ) != 1 ) |
1130 | 0 | { |
1131 | 0 | libcerror_error_set( |
1132 | 0 | error, |
1133 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1134 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1135 | 0 | "%s: unable to split line string into types.", |
1136 | 0 | function ); |
1137 | |
|
1138 | 0 | goto on_error; |
1139 | 0 | } |
1140 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
1141 | 0 | types, |
1142 | 0 | &number_of_types, |
1143 | 0 | error ) != 1 ) |
1144 | 0 | { |
1145 | 0 | libcerror_error_set( |
1146 | 0 | error, |
1147 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1148 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1149 | 0 | "%s: unable to retrieve number of types", |
1150 | 0 | function ); |
1151 | |
|
1152 | 0 | goto on_error; |
1153 | 0 | } |
1154 | 0 | if( libewf_line_reader_read_utf8_string( |
1155 | 0 | line_reader, |
1156 | 0 | &line_string, |
1157 | 0 | &line_string_size, |
1158 | 0 | error ) != 1 ) |
1159 | 0 | { |
1160 | 0 | libcerror_error_set( |
1161 | 0 | error, |
1162 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1163 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1164 | 0 | "%s: unable to read line: %d.", |
1165 | 0 | function, |
1166 | 0 | line_reader->line_index ); |
1167 | |
|
1168 | 0 | goto on_error; |
1169 | 0 | } |
1170 | 0 | if( libfvalue_utf8_string_split( |
1171 | 0 | line_string, |
1172 | 0 | line_string_size, |
1173 | 0 | (uint8_t) '\t', |
1174 | 0 | &values, |
1175 | 0 | error ) != 1 ) |
1176 | 0 | { |
1177 | 0 | libcerror_error_set( |
1178 | 0 | error, |
1179 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1180 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1181 | 0 | "%s: unable to split line string into values.", |
1182 | 0 | function ); |
1183 | |
|
1184 | 0 | goto on_error; |
1185 | 0 | } |
1186 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
1187 | 0 | values, |
1188 | 0 | &number_of_values, |
1189 | 0 | error ) != 1 ) |
1190 | 0 | { |
1191 | 0 | libcerror_error_set( |
1192 | 0 | error, |
1193 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1194 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1195 | 0 | "%s: unable to retrieve number of values", |
1196 | 0 | function ); |
1197 | |
|
1198 | 0 | goto on_error; |
1199 | 0 | } |
1200 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1201 | | if( number_of_types != number_of_values ) |
1202 | | { |
1203 | | if( libcnotify_verbose != 0 ) |
1204 | | { |
1205 | | libcnotify_printf( |
1206 | | "%s: mismatch in number of types and values.\n", |
1207 | | function ); |
1208 | | } |
1209 | | } |
1210 | | #endif |
1211 | 0 | for( value_index = 0; |
1212 | 0 | value_index < number_of_types; |
1213 | 0 | value_index++ ) |
1214 | 0 | { |
1215 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1216 | 0 | types, |
1217 | 0 | value_index, |
1218 | 0 | &type_string, |
1219 | 0 | &type_string_size, |
1220 | 0 | error ) != 1 ) |
1221 | 0 | { |
1222 | 0 | libcerror_error_set( |
1223 | 0 | error, |
1224 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1225 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1226 | 0 | "%s: unable to retrieve type string: %d.", |
1227 | 0 | function, |
1228 | 0 | value_index ); |
1229 | |
|
1230 | 0 | goto on_error; |
1231 | 0 | } |
1232 | 0 | if( ( type_string == NULL ) |
1233 | 0 | || ( type_string_size < 2 ) |
1234 | 0 | || ( type_string[ 0 ] == 0 ) ) |
1235 | 0 | { |
1236 | 0 | libcerror_error_set( |
1237 | 0 | error, |
1238 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1239 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1240 | 0 | "%s: missing type string: %d.", |
1241 | 0 | function, |
1242 | 0 | value_index ); |
1243 | |
|
1244 | 0 | goto on_error; |
1245 | 0 | } |
1246 | 0 | if( value_index >= number_of_values ) |
1247 | 0 | { |
1248 | 0 | value_string = NULL; |
1249 | 0 | value_string_size = 0; |
1250 | 0 | } |
1251 | 0 | else |
1252 | 0 | { |
1253 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
1254 | 0 | values, |
1255 | 0 | value_index, |
1256 | 0 | &value_string, |
1257 | 0 | &value_string_size, |
1258 | 0 | error ) != 1 ) |
1259 | 0 | { |
1260 | 0 | libcerror_error_set( |
1261 | 0 | error, |
1262 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1263 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1264 | 0 | "%s: unable to retrieve value string: %d.", |
1265 | 0 | function, |
1266 | 0 | value_index ); |
1267 | |
|
1268 | 0 | goto on_error; |
1269 | 0 | } |
1270 | 0 | if( ( value_string == NULL ) |
1271 | 0 | || ( value_string_size < 2 ) |
1272 | 0 | || ( value_string[ 0 ] == 0 ) ) |
1273 | 0 | { |
1274 | 0 | value_string = NULL; |
1275 | 0 | value_string_size = 0; |
1276 | 0 | } |
1277 | 0 | } |
1278 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1279 | | if( libcnotify_verbose != 0 ) |
1280 | | { |
1281 | | libcnotify_printf( |
1282 | | "%s: type: %3s with value\t\t:", |
1283 | | function, |
1284 | | (char *) type_string ); |
1285 | | |
1286 | | if( value_string != NULL ) |
1287 | | { |
1288 | | libcnotify_printf( |
1289 | | " %s", |
1290 | | (char *) value_string ); |
1291 | | } |
1292 | | libcnotify_printf( |
1293 | | "\n" ); |
1294 | | } |
1295 | | #endif |
1296 | | /* Ignore empty values |
1297 | | */ |
1298 | 0 | if( value_string == NULL ) |
1299 | 0 | { |
1300 | 0 | continue; |
1301 | 0 | } |
1302 | 0 | if( type_string_size == 3 ) |
1303 | 0 | { |
1304 | 0 | if( ( type_string[ 0 ] == (uint8_t) 'c' ) |
1305 | 0 | && ( type_string[ 1 ] == (uint8_t) 'l' ) ) |
1306 | 0 | { |
1307 | 0 | } |
1308 | 0 | else if( ( type_string[ 0 ] == (uint8_t) 't' ) |
1309 | 0 | && ( type_string[ 1 ] == (uint8_t) 'b' ) ) |
1310 | 0 | { |
1311 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
1312 | 0 | value_string, |
1313 | 0 | value_string_size, |
1314 | 0 | &value_64bit, |
1315 | 0 | 64, |
1316 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
1317 | 0 | error ) != 1 ) |
1318 | 0 | { |
1319 | 0 | libcerror_error_set( |
1320 | 0 | error, |
1321 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1322 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
1323 | 0 | "%s: unable to set media size.", |
1324 | 0 | function ); |
1325 | |
|
1326 | 0 | goto on_error; |
1327 | 0 | } |
1328 | 0 | *media_size = (size64_t) value_64bit; |
1329 | 0 | } |
1330 | 0 | } |
1331 | 0 | } |
1332 | 0 | if( libfvalue_split_utf8_string_free( |
1333 | 0 | &values, |
1334 | 0 | error ) != 1 ) |
1335 | 0 | { |
1336 | 0 | libcerror_error_set( |
1337 | 0 | error, |
1338 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1339 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1340 | 0 | "%s: unable to free split values.", |
1341 | 0 | function ); |
1342 | |
|
1343 | 0 | goto on_error; |
1344 | 0 | } |
1345 | 0 | if( libfvalue_split_utf8_string_free( |
1346 | 0 | &types, |
1347 | 0 | error ) != 1 ) |
1348 | 0 | { |
1349 | 0 | libcerror_error_set( |
1350 | 0 | error, |
1351 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1352 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1353 | 0 | "%s: unable to free split types.", |
1354 | 0 | function ); |
1355 | |
|
1356 | 0 | goto on_error; |
1357 | 0 | } |
1358 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1359 | | if( libcnotify_verbose != 0 ) |
1360 | | { |
1361 | | libcnotify_printf( |
1362 | | "\n" ); |
1363 | | } |
1364 | | #endif |
1365 | 0 | return( 1 ); |
1366 | | |
1367 | 0 | on_error: |
1368 | 0 | if( values != NULL ) |
1369 | 0 | { |
1370 | 0 | libfvalue_split_utf8_string_free( |
1371 | 0 | &values, |
1372 | 0 | NULL ); |
1373 | 0 | } |
1374 | 0 | if( types != NULL ) |
1375 | 0 | { |
1376 | 0 | libfvalue_split_utf8_string_free( |
1377 | 0 | &types, |
1378 | 0 | NULL ); |
1379 | 0 | } |
1380 | 0 | return( -1 ); |
1381 | 0 | } |
1382 | | |
1383 | | /* Parses the "perm" category |
1384 | | * Returns 1 if successful or -1 on error |
1385 | | */ |
1386 | | int libewf_single_files_parse_perm_category( |
1387 | | libewf_single_files_t *single_files, |
1388 | | libewf_line_reader_t *line_reader, |
1389 | | libcerror_error_t **error ) |
1390 | 0 | { |
1391 | 0 | libewf_lef_permission_t *lef_permission = NULL; |
1392 | 0 | libewf_permission_group_t *permission_group = NULL; |
1393 | 0 | libfvalue_split_utf8_string_t *types = NULL; |
1394 | 0 | uint8_t *line_string = NULL; |
1395 | 0 | static char *function = "libewf_single_files_parse_perm_category"; |
1396 | 0 | size_t line_string_size = 0; |
1397 | 0 | int copy_of_number_of_permission_groups = 0; |
1398 | 0 | int entry_index = 0; |
1399 | 0 | int number_of_permission_groups = 0; |
1400 | 0 | int permission_group_index = 0; |
1401 | |
|
1402 | 0 | if( single_files == NULL ) |
1403 | 0 | { |
1404 | 0 | libcerror_error_set( |
1405 | 0 | error, |
1406 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1407 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1408 | 0 | "%s: invalid single files.", |
1409 | 0 | function ); |
1410 | |
|
1411 | 0 | return( -1 ); |
1412 | 0 | } |
1413 | 0 | if( line_reader == NULL ) |
1414 | 0 | { |
1415 | 0 | libcerror_error_set( |
1416 | 0 | error, |
1417 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1418 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1419 | 0 | "%s: invalid line reader.", |
1420 | 0 | function ); |
1421 | |
|
1422 | 0 | return( -1 ); |
1423 | 0 | } |
1424 | 0 | if( libewf_line_reader_read_utf8_string( |
1425 | 0 | line_reader, |
1426 | 0 | &line_string, |
1427 | 0 | &line_string_size, |
1428 | 0 | error ) != 1 ) |
1429 | 0 | { |
1430 | 0 | libcerror_error_set( |
1431 | 0 | error, |
1432 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1433 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1434 | 0 | "%s: unable to read line: %d.", |
1435 | 0 | function, |
1436 | 0 | line_reader->line_index ); |
1437 | |
|
1438 | 0 | goto on_error; |
1439 | 0 | } |
1440 | 0 | if( ( line_string_size != 5 ) |
1441 | 0 | || ( line_string[ 0 ] != (uint8_t) 'p' ) |
1442 | 0 | || ( line_string[ 1 ] != (uint8_t) 'e' ) |
1443 | 0 | || ( line_string[ 2 ] != (uint8_t) 'r' ) |
1444 | 0 | || ( line_string[ 3 ] != (uint8_t) 'm' ) ) |
1445 | 0 | { |
1446 | 0 | libcerror_error_set( |
1447 | 0 | error, |
1448 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1449 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1450 | 0 | "%s: unsupported category header.", |
1451 | 0 | function ); |
1452 | |
|
1453 | 0 | goto on_error; |
1454 | 0 | } |
1455 | 0 | if( libewf_single_files_parse_category_number_of_entries( |
1456 | 0 | single_files, |
1457 | 0 | line_reader, |
1458 | 0 | &number_of_permission_groups, |
1459 | 0 | error ) != 1 ) |
1460 | 0 | { |
1461 | 0 | libcerror_error_set( |
1462 | 0 | error, |
1463 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1464 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1465 | 0 | "%s: unable to parse number of permission groups in line: %d.", |
1466 | 0 | function, |
1467 | 0 | line_reader->line_index ); |
1468 | |
|
1469 | 0 | goto on_error; |
1470 | 0 | } |
1471 | 0 | if( libewf_single_files_parse_category_types( |
1472 | 0 | single_files, |
1473 | 0 | line_reader, |
1474 | 0 | &types, |
1475 | 0 | error ) != 1 ) |
1476 | 0 | { |
1477 | 0 | libcerror_error_set( |
1478 | 0 | error, |
1479 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1480 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1481 | 0 | "%s: unable to parse types in line: %d.", |
1482 | 0 | function, |
1483 | 0 | line_reader->line_index ); |
1484 | |
|
1485 | 0 | goto on_error; |
1486 | 0 | } |
1487 | 0 | if( libewf_single_files_parse_number_of_entries( |
1488 | 0 | single_files, |
1489 | 0 | line_reader, |
1490 | 0 | ©_of_number_of_permission_groups, |
1491 | 0 | error ) != 1 ) |
1492 | 0 | { |
1493 | 0 | libcerror_error_set( |
1494 | 0 | error, |
1495 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1496 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1497 | 0 | "%s: unable to parse number of permission groups in line: %d.", |
1498 | 0 | function, |
1499 | 0 | line_reader->line_index ); |
1500 | |
|
1501 | 0 | goto on_error; |
1502 | 0 | } |
1503 | 0 | if( number_of_permission_groups != copy_of_number_of_permission_groups ) |
1504 | 0 | { |
1505 | 0 | libcerror_error_set( |
1506 | 0 | error, |
1507 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1508 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1509 | 0 | "%s: mismatch between number of permission groups and copy.", |
1510 | 0 | function ); |
1511 | |
|
1512 | 0 | goto on_error; |
1513 | 0 | } |
1514 | | /* Parse the category root entry |
1515 | | */ |
1516 | 0 | if( libewf_line_reader_read_utf8_string( |
1517 | 0 | line_reader, |
1518 | 0 | &line_string, |
1519 | 0 | &line_string_size, |
1520 | 0 | error ) != 1 ) |
1521 | 0 | { |
1522 | 0 | libcerror_error_set( |
1523 | 0 | error, |
1524 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1525 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1526 | 0 | "%s: unable to read line: %d.", |
1527 | 0 | function, |
1528 | 0 | line_reader->line_index ); |
1529 | |
|
1530 | 0 | goto on_error; |
1531 | 0 | } |
1532 | 0 | if( libewf_lef_permission_initialize( |
1533 | 0 | &lef_permission, |
1534 | 0 | error ) != 1 ) |
1535 | 0 | { |
1536 | 0 | libcerror_error_set( |
1537 | 0 | error, |
1538 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1539 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1540 | 0 | "%s: unable to create permission.", |
1541 | 0 | function ); |
1542 | |
|
1543 | 0 | goto on_error; |
1544 | 0 | } |
1545 | 0 | if( libewf_lef_permission_read_data( |
1546 | 0 | lef_permission, |
1547 | 0 | types, |
1548 | 0 | line_string, |
1549 | 0 | line_string_size, |
1550 | 0 | error ) != 1 ) |
1551 | 0 | { |
1552 | 0 | libcerror_error_set( |
1553 | 0 | error, |
1554 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1555 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1556 | 0 | "%s: unable to read permission.", |
1557 | 0 | function ); |
1558 | |
|
1559 | 0 | goto on_error; |
1560 | 0 | } |
1561 | 0 | if( lef_permission->property_type != 10 ) |
1562 | 0 | { |
1563 | 0 | libcerror_error_set( |
1564 | 0 | error, |
1565 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1566 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1567 | 0 | "%s: unsupported permission group type.", |
1568 | 0 | function ); |
1569 | |
|
1570 | 0 | goto on_error; |
1571 | 0 | } |
1572 | 0 | if( libewf_lef_permission_free( |
1573 | 0 | &lef_permission, |
1574 | 0 | error ) != 1 ) |
1575 | 0 | { |
1576 | 0 | libcerror_error_set( |
1577 | 0 | error, |
1578 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1579 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1580 | 0 | "%s: unable to free permission.", |
1581 | 0 | function ); |
1582 | |
|
1583 | 0 | goto on_error; |
1584 | 0 | } |
1585 | 0 | for( permission_group_index = 0; |
1586 | 0 | permission_group_index < number_of_permission_groups; |
1587 | 0 | permission_group_index++ ) |
1588 | 0 | { |
1589 | 0 | if( libewf_permission_group_initialize( |
1590 | 0 | &permission_group, |
1591 | 0 | error ) != 1 ) |
1592 | 0 | { |
1593 | 0 | libcerror_error_set( |
1594 | 0 | error, |
1595 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1596 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1597 | 0 | "%s: unable to create permission group.", |
1598 | 0 | function ); |
1599 | |
|
1600 | 0 | goto on_error; |
1601 | 0 | } |
1602 | 0 | if( libewf_single_files_parse_permission_group( |
1603 | 0 | single_files, |
1604 | 0 | line_reader, |
1605 | 0 | types, |
1606 | 0 | permission_group, |
1607 | 0 | error ) != 1 ) |
1608 | 0 | { |
1609 | 0 | libcerror_error_set( |
1610 | 0 | error, |
1611 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1612 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1613 | 0 | "%s: unable to parse permission group: %d.", |
1614 | 0 | function, |
1615 | 0 | permission_group_index ); |
1616 | |
|
1617 | 0 | goto on_error; |
1618 | 0 | } |
1619 | 0 | if( libcdata_array_append_entry( |
1620 | 0 | single_files->permission_groups, |
1621 | 0 | &entry_index, |
1622 | 0 | (intptr_t *) permission_group, |
1623 | 0 | error ) != 1 ) |
1624 | 0 | { |
1625 | 0 | libcerror_error_set( |
1626 | 0 | error, |
1627 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1628 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1629 | 0 | "%s: unable to append permission group: %d to array.", |
1630 | 0 | function, |
1631 | 0 | permission_group_index ); |
1632 | |
|
1633 | 0 | goto on_error; |
1634 | 0 | } |
1635 | 0 | permission_group = NULL; |
1636 | 0 | } |
1637 | | /* The category should be followed by an empty line |
1638 | | */ |
1639 | 0 | if( libewf_line_reader_read_utf8_string( |
1640 | 0 | line_reader, |
1641 | 0 | &line_string, |
1642 | 0 | &line_string_size, |
1643 | 0 | error ) != 1 ) |
1644 | 0 | { |
1645 | 0 | libcerror_error_set( |
1646 | 0 | error, |
1647 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1648 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1649 | 0 | "%s: unable to read line: %d.", |
1650 | 0 | function, |
1651 | 0 | line_reader->line_index ); |
1652 | |
|
1653 | 0 | goto on_error; |
1654 | 0 | } |
1655 | 0 | if( ( line_string_size != 1 ) |
1656 | 0 | || ( line_string[ 0 ] != 0 ) ) |
1657 | 0 | { |
1658 | 0 | libcerror_error_set( |
1659 | 0 | error, |
1660 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1661 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1662 | 0 | "%s: unsupported empty line string: %d - not empty.", |
1663 | 0 | function, |
1664 | 0 | line_reader->line_index - 1 ); |
1665 | |
|
1666 | 0 | goto on_error; |
1667 | 0 | } |
1668 | 0 | if( libfvalue_split_utf8_string_free( |
1669 | 0 | &types, |
1670 | 0 | error ) != 1 ) |
1671 | 0 | { |
1672 | 0 | libcerror_error_set( |
1673 | 0 | error, |
1674 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1675 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1676 | 0 | "%s: unable to free split types.", |
1677 | 0 | function ); |
1678 | |
|
1679 | 0 | goto on_error; |
1680 | 0 | } |
1681 | 0 | return( 1 ); |
1682 | | |
1683 | 0 | on_error: |
1684 | 0 | if( permission_group != NULL ) |
1685 | 0 | { |
1686 | 0 | libewf_permission_group_free( |
1687 | 0 | &permission_group, |
1688 | 0 | NULL ); |
1689 | 0 | } |
1690 | 0 | if( lef_permission != NULL ) |
1691 | 0 | { |
1692 | 0 | libewf_lef_permission_free( |
1693 | 0 | &lef_permission, |
1694 | 0 | NULL ); |
1695 | 0 | } |
1696 | 0 | if( types != NULL ) |
1697 | 0 | { |
1698 | 0 | libfvalue_split_utf8_string_free( |
1699 | 0 | &types, |
1700 | 0 | NULL ); |
1701 | 0 | } |
1702 | 0 | return( -1 ); |
1703 | 0 | } |
1704 | | |
1705 | | /* Parses a permission group |
1706 | | * Returns 1 if successful or -1 on error |
1707 | | */ |
1708 | | int libewf_single_files_parse_permission_group( |
1709 | | libewf_single_files_t *single_files, |
1710 | | libewf_line_reader_t *line_reader, |
1711 | | libfvalue_split_utf8_string_t *types, |
1712 | | libewf_permission_group_t *permission_group, |
1713 | | libcerror_error_t **error ) |
1714 | 0 | { |
1715 | 0 | libewf_lef_permission_t *lef_permission = NULL; |
1716 | 0 | uint8_t *line_string = NULL; |
1717 | 0 | static char *function = "libewf_single_files_parse_permission_group"; |
1718 | 0 | size_t line_string_size = 0; |
1719 | 0 | int number_of_entries = 0; |
1720 | 0 | int number_of_permissions = 0; |
1721 | 0 | int permission_index = 0; |
1722 | |
|
1723 | 0 | if( single_files == NULL ) |
1724 | 0 | { |
1725 | 0 | libcerror_error_set( |
1726 | 0 | error, |
1727 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1728 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1729 | 0 | "%s: invalid single files.", |
1730 | 0 | function ); |
1731 | |
|
1732 | 0 | return( -1 ); |
1733 | 0 | } |
1734 | 0 | if( line_reader == NULL ) |
1735 | 0 | { |
1736 | 0 | libcerror_error_set( |
1737 | 0 | error, |
1738 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1739 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1740 | 0 | "%s: invalid line reader.", |
1741 | 0 | function ); |
1742 | |
|
1743 | 0 | return( -1 ); |
1744 | 0 | } |
1745 | 0 | if( libewf_single_files_parse_number_of_entries( |
1746 | 0 | single_files, |
1747 | 0 | line_reader, |
1748 | 0 | &number_of_permissions, |
1749 | 0 | error ) != 1 ) |
1750 | 0 | { |
1751 | 0 | libcerror_error_set( |
1752 | 0 | error, |
1753 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1754 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1755 | 0 | "%s: unable to parse number of permissions in line: %d.", |
1756 | 0 | function, |
1757 | 0 | line_reader->line_index ); |
1758 | |
|
1759 | 0 | goto on_error; |
1760 | 0 | } |
1761 | | /* Parse the permission group entry |
1762 | | */ |
1763 | 0 | if( libewf_line_reader_read_utf8_string( |
1764 | 0 | line_reader, |
1765 | 0 | &line_string, |
1766 | 0 | &line_string_size, |
1767 | 0 | error ) != 1 ) |
1768 | 0 | { |
1769 | 0 | libcerror_error_set( |
1770 | 0 | error, |
1771 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1772 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1773 | 0 | "%s: unable to read line: %d.", |
1774 | 0 | function, |
1775 | 0 | line_reader->line_index ); |
1776 | |
|
1777 | 0 | goto on_error; |
1778 | 0 | } |
1779 | 0 | if( libewf_lef_permission_initialize( |
1780 | 0 | &lef_permission, |
1781 | 0 | error ) != 1 ) |
1782 | 0 | { |
1783 | 0 | libcerror_error_set( |
1784 | 0 | error, |
1785 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1786 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1787 | 0 | "%s: unable to create permission.", |
1788 | 0 | function ); |
1789 | |
|
1790 | 0 | goto on_error; |
1791 | 0 | } |
1792 | 0 | if( libewf_lef_permission_read_data( |
1793 | 0 | lef_permission, |
1794 | 0 | types, |
1795 | 0 | line_string, |
1796 | 0 | line_string_size, |
1797 | 0 | error ) != 1 ) |
1798 | 0 | { |
1799 | 0 | libcerror_error_set( |
1800 | 0 | error, |
1801 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1802 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1803 | 0 | "%s: unable to read permission", |
1804 | 0 | function ); |
1805 | |
|
1806 | 0 | goto on_error; |
1807 | 0 | } |
1808 | 0 | if( lef_permission->property_type != 10 ) |
1809 | 0 | { |
1810 | 0 | libcerror_error_set( |
1811 | 0 | error, |
1812 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1813 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1814 | 0 | "%s: unsupported permission group type.", |
1815 | 0 | function ); |
1816 | |
|
1817 | 0 | goto on_error; |
1818 | 0 | } |
1819 | 0 | if( libewf_lef_permission_free( |
1820 | 0 | &lef_permission, |
1821 | 0 | error ) != 1 ) |
1822 | 0 | { |
1823 | 0 | libcerror_error_set( |
1824 | 0 | error, |
1825 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1826 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1827 | 0 | "%s: unable to free permission.", |
1828 | 0 | function ); |
1829 | |
|
1830 | 0 | goto on_error; |
1831 | 0 | } |
1832 | 0 | for( permission_index = 0; |
1833 | 0 | permission_index < number_of_permissions; |
1834 | 0 | permission_index++ ) |
1835 | 0 | { |
1836 | 0 | if( libewf_single_files_parse_number_of_entries( |
1837 | 0 | single_files, |
1838 | 0 | line_reader, |
1839 | 0 | &number_of_entries, |
1840 | 0 | error ) != 1 ) |
1841 | 0 | { |
1842 | 0 | libcerror_error_set( |
1843 | 0 | error, |
1844 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1845 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1846 | 0 | "%s: unable to parse number of entries in line: %d.", |
1847 | 0 | function, |
1848 | 0 | line_reader->line_index ); |
1849 | |
|
1850 | 0 | goto on_error; |
1851 | 0 | } |
1852 | 0 | if( number_of_entries != 0 ) |
1853 | 0 | { |
1854 | 0 | libcerror_error_set( |
1855 | 0 | error, |
1856 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1857 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1858 | 0 | "%s: invalid number of entries value out of bounds.", |
1859 | 0 | function ); |
1860 | |
|
1861 | 0 | goto on_error; |
1862 | 0 | } |
1863 | | /* Parse the permission entry |
1864 | | */ |
1865 | 0 | if( libewf_line_reader_read_utf8_string( |
1866 | 0 | line_reader, |
1867 | 0 | &line_string, |
1868 | 0 | &line_string_size, |
1869 | 0 | error ) != 1 ) |
1870 | 0 | { |
1871 | 0 | libcerror_error_set( |
1872 | 0 | error, |
1873 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1874 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1875 | 0 | "%s: unable to read line: %d.", |
1876 | 0 | function, |
1877 | 0 | line_reader->line_index ); |
1878 | |
|
1879 | 0 | goto on_error; |
1880 | 0 | } |
1881 | 0 | if( libewf_lef_permission_initialize( |
1882 | 0 | &lef_permission, |
1883 | 0 | error ) != 1 ) |
1884 | 0 | { |
1885 | 0 | libcerror_error_set( |
1886 | 0 | error, |
1887 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1888 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1889 | 0 | "%s: unable to create permission: %d.", |
1890 | 0 | function, |
1891 | 0 | permission_index ); |
1892 | |
|
1893 | 0 | goto on_error; |
1894 | 0 | } |
1895 | 0 | if( libewf_lef_permission_read_data( |
1896 | 0 | lef_permission, |
1897 | 0 | types, |
1898 | 0 | line_string, |
1899 | 0 | line_string_size, |
1900 | 0 | error ) != 1 ) |
1901 | 0 | { |
1902 | 0 | libcerror_error_set( |
1903 | 0 | error, |
1904 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1905 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1906 | 0 | "%s: unable to read permission: %d", |
1907 | 0 | function, |
1908 | 0 | permission_index ); |
1909 | |
|
1910 | 0 | goto on_error; |
1911 | 0 | } |
1912 | 0 | if( libewf_permission_group_append_permission( |
1913 | 0 | permission_group, |
1914 | 0 | lef_permission, |
1915 | 0 | error ) != 1 ) |
1916 | 0 | { |
1917 | 0 | libcerror_error_set( |
1918 | 0 | error, |
1919 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1920 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1921 | 0 | "%s: unable to append permission: %d to group.", |
1922 | 0 | function, |
1923 | 0 | permission_index ); |
1924 | |
|
1925 | 0 | goto on_error; |
1926 | 0 | } |
1927 | 0 | lef_permission = NULL; |
1928 | 0 | } |
1929 | 0 | return( 1 ); |
1930 | | |
1931 | 0 | on_error: |
1932 | 0 | if( lef_permission != NULL ) |
1933 | 0 | { |
1934 | 0 | libewf_lef_permission_free( |
1935 | 0 | &lef_permission, |
1936 | 0 | NULL ); |
1937 | 0 | } |
1938 | 0 | return( -1 ); |
1939 | 0 | } |
1940 | | |
1941 | | /* Parses the "srce" category |
1942 | | * Returns 1 if successful or -1 on error |
1943 | | */ |
1944 | | int libewf_single_files_parse_srce_category( |
1945 | | libewf_single_files_t *single_files, |
1946 | | libewf_line_reader_t *line_reader, |
1947 | | libcerror_error_t **error ) |
1948 | 0 | { |
1949 | 0 | libewf_lef_source_t *lef_source = NULL; |
1950 | 0 | libfvalue_split_utf8_string_t *types = NULL; |
1951 | 0 | uint8_t *line_string = NULL; |
1952 | 0 | static char *function = "libewf_single_files_parse_srce_category"; |
1953 | 0 | size_t line_string_size = 0; |
1954 | 0 | int copy_of_number_of_sources = 0; |
1955 | 0 | int entry_index = 0; |
1956 | 0 | int number_of_entries = 0; |
1957 | 0 | int number_of_sources = 0; |
1958 | 0 | int source_identifier = 0; |
1959 | 0 | int source_index = 0; |
1960 | |
|
1961 | 0 | if( single_files == NULL ) |
1962 | 0 | { |
1963 | 0 | libcerror_error_set( |
1964 | 0 | error, |
1965 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1966 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1967 | 0 | "%s: invalid single files.", |
1968 | 0 | function ); |
1969 | |
|
1970 | 0 | return( -1 ); |
1971 | 0 | } |
1972 | 0 | if( line_reader == NULL ) |
1973 | 0 | { |
1974 | 0 | libcerror_error_set( |
1975 | 0 | error, |
1976 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1977 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1978 | 0 | "%s: invalid line reader.", |
1979 | 0 | function ); |
1980 | |
|
1981 | 0 | return( -1 ); |
1982 | 0 | } |
1983 | 0 | if( libewf_line_reader_read_utf8_string( |
1984 | 0 | line_reader, |
1985 | 0 | &line_string, |
1986 | 0 | &line_string_size, |
1987 | 0 | error ) != 1 ) |
1988 | 0 | { |
1989 | 0 | libcerror_error_set( |
1990 | 0 | error, |
1991 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1992 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
1993 | 0 | "%s: unable to read line: %d.", |
1994 | 0 | function, |
1995 | 0 | line_reader->line_index ); |
1996 | |
|
1997 | 0 | goto on_error; |
1998 | 0 | } |
1999 | 0 | if( ( line_string_size != 5 ) |
2000 | 0 | || ( line_string[ 0 ] != (uint8_t) 's' ) |
2001 | 0 | || ( line_string[ 1 ] != (uint8_t) 'r' ) |
2002 | 0 | || ( line_string[ 2 ] != (uint8_t) 'c' ) |
2003 | 0 | || ( line_string[ 3 ] != (uint8_t) 'e' ) ) |
2004 | 0 | { |
2005 | 0 | libcerror_error_set( |
2006 | 0 | error, |
2007 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2008 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2009 | 0 | "%s: unsupported category header.", |
2010 | 0 | function ); |
2011 | |
|
2012 | 0 | goto on_error; |
2013 | 0 | } |
2014 | 0 | if( libewf_single_files_parse_category_number_of_entries( |
2015 | 0 | single_files, |
2016 | 0 | line_reader, |
2017 | 0 | &number_of_sources, |
2018 | 0 | error ) != 1 ) |
2019 | 0 | { |
2020 | 0 | libcerror_error_set( |
2021 | 0 | error, |
2022 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2023 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2024 | 0 | "%s: unable to parse number of sources in line: %d.", |
2025 | 0 | function, |
2026 | 0 | line_reader->line_index ); |
2027 | |
|
2028 | 0 | goto on_error; |
2029 | 0 | } |
2030 | 0 | if( libewf_single_files_parse_category_types( |
2031 | 0 | single_files, |
2032 | 0 | line_reader, |
2033 | 0 | &types, |
2034 | 0 | error ) != 1 ) |
2035 | 0 | { |
2036 | 0 | libcerror_error_set( |
2037 | 0 | error, |
2038 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2039 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2040 | 0 | "%s: unable to parse types in line: %d.", |
2041 | 0 | function, |
2042 | 0 | line_reader->line_index ); |
2043 | |
|
2044 | 0 | goto on_error; |
2045 | 0 | } |
2046 | 0 | if( libewf_single_files_parse_number_of_entries( |
2047 | 0 | single_files, |
2048 | 0 | line_reader, |
2049 | 0 | ©_of_number_of_sources, |
2050 | 0 | error ) != 1 ) |
2051 | 0 | { |
2052 | 0 | libcerror_error_set( |
2053 | 0 | error, |
2054 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2055 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2056 | 0 | "%s: unable to parse number of sources in line: %d.", |
2057 | 0 | function, |
2058 | 0 | line_reader->line_index ); |
2059 | |
|
2060 | 0 | goto on_error; |
2061 | 0 | } |
2062 | 0 | if( number_of_sources != copy_of_number_of_sources ) |
2063 | 0 | { |
2064 | 0 | libcerror_error_set( |
2065 | 0 | error, |
2066 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2067 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2068 | 0 | "%s: mismatch between number of sources and copy.", |
2069 | 0 | function ); |
2070 | |
|
2071 | 0 | goto on_error; |
2072 | 0 | } |
2073 | | /* Parse the category root entry |
2074 | | */ |
2075 | 0 | if( libewf_line_reader_read_utf8_string( |
2076 | 0 | line_reader, |
2077 | 0 | &line_string, |
2078 | 0 | &line_string_size, |
2079 | 0 | error ) != 1 ) |
2080 | 0 | { |
2081 | 0 | libcerror_error_set( |
2082 | 0 | error, |
2083 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2084 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2085 | 0 | "%s: unable to read line: %d.", |
2086 | 0 | function, |
2087 | 0 | line_reader->line_index ); |
2088 | |
|
2089 | 0 | goto on_error; |
2090 | 0 | } |
2091 | 0 | if( libewf_lef_source_initialize( |
2092 | 0 | &lef_source, |
2093 | 0 | error ) != 1 ) |
2094 | 0 | { |
2095 | 0 | libcerror_error_set( |
2096 | 0 | error, |
2097 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2098 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2099 | 0 | "%s: unable to create source.", |
2100 | 0 | function ); |
2101 | |
|
2102 | 0 | goto on_error; |
2103 | 0 | } |
2104 | 0 | if( libewf_lef_source_read_data( |
2105 | 0 | lef_source, |
2106 | 0 | types, |
2107 | 0 | line_string, |
2108 | 0 | line_string_size, |
2109 | 0 | error ) != 1 ) |
2110 | 0 | { |
2111 | 0 | libcerror_error_set( |
2112 | 0 | error, |
2113 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2114 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2115 | 0 | "%s: unable to read source", |
2116 | 0 | function ); |
2117 | |
|
2118 | 0 | goto on_error; |
2119 | 0 | } |
2120 | | /* Append the category root so that the source identifiers and array entries align |
2121 | | */ |
2122 | 0 | if( libcdata_array_append_entry( |
2123 | 0 | single_files->sources, |
2124 | 0 | &entry_index, |
2125 | 0 | (intptr_t *) lef_source, |
2126 | 0 | error ) != 1 ) |
2127 | 0 | { |
2128 | 0 | libcerror_error_set( |
2129 | 0 | error, |
2130 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2131 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2132 | 0 | "%s: unable to append category root source to array.", |
2133 | 0 | function ); |
2134 | |
|
2135 | 0 | goto on_error; |
2136 | 0 | } |
2137 | 0 | lef_source = NULL; |
2138 | |
|
2139 | 0 | for( source_index = 0; |
2140 | 0 | source_index < number_of_sources; |
2141 | 0 | source_index++ ) |
2142 | 0 | { |
2143 | 0 | if( libewf_single_files_parse_number_of_entries( |
2144 | 0 | single_files, |
2145 | 0 | line_reader, |
2146 | 0 | &number_of_entries, |
2147 | 0 | error ) != 1 ) |
2148 | 0 | { |
2149 | 0 | libcerror_error_set( |
2150 | 0 | error, |
2151 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2152 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2153 | 0 | "%s: unable to parse number of entries in line: %d.", |
2154 | 0 | function, |
2155 | 0 | line_reader->line_index ); |
2156 | |
|
2157 | 0 | goto on_error; |
2158 | 0 | } |
2159 | 0 | if( number_of_entries != 0 ) |
2160 | 0 | { |
2161 | 0 | libcerror_error_set( |
2162 | 0 | error, |
2163 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2164 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2165 | 0 | "%s: invalid number of entries value out of bounds.", |
2166 | 0 | function ); |
2167 | |
|
2168 | 0 | goto on_error; |
2169 | 0 | } |
2170 | | /* Parse the source entry |
2171 | | */ |
2172 | 0 | if( libewf_line_reader_read_utf8_string( |
2173 | 0 | line_reader, |
2174 | 0 | &line_string, |
2175 | 0 | &line_string_size, |
2176 | 0 | error ) != 1 ) |
2177 | 0 | { |
2178 | 0 | libcerror_error_set( |
2179 | 0 | error, |
2180 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2181 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2182 | 0 | "%s: unable to read line: %d.", |
2183 | 0 | function, |
2184 | 0 | line_reader->line_index ); |
2185 | |
|
2186 | 0 | goto on_error; |
2187 | 0 | } |
2188 | 0 | if( libewf_lef_source_initialize( |
2189 | 0 | &lef_source, |
2190 | 0 | error ) != 1 ) |
2191 | 0 | { |
2192 | 0 | libcerror_error_set( |
2193 | 0 | error, |
2194 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2195 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2196 | 0 | "%s: unable to create source: %d.", |
2197 | 0 | function, |
2198 | 0 | source_index ); |
2199 | |
|
2200 | 0 | goto on_error; |
2201 | 0 | } |
2202 | 0 | if( libewf_lef_source_read_data( |
2203 | 0 | lef_source, |
2204 | 0 | types, |
2205 | 0 | line_string, |
2206 | 0 | line_string_size, |
2207 | 0 | error ) != 1 ) |
2208 | 0 | { |
2209 | 0 | libcerror_error_set( |
2210 | 0 | error, |
2211 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2212 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2213 | 0 | "%s: unable to read source: %d", |
2214 | 0 | function, |
2215 | 0 | source_index ); |
2216 | |
|
2217 | 0 | goto on_error; |
2218 | 0 | } |
2219 | 0 | if( libewf_lef_source_get_identifier( |
2220 | 0 | lef_source, |
2221 | 0 | &source_identifier, |
2222 | 0 | error ) != 1 ) |
2223 | 0 | { |
2224 | 0 | libcerror_error_set( |
2225 | 0 | error, |
2226 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2227 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2228 | 0 | "%s: unable to retrieve source: %d identifier.", |
2229 | 0 | function, |
2230 | 0 | line_reader->line_index ); |
2231 | |
|
2232 | 0 | goto on_error; |
2233 | 0 | } |
2234 | 0 | if( source_identifier != ( source_index + 1 ) ) |
2235 | 0 | { |
2236 | 0 | libcerror_error_set( |
2237 | 0 | error, |
2238 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2239 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2240 | 0 | "%s: mismatch between source identifier and index.", |
2241 | 0 | function ); |
2242 | |
|
2243 | 0 | goto on_error; |
2244 | 0 | } |
2245 | 0 | if( libcdata_array_append_entry( |
2246 | 0 | single_files->sources, |
2247 | 0 | &entry_index, |
2248 | 0 | (intptr_t *) lef_source, |
2249 | 0 | error ) != 1 ) |
2250 | 0 | { |
2251 | 0 | libcerror_error_set( |
2252 | 0 | error, |
2253 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2254 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2255 | 0 | "%s: unable to append source: %d to array.", |
2256 | 0 | function, |
2257 | 0 | source_index ); |
2258 | |
|
2259 | 0 | goto on_error; |
2260 | 0 | } |
2261 | 0 | lef_source = NULL; |
2262 | 0 | } |
2263 | | /* The category should be followed by an empty line |
2264 | | */ |
2265 | 0 | if( libewf_line_reader_read_utf8_string( |
2266 | 0 | line_reader, |
2267 | 0 | &line_string, |
2268 | 0 | &line_string_size, |
2269 | 0 | error ) != 1 ) |
2270 | 0 | { |
2271 | 0 | libcerror_error_set( |
2272 | 0 | error, |
2273 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2274 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2275 | 0 | "%s: unable to read line: %d.", |
2276 | 0 | function, |
2277 | 0 | line_reader->line_index ); |
2278 | |
|
2279 | 0 | goto on_error; |
2280 | 0 | } |
2281 | 0 | if( ( line_string_size != 1 ) |
2282 | 0 | || ( line_string[ 0 ] != 0 ) ) |
2283 | 0 | { |
2284 | 0 | libcerror_error_set( |
2285 | 0 | error, |
2286 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2287 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2288 | 0 | "%s: unsupported empty line string: %d - not empty.", |
2289 | 0 | function, |
2290 | 0 | line_reader->line_index - 1 ); |
2291 | |
|
2292 | 0 | goto on_error; |
2293 | 0 | } |
2294 | 0 | if( libfvalue_split_utf8_string_free( |
2295 | 0 | &types, |
2296 | 0 | error ) != 1 ) |
2297 | 0 | { |
2298 | 0 | libcerror_error_set( |
2299 | 0 | error, |
2300 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2301 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2302 | 0 | "%s: unable to free split types.", |
2303 | 0 | function ); |
2304 | |
|
2305 | 0 | goto on_error; |
2306 | 0 | } |
2307 | 0 | return( 1 ); |
2308 | | |
2309 | 0 | on_error: |
2310 | 0 | if( lef_source != NULL ) |
2311 | 0 | { |
2312 | 0 | libewf_lef_source_free( |
2313 | 0 | &lef_source, |
2314 | 0 | NULL ); |
2315 | 0 | } |
2316 | 0 | if( types != NULL ) |
2317 | 0 | { |
2318 | 0 | libfvalue_split_utf8_string_free( |
2319 | 0 | &types, |
2320 | 0 | NULL ); |
2321 | 0 | } |
2322 | 0 | return( -1 ); |
2323 | 0 | } |
2324 | | |
2325 | | /* Parses the "sub" category |
2326 | | * Returns 1 if successful or -1 on error |
2327 | | */ |
2328 | | int libewf_single_files_parse_sub_category( |
2329 | | libewf_single_files_t *single_files, |
2330 | | libewf_line_reader_t *line_reader, |
2331 | | libcerror_error_t **error ) |
2332 | 0 | { |
2333 | 0 | libewf_lef_subject_t *lef_subject = NULL; |
2334 | 0 | libfvalue_split_utf8_string_t *types = NULL; |
2335 | 0 | uint8_t *line_string = NULL; |
2336 | 0 | static char *function = "libewf_single_files_parse_sub_category"; |
2337 | 0 | size_t line_string_size = 0; |
2338 | 0 | int copy_of_number_of_subjects = 0; |
2339 | 0 | int number_of_entries = 0; |
2340 | 0 | int number_of_subjects = 0; |
2341 | 0 | int subject_index = 0; |
2342 | |
|
2343 | 0 | if( single_files == NULL ) |
2344 | 0 | { |
2345 | 0 | libcerror_error_set( |
2346 | 0 | error, |
2347 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2348 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2349 | 0 | "%s: invalid single files.", |
2350 | 0 | function ); |
2351 | |
|
2352 | 0 | return( -1 ); |
2353 | 0 | } |
2354 | 0 | if( line_reader == NULL ) |
2355 | 0 | { |
2356 | 0 | libcerror_error_set( |
2357 | 0 | error, |
2358 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2359 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2360 | 0 | "%s: invalid line reader.", |
2361 | 0 | function ); |
2362 | |
|
2363 | 0 | return( -1 ); |
2364 | 0 | } |
2365 | 0 | if( libewf_line_reader_read_utf8_string( |
2366 | 0 | line_reader, |
2367 | 0 | &line_string, |
2368 | 0 | &line_string_size, |
2369 | 0 | error ) != 1 ) |
2370 | 0 | { |
2371 | 0 | libcerror_error_set( |
2372 | 0 | error, |
2373 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2374 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2375 | 0 | "%s: unable to read line: %d.", |
2376 | 0 | function, |
2377 | 0 | line_reader->line_index ); |
2378 | |
|
2379 | 0 | goto on_error; |
2380 | 0 | } |
2381 | 0 | if( ( line_string_size != 4 ) |
2382 | 0 | || ( line_string[ 0 ] != (uint8_t) 's' ) |
2383 | 0 | || ( line_string[ 1 ] != (uint8_t) 'u' ) |
2384 | 0 | || ( line_string[ 2 ] != (uint8_t) 'b' ) ) |
2385 | 0 | { |
2386 | 0 | libcerror_error_set( |
2387 | 0 | error, |
2388 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2389 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2390 | 0 | "%s: unsupported category header.", |
2391 | 0 | function ); |
2392 | |
|
2393 | 0 | goto on_error; |
2394 | 0 | } |
2395 | 0 | if( libewf_single_files_parse_category_number_of_entries( |
2396 | 0 | single_files, |
2397 | 0 | line_reader, |
2398 | 0 | &number_of_subjects, |
2399 | 0 | error ) != 1 ) |
2400 | 0 | { |
2401 | 0 | libcerror_error_set( |
2402 | 0 | error, |
2403 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2404 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2405 | 0 | "%s: unable to parse number of subjects in line: %d.", |
2406 | 0 | function, |
2407 | 0 | line_reader->line_index ); |
2408 | |
|
2409 | 0 | goto on_error; |
2410 | 0 | } |
2411 | 0 | if( libewf_single_files_parse_category_types( |
2412 | 0 | single_files, |
2413 | 0 | line_reader, |
2414 | 0 | &types, |
2415 | 0 | error ) != 1 ) |
2416 | 0 | { |
2417 | 0 | libcerror_error_set( |
2418 | 0 | error, |
2419 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2420 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2421 | 0 | "%s: unable to parse types in line: %d.", |
2422 | 0 | function, |
2423 | 0 | line_reader->line_index ); |
2424 | |
|
2425 | 0 | goto on_error; |
2426 | 0 | } |
2427 | 0 | if( libewf_single_files_parse_number_of_entries( |
2428 | 0 | single_files, |
2429 | 0 | line_reader, |
2430 | 0 | ©_of_number_of_subjects, |
2431 | 0 | error ) != 1 ) |
2432 | 0 | { |
2433 | 0 | libcerror_error_set( |
2434 | 0 | error, |
2435 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2436 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2437 | 0 | "%s: unable to parse number of subjects in line: %d.", |
2438 | 0 | function, |
2439 | 0 | line_reader->line_index ); |
2440 | |
|
2441 | 0 | goto on_error; |
2442 | 0 | } |
2443 | 0 | if( number_of_subjects != copy_of_number_of_subjects ) |
2444 | 0 | { |
2445 | 0 | libcerror_error_set( |
2446 | 0 | error, |
2447 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2448 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2449 | 0 | "%s: mismatch between number of subjects and copy.", |
2450 | 0 | function ); |
2451 | |
|
2452 | 0 | goto on_error; |
2453 | 0 | } |
2454 | | /* Parse the category root entry |
2455 | | */ |
2456 | 0 | if( libewf_line_reader_read_utf8_string( |
2457 | 0 | line_reader, |
2458 | 0 | &line_string, |
2459 | 0 | &line_string_size, |
2460 | 0 | error ) != 1 ) |
2461 | 0 | { |
2462 | 0 | libcerror_error_set( |
2463 | 0 | error, |
2464 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2465 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2466 | 0 | "%s: unable to read line: %d.", |
2467 | 0 | function, |
2468 | 0 | line_reader->line_index ); |
2469 | |
|
2470 | 0 | goto on_error; |
2471 | 0 | } |
2472 | 0 | if( libewf_lef_subject_initialize( |
2473 | 0 | &lef_subject, |
2474 | 0 | error ) != 1 ) |
2475 | 0 | { |
2476 | 0 | libcerror_error_set( |
2477 | 0 | error, |
2478 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2479 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2480 | 0 | "%s: unable to create subject.", |
2481 | 0 | function ); |
2482 | |
|
2483 | 0 | goto on_error; |
2484 | 0 | } |
2485 | 0 | if( libewf_lef_subject_read_data( |
2486 | 0 | lef_subject, |
2487 | 0 | types, |
2488 | 0 | line_string, |
2489 | 0 | line_string_size, |
2490 | 0 | error ) != 1 ) |
2491 | 0 | { |
2492 | 0 | libcerror_error_set( |
2493 | 0 | error, |
2494 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2495 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2496 | 0 | "%s: unable to read subject", |
2497 | 0 | function ); |
2498 | |
|
2499 | 0 | goto on_error; |
2500 | 0 | } |
2501 | | /* TODO implement */ |
2502 | | |
2503 | 0 | if( libewf_lef_subject_free( |
2504 | 0 | &lef_subject, |
2505 | 0 | error ) != 1 ) |
2506 | 0 | { |
2507 | 0 | libcerror_error_set( |
2508 | 0 | error, |
2509 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2510 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2511 | 0 | "%s: unable to free subject.", |
2512 | 0 | function ); |
2513 | |
|
2514 | 0 | goto on_error; |
2515 | 0 | } |
2516 | 0 | for( subject_index = 0; |
2517 | 0 | subject_index < number_of_subjects; |
2518 | 0 | subject_index++ ) |
2519 | 0 | { |
2520 | 0 | if( libewf_single_files_parse_number_of_entries( |
2521 | 0 | single_files, |
2522 | 0 | line_reader, |
2523 | 0 | &number_of_entries, |
2524 | 0 | error ) != 1 ) |
2525 | 0 | { |
2526 | 0 | libcerror_error_set( |
2527 | 0 | error, |
2528 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2529 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2530 | 0 | "%s: unable to parse number of entries in line: %d.", |
2531 | 0 | function, |
2532 | 0 | line_reader->line_index ); |
2533 | |
|
2534 | 0 | goto on_error; |
2535 | 0 | } |
2536 | 0 | if( number_of_entries != 0 ) |
2537 | 0 | { |
2538 | 0 | libcerror_error_set( |
2539 | 0 | error, |
2540 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2541 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2542 | 0 | "%s: invalid number of entries value out of bounds.", |
2543 | 0 | function ); |
2544 | |
|
2545 | 0 | goto on_error; |
2546 | 0 | } |
2547 | | /* Parse the subject entry |
2548 | | */ |
2549 | 0 | if( libewf_line_reader_read_utf8_string( |
2550 | 0 | line_reader, |
2551 | 0 | &line_string, |
2552 | 0 | &line_string_size, |
2553 | 0 | error ) != 1 ) |
2554 | 0 | { |
2555 | 0 | libcerror_error_set( |
2556 | 0 | error, |
2557 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2558 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2559 | 0 | "%s: unable to read line: %d.", |
2560 | 0 | function, |
2561 | 0 | line_reader->line_index ); |
2562 | |
|
2563 | 0 | goto on_error; |
2564 | 0 | } |
2565 | 0 | if( libewf_lef_subject_initialize( |
2566 | 0 | &lef_subject, |
2567 | 0 | error ) != 1 ) |
2568 | 0 | { |
2569 | 0 | libcerror_error_set( |
2570 | 0 | error, |
2571 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2572 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2573 | 0 | "%s: unable to create subject: %d.", |
2574 | 0 | function, |
2575 | 0 | subject_index ); |
2576 | |
|
2577 | 0 | goto on_error; |
2578 | 0 | } |
2579 | 0 | if( libewf_lef_subject_read_data( |
2580 | 0 | lef_subject, |
2581 | 0 | types, |
2582 | 0 | line_string, |
2583 | 0 | line_string_size, |
2584 | 0 | error ) != 1 ) |
2585 | 0 | { |
2586 | 0 | libcerror_error_set( |
2587 | 0 | error, |
2588 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2589 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2590 | 0 | "%s: unable to read subject: %d", |
2591 | 0 | function, |
2592 | 0 | subject_index ); |
2593 | |
|
2594 | 0 | goto on_error; |
2595 | 0 | } |
2596 | | /* TODO implement append subject to array */ |
2597 | | |
2598 | 0 | if( libewf_lef_subject_free( |
2599 | 0 | &lef_subject, |
2600 | 0 | error ) != 1 ) |
2601 | 0 | { |
2602 | 0 | libcerror_error_set( |
2603 | 0 | error, |
2604 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2605 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2606 | 0 | "%s: unable to free subject.", |
2607 | 0 | function ); |
2608 | |
|
2609 | 0 | goto on_error; |
2610 | 0 | } |
2611 | 0 | } |
2612 | | /* The category should be followed by an empty line |
2613 | | */ |
2614 | 0 | if( libewf_line_reader_read_utf8_string( |
2615 | 0 | line_reader, |
2616 | 0 | &line_string, |
2617 | 0 | &line_string_size, |
2618 | 0 | error ) != 1 ) |
2619 | 0 | { |
2620 | 0 | libcerror_error_set( |
2621 | 0 | error, |
2622 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2623 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2624 | 0 | "%s: unable to read line: %d.", |
2625 | 0 | function, |
2626 | 0 | line_reader->line_index ); |
2627 | |
|
2628 | 0 | goto on_error; |
2629 | 0 | } |
2630 | 0 | if( ( line_string_size != 1 ) |
2631 | 0 | || ( line_string[ 0 ] != 0 ) ) |
2632 | 0 | { |
2633 | 0 | libcerror_error_set( |
2634 | 0 | error, |
2635 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2636 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2637 | 0 | "%s: unsupported empty line string: %d - not empty.", |
2638 | 0 | function, |
2639 | 0 | line_reader->line_index - 1 ); |
2640 | |
|
2641 | 0 | goto on_error; |
2642 | 0 | } |
2643 | 0 | if( libfvalue_split_utf8_string_free( |
2644 | 0 | &types, |
2645 | 0 | error ) != 1 ) |
2646 | 0 | { |
2647 | 0 | libcerror_error_set( |
2648 | 0 | error, |
2649 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2650 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2651 | 0 | "%s: unable to free split types.", |
2652 | 0 | function ); |
2653 | |
|
2654 | 0 | goto on_error; |
2655 | 0 | } |
2656 | 0 | return( 1 ); |
2657 | | |
2658 | 0 | on_error: |
2659 | 0 | if( lef_subject != NULL ) |
2660 | 0 | { |
2661 | 0 | libewf_lef_subject_free( |
2662 | 0 | &lef_subject, |
2663 | 0 | NULL ); |
2664 | 0 | } |
2665 | 0 | if( types != NULL ) |
2666 | 0 | { |
2667 | 0 | libfvalue_split_utf8_string_free( |
2668 | 0 | &types, |
2669 | 0 | NULL ); |
2670 | 0 | } |
2671 | 0 | return( -1 ); |
2672 | 0 | } |
2673 | | |
2674 | | /* Parses the "entry" category |
2675 | | * Returns 1 if successful or -1 on error |
2676 | | */ |
2677 | | int libewf_single_files_parse_entry_category( |
2678 | | libewf_single_files_t *single_files, |
2679 | | libewf_line_reader_t *line_reader, |
2680 | | uint8_t *format, |
2681 | | libcerror_error_t **error ) |
2682 | 0 | { |
2683 | 0 | libfvalue_split_utf8_string_t *types = NULL; |
2684 | 0 | uint8_t *line_string = NULL; |
2685 | 0 | static char *function = "libewf_single_files_parse_entry_category"; |
2686 | 0 | size_t line_string_size = 0; |
2687 | 0 | int number_of_sub_entries = 0; |
2688 | |
|
2689 | 0 | if( single_files == NULL ) |
2690 | 0 | { |
2691 | 0 | libcerror_error_set( |
2692 | 0 | error, |
2693 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2694 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2695 | 0 | "%s: invalid single files.", |
2696 | 0 | function ); |
2697 | |
|
2698 | 0 | return( -1 ); |
2699 | 0 | } |
2700 | 0 | if( single_files->file_entry_tree_root_node != NULL ) |
2701 | 0 | { |
2702 | 0 | libcerror_error_set( |
2703 | 0 | error, |
2704 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2705 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
2706 | 0 | "%s: invalid single files - file entry tree root node value already set.", |
2707 | 0 | function ); |
2708 | |
|
2709 | 0 | return( -1 ); |
2710 | 0 | } |
2711 | 0 | if( line_reader == NULL ) |
2712 | 0 | { |
2713 | 0 | libcerror_error_set( |
2714 | 0 | error, |
2715 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2716 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2717 | 0 | "%s: invalid line reader.", |
2718 | 0 | function ); |
2719 | |
|
2720 | 0 | return( -1 ); |
2721 | 0 | } |
2722 | 0 | if( libewf_line_reader_read_utf8_string( |
2723 | 0 | line_reader, |
2724 | 0 | &line_string, |
2725 | 0 | &line_string_size, |
2726 | 0 | error ) != 1 ) |
2727 | 0 | { |
2728 | 0 | libcerror_error_set( |
2729 | 0 | error, |
2730 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2731 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2732 | 0 | "%s: unable to read line: %d.", |
2733 | 0 | function, |
2734 | 0 | line_reader->line_index ); |
2735 | |
|
2736 | 0 | goto on_error; |
2737 | 0 | } |
2738 | 0 | if( ( line_string_size != 6 ) |
2739 | 0 | || ( line_string[ 0 ] != (uint8_t) 'e' ) |
2740 | 0 | || ( line_string[ 1 ] != (uint8_t) 'n' ) |
2741 | 0 | || ( line_string[ 2 ] != (uint8_t) 't' ) |
2742 | 0 | || ( line_string[ 3 ] != (uint8_t) 'r' ) |
2743 | 0 | || ( line_string[ 4 ] != (uint8_t) 'y' ) ) |
2744 | 0 | { |
2745 | 0 | libcerror_error_set( |
2746 | 0 | error, |
2747 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2748 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2749 | 0 | "%s: unsupported category header.", |
2750 | 0 | function ); |
2751 | |
|
2752 | 0 | goto on_error; |
2753 | 0 | } |
2754 | 0 | if( libewf_single_files_parse_category_number_of_entries( |
2755 | 0 | single_files, |
2756 | 0 | line_reader, |
2757 | 0 | &number_of_sub_entries, |
2758 | 0 | error ) != 1 ) |
2759 | 0 | { |
2760 | 0 | libcerror_error_set( |
2761 | 0 | error, |
2762 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2763 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2764 | 0 | "%s: unable to parse number of entries in line: %d.", |
2765 | 0 | function, |
2766 | 0 | line_reader->line_index ); |
2767 | |
|
2768 | 0 | goto on_error; |
2769 | 0 | } |
2770 | 0 | if( libewf_single_files_parse_category_types( |
2771 | 0 | single_files, |
2772 | 0 | line_reader, |
2773 | 0 | &types, |
2774 | 0 | error ) != 1 ) |
2775 | 0 | { |
2776 | 0 | libcerror_error_set( |
2777 | 0 | error, |
2778 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2779 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2780 | 0 | "%s: unable to parse types in line: %d.", |
2781 | 0 | function, |
2782 | 0 | line_reader->line_index ); |
2783 | |
|
2784 | 0 | goto on_error; |
2785 | 0 | } |
2786 | 0 | if( libewf_single_files_parse_format( |
2787 | 0 | types, |
2788 | 0 | format, |
2789 | 0 | error ) != 1 ) |
2790 | 0 | { |
2791 | 0 | libcerror_error_set( |
2792 | 0 | error, |
2793 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2794 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2795 | 0 | "%s: unable to parse format.", |
2796 | 0 | function ); |
2797 | |
|
2798 | 0 | goto on_error; |
2799 | 0 | } |
2800 | 0 | if( libcdata_tree_node_initialize( |
2801 | 0 | &( single_files->file_entry_tree_root_node ), |
2802 | 0 | error ) != 1 ) |
2803 | 0 | { |
2804 | 0 | libcerror_error_set( |
2805 | 0 | error, |
2806 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2807 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2808 | 0 | "%s: unable to create file entry tree root node.", |
2809 | 0 | function ); |
2810 | |
|
2811 | 0 | goto on_error; |
2812 | 0 | } |
2813 | 0 | if( libewf_single_files_parse_file_entry( |
2814 | 0 | single_files, |
2815 | 0 | line_reader, |
2816 | 0 | single_files->file_entry_tree_root_node, |
2817 | 0 | types, |
2818 | 0 | error ) != 1 ) |
2819 | 0 | { |
2820 | 0 | libcerror_error_set( |
2821 | 0 | error, |
2822 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2823 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2824 | 0 | "%s: unable to parse file entry.", |
2825 | 0 | function ); |
2826 | |
|
2827 | 0 | goto on_error; |
2828 | 0 | } |
2829 | | /* The category should be followed by an empty line |
2830 | | */ |
2831 | 0 | if( libewf_line_reader_read_utf8_string( |
2832 | 0 | line_reader, |
2833 | 0 | &line_string, |
2834 | 0 | &line_string_size, |
2835 | 0 | error ) != 1 ) |
2836 | 0 | { |
2837 | 0 | libcerror_error_set( |
2838 | 0 | error, |
2839 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2840 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2841 | 0 | "%s: unable to read line: %d.", |
2842 | 0 | function, |
2843 | 0 | line_reader->line_index ); |
2844 | |
|
2845 | 0 | goto on_error; |
2846 | 0 | } |
2847 | 0 | if( ( line_string_size != 1 ) |
2848 | 0 | || ( line_string[ 0 ] != 0 ) ) |
2849 | 0 | { |
2850 | 0 | libcerror_error_set( |
2851 | 0 | error, |
2852 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2853 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2854 | 0 | "%s: unsupported empty line string: %d - not empty.", |
2855 | 0 | function, |
2856 | 0 | line_reader->line_index - 1 ); |
2857 | |
|
2858 | 0 | goto on_error; |
2859 | 0 | } |
2860 | 0 | if( libfvalue_split_utf8_string_free( |
2861 | 0 | &types, |
2862 | 0 | error ) != 1 ) |
2863 | 0 | { |
2864 | 0 | libcerror_error_set( |
2865 | 0 | error, |
2866 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2867 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2868 | 0 | "%s: unable to free split types.", |
2869 | 0 | function ); |
2870 | |
|
2871 | 0 | goto on_error; |
2872 | 0 | } |
2873 | 0 | return( 1 ); |
2874 | | |
2875 | 0 | on_error: |
2876 | 0 | if( single_files->file_entry_tree_root_node != NULL ) |
2877 | 0 | { |
2878 | 0 | libcdata_tree_node_free( |
2879 | 0 | &( single_files->file_entry_tree_root_node ), |
2880 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
2881 | 0 | NULL ); |
2882 | 0 | } |
2883 | 0 | if( types != NULL ) |
2884 | 0 | { |
2885 | 0 | libfvalue_split_utf8_string_free( |
2886 | 0 | &types, |
2887 | 0 | NULL ); |
2888 | 0 | } |
2889 | 0 | return( -1 ); |
2890 | 0 | } |
2891 | | |
2892 | | /* Parses a file entry string for the values |
2893 | | * Returns 1 if successful or -1 on error |
2894 | | */ |
2895 | | int libewf_single_files_parse_file_entry( |
2896 | | libewf_single_files_t *single_files, |
2897 | | libewf_line_reader_t *line_reader, |
2898 | | libcdata_tree_node_t *parent_file_entry_node, |
2899 | | libfvalue_split_utf8_string_t *types, |
2900 | | libcerror_error_t **error ) |
2901 | 0 | { |
2902 | 0 | libcdata_tree_node_t *file_entry_node = NULL; |
2903 | 0 | libewf_lef_file_entry_t *lef_file_entry = NULL; |
2904 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
2905 | 0 | const uint8_t *line_data = NULL; |
2906 | 0 | static char *function = "libewf_single_files_parse_file_entry"; |
2907 | 0 | size_t line_data_size = 0; |
2908 | 0 | int number_of_sub_entries = 0; |
2909 | 0 | int sub_entry_index = 0; |
2910 | |
|
2911 | 0 | if( single_files == NULL ) |
2912 | 0 | { |
2913 | 0 | libcerror_error_set( |
2914 | 0 | error, |
2915 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2916 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2917 | 0 | "%s: invalid single files.", |
2918 | 0 | function ); |
2919 | |
|
2920 | 0 | return( -1 ); |
2921 | 0 | } |
2922 | 0 | if( line_reader == NULL ) |
2923 | 0 | { |
2924 | 0 | libcerror_error_set( |
2925 | 0 | error, |
2926 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2927 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2928 | 0 | "%s: invalid line reader.", |
2929 | 0 | function ); |
2930 | |
|
2931 | 0 | return( -1 ); |
2932 | 0 | } |
2933 | 0 | if( parent_file_entry_node == NULL ) |
2934 | 0 | { |
2935 | 0 | libcerror_error_set( |
2936 | 0 | error, |
2937 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2938 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2939 | 0 | "%s: invalid parent file entry node.", |
2940 | 0 | function ); |
2941 | |
|
2942 | 0 | return( -1 ); |
2943 | 0 | } |
2944 | 0 | if( libewf_single_files_parse_file_entry_number_of_sub_entries( |
2945 | 0 | single_files, |
2946 | 0 | line_reader, |
2947 | 0 | &number_of_sub_entries, |
2948 | 0 | error ) != 1 ) |
2949 | 0 | { |
2950 | 0 | libcerror_error_set( |
2951 | 0 | error, |
2952 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2953 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2954 | 0 | "%s: unable to parse file entry number of sub entries.", |
2955 | 0 | function ); |
2956 | |
|
2957 | 0 | goto on_error; |
2958 | 0 | } |
2959 | 0 | if( libewf_line_reader_read_data( |
2960 | 0 | line_reader, |
2961 | 0 | &line_data, |
2962 | 0 | &line_data_size, |
2963 | 0 | error ) != 1 ) |
2964 | 0 | { |
2965 | 0 | libcerror_error_set( |
2966 | 0 | error, |
2967 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2968 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2969 | 0 | "%s: unable to read line: %d data.", |
2970 | 0 | function, |
2971 | 0 | line_reader->line_index ); |
2972 | |
|
2973 | 0 | goto on_error; |
2974 | 0 | } |
2975 | 0 | if( libewf_lef_file_entry_initialize( |
2976 | 0 | &lef_file_entry, |
2977 | 0 | error ) != 1 ) |
2978 | 0 | { |
2979 | 0 | libcerror_error_set( |
2980 | 0 | error, |
2981 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2982 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2983 | 0 | "%s: unable to create file entry.", |
2984 | 0 | function ); |
2985 | |
|
2986 | 0 | goto on_error; |
2987 | 0 | } |
2988 | 0 | if( libewf_lef_file_entry_read_data( |
2989 | 0 | lef_file_entry, |
2990 | 0 | types, |
2991 | 0 | line_data, |
2992 | 0 | line_data_size, |
2993 | 0 | error ) != 1 ) |
2994 | 0 | { |
2995 | 0 | libcerror_error_set( |
2996 | 0 | error, |
2997 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2998 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2999 | 0 | "%s: unable to read file entry", |
3000 | 0 | function ); |
3001 | |
|
3002 | 0 | goto on_error; |
3003 | 0 | } |
3004 | 0 | if( libcdata_tree_node_set_value( |
3005 | 0 | parent_file_entry_node, |
3006 | 0 | (intptr_t *) lef_file_entry, |
3007 | 0 | error ) != 1 ) |
3008 | 0 | { |
3009 | 0 | libcerror_error_set( |
3010 | 0 | error, |
3011 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3012 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3013 | 0 | "%s: unable to set file entry in node.", |
3014 | 0 | function ); |
3015 | |
|
3016 | 0 | goto on_error; |
3017 | 0 | } |
3018 | 0 | lef_file_entry = NULL; |
3019 | |
|
3020 | 0 | for( sub_entry_index = 0; |
3021 | 0 | sub_entry_index < number_of_sub_entries; |
3022 | 0 | sub_entry_index++ ) |
3023 | 0 | { |
3024 | 0 | if( libcdata_tree_node_initialize( |
3025 | 0 | &file_entry_node, |
3026 | 0 | error ) != 1 ) |
3027 | 0 | { |
3028 | 0 | libcerror_error_set( |
3029 | 0 | error, |
3030 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3031 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3032 | 0 | "%s: unable to create sub file entry: %d node.", |
3033 | 0 | function, |
3034 | 0 | sub_entry_index ); |
3035 | |
|
3036 | 0 | goto on_error; |
3037 | 0 | } |
3038 | 0 | if( libewf_single_files_parse_file_entry( |
3039 | 0 | single_files, |
3040 | 0 | line_reader, |
3041 | 0 | file_entry_node, |
3042 | 0 | types, |
3043 | 0 | error ) != 1 ) |
3044 | 0 | { |
3045 | 0 | libcerror_error_set( |
3046 | 0 | error, |
3047 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3048 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3049 | 0 | "%s: unable to parse sub file entry: %d.", |
3050 | 0 | function, |
3051 | 0 | sub_entry_index ); |
3052 | |
|
3053 | 0 | goto on_error; |
3054 | 0 | } |
3055 | 0 | if( libcdata_tree_node_append_node( |
3056 | 0 | parent_file_entry_node, |
3057 | 0 | file_entry_node, |
3058 | 0 | error ) != 1 ) |
3059 | 0 | { |
3060 | 0 | libcerror_error_set( |
3061 | 0 | error, |
3062 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3063 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
3064 | 0 | "%s: unable to append sub file entry: %d node to parent.", |
3065 | 0 | function, |
3066 | 0 | sub_entry_index ); |
3067 | |
|
3068 | 0 | goto on_error; |
3069 | 0 | } |
3070 | 0 | file_entry_node = NULL; |
3071 | 0 | } |
3072 | 0 | return( 1 ); |
3073 | | |
3074 | 0 | on_error: |
3075 | 0 | if( file_entry_node != NULL ) |
3076 | 0 | { |
3077 | 0 | libcdata_tree_node_free( |
3078 | 0 | &file_entry_node, |
3079 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_lef_file_entry_free, |
3080 | 0 | NULL ); |
3081 | 0 | } |
3082 | 0 | if( lef_file_entry != NULL ) |
3083 | 0 | { |
3084 | 0 | libewf_lef_file_entry_free( |
3085 | 0 | &lef_file_entry, |
3086 | 0 | NULL ); |
3087 | 0 | } |
3088 | 0 | if( values != NULL ) |
3089 | 0 | { |
3090 | 0 | libfvalue_split_utf8_string_free( |
3091 | 0 | &values, |
3092 | 0 | NULL ); |
3093 | 0 | } |
3094 | 0 | return( -1 ); |
3095 | 0 | } |
3096 | | |
3097 | | /* Parses a file entry string for the number of sub entries |
3098 | | * Returns 1 if successful or -1 on error |
3099 | | */ |
3100 | | int libewf_single_files_parse_file_entry_number_of_sub_entries( |
3101 | | libewf_single_files_t *single_files, |
3102 | | libewf_line_reader_t *line_reader, |
3103 | | int *number_of_sub_entries, |
3104 | | libcerror_error_t **error ) |
3105 | 0 | { |
3106 | 0 | libfvalue_split_utf8_string_t *values = NULL; |
3107 | 0 | uint8_t *line_string = NULL; |
3108 | 0 | uint8_t *value_string = NULL; |
3109 | 0 | static char *function = "libewf_single_files_parse_file_entry_number_of_sub_entries"; |
3110 | 0 | size_t line_string_size = 0; |
3111 | 0 | size_t value_string_size = 0; |
3112 | 0 | uint64_t value_64bit = 0; |
3113 | 0 | int number_of_values = 0; |
3114 | |
|
3115 | 0 | if( single_files == NULL ) |
3116 | 0 | { |
3117 | 0 | libcerror_error_set( |
3118 | 0 | error, |
3119 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3120 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3121 | 0 | "%s: invalid single files.", |
3122 | 0 | function ); |
3123 | |
|
3124 | 0 | return( -1 ); |
3125 | 0 | } |
3126 | 0 | if( line_reader == NULL ) |
3127 | 0 | { |
3128 | 0 | libcerror_error_set( |
3129 | 0 | error, |
3130 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3131 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3132 | 0 | "%s: invalid line reader.", |
3133 | 0 | function ); |
3134 | |
|
3135 | 0 | return( -1 ); |
3136 | 0 | } |
3137 | 0 | if( number_of_sub_entries == NULL ) |
3138 | 0 | { |
3139 | 0 | libcerror_error_set( |
3140 | 0 | error, |
3141 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3142 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3143 | 0 | "%s: invalid number of sub entries.", |
3144 | 0 | function ); |
3145 | |
|
3146 | 0 | return( -1 ); |
3147 | 0 | } |
3148 | 0 | if( libewf_line_reader_read_utf8_string( |
3149 | 0 | line_reader, |
3150 | 0 | &line_string, |
3151 | 0 | &line_string_size, |
3152 | 0 | error ) != 1 ) |
3153 | 0 | { |
3154 | 0 | libcerror_error_set( |
3155 | 0 | error, |
3156 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
3157 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
3158 | 0 | "%s: unable to read line: %d.", |
3159 | 0 | function, |
3160 | 0 | line_reader->line_index ); |
3161 | |
|
3162 | 0 | goto on_error; |
3163 | 0 | } |
3164 | 0 | if( libfvalue_utf8_string_split( |
3165 | 0 | line_string, |
3166 | 0 | line_string_size, |
3167 | 0 | (uint8_t) '\t', |
3168 | 0 | &values, |
3169 | 0 | error ) != 1 ) |
3170 | 0 | { |
3171 | 0 | libcerror_error_set( |
3172 | 0 | error, |
3173 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3174 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3175 | 0 | "%s: unable to split line string into values.", |
3176 | 0 | function ); |
3177 | |
|
3178 | 0 | goto on_error; |
3179 | 0 | } |
3180 | 0 | if( libfvalue_split_utf8_string_get_number_of_segments( |
3181 | 0 | values, |
3182 | 0 | &number_of_values, |
3183 | 0 | error ) != 1 ) |
3184 | 0 | { |
3185 | 0 | libcerror_error_set( |
3186 | 0 | error, |
3187 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3188 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3189 | 0 | "%s: unable to retrieve number of values", |
3190 | 0 | function ); |
3191 | |
|
3192 | 0 | goto on_error; |
3193 | 0 | } |
3194 | 0 | if( number_of_values != 2 ) |
3195 | 0 | { |
3196 | 0 | libcerror_error_set( |
3197 | 0 | error, |
3198 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3199 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
3200 | 0 | "%s: unsupported number of values.", |
3201 | 0 | function ); |
3202 | |
|
3203 | 0 | goto on_error; |
3204 | 0 | } |
3205 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
3206 | 0 | values, |
3207 | 0 | 0, |
3208 | 0 | &value_string, |
3209 | 0 | &value_string_size, |
3210 | 0 | error ) != 1 ) |
3211 | 0 | { |
3212 | 0 | libcerror_error_set( |
3213 | 0 | error, |
3214 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3215 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3216 | 0 | "%s: unable to retrieve value string: 0.", |
3217 | 0 | function ); |
3218 | |
|
3219 | 0 | goto on_error; |
3220 | 0 | } |
3221 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
3222 | 0 | values, |
3223 | 0 | 0, |
3224 | 0 | &value_string, |
3225 | 0 | &value_string_size, |
3226 | 0 | error ) != 1 ) |
3227 | 0 | { |
3228 | 0 | libcerror_error_set( |
3229 | 0 | error, |
3230 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3231 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3232 | 0 | "%s: unable to retrieve value string: 0.", |
3233 | 0 | function ); |
3234 | |
|
3235 | 0 | goto on_error; |
3236 | 0 | } |
3237 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
3238 | 0 | value_string, |
3239 | 0 | value_string_size, |
3240 | 0 | &value_64bit, |
3241 | 0 | 64, |
3242 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
3243 | 0 | error ) != 1 ) |
3244 | 0 | { |
3245 | 0 | libcerror_error_set( |
3246 | 0 | error, |
3247 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
3248 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
3249 | 0 | "%s: unable to set number of entries in parent value.", |
3250 | 0 | function ); |
3251 | |
|
3252 | 0 | goto on_error; |
3253 | 0 | } |
3254 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
3255 | 0 | { |
3256 | 0 | libcerror_error_set( |
3257 | 0 | error, |
3258 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3259 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3260 | 0 | "%s: invalid number of entries in parent value out of bounds.", |
3261 | 0 | function ); |
3262 | |
|
3263 | 0 | goto on_error; |
3264 | 0 | } |
3265 | 0 | if( ( value_64bit != 0 ) |
3266 | 0 | && ( value_64bit != 26 ) ) |
3267 | 0 | { |
3268 | 0 | libcerror_error_set( |
3269 | 0 | error, |
3270 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3271 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
3272 | 0 | "%s: unsupported number of entries in parent value.", |
3273 | 0 | function ); |
3274 | |
|
3275 | 0 | goto on_error; |
3276 | 0 | } |
3277 | 0 | if( libfvalue_split_utf8_string_get_segment_by_index( |
3278 | 0 | values, |
3279 | 0 | 1, |
3280 | 0 | &value_string, |
3281 | 0 | &value_string_size, |
3282 | 0 | error ) != 1 ) |
3283 | 0 | { |
3284 | 0 | libcerror_error_set( |
3285 | 0 | error, |
3286 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3287 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3288 | 0 | "%s: unable to retrieve value string: 1.", |
3289 | 0 | function ); |
3290 | |
|
3291 | 0 | goto on_error; |
3292 | 0 | } |
3293 | 0 | if( libfvalue_utf8_string_copy_to_integer( |
3294 | 0 | value_string, |
3295 | 0 | value_string_size, |
3296 | 0 | &value_64bit, |
3297 | 0 | 64, |
3298 | 0 | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
3299 | 0 | error ) != 1 ) |
3300 | 0 | { |
3301 | 0 | libcerror_error_set( |
3302 | 0 | error, |
3303 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
3304 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
3305 | 0 | "%s: unable to set number of sub entries.", |
3306 | 0 | function ); |
3307 | |
|
3308 | 0 | goto on_error; |
3309 | 0 | } |
3310 | 0 | if( value_64bit > (uint64_t) INT_MAX ) |
3311 | 0 | { |
3312 | 0 | libcerror_error_set( |
3313 | 0 | error, |
3314 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3315 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3316 | 0 | "%s: invalid number of sub entries value out of bounds.", |
3317 | 0 | function ); |
3318 | |
|
3319 | 0 | goto on_error; |
3320 | 0 | } |
3321 | 0 | if( libfvalue_split_utf8_string_free( |
3322 | 0 | &values, |
3323 | 0 | error ) != 1 ) |
3324 | 0 | { |
3325 | 0 | libcerror_error_set( |
3326 | 0 | error, |
3327 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3328 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3329 | 0 | "%s: unable to free split values.", |
3330 | 0 | function ); |
3331 | |
|
3332 | 0 | goto on_error; |
3333 | 0 | } |
3334 | 0 | *number_of_sub_entries = (int) value_64bit; |
3335 | |
|
3336 | 0 | return( 1 ); |
3337 | | |
3338 | 0 | on_error: |
3339 | 0 | if( values != NULL ) |
3340 | 0 | { |
3341 | 0 | libfvalue_split_utf8_string_free( |
3342 | 0 | &values, |
3343 | 0 | NULL ); |
3344 | 0 | } |
3345 | 0 | return( -1 ); |
3346 | 0 | } |
3347 | | |
3348 | | /* Reads the single files |
3349 | | * Returns 1 if successful or -1 on error |
3350 | | */ |
3351 | | int libewf_single_files_read_data_stream( |
3352 | | libewf_single_files_t *single_files, |
3353 | | libfdata_stream_t *data_stream, |
3354 | | libbfio_pool_t *file_io_pool, |
3355 | | size64_t *media_size, |
3356 | | uint8_t *format, |
3357 | | libcerror_error_t **error ) |
3358 | 89 | { |
3359 | 89 | libewf_line_reader_t *line_reader = NULL; |
3360 | 89 | uint8_t *line_string = NULL; |
3361 | 89 | static char *function = "libewf_single_files_read_data_stream"; |
3362 | 89 | size_t line_string_size = 0; |
3363 | | |
3364 | 89 | if( single_files == NULL ) |
3365 | 0 | { |
3366 | 0 | libcerror_error_set( |
3367 | 0 | error, |
3368 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3369 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3370 | 0 | "%s: invalid single files.", |
3371 | 0 | function ); |
3372 | |
|
3373 | 0 | return( -1 ); |
3374 | 0 | } |
3375 | 89 | if( libewf_line_reader_initialize( |
3376 | 89 | &line_reader, |
3377 | 89 | data_stream, |
3378 | 89 | file_io_pool, |
3379 | 89 | error ) != 1 ) |
3380 | 0 | { |
3381 | 0 | libcerror_error_set( |
3382 | 0 | error, |
3383 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3384 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3385 | 0 | "%s: unable to create line reader.", |
3386 | 0 | function ); |
3387 | |
|
3388 | 0 | goto on_error; |
3389 | 0 | } |
3390 | 89 | if( libewf_line_reader_read_utf8_string( |
3391 | 89 | line_reader, |
3392 | 89 | &line_string, |
3393 | 89 | &line_string_size, |
3394 | 89 | error ) != 1 ) |
3395 | 9 | { |
3396 | 9 | libcerror_error_set( |
3397 | 9 | error, |
3398 | 9 | LIBCERROR_ERROR_DOMAIN_IO, |
3399 | 9 | LIBCERROR_IO_ERROR_READ_FAILED, |
3400 | 9 | "%s: unable to read line: %d.", |
3401 | 9 | function, |
3402 | 9 | line_reader->line_index ); |
3403 | | |
3404 | 9 | goto on_error; |
3405 | 9 | } |
3406 | 80 | if( ( line_string_size != 2 ) |
3407 | 80 | || ( line_string[ 0 ] != (uint8_t) '5' ) ) |
3408 | 61 | { |
3409 | 61 | libcerror_error_set( |
3410 | 61 | error, |
3411 | 61 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3412 | 61 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
3413 | 61 | "%s: unsupported number of categories string.", |
3414 | 61 | function ); |
3415 | | |
3416 | 61 | goto on_error; |
3417 | 61 | } |
3418 | 19 | if( libewf_single_files_parse_rec_category( |
3419 | 19 | single_files, |
3420 | 19 | line_reader, |
3421 | 19 | media_size, |
3422 | 19 | error ) != 1 ) |
3423 | 19 | { |
3424 | 19 | libcerror_error_set( |
3425 | 19 | error, |
3426 | 19 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3427 | 19 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3428 | 19 | "%s: unable to parse rec category.", |
3429 | 19 | function ); |
3430 | | |
3431 | 19 | goto on_error; |
3432 | 19 | } |
3433 | 0 | if( libewf_single_files_parse_perm_category( |
3434 | 0 | single_files, |
3435 | 0 | line_reader, |
3436 | 0 | error ) != 1 ) |
3437 | 0 | { |
3438 | 0 | libcerror_error_set( |
3439 | 0 | error, |
3440 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3441 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3442 | 0 | "%s: unable to parse perm category.", |
3443 | 0 | function ); |
3444 | |
|
3445 | 0 | goto on_error; |
3446 | 0 | } |
3447 | 0 | if( libewf_single_files_parse_srce_category( |
3448 | 0 | single_files, |
3449 | 0 | line_reader, |
3450 | 0 | error ) != 1 ) |
3451 | 0 | { |
3452 | 0 | libcerror_error_set( |
3453 | 0 | error, |
3454 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3455 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3456 | 0 | "%s: unable to parse srce category.", |
3457 | 0 | function ); |
3458 | |
|
3459 | 0 | goto on_error; |
3460 | 0 | } |
3461 | 0 | if( libewf_single_files_parse_sub_category( |
3462 | 0 | single_files, |
3463 | 0 | line_reader, |
3464 | 0 | error ) != 1 ) |
3465 | 0 | { |
3466 | 0 | libcerror_error_set( |
3467 | 0 | error, |
3468 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3469 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3470 | 0 | "%s: unable to parse sub category.", |
3471 | 0 | function ); |
3472 | |
|
3473 | 0 | goto on_error; |
3474 | 0 | } |
3475 | 0 | if( libewf_single_files_parse_entry_category( |
3476 | 0 | single_files, |
3477 | 0 | line_reader, |
3478 | 0 | format, |
3479 | 0 | error ) != 1 ) |
3480 | 0 | { |
3481 | 0 | libcerror_error_set( |
3482 | 0 | error, |
3483 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
3484 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
3485 | 0 | "%s: unable to parse entry category.", |
3486 | 0 | function ); |
3487 | |
|
3488 | 0 | goto on_error; |
3489 | 0 | } |
3490 | 0 | if( libewf_line_reader_free( |
3491 | 0 | &line_reader, |
3492 | 0 | error ) != 1 ) |
3493 | 0 | { |
3494 | 0 | libcerror_error_set( |
3495 | 0 | error, |
3496 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3497 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3498 | 0 | "%s: unable to free line reader.", |
3499 | 0 | function ); |
3500 | |
|
3501 | 0 | goto on_error; |
3502 | 0 | } |
3503 | 0 | return( 1 ); |
3504 | | |
3505 | 89 | on_error: |
3506 | 89 | if( line_reader != NULL ) |
3507 | 89 | { |
3508 | 89 | libewf_line_reader_free( |
3509 | 89 | &line_reader, |
3510 | 89 | NULL ); |
3511 | 89 | } |
3512 | 89 | return( -1 ); |
3513 | 0 | } |
3514 | | |
3515 | | /* Retrieves the file entry tree root node |
3516 | | * Returns 1 if successful or -1 on error |
3517 | | */ |
3518 | | int libewf_single_files_get_file_entry_tree_root_node( |
3519 | | libewf_single_files_t *single_files, |
3520 | | libcdata_tree_node_t **root_node, |
3521 | | libcerror_error_t **error ) |
3522 | 0 | { |
3523 | 0 | static char *function = "libewf_single_files_get_file_entry_tree_root_node"; |
3524 | |
|
3525 | 0 | if( single_files == NULL ) |
3526 | 0 | { |
3527 | 0 | libcerror_error_set( |
3528 | 0 | error, |
3529 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3530 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3531 | 0 | "%s: invalid single files.", |
3532 | 0 | function ); |
3533 | |
|
3534 | 0 | return( -1 ); |
3535 | 0 | } |
3536 | 0 | if( root_node == NULL ) |
3537 | 0 | { |
3538 | 0 | libcerror_error_set( |
3539 | 0 | error, |
3540 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3541 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3542 | 0 | "%s: invalid root node.", |
3543 | 0 | function ); |
3544 | |
|
3545 | 0 | return( -1 ); |
3546 | 0 | } |
3547 | 0 | *root_node = single_files->file_entry_tree_root_node; |
3548 | |
|
3549 | 0 | return( 1 ); |
3550 | 0 | } |
3551 | | |
3552 | | /* Retrieves a specific permission group |
3553 | | * Returns 1 if successful or -1 on error |
3554 | | */ |
3555 | | int libewf_single_files_get_permission_group_by_index( |
3556 | | libewf_single_files_t *single_files, |
3557 | | int permission_group_index, |
3558 | | libewf_permission_group_t **permission_group, |
3559 | | libcerror_error_t **error ) |
3560 | 0 | { |
3561 | 0 | static char *function = "libewf_single_files_get_permission_group_by_index"; |
3562 | |
|
3563 | 0 | if( single_files == NULL ) |
3564 | 0 | { |
3565 | 0 | libcerror_error_set( |
3566 | 0 | error, |
3567 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3568 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3569 | 0 | "%s: invalid single files.", |
3570 | 0 | function ); |
3571 | |
|
3572 | 0 | return( -1 ); |
3573 | 0 | } |
3574 | 0 | if( libcdata_array_get_entry_by_index( |
3575 | 0 | single_files->permission_groups, |
3576 | 0 | permission_group_index, |
3577 | 0 | (intptr_t **) permission_group, |
3578 | 0 | error ) != 1 ) |
3579 | 0 | { |
3580 | 0 | libcerror_error_set( |
3581 | 0 | error, |
3582 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3583 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3584 | 0 | "%s: unable to retrieve entry: %d from permission groups array.", |
3585 | 0 | function, |
3586 | 0 | permission_group_index ); |
3587 | |
|
3588 | 0 | return( -1 ); |
3589 | 0 | } |
3590 | 0 | return( 1 ); |
3591 | 0 | } |
3592 | | |
3593 | | /* Retrieves a specific source |
3594 | | * Returns 1 if successful or -1 on error |
3595 | | */ |
3596 | | int libewf_single_files_get_source_by_index( |
3597 | | libewf_single_files_t *single_files, |
3598 | | int source_index, |
3599 | | libewf_lef_source_t **lef_source, |
3600 | | libcerror_error_t **error ) |
3601 | 0 | { |
3602 | 0 | static char *function = "libewf_single_files_get_source_by_index"; |
3603 | |
|
3604 | 0 | if( single_files == NULL ) |
3605 | 0 | { |
3606 | 0 | libcerror_error_set( |
3607 | 0 | error, |
3608 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3609 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3610 | 0 | "%s: invalid single files.", |
3611 | 0 | function ); |
3612 | |
|
3613 | 0 | return( -1 ); |
3614 | 0 | } |
3615 | 0 | if( libcdata_array_get_entry_by_index( |
3616 | 0 | single_files->sources, |
3617 | 0 | source_index, |
3618 | 0 | (intptr_t **) lef_source, |
3619 | 0 | error ) != 1 ) |
3620 | 0 | { |
3621 | 0 | libcerror_error_set( |
3622 | 0 | error, |
3623 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3624 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3625 | 0 | "%s: unable to retrieve entry: %d from sources array.", |
3626 | 0 | function, |
3627 | 0 | source_index ); |
3628 | |
|
3629 | 0 | return( -1 ); |
3630 | 0 | } |
3631 | 0 | return( 1 ); |
3632 | 0 | } |
3633 | | |