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