/src/libesedb/libesedb/libesedb_index.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Index 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 <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libesedb_catalog_definition.h" |
27 | | #include "libesedb_data_definition.h" |
28 | | #include "libesedb_definitions.h" |
29 | | #include "libesedb_io_handle.h" |
30 | | #include "libesedb_index.h" |
31 | | #include "libesedb_libbfio.h" |
32 | | #include "libesedb_libcerror.h" |
33 | | #include "libesedb_libcnotify.h" |
34 | | #include "libesedb_libfcache.h" |
35 | | #include "libesedb_libfdata.h" |
36 | | #include "libesedb_page_tree.h" |
37 | | #include "libesedb_page_tree_key.h" |
38 | | #include "libesedb_record.h" |
39 | | #include "libesedb_types.h" |
40 | | |
41 | | /* Creates an index |
42 | | * Make sure the value index is referencing, is set to NULL |
43 | | * Returns 1 if successful or -1 on error |
44 | | */ |
45 | | int libesedb_index_initialize( |
46 | | libesedb_index_t **index, |
47 | | libbfio_handle_t *file_io_handle, |
48 | | libesedb_io_handle_t *io_handle, |
49 | | libesedb_table_definition_t *table_definition, |
50 | | libesedb_table_definition_t *template_table_definition, |
51 | | libesedb_catalog_definition_t *index_catalog_definition, |
52 | | libfdata_vector_t *pages_vector, |
53 | | libfcache_cache_t *pages_cache, |
54 | | libfdata_vector_t *long_values_pages_vector, |
55 | | libfcache_cache_t *long_values_pages_cache, |
56 | | libesedb_page_tree_t *table_page_tree, |
57 | | libesedb_page_tree_t *long_values_page_tree, |
58 | | libcerror_error_t **error ) |
59 | 0 | { |
60 | 0 | libesedb_internal_index_t *internal_index = NULL; |
61 | 0 | static char *function = "libesedb_index_initialize"; |
62 | |
|
63 | 0 | if( index == NULL ) |
64 | 0 | { |
65 | 0 | libcerror_error_set( |
66 | 0 | error, |
67 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
68 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
69 | 0 | "%s: invalid index.", |
70 | 0 | function ); |
71 | |
|
72 | 0 | return( -1 ); |
73 | 0 | } |
74 | 0 | if( *index != NULL ) |
75 | 0 | { |
76 | 0 | libcerror_error_set( |
77 | 0 | error, |
78 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
79 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
80 | 0 | "%s: invalid index value already set.", |
81 | 0 | function ); |
82 | |
|
83 | 0 | return( -1 ); |
84 | 0 | } |
85 | 0 | if( table_definition == NULL ) |
86 | 0 | { |
87 | 0 | libcerror_error_set( |
88 | 0 | error, |
89 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
90 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
91 | 0 | "%s: invalid table definition.", |
92 | 0 | function ); |
93 | |
|
94 | 0 | return( -1 ); |
95 | 0 | } |
96 | 0 | if( index_catalog_definition == NULL ) |
97 | 0 | { |
98 | 0 | libcerror_error_set( |
99 | 0 | error, |
100 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
101 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
102 | 0 | "%s: invalid index catalog definition.", |
103 | 0 | function ); |
104 | |
|
105 | 0 | return( -1 ); |
106 | 0 | } |
107 | 0 | internal_index = memory_allocate_structure( |
108 | 0 | libesedb_internal_index_t ); |
109 | |
|
110 | 0 | if( internal_index == NULL ) |
111 | 0 | { |
112 | 0 | libcerror_error_set( |
113 | 0 | error, |
114 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
115 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
116 | 0 | "%s: unable to create index.", |
117 | 0 | function ); |
118 | |
|
119 | 0 | goto on_error; |
120 | 0 | } |
121 | 0 | if( memory_set( |
122 | 0 | internal_index, |
123 | 0 | 0, |
124 | 0 | sizeof( libesedb_internal_index_t ) ) == NULL ) |
125 | 0 | { |
126 | 0 | libcerror_error_set( |
127 | 0 | error, |
128 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
129 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
130 | 0 | "%s: unable to clear index.", |
131 | 0 | function ); |
132 | |
|
133 | 0 | memory_free( |
134 | 0 | internal_index ); |
135 | |
|
136 | 0 | return( -1 ); |
137 | 0 | } |
138 | | /* TODO (template) table definition required ? */ |
139 | | |
140 | 0 | if( libesedb_page_tree_initialize( |
141 | 0 | &( internal_index->index_page_tree ), |
142 | 0 | io_handle, |
143 | 0 | pages_vector, |
144 | 0 | pages_cache, |
145 | 0 | index_catalog_definition->identifier, |
146 | 0 | index_catalog_definition->father_data_page_number, |
147 | 0 | NULL, |
148 | 0 | NULL, |
149 | 0 | error ) != 1 ) |
150 | 0 | { |
151 | 0 | libcerror_error_set( |
152 | 0 | error, |
153 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
154 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
155 | 0 | "%s: unable to create index page tree.", |
156 | 0 | function ); |
157 | |
|
158 | 0 | goto on_error; |
159 | 0 | } |
160 | 0 | internal_index->io_handle = io_handle; |
161 | 0 | internal_index->file_io_handle = file_io_handle; |
162 | 0 | internal_index->table_definition = table_definition; |
163 | 0 | internal_index->template_table_definition = template_table_definition; |
164 | 0 | internal_index->index_catalog_definition = index_catalog_definition; |
165 | 0 | internal_index->pages_vector = pages_vector; |
166 | 0 | internal_index->pages_cache = pages_cache; |
167 | 0 | internal_index->long_values_pages_vector = long_values_pages_vector; |
168 | 0 | internal_index->long_values_pages_cache = long_values_pages_cache; |
169 | 0 | internal_index->table_page_tree = table_page_tree; |
170 | 0 | internal_index->long_values_page_tree = long_values_page_tree; |
171 | |
|
172 | 0 | *index = (libesedb_index_t *) internal_index; |
173 | |
|
174 | 0 | return( 1 ); |
175 | | |
176 | 0 | on_error: |
177 | 0 | if( internal_index != NULL ) |
178 | 0 | { |
179 | 0 | memory_free( |
180 | 0 | internal_index ); |
181 | 0 | } |
182 | 0 | return( -1 ); |
183 | 0 | } |
184 | | |
185 | | /* Frees an index |
186 | | * Returns 1 if successful or -1 on error |
187 | | */ |
188 | | int libesedb_index_free( |
189 | | libesedb_index_t **index, |
190 | | libcerror_error_t **error ) |
191 | 0 | { |
192 | 0 | libesedb_internal_index_t *internal_index = NULL; |
193 | 0 | static char *function = "libesedb_index_free"; |
194 | 0 | int result = 1; |
195 | |
|
196 | 0 | if( index == NULL ) |
197 | 0 | { |
198 | 0 | libcerror_error_set( |
199 | 0 | error, |
200 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
201 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
202 | 0 | "%s: invalid index.", |
203 | 0 | function ); |
204 | |
|
205 | 0 | return( -1 ); |
206 | 0 | } |
207 | 0 | if( *index != NULL ) |
208 | 0 | { |
209 | 0 | internal_index = (libesedb_internal_index_t *) *index; |
210 | 0 | *index = NULL; |
211 | | |
212 | | /* The io_handle, file_io_handle, table_definition, template_table_definition, |
213 | | * index_catalog_definition, pages_vector, pages_cache, table_page_tree and |
214 | | * long_values_page_tree references are freed elsewhere |
215 | | */ |
216 | 0 | if( libesedb_page_tree_free( |
217 | 0 | &( internal_index->index_page_tree ), |
218 | 0 | error ) != 1 ) |
219 | 0 | { |
220 | 0 | libcerror_error_set( |
221 | 0 | error, |
222 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
223 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
224 | 0 | "%s: unable to free index page tree.", |
225 | 0 | function ); |
226 | |
|
227 | 0 | result = -1; |
228 | 0 | } |
229 | 0 | memory_free( |
230 | 0 | internal_index ); |
231 | 0 | } |
232 | 0 | return( result ); |
233 | 0 | } |
234 | | |
235 | | /* Retrieves the index identifier or Father Data Page (FDP) object identifier |
236 | | * Returns 1 if successful or -1 on error |
237 | | */ |
238 | | int libesedb_index_get_identifier( |
239 | | libesedb_index_t *index, |
240 | | uint32_t *identifier, |
241 | | libcerror_error_t **error ) |
242 | 0 | { |
243 | 0 | libesedb_internal_index_t *internal_index = NULL; |
244 | 0 | static char *function = "libesedb_index_get_identifier"; |
245 | |
|
246 | 0 | if( index == NULL ) |
247 | 0 | { |
248 | 0 | libcerror_error_set( |
249 | 0 | error, |
250 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
251 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
252 | 0 | "%s: invalid index.", |
253 | 0 | function ); |
254 | |
|
255 | 0 | return( -1 ); |
256 | 0 | } |
257 | 0 | internal_index = (libesedb_internal_index_t *) index; |
258 | |
|
259 | 0 | if( libesedb_catalog_definition_get_identifier( |
260 | 0 | internal_index->index_catalog_definition, |
261 | 0 | identifier, |
262 | 0 | error ) != 1 ) |
263 | 0 | { |
264 | 0 | libcerror_error_set( |
265 | 0 | error, |
266 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
267 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
268 | 0 | "%s: unable to retrieve catalog definition identifier.", |
269 | 0 | function ); |
270 | |
|
271 | 0 | return( -1 ); |
272 | 0 | } |
273 | 0 | return( 1 ); |
274 | 0 | } |
275 | | |
276 | | /* Retrieves the size of the UTF-8 encoded string of the index name |
277 | | * The returned size includes the end of string character |
278 | | * Returns 1 if successful or -1 on error |
279 | | */ |
280 | | int libesedb_index_get_utf8_name_size( |
281 | | libesedb_index_t *index, |
282 | | size_t *utf8_string_size, |
283 | | libcerror_error_t **error ) |
284 | 0 | { |
285 | 0 | libesedb_internal_index_t *internal_index = NULL; |
286 | 0 | static char *function = "libesedb_index_get_utf8_string_size"; |
287 | |
|
288 | 0 | if( index == NULL ) |
289 | 0 | { |
290 | 0 | libcerror_error_set( |
291 | 0 | error, |
292 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
293 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
294 | 0 | "%s: invalid index.", |
295 | 0 | function ); |
296 | |
|
297 | 0 | return( -1 ); |
298 | 0 | } |
299 | 0 | internal_index = (libesedb_internal_index_t *) index; |
300 | |
|
301 | 0 | if( internal_index->io_handle == NULL ) |
302 | 0 | { |
303 | 0 | libcerror_error_set( |
304 | 0 | error, |
305 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
306 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
307 | 0 | "%s: invalid index - missing IO handle.", |
308 | 0 | function ); |
309 | |
|
310 | 0 | return( -1 ); |
311 | 0 | } |
312 | 0 | if( libesedb_catalog_definition_get_utf8_name_size( |
313 | 0 | internal_index->index_catalog_definition, |
314 | 0 | utf8_string_size, |
315 | 0 | internal_index->io_handle->ascii_codepage, |
316 | 0 | error ) != 1 ) |
317 | 0 | { |
318 | 0 | libcerror_error_set( |
319 | 0 | error, |
320 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
321 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
322 | 0 | "%s: unable to retrieve UTF-8 string size.", |
323 | 0 | function ); |
324 | |
|
325 | 0 | return( -1 ); |
326 | 0 | } |
327 | 0 | return( 1 ); |
328 | 0 | } |
329 | | |
330 | | /* Retrieves the UTF-8 encoded string of the index name |
331 | | * The size should include the end of string character |
332 | | * Returns 1 if successful or -1 on error |
333 | | */ |
334 | | int libesedb_index_get_utf8_name( |
335 | | libesedb_index_t *index, |
336 | | uint8_t *utf8_string, |
337 | | size_t utf8_string_size, |
338 | | libcerror_error_t **error ) |
339 | 0 | { |
340 | 0 | libesedb_internal_index_t *internal_index = NULL; |
341 | 0 | static char *function = "libesedb_index_get_utf8_string"; |
342 | |
|
343 | 0 | if( index == NULL ) |
344 | 0 | { |
345 | 0 | libcerror_error_set( |
346 | 0 | error, |
347 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
348 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
349 | 0 | "%s: invalid index.", |
350 | 0 | function ); |
351 | |
|
352 | 0 | return( -1 ); |
353 | 0 | } |
354 | 0 | internal_index = (libesedb_internal_index_t *) index; |
355 | |
|
356 | 0 | if( internal_index->io_handle == NULL ) |
357 | 0 | { |
358 | 0 | libcerror_error_set( |
359 | 0 | error, |
360 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
361 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
362 | 0 | "%s: invalid index - missing IO handle.", |
363 | 0 | function ); |
364 | |
|
365 | 0 | return( -1 ); |
366 | 0 | } |
367 | 0 | if( libesedb_catalog_definition_get_utf8_name( |
368 | 0 | internal_index->index_catalog_definition, |
369 | 0 | utf8_string, |
370 | 0 | utf8_string_size, |
371 | 0 | internal_index->io_handle->ascii_codepage, |
372 | 0 | error ) != 1 ) |
373 | 0 | { |
374 | 0 | libcerror_error_set( |
375 | 0 | error, |
376 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
377 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
378 | 0 | "%s: unable to retrieve UTF-8 string.", |
379 | 0 | function ); |
380 | |
|
381 | 0 | return( -1 ); |
382 | 0 | } |
383 | 0 | return( 1 ); |
384 | 0 | } |
385 | | |
386 | | /* Retrieves the size of the UTF-16 encoded string of the index name |
387 | | * The returned size includes the end of string character |
388 | | * Returns 1 if successful or -1 on error |
389 | | */ |
390 | | int libesedb_index_get_utf16_name_size( |
391 | | libesedb_index_t *index, |
392 | | size_t *utf16_string_size, |
393 | | libcerror_error_t **error ) |
394 | 0 | { |
395 | 0 | libesedb_internal_index_t *internal_index = NULL; |
396 | 0 | static char *function = "libesedb_index_get_utf16_string_size"; |
397 | |
|
398 | 0 | if( index == NULL ) |
399 | 0 | { |
400 | 0 | libcerror_error_set( |
401 | 0 | error, |
402 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
403 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
404 | 0 | "%s: invalid index.", |
405 | 0 | function ); |
406 | |
|
407 | 0 | return( -1 ); |
408 | 0 | } |
409 | 0 | internal_index = (libesedb_internal_index_t *) index; |
410 | |
|
411 | 0 | if( internal_index->io_handle == NULL ) |
412 | 0 | { |
413 | 0 | libcerror_error_set( |
414 | 0 | error, |
415 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
416 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
417 | 0 | "%s: invalid index - missing IO handle.", |
418 | 0 | function ); |
419 | |
|
420 | 0 | return( -1 ); |
421 | 0 | } |
422 | 0 | if( libesedb_catalog_definition_get_utf16_name_size( |
423 | 0 | internal_index->index_catalog_definition, |
424 | 0 | utf16_string_size, |
425 | 0 | internal_index->io_handle->ascii_codepage, |
426 | 0 | error ) != 1 ) |
427 | 0 | { |
428 | 0 | libcerror_error_set( |
429 | 0 | error, |
430 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
431 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
432 | 0 | "%s: unable to retrieve UTF-16 string size.", |
433 | 0 | function ); |
434 | |
|
435 | 0 | return( -1 ); |
436 | 0 | } |
437 | 0 | return( 1 ); |
438 | 0 | } |
439 | | |
440 | | /* Retrieves the UTF-16 encoded string of the index name |
441 | | * The size should include the end of string character |
442 | | * Returns 1 if successful or -1 on error |
443 | | */ |
444 | | int libesedb_index_get_utf16_name( |
445 | | libesedb_index_t *index, |
446 | | uint16_t *utf16_string, |
447 | | size_t utf16_string_size, |
448 | | libcerror_error_t **error ) |
449 | 0 | { |
450 | 0 | libesedb_internal_index_t *internal_index = NULL; |
451 | 0 | static char *function = "libesedb_index_get_utf16_string"; |
452 | |
|
453 | 0 | if( index == NULL ) |
454 | 0 | { |
455 | 0 | libcerror_error_set( |
456 | 0 | error, |
457 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
458 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
459 | 0 | "%s: invalid index.", |
460 | 0 | function ); |
461 | |
|
462 | 0 | return( -1 ); |
463 | 0 | } |
464 | 0 | internal_index = (libesedb_internal_index_t *) index; |
465 | |
|
466 | 0 | if( internal_index->io_handle == NULL ) |
467 | 0 | { |
468 | 0 | libcerror_error_set( |
469 | 0 | error, |
470 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
471 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
472 | 0 | "%s: invalid index - missing IO handle.", |
473 | 0 | function ); |
474 | |
|
475 | 0 | return( -1 ); |
476 | 0 | } |
477 | 0 | if( libesedb_catalog_definition_get_utf16_name( |
478 | 0 | internal_index->index_catalog_definition, |
479 | 0 | utf16_string, |
480 | 0 | utf16_string_size, |
481 | 0 | internal_index->io_handle->ascii_codepage, |
482 | 0 | error ) != 1 ) |
483 | 0 | { |
484 | 0 | libcerror_error_set( |
485 | 0 | error, |
486 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
487 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
488 | 0 | "%s: unable to retrieve UTF-16 string.", |
489 | 0 | function ); |
490 | |
|
491 | 0 | return( -1 ); |
492 | 0 | } |
493 | 0 | return( 1 ); |
494 | 0 | } |
495 | | |
496 | | /* Retrieves the number of records in the index |
497 | | * Returns 1 if successful or -1 on error |
498 | | */ |
499 | | int libesedb_index_get_number_of_records( |
500 | | libesedb_index_t *index, |
501 | | int *number_of_records, |
502 | | libcerror_error_t **error ) |
503 | 0 | { |
504 | 0 | libesedb_internal_index_t *internal_index = NULL; |
505 | 0 | static char *function = "libesedb_index_get_number_of_records"; |
506 | |
|
507 | 0 | if( index == NULL ) |
508 | 0 | { |
509 | 0 | libcerror_error_set( |
510 | 0 | error, |
511 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
512 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
513 | 0 | "%s: invalid index.", |
514 | 0 | function ); |
515 | |
|
516 | 0 | return( -1 ); |
517 | 0 | } |
518 | 0 | internal_index = (libesedb_internal_index_t *) index; |
519 | |
|
520 | 0 | if( libesedb_page_tree_get_number_of_leaf_values( |
521 | 0 | internal_index->index_page_tree, |
522 | 0 | internal_index->file_io_handle, |
523 | 0 | number_of_records, |
524 | 0 | error ) != 1 ) |
525 | 0 | { |
526 | 0 | libcerror_error_set( |
527 | 0 | error, |
528 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
529 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
530 | 0 | "%s: unable to retrieve number of leaf values from index page tree.", |
531 | 0 | function ); |
532 | |
|
533 | 0 | return( -1 ); |
534 | 0 | } |
535 | 0 | return( 1 ); |
536 | 0 | } |
537 | | |
538 | | /* Retrieves a specific record |
539 | | * Returns 1 if successful or -1 on error |
540 | | */ |
541 | | int libesedb_index_get_record( |
542 | | libesedb_index_t *index, |
543 | | int record_entry, |
544 | | libesedb_record_t **record, |
545 | | libcerror_error_t **error ) |
546 | 0 | { |
547 | 0 | libesedb_data_definition_t *index_data_definition = NULL; |
548 | 0 | libesedb_data_definition_t *record_data_definition = NULL; |
549 | 0 | libesedb_internal_index_t *internal_index = NULL; |
550 | 0 | libesedb_page_tree_key_t *key = NULL; |
551 | 0 | uint8_t *index_data = NULL; |
552 | 0 | static char *function = "libesedb_index_get_record"; |
553 | 0 | size_t index_data_size = 0; |
554 | |
|
555 | 0 | if( index == NULL ) |
556 | 0 | { |
557 | 0 | libcerror_error_set( |
558 | 0 | error, |
559 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
560 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
561 | 0 | "%s: invalid index.", |
562 | 0 | function ); |
563 | |
|
564 | 0 | return( -1 ); |
565 | 0 | } |
566 | 0 | internal_index = (libesedb_internal_index_t *) index; |
567 | |
|
568 | 0 | if( record == NULL ) |
569 | 0 | { |
570 | 0 | libcerror_error_set( |
571 | 0 | error, |
572 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
573 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
574 | 0 | "%s: invalid record.", |
575 | 0 | function ); |
576 | |
|
577 | 0 | return( -1 ); |
578 | 0 | } |
579 | 0 | if( *record != NULL ) |
580 | 0 | { |
581 | 0 | libcerror_error_set( |
582 | 0 | error, |
583 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
584 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
585 | 0 | "%s: invalid record value already set.", |
586 | 0 | function ); |
587 | |
|
588 | 0 | return( -1 ); |
589 | 0 | } |
590 | 0 | if( libesedb_page_tree_get_leaf_value_by_index( |
591 | 0 | internal_index->index_page_tree, |
592 | 0 | internal_index->file_io_handle, |
593 | 0 | record_entry, |
594 | 0 | &index_data_definition, |
595 | 0 | error ) != 1 ) |
596 | 0 | { |
597 | 0 | libcerror_error_set( |
598 | 0 | error, |
599 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
600 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
601 | 0 | "%s: unable to retrieve leaf value: %d from index values tree.", |
602 | 0 | function, |
603 | 0 | record_entry ); |
604 | |
|
605 | 0 | goto on_error; |
606 | 0 | } |
607 | 0 | if( libesedb_data_definition_read_data( |
608 | 0 | index_data_definition, |
609 | 0 | internal_index->file_io_handle, |
610 | 0 | internal_index->io_handle, |
611 | 0 | internal_index->pages_vector, |
612 | 0 | internal_index->pages_cache, |
613 | 0 | &index_data, |
614 | 0 | &index_data_size, |
615 | 0 | error ) != 1 ) |
616 | 0 | { |
617 | 0 | libcerror_error_set( |
618 | 0 | error, |
619 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
620 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
621 | 0 | "%s: unable to read index data definition data.", |
622 | 0 | function ); |
623 | |
|
624 | 0 | goto on_error; |
625 | 0 | } |
626 | 0 | if( libesedb_data_definition_free( |
627 | 0 | &index_data_definition, |
628 | 0 | error ) != 1 ) |
629 | 0 | { |
630 | 0 | libcerror_error_set( |
631 | 0 | error, |
632 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
633 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
634 | 0 | "%s: unable to free index data definition.", |
635 | 0 | function ); |
636 | |
|
637 | 0 | goto on_error; |
638 | 0 | } |
639 | 0 | if( libesedb_page_tree_key_initialize( |
640 | 0 | &key, |
641 | 0 | error ) != 1 ) |
642 | 0 | { |
643 | 0 | libcerror_error_set( |
644 | 0 | error, |
645 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
646 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
647 | 0 | "%s: unable to create key.", |
648 | 0 | function ); |
649 | |
|
650 | 0 | goto on_error; |
651 | 0 | } |
652 | 0 | if( libesedb_page_tree_key_set_data( |
653 | 0 | key, |
654 | 0 | index_data, |
655 | 0 | index_data_size, |
656 | 0 | error ) != 1 ) |
657 | 0 | { |
658 | 0 | libcerror_error_set( |
659 | 0 | error, |
660 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
661 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
662 | 0 | "%s: unable to set index data in key.", |
663 | 0 | function ); |
664 | |
|
665 | 0 | goto on_error; |
666 | 0 | } |
667 | 0 | key->type = LIBESEDB_KEY_TYPE_INDEX_VALUE; |
668 | |
|
669 | 0 | if( libesedb_page_tree_get_leaf_value_by_key( |
670 | 0 | internal_index->table_page_tree, |
671 | 0 | internal_index->file_io_handle, |
672 | 0 | key, |
673 | 0 | &record_data_definition, |
674 | 0 | error ) != 1 ) |
675 | 0 | { |
676 | 0 | libcerror_error_set( |
677 | 0 | error, |
678 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
679 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
680 | 0 | "%s: unable to retrieve leaf value by key.", |
681 | 0 | function ); |
682 | |
|
683 | 0 | goto on_error; |
684 | 0 | } |
685 | 0 | if( libesedb_page_tree_key_free( |
686 | 0 | &key, |
687 | 0 | error ) != 1 ) |
688 | 0 | { |
689 | 0 | libcerror_error_set( |
690 | 0 | error, |
691 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
692 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
693 | 0 | "%s: unable to free key.", |
694 | 0 | function ); |
695 | |
|
696 | 0 | goto on_error; |
697 | 0 | } |
698 | 0 | if( libesedb_record_initialize( |
699 | 0 | record, |
700 | 0 | internal_index->file_io_handle, |
701 | 0 | internal_index->io_handle, |
702 | 0 | internal_index->table_definition, |
703 | 0 | internal_index->template_table_definition, |
704 | 0 | internal_index->pages_vector, |
705 | 0 | internal_index->pages_cache, |
706 | 0 | internal_index->long_values_pages_vector, |
707 | 0 | internal_index->long_values_pages_cache, |
708 | 0 | record_data_definition, |
709 | 0 | internal_index->long_values_page_tree, |
710 | 0 | error ) != 1 ) |
711 | 0 | { |
712 | 0 | libcerror_error_set( |
713 | 0 | error, |
714 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
715 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
716 | 0 | "%s: unable to create record.", |
717 | 0 | function ); |
718 | |
|
719 | 0 | goto on_error; |
720 | 0 | } |
721 | 0 | return( 1 ); |
722 | | |
723 | 0 | on_error: |
724 | 0 | if( record_data_definition != NULL ) |
725 | 0 | { |
726 | 0 | libesedb_data_definition_free( |
727 | 0 | &record_data_definition, |
728 | 0 | NULL ); |
729 | 0 | } |
730 | 0 | if( index_data_definition != NULL ) |
731 | 0 | { |
732 | 0 | libesedb_data_definition_free( |
733 | 0 | &index_data_definition, |
734 | 0 | NULL ); |
735 | 0 | } |
736 | 0 | if( key != NULL ) |
737 | 0 | { |
738 | 0 | libesedb_page_tree_key_free( |
739 | 0 | &key, |
740 | 0 | NULL ); |
741 | 0 | } |
742 | 0 | return( -1 ); |
743 | 0 | } |
744 | | |