/src/libesedb/libesedb/libesedb_table.c
Line | Count | Source |
1 | | /* |
2 | | * Table functions |
3 | | * |
4 | | * Copyright (C) 2009-2026, 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_column.h" |
27 | | #include "libesedb_data_definition.h" |
28 | | #include "libesedb_definitions.h" |
29 | | #include "libesedb_index.h" |
30 | | #include "libesedb_io_handle.h" |
31 | | #include "libesedb_libbfio.h" |
32 | | #include "libesedb_libcdata.h" |
33 | | #include "libesedb_libcerror.h" |
34 | | #include "libesedb_libfcache.h" |
35 | | #include "libesedb_libfdata.h" |
36 | | #include "libesedb_page_tree.h" |
37 | | #include "libesedb_record.h" |
38 | | #include "libesedb_table.h" |
39 | | #include "libesedb_table_definition.h" |
40 | | #include "libesedb_types.h" |
41 | | |
42 | | /* Creates a table |
43 | | * Make sure the value table is referencing, is set to NULL |
44 | | * Returns 1 if successful or -1 on error |
45 | | */ |
46 | | int libesedb_table_initialize( |
47 | | libesedb_table_t **table, |
48 | | libbfio_handle_t *file_io_handle, |
49 | | libesedb_io_handle_t *io_handle, |
50 | | libesedb_table_definition_t *table_definition, |
51 | | libesedb_table_definition_t *template_table_definition, |
52 | | libcerror_error_t **error ) |
53 | 87 | { |
54 | 87 | libesedb_internal_table_t *internal_table = NULL; |
55 | 87 | static char *function = "libesedb_table_initialize"; |
56 | 87 | int segment_index = 0; |
57 | | |
58 | 87 | if( table == NULL ) |
59 | 0 | { |
60 | 0 | libcerror_error_set( |
61 | 0 | error, |
62 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
63 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
64 | 0 | "%s: invalid table.", |
65 | 0 | function ); |
66 | |
|
67 | 0 | return( -1 ); |
68 | 0 | } |
69 | 87 | if( *table != NULL ) |
70 | 0 | { |
71 | 0 | libcerror_error_set( |
72 | 0 | error, |
73 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
74 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
75 | 0 | "%s: invalid table value already set.", |
76 | 0 | function ); |
77 | |
|
78 | 0 | return( -1 ); |
79 | 0 | } |
80 | 87 | if( io_handle == NULL ) |
81 | 0 | { |
82 | 0 | libcerror_error_set( |
83 | 0 | error, |
84 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
85 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
86 | 0 | "%s: invalid IO handle.", |
87 | 0 | function ); |
88 | |
|
89 | 0 | return( -1 ); |
90 | 0 | } |
91 | 87 | if( table_definition == NULL ) |
92 | 0 | { |
93 | 0 | libcerror_error_set( |
94 | 0 | error, |
95 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
96 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
97 | 0 | "%s: invalid table definition.", |
98 | 0 | function ); |
99 | |
|
100 | 0 | return( -1 ); |
101 | 0 | } |
102 | 87 | if( table_definition->table_catalog_definition == NULL ) |
103 | 0 | { |
104 | 0 | libcerror_error_set( |
105 | 0 | error, |
106 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
107 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
108 | 0 | "%s: invalid table definition - missing table catalog definition.", |
109 | 0 | function ); |
110 | |
|
111 | 0 | return( -1 ); |
112 | 0 | } |
113 | 87 | internal_table = memory_allocate_structure( |
114 | 87 | libesedb_internal_table_t ); |
115 | | |
116 | 87 | if( internal_table == NULL ) |
117 | 0 | { |
118 | 0 | libcerror_error_set( |
119 | 0 | error, |
120 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
121 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
122 | 0 | "%s: unable to create table.", |
123 | 0 | function ); |
124 | |
|
125 | 0 | goto on_error; |
126 | 0 | } |
127 | 87 | if( memory_set( |
128 | 87 | internal_table, |
129 | 87 | 0, |
130 | 87 | sizeof( libesedb_internal_table_t ) ) == NULL ) |
131 | 0 | { |
132 | 0 | libcerror_error_set( |
133 | 0 | error, |
134 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
135 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
136 | 0 | "%s: unable to clear table.", |
137 | 0 | function ); |
138 | |
|
139 | 0 | memory_free( |
140 | 0 | internal_table ); |
141 | |
|
142 | 0 | return( -1 ); |
143 | 0 | } |
144 | | /* TODO add clone function ? |
145 | | */ |
146 | 87 | if( libfdata_vector_initialize( |
147 | 87 | &( internal_table->pages_vector ), |
148 | 87 | (size64_t) io_handle->page_size, |
149 | 87 | (intptr_t *) io_handle, |
150 | 87 | NULL, |
151 | 87 | NULL, |
152 | 87 | (int (*)(intptr_t *, intptr_t *, libfdata_vector_t *, libfdata_cache_t *, int, int, off64_t, size64_t, uint32_t, uint8_t, libcerror_error_t **)) &libesedb_io_handle_read_page, |
153 | 87 | NULL, |
154 | 87 | LIBFDATA_DATA_HANDLE_FLAG_NON_MANAGED, |
155 | 87 | error ) != 1 ) |
156 | 0 | { |
157 | 0 | libcerror_error_set( |
158 | 0 | error, |
159 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
160 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
161 | 0 | "%s: unable to create pages vector.", |
162 | 0 | function ); |
163 | |
|
164 | 0 | goto on_error; |
165 | 0 | } |
166 | 87 | if( libfdata_vector_append_segment( |
167 | 87 | internal_table->pages_vector, |
168 | 87 | &segment_index, |
169 | 87 | 0, |
170 | 87 | io_handle->pages_data_offset, |
171 | 87 | io_handle->pages_data_size, |
172 | 87 | 0, |
173 | 87 | error ) != 1 ) |
174 | 0 | { |
175 | 0 | libcerror_error_set( |
176 | 0 | error, |
177 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
178 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
179 | 0 | "%s: unable to append segment to pages vector.", |
180 | 0 | function ); |
181 | |
|
182 | 0 | goto on_error; |
183 | 0 | } |
184 | 87 | if( libfcache_cache_initialize( |
185 | 87 | &( internal_table->pages_cache ), |
186 | 87 | LIBESEDB_MAXIMUM_CACHE_ENTRIES_PAGES, |
187 | 87 | error ) != 1 ) |
188 | 0 | { |
189 | 0 | libcerror_error_set( |
190 | 0 | error, |
191 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
192 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
193 | 0 | "%s: unable to create pages cache.", |
194 | 0 | function ); |
195 | |
|
196 | 0 | goto on_error; |
197 | 0 | } |
198 | 87 | if( libesedb_page_tree_initialize( |
199 | 87 | &( internal_table->table_page_tree ), |
200 | 87 | io_handle, |
201 | 87 | internal_table->pages_vector, |
202 | 87 | internal_table->pages_cache, |
203 | 87 | table_definition->table_catalog_definition->identifier, |
204 | 87 | table_definition->table_catalog_definition->father_data_page_number, |
205 | 87 | table_definition, |
206 | 87 | template_table_definition, |
207 | 87 | error ) != 1 ) |
208 | 51 | { |
209 | 51 | libcerror_error_set( |
210 | 51 | error, |
211 | 51 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
212 | 51 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
213 | 51 | "%s: unable to create table page tree.", |
214 | 51 | function ); |
215 | | |
216 | 51 | goto on_error; |
217 | 51 | } |
218 | 36 | if( table_definition->long_value_catalog_definition != NULL ) |
219 | 22 | { |
220 | | /* TODO add clone function ? |
221 | | */ |
222 | 22 | if( libfdata_vector_initialize( |
223 | 22 | &( internal_table->long_values_pages_vector ), |
224 | 22 | (size64_t) io_handle->page_size, |
225 | 22 | (intptr_t *) io_handle, |
226 | 22 | NULL, |
227 | 22 | NULL, |
228 | 22 | (int (*)(intptr_t *, intptr_t *, libfdata_vector_t *, libfdata_cache_t *, int, int, off64_t, size64_t, uint32_t, uint8_t, libcerror_error_t **)) &libesedb_io_handle_read_page, |
229 | 22 | NULL, |
230 | 22 | LIBFDATA_DATA_HANDLE_FLAG_NON_MANAGED, |
231 | 22 | error ) != 1 ) |
232 | 0 | { |
233 | 0 | libcerror_error_set( |
234 | 0 | error, |
235 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
236 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
237 | 0 | "%s: unable to create long values pages vector.", |
238 | 0 | function ); |
239 | |
|
240 | 0 | goto on_error; |
241 | 0 | } |
242 | 22 | if( libfdata_vector_append_segment( |
243 | 22 | internal_table->long_values_pages_vector, |
244 | 22 | &segment_index, |
245 | 22 | 0, |
246 | 22 | io_handle->pages_data_offset, |
247 | 22 | io_handle->pages_data_size, |
248 | 22 | 0, |
249 | 22 | error ) != 1 ) |
250 | 0 | { |
251 | 0 | libcerror_error_set( |
252 | 0 | error, |
253 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
254 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
255 | 0 | "%s: unable to append segment to long values pages vector.", |
256 | 0 | function ); |
257 | |
|
258 | 0 | goto on_error; |
259 | 0 | } |
260 | 22 | if( libfcache_cache_initialize( |
261 | 22 | &( internal_table->long_values_pages_cache ), |
262 | 22 | LIBESEDB_MAXIMUM_CACHE_ENTRIES_PAGES, |
263 | 22 | error ) != 1 ) |
264 | 0 | { |
265 | 0 | libcerror_error_set( |
266 | 0 | error, |
267 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
268 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
269 | 0 | "%s: unable to create long values pages cache.", |
270 | 0 | function ); |
271 | |
|
272 | 0 | goto on_error; |
273 | 0 | } |
274 | 22 | if( libesedb_page_tree_initialize( |
275 | 22 | &( internal_table->long_values_page_tree ), |
276 | 22 | io_handle, |
277 | 22 | internal_table->long_values_pages_vector, |
278 | 22 | internal_table->long_values_pages_cache, |
279 | 22 | table_definition->long_value_catalog_definition->identifier, |
280 | 22 | table_definition->long_value_catalog_definition->father_data_page_number, |
281 | 22 | table_definition, |
282 | 22 | template_table_definition, |
283 | 22 | error ) != 1 ) |
284 | 15 | { |
285 | 15 | libcerror_error_set( |
286 | 15 | error, |
287 | 15 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
288 | 15 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
289 | 15 | "%s: unable to create long value page tree.", |
290 | 15 | function ); |
291 | | |
292 | 15 | goto on_error; |
293 | 15 | } |
294 | 22 | } |
295 | 21 | internal_table->io_handle = io_handle; |
296 | 21 | internal_table->file_io_handle = file_io_handle; |
297 | 21 | internal_table->table_definition = table_definition; |
298 | 21 | internal_table->template_table_definition = template_table_definition; |
299 | | |
300 | 21 | *table = (libesedb_table_t *) internal_table; |
301 | | |
302 | 21 | return( 1 ); |
303 | | |
304 | 66 | on_error: |
305 | 66 | if( internal_table != NULL ) |
306 | 66 | { |
307 | 66 | if( internal_table->long_values_pages_cache != NULL ) |
308 | 15 | { |
309 | 15 | libfcache_cache_free( |
310 | 15 | &( internal_table->long_values_pages_cache ), |
311 | 15 | NULL ); |
312 | 15 | } |
313 | 66 | if( internal_table->long_values_pages_vector != NULL ) |
314 | 15 | { |
315 | 15 | libfdata_vector_free( |
316 | 15 | &( internal_table->long_values_pages_vector ), |
317 | 15 | NULL ); |
318 | 15 | } |
319 | 66 | if( internal_table->long_values_page_tree != NULL ) |
320 | 0 | { |
321 | 0 | libesedb_page_tree_free( |
322 | 0 | &( internal_table->long_values_page_tree ), |
323 | 0 | NULL ); |
324 | 0 | } |
325 | 66 | if( internal_table->table_page_tree != NULL ) |
326 | 15 | { |
327 | 15 | libesedb_page_tree_free( |
328 | 15 | &( internal_table->table_page_tree ), |
329 | 15 | NULL ); |
330 | 15 | } |
331 | 66 | if( internal_table->pages_cache != NULL ) |
332 | 66 | { |
333 | 66 | libfcache_cache_free( |
334 | 66 | &( internal_table->pages_cache ), |
335 | 66 | NULL ); |
336 | 66 | } |
337 | 66 | if( internal_table->pages_vector != NULL ) |
338 | 66 | { |
339 | 66 | libfdata_vector_free( |
340 | 66 | &( internal_table->pages_vector ), |
341 | 66 | NULL ); |
342 | 66 | } |
343 | 66 | memory_free( |
344 | 66 | internal_table ); |
345 | 66 | } |
346 | 66 | return( -1 ); |
347 | 36 | } |
348 | | |
349 | | /* Frees a table |
350 | | * Returns 1 if successful or -1 on error |
351 | | */ |
352 | | int libesedb_table_free( |
353 | | libesedb_table_t **table, |
354 | | libcerror_error_t **error ) |
355 | 21 | { |
356 | 21 | libesedb_internal_table_t *internal_table = NULL; |
357 | 21 | static char *function = "libesedb_table_free"; |
358 | 21 | int result = 1; |
359 | | |
360 | 21 | if( table == NULL ) |
361 | 0 | { |
362 | 0 | libcerror_error_set( |
363 | 0 | error, |
364 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
365 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
366 | 0 | "%s: invalid table.", |
367 | 0 | function ); |
368 | |
|
369 | 0 | return( -1 ); |
370 | 0 | } |
371 | 21 | if( *table != NULL ) |
372 | 21 | { |
373 | 21 | internal_table = (libesedb_internal_table_t *) *table; |
374 | 21 | *table = NULL; |
375 | | |
376 | | /* The io_handle, file_io_handle and table_definition references |
377 | | * are freed elsewhere |
378 | | */ |
379 | 21 | if( libfdata_vector_free( |
380 | 21 | &( internal_table->pages_vector ), |
381 | 21 | error ) != 1 ) |
382 | 0 | { |
383 | 0 | libcerror_error_set( |
384 | 0 | error, |
385 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
386 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
387 | 0 | "%s: unable to free pages vector.", |
388 | 0 | function ); |
389 | |
|
390 | 0 | result = -1; |
391 | 0 | } |
392 | 21 | if( libfcache_cache_free( |
393 | 21 | &( internal_table->pages_cache ), |
394 | 21 | error ) != 1 ) |
395 | 0 | { |
396 | 0 | libcerror_error_set( |
397 | 0 | error, |
398 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
399 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
400 | 0 | "%s: unable to free pages cache.", |
401 | 0 | function ); |
402 | |
|
403 | 0 | result = -1; |
404 | 0 | } |
405 | 21 | if( internal_table->long_values_pages_vector != NULL ) |
406 | 7 | { |
407 | 7 | if( libfdata_vector_free( |
408 | 7 | &( internal_table->long_values_pages_vector ), |
409 | 7 | error ) != 1 ) |
410 | 0 | { |
411 | 0 | libcerror_error_set( |
412 | 0 | error, |
413 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
414 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
415 | 0 | "%s: unable to free long values pages vector.", |
416 | 0 | function ); |
417 | |
|
418 | 0 | result = -1; |
419 | 0 | } |
420 | 7 | } |
421 | 21 | if( internal_table->long_values_pages_cache != NULL ) |
422 | 7 | { |
423 | 7 | if( libfcache_cache_free( |
424 | 7 | &( internal_table->long_values_pages_cache ), |
425 | 7 | error ) != 1 ) |
426 | 0 | { |
427 | 0 | libcerror_error_set( |
428 | 0 | error, |
429 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
430 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
431 | 0 | "%s: unable to free long values pages cache.", |
432 | 0 | function ); |
433 | |
|
434 | 0 | result = -1; |
435 | 0 | } |
436 | 7 | } |
437 | 21 | if( internal_table->long_values_page_tree != NULL ) |
438 | 7 | { |
439 | 7 | if( libesedb_page_tree_free( |
440 | 7 | &( internal_table->long_values_page_tree ), |
441 | 7 | error ) != 1 ) |
442 | 0 | { |
443 | 0 | libcerror_error_set( |
444 | 0 | error, |
445 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
446 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
447 | 0 | "%s: unable to free long values page tree.", |
448 | 0 | function ); |
449 | |
|
450 | 0 | result = -1; |
451 | 0 | } |
452 | 7 | } |
453 | 21 | if( libesedb_page_tree_free( |
454 | 21 | &( internal_table->table_page_tree ), |
455 | 21 | error ) != 1 ) |
456 | 0 | { |
457 | 0 | libcerror_error_set( |
458 | 0 | error, |
459 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
460 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
461 | 0 | "%s: unable to free table page tree.", |
462 | 0 | function ); |
463 | |
|
464 | 0 | result = -1; |
465 | 0 | } |
466 | 21 | memory_free( |
467 | 21 | internal_table ); |
468 | 21 | } |
469 | 21 | return( result ); |
470 | 21 | } |
471 | | |
472 | | /* Retrieves the table identifier or Father Data Page (FDP) object identifier |
473 | | * Returns 1 if successful or -1 on error |
474 | | */ |
475 | | int libesedb_table_get_identifier( |
476 | | libesedb_table_t *table, |
477 | | uint32_t *identifier, |
478 | | libcerror_error_t **error ) |
479 | 0 | { |
480 | 0 | libesedb_internal_table_t *internal_table = NULL; |
481 | 0 | static char *function = "libesedb_table_get_identifier"; |
482 | |
|
483 | 0 | if( table == NULL ) |
484 | 0 | { |
485 | 0 | libcerror_error_set( |
486 | 0 | error, |
487 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
488 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
489 | 0 | "%s: invalid table.", |
490 | 0 | function ); |
491 | |
|
492 | 0 | return( -1 ); |
493 | 0 | } |
494 | 0 | internal_table = (libesedb_internal_table_t *) table; |
495 | |
|
496 | 0 | if( internal_table->table_definition == NULL ) |
497 | 0 | { |
498 | 0 | libcerror_error_set( |
499 | 0 | error, |
500 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
501 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
502 | 0 | "%s: invalid table - missing table definition.", |
503 | 0 | function ); |
504 | |
|
505 | 0 | return( -1 ); |
506 | 0 | } |
507 | 0 | if( libesedb_catalog_definition_get_identifier( |
508 | 0 | internal_table->table_definition->table_catalog_definition, |
509 | 0 | identifier, |
510 | 0 | error ) != 1 ) |
511 | 0 | { |
512 | 0 | libcerror_error_set( |
513 | 0 | error, |
514 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
515 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
516 | 0 | "%s: unable to retrieve catalog definition identifier.", |
517 | 0 | function ); |
518 | |
|
519 | 0 | return( -1 ); |
520 | 0 | } |
521 | 0 | return( 1 ); |
522 | 0 | } |
523 | | |
524 | | /* Retrieves the size of the UTF-8 encoded string of the table name |
525 | | * The returned size includes the end of string character |
526 | | * Returns 1 if successful or -1 on error |
527 | | */ |
528 | | int libesedb_table_get_utf8_name_size( |
529 | | libesedb_table_t *table, |
530 | | size_t *utf8_string_size, |
531 | | libcerror_error_t **error ) |
532 | 0 | { |
533 | 0 | libesedb_internal_table_t *internal_table = NULL; |
534 | 0 | static char *function = "libesedb_table_get_utf8_name_size"; |
535 | |
|
536 | 0 | if( table == NULL ) |
537 | 0 | { |
538 | 0 | libcerror_error_set( |
539 | 0 | error, |
540 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
541 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
542 | 0 | "%s: invalid table.", |
543 | 0 | function ); |
544 | |
|
545 | 0 | return( -1 ); |
546 | 0 | } |
547 | 0 | internal_table = (libesedb_internal_table_t *) table; |
548 | |
|
549 | 0 | if( internal_table->io_handle == NULL ) |
550 | 0 | { |
551 | 0 | libcerror_error_set( |
552 | 0 | error, |
553 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
554 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
555 | 0 | "%s: invalid table - missing IO handle.", |
556 | 0 | function ); |
557 | |
|
558 | 0 | return( -1 ); |
559 | 0 | } |
560 | 0 | if( internal_table->table_definition == NULL ) |
561 | 0 | { |
562 | 0 | libcerror_error_set( |
563 | 0 | error, |
564 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
565 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
566 | 0 | "%s: invalid table - missing table definition.", |
567 | 0 | function ); |
568 | |
|
569 | 0 | return( -1 ); |
570 | 0 | } |
571 | 0 | if( libesedb_catalog_definition_get_utf8_name_size( |
572 | 0 | internal_table->table_definition->table_catalog_definition, |
573 | 0 | utf8_string_size, |
574 | 0 | internal_table->io_handle->ascii_codepage, |
575 | 0 | error ) != 1 ) |
576 | 0 | { |
577 | 0 | libcerror_error_set( |
578 | 0 | error, |
579 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
580 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
581 | 0 | "%s: unable to retrieve UTF-8 string size.", |
582 | 0 | function ); |
583 | |
|
584 | 0 | return( -1 ); |
585 | 0 | } |
586 | 0 | return( 1 ); |
587 | 0 | } |
588 | | |
589 | | /* Retrieves the UTF-8 encoded string of the table name |
590 | | * The size should include the end of string character |
591 | | * Returns 1 if successful or -1 on error |
592 | | */ |
593 | | int libesedb_table_get_utf8_name( |
594 | | libesedb_table_t *table, |
595 | | uint8_t *utf8_string, |
596 | | size_t utf8_string_size, |
597 | | libcerror_error_t **error ) |
598 | 0 | { |
599 | 0 | libesedb_internal_table_t *internal_table = NULL; |
600 | 0 | static char *function = "libesedb_table_get_utf8_name"; |
601 | |
|
602 | 0 | if( table == NULL ) |
603 | 0 | { |
604 | 0 | libcerror_error_set( |
605 | 0 | error, |
606 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
607 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
608 | 0 | "%s: invalid table.", |
609 | 0 | function ); |
610 | |
|
611 | 0 | return( -1 ); |
612 | 0 | } |
613 | 0 | internal_table = (libesedb_internal_table_t *) table; |
614 | |
|
615 | 0 | if( internal_table->io_handle == NULL ) |
616 | 0 | { |
617 | 0 | libcerror_error_set( |
618 | 0 | error, |
619 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
620 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
621 | 0 | "%s: invalid table - missing IO handle.", |
622 | 0 | function ); |
623 | |
|
624 | 0 | return( -1 ); |
625 | 0 | } |
626 | 0 | if( internal_table->table_definition == NULL ) |
627 | 0 | { |
628 | 0 | libcerror_error_set( |
629 | 0 | error, |
630 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
631 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
632 | 0 | "%s: invalid table - missing table definition.", |
633 | 0 | function ); |
634 | |
|
635 | 0 | return( -1 ); |
636 | 0 | } |
637 | 0 | if( libesedb_catalog_definition_get_utf8_name( |
638 | 0 | internal_table->table_definition->table_catalog_definition, |
639 | 0 | utf8_string, |
640 | 0 | utf8_string_size, |
641 | 0 | internal_table->io_handle->ascii_codepage, |
642 | 0 | error ) != 1 ) |
643 | 0 | { |
644 | 0 | libcerror_error_set( |
645 | 0 | error, |
646 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
647 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
648 | 0 | "%s: unable to retrieve UTF-8 string.", |
649 | 0 | function ); |
650 | |
|
651 | 0 | return( -1 ); |
652 | 0 | } |
653 | 0 | return( 1 ); |
654 | 0 | } |
655 | | |
656 | | /* Retrieves the size of the UTF-16 encoded string of the table name |
657 | | * The returned size includes the end of string character |
658 | | * Returns 1 if successful or -1 on error |
659 | | */ |
660 | | int libesedb_table_get_utf16_name_size( |
661 | | libesedb_table_t *table, |
662 | | size_t *utf16_string_size, |
663 | | libcerror_error_t **error ) |
664 | 0 | { |
665 | 0 | libesedb_internal_table_t *internal_table = NULL; |
666 | 0 | static char *function = "libesedb_table_get_utf16_name_size"; |
667 | |
|
668 | 0 | if( table == 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 table.", |
675 | 0 | function ); |
676 | |
|
677 | 0 | return( -1 ); |
678 | 0 | } |
679 | 0 | internal_table = (libesedb_internal_table_t *) table; |
680 | |
|
681 | 0 | if( internal_table->io_handle == NULL ) |
682 | 0 | { |
683 | 0 | libcerror_error_set( |
684 | 0 | error, |
685 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
686 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
687 | 0 | "%s: invalid table - missing IO handle.", |
688 | 0 | function ); |
689 | |
|
690 | 0 | return( -1 ); |
691 | 0 | } |
692 | 0 | if( internal_table->table_definition == NULL ) |
693 | 0 | { |
694 | 0 | libcerror_error_set( |
695 | 0 | error, |
696 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
697 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
698 | 0 | "%s: invalid table - missing table definition.", |
699 | 0 | function ); |
700 | |
|
701 | 0 | return( -1 ); |
702 | 0 | } |
703 | 0 | if( libesedb_catalog_definition_get_utf16_name_size( |
704 | 0 | internal_table->table_definition->table_catalog_definition, |
705 | 0 | utf16_string_size, |
706 | 0 | internal_table->io_handle->ascii_codepage, |
707 | 0 | error ) != 1 ) |
708 | 0 | { |
709 | 0 | libcerror_error_set( |
710 | 0 | error, |
711 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
712 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
713 | 0 | "%s: unable to retrieve UTF-16 string size.", |
714 | 0 | function ); |
715 | |
|
716 | 0 | return( -1 ); |
717 | 0 | } |
718 | 0 | return( 1 ); |
719 | 0 | } |
720 | | |
721 | | /* Retrieves the UTF-16 encoded string of the table name |
722 | | * The size should include the end of string character |
723 | | * Returns 1 if successful or -1 on error |
724 | | */ |
725 | | int libesedb_table_get_utf16_name( |
726 | | libesedb_table_t *table, |
727 | | uint16_t *utf16_string, |
728 | | size_t utf16_string_size, |
729 | | libcerror_error_t **error ) |
730 | 0 | { |
731 | 0 | libesedb_internal_table_t *internal_table = NULL; |
732 | 0 | static char *function = "libesedb_table_get_utf16_name"; |
733 | |
|
734 | 0 | if( table == NULL ) |
735 | 0 | { |
736 | 0 | libcerror_error_set( |
737 | 0 | error, |
738 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
739 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
740 | 0 | "%s: invalid table.", |
741 | 0 | function ); |
742 | |
|
743 | 0 | return( -1 ); |
744 | 0 | } |
745 | 0 | internal_table = (libesedb_internal_table_t *) table; |
746 | |
|
747 | 0 | if( internal_table->io_handle == NULL ) |
748 | 0 | { |
749 | 0 | libcerror_error_set( |
750 | 0 | error, |
751 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
752 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
753 | 0 | "%s: invalid table - missing IO handle.", |
754 | 0 | function ); |
755 | |
|
756 | 0 | return( -1 ); |
757 | 0 | } |
758 | 0 | if( internal_table->table_definition == NULL ) |
759 | 0 | { |
760 | 0 | libcerror_error_set( |
761 | 0 | error, |
762 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
763 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
764 | 0 | "%s: invalid table - missing table definition.", |
765 | 0 | function ); |
766 | |
|
767 | 0 | return( -1 ); |
768 | 0 | } |
769 | 0 | if( libesedb_catalog_definition_get_utf16_name( |
770 | 0 | internal_table->table_definition->table_catalog_definition, |
771 | 0 | utf16_string, |
772 | 0 | utf16_string_size, |
773 | 0 | internal_table->io_handle->ascii_codepage, |
774 | 0 | error ) != 1 ) |
775 | 0 | { |
776 | 0 | libcerror_error_set( |
777 | 0 | error, |
778 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
779 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
780 | 0 | "%s: unable to retrieve UTF-16 string.", |
781 | 0 | function ); |
782 | |
|
783 | 0 | return( -1 ); |
784 | 0 | } |
785 | 0 | return( 1 ); |
786 | 0 | } |
787 | | |
788 | | /* Retrieves the size of the UTF-8 encoded string of the template name |
789 | | * The returned size includes the end of string character |
790 | | * Returns 1 if successful or -1 on error |
791 | | */ |
792 | | int libesedb_table_get_utf8_template_name_size( |
793 | | libesedb_table_t *table, |
794 | | size_t *utf8_string_size, |
795 | | libcerror_error_t **error ) |
796 | 0 | { |
797 | 0 | libesedb_internal_table_t *internal_table = NULL; |
798 | 0 | static char *function = "libesedb_table_get_utf8_template_name_size"; |
799 | |
|
800 | 0 | if( table == NULL ) |
801 | 0 | { |
802 | 0 | libcerror_error_set( |
803 | 0 | error, |
804 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
805 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
806 | 0 | "%s: invalid table.", |
807 | 0 | function ); |
808 | |
|
809 | 0 | return( -1 ); |
810 | 0 | } |
811 | 0 | internal_table = (libesedb_internal_table_t *) table; |
812 | |
|
813 | 0 | if( internal_table->io_handle == NULL ) |
814 | 0 | { |
815 | 0 | libcerror_error_set( |
816 | 0 | error, |
817 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
818 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
819 | 0 | "%s: invalid table - missing IO handle.", |
820 | 0 | function ); |
821 | |
|
822 | 0 | return( -1 ); |
823 | 0 | } |
824 | 0 | if( internal_table->table_definition == NULL ) |
825 | 0 | { |
826 | 0 | libcerror_error_set( |
827 | 0 | error, |
828 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
829 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
830 | 0 | "%s: invalid table - missing table definition.", |
831 | 0 | function ); |
832 | |
|
833 | 0 | return( -1 ); |
834 | 0 | } |
835 | 0 | if( libesedb_catalog_definition_get_utf8_template_name_size( |
836 | 0 | internal_table->table_definition->table_catalog_definition, |
837 | 0 | utf8_string_size, |
838 | 0 | internal_table->io_handle->ascii_codepage, |
839 | 0 | error ) != 1 ) |
840 | 0 | { |
841 | 0 | libcerror_error_set( |
842 | 0 | error, |
843 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
844 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
845 | 0 | "%s: unable to retrieve UTF-8 string size.", |
846 | 0 | function ); |
847 | |
|
848 | 0 | return( -1 ); |
849 | 0 | } |
850 | 0 | return( 1 ); |
851 | 0 | } |
852 | | |
853 | | /* Retrieves the UTF-8 encoded string of the template name |
854 | | * The size should include the end of string character |
855 | | * Returns 1 if successful or -1 on error |
856 | | */ |
857 | | int libesedb_table_get_utf8_template_name( |
858 | | libesedb_table_t *table, |
859 | | uint8_t *utf8_string, |
860 | | size_t utf8_string_size, |
861 | | libcerror_error_t **error ) |
862 | 0 | { |
863 | 0 | libesedb_internal_table_t *internal_table = NULL; |
864 | 0 | static char *function = "libesedb_table_get_utf8_template_name"; |
865 | |
|
866 | 0 | if( table == NULL ) |
867 | 0 | { |
868 | 0 | libcerror_error_set( |
869 | 0 | error, |
870 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
871 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
872 | 0 | "%s: invalid table.", |
873 | 0 | function ); |
874 | |
|
875 | 0 | return( -1 ); |
876 | 0 | } |
877 | 0 | internal_table = (libesedb_internal_table_t *) table; |
878 | |
|
879 | 0 | if( internal_table->io_handle == NULL ) |
880 | 0 | { |
881 | 0 | libcerror_error_set( |
882 | 0 | error, |
883 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
884 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
885 | 0 | "%s: invalid table - missing IO handle.", |
886 | 0 | function ); |
887 | |
|
888 | 0 | return( -1 ); |
889 | 0 | } |
890 | 0 | if( internal_table->table_definition == NULL ) |
891 | 0 | { |
892 | 0 | libcerror_error_set( |
893 | 0 | error, |
894 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
895 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
896 | 0 | "%s: invalid table - missing table definition.", |
897 | 0 | function ); |
898 | |
|
899 | 0 | return( -1 ); |
900 | 0 | } |
901 | 0 | if( libesedb_catalog_definition_get_utf8_template_name( |
902 | 0 | internal_table->table_definition->table_catalog_definition, |
903 | 0 | utf8_string, |
904 | 0 | utf8_string_size, |
905 | 0 | internal_table->io_handle->ascii_codepage, |
906 | 0 | error ) != 1 ) |
907 | 0 | { |
908 | 0 | libcerror_error_set( |
909 | 0 | error, |
910 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
911 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
912 | 0 | "%s: unable to retrieve UTF-8 string.", |
913 | 0 | function ); |
914 | |
|
915 | 0 | return( -1 ); |
916 | 0 | } |
917 | 0 | return( 1 ); |
918 | 0 | } |
919 | | |
920 | | /* Retrieves the size of the UTF-16 encoded string of the template name |
921 | | * The returned size includes the end of string character |
922 | | * Returns 1 if successful or -1 on error |
923 | | */ |
924 | | int libesedb_table_get_utf16_template_name_size( |
925 | | libesedb_table_t *table, |
926 | | size_t *utf16_string_size, |
927 | | libcerror_error_t **error ) |
928 | 0 | { |
929 | 0 | libesedb_internal_table_t *internal_table = NULL; |
930 | 0 | static char *function = "libesedb_table_get_utf16_template_name_size"; |
931 | |
|
932 | 0 | if( table == NULL ) |
933 | 0 | { |
934 | 0 | libcerror_error_set( |
935 | 0 | error, |
936 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
937 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
938 | 0 | "%s: invalid table.", |
939 | 0 | function ); |
940 | |
|
941 | 0 | return( -1 ); |
942 | 0 | } |
943 | 0 | internal_table = (libesedb_internal_table_t *) table; |
944 | |
|
945 | 0 | if( internal_table->io_handle == NULL ) |
946 | 0 | { |
947 | 0 | libcerror_error_set( |
948 | 0 | error, |
949 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
950 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
951 | 0 | "%s: invalid table - missing IO handle.", |
952 | 0 | function ); |
953 | |
|
954 | 0 | return( -1 ); |
955 | 0 | } |
956 | 0 | if( internal_table->table_definition == NULL ) |
957 | 0 | { |
958 | 0 | libcerror_error_set( |
959 | 0 | error, |
960 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
961 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
962 | 0 | "%s: invalid table - missing table definition.", |
963 | 0 | function ); |
964 | |
|
965 | 0 | return( -1 ); |
966 | 0 | } |
967 | 0 | if( libesedb_catalog_definition_get_utf16_template_name_size( |
968 | 0 | internal_table->table_definition->table_catalog_definition, |
969 | 0 | utf16_string_size, |
970 | 0 | internal_table->io_handle->ascii_codepage, |
971 | 0 | error ) != 1 ) |
972 | 0 | { |
973 | 0 | libcerror_error_set( |
974 | 0 | error, |
975 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
976 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
977 | 0 | "%s: unable to retrieve UTF-16 string size.", |
978 | 0 | function ); |
979 | |
|
980 | 0 | return( -1 ); |
981 | 0 | } |
982 | 0 | return( 1 ); |
983 | 0 | } |
984 | | |
985 | | /* Retrieves the UTF-16 encoded string of the template name |
986 | | * The size should include the end of string character |
987 | | * Returns 1 if successful or -1 on error |
988 | | */ |
989 | | int libesedb_table_get_utf16_template_name( |
990 | | libesedb_table_t *table, |
991 | | uint16_t *utf16_string, |
992 | | size_t utf16_string_size, |
993 | | libcerror_error_t **error ) |
994 | 0 | { |
995 | 0 | libesedb_internal_table_t *internal_table = NULL; |
996 | 0 | static char *function = "libesedb_table_get_utf16_template_name"; |
997 | |
|
998 | 0 | if( table == NULL ) |
999 | 0 | { |
1000 | 0 | libcerror_error_set( |
1001 | 0 | error, |
1002 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1003 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1004 | 0 | "%s: invalid table.", |
1005 | 0 | function ); |
1006 | |
|
1007 | 0 | return( -1 ); |
1008 | 0 | } |
1009 | 0 | internal_table = (libesedb_internal_table_t *) table; |
1010 | |
|
1011 | 0 | if( internal_table->io_handle == NULL ) |
1012 | 0 | { |
1013 | 0 | libcerror_error_set( |
1014 | 0 | error, |
1015 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1016 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1017 | 0 | "%s: invalid table - missing IO handle.", |
1018 | 0 | function ); |
1019 | |
|
1020 | 0 | return( -1 ); |
1021 | 0 | } |
1022 | 0 | if( internal_table->table_definition == NULL ) |
1023 | 0 | { |
1024 | 0 | libcerror_error_set( |
1025 | 0 | error, |
1026 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1027 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1028 | 0 | "%s: invalid table - missing table definition.", |
1029 | 0 | function ); |
1030 | |
|
1031 | 0 | return( -1 ); |
1032 | 0 | } |
1033 | 0 | if( libesedb_catalog_definition_get_utf16_template_name( |
1034 | 0 | internal_table->table_definition->table_catalog_definition, |
1035 | 0 | utf16_string, |
1036 | 0 | utf16_string_size, |
1037 | 0 | internal_table->io_handle->ascii_codepage, |
1038 | 0 | error ) != 1 ) |
1039 | 0 | { |
1040 | 0 | libcerror_error_set( |
1041 | 0 | error, |
1042 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1043 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1044 | 0 | "%s: unable to retrieve UTF-16 string.", |
1045 | 0 | function ); |
1046 | |
|
1047 | 0 | return( -1 ); |
1048 | 0 | } |
1049 | 0 | return( 1 ); |
1050 | 0 | } |
1051 | | |
1052 | | /* Retrieves the number of columns in the table |
1053 | | * |
1054 | | * Use the flag LIBESEDB_GET_COLUMN_FLAG_IGNORE_TEMPLATE_TABLE to retrieve the number of columns |
1055 | | * ignoring the template table |
1056 | | * |
1057 | | * Returns 1 if successful or -1 on error |
1058 | | */ |
1059 | | int libesedb_table_get_number_of_columns( |
1060 | | libesedb_table_t *table, |
1061 | | int *number_of_columns, |
1062 | | uint8_t flags, |
1063 | | libcerror_error_t **error ) |
1064 | 14 | { |
1065 | 14 | libesedb_internal_table_t *internal_table = NULL; |
1066 | 14 | static char *function = "libesedb_table_get_number_of_columns"; |
1067 | 14 | int template_table_number_of_columns = 0; |
1068 | | |
1069 | 14 | if( table == NULL ) |
1070 | 0 | { |
1071 | 0 | libcerror_error_set( |
1072 | 0 | error, |
1073 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1074 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1075 | 0 | "%s: invalid table.", |
1076 | 0 | function ); |
1077 | |
|
1078 | 0 | return( -1 ); |
1079 | 0 | } |
1080 | 14 | internal_table = (libesedb_internal_table_t *) table; |
1081 | | |
1082 | 14 | if( number_of_columns == NULL ) |
1083 | 0 | { |
1084 | 0 | libcerror_error_set( |
1085 | 0 | error, |
1086 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1087 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1088 | 0 | "%s: invalid number of columns.", |
1089 | 0 | function ); |
1090 | |
|
1091 | 0 | return( -1 ); |
1092 | 0 | } |
1093 | 14 | if( ( flags & ~( LIBESEDB_GET_COLUMN_FLAG_IGNORE_TEMPLATE_TABLE ) ) != 0 ) |
1094 | 0 | { |
1095 | 0 | libcerror_error_set( |
1096 | 0 | error, |
1097 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1098 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1099 | 0 | "%s: unsupported flags.", |
1100 | 0 | function ); |
1101 | |
|
1102 | 0 | return( -1 ); |
1103 | 0 | } |
1104 | 14 | if( ( ( flags & LIBESEDB_GET_COLUMN_FLAG_IGNORE_TEMPLATE_TABLE ) == 0 ) |
1105 | 14 | && ( internal_table->template_table_definition != NULL ) ) |
1106 | 1 | { |
1107 | 1 | if( libesedb_table_definition_get_number_of_column_catalog_definitions( |
1108 | 1 | internal_table->template_table_definition, |
1109 | 1 | &template_table_number_of_columns, |
1110 | 1 | error ) != 1 ) |
1111 | 0 | { |
1112 | 0 | libcerror_error_set( |
1113 | 0 | error, |
1114 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1115 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1116 | 0 | "%s: unable to retrieve number of columns from template table.", |
1117 | 0 | function ); |
1118 | |
|
1119 | 0 | return( -1 ); |
1120 | 0 | } |
1121 | 1 | } |
1122 | 14 | if( libesedb_table_definition_get_number_of_column_catalog_definitions( |
1123 | 14 | internal_table->table_definition, |
1124 | 14 | number_of_columns, |
1125 | 14 | error ) != 1 ) |
1126 | 0 | { |
1127 | 0 | libcerror_error_set( |
1128 | 0 | error, |
1129 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1130 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1131 | 0 | "%s: unable to retrieve number of columns from table.", |
1132 | 0 | function ); |
1133 | |
|
1134 | 0 | return( -1 ); |
1135 | 0 | } |
1136 | 14 | *number_of_columns += template_table_number_of_columns; |
1137 | | |
1138 | 14 | return( 1 ); |
1139 | 14 | } |
1140 | | |
1141 | | /* Retrieves a specific column |
1142 | | * |
1143 | | * Use the flag LIBESEDB_GET_COLUMN_FLAG_IGNORE_TEMPLATE_TABLE to retrieve the column |
1144 | | * ignoring the template table |
1145 | | * |
1146 | | * Returns 1 if successful or -1 on error |
1147 | | */ |
1148 | | int libesedb_table_get_column( |
1149 | | libesedb_table_t *table, |
1150 | | int column_entry, |
1151 | | libesedb_column_t **column, |
1152 | | uint8_t flags, |
1153 | | libcerror_error_t **error ) |
1154 | 9 | { |
1155 | 9 | libesedb_catalog_definition_t *column_catalog_definition = NULL; |
1156 | 9 | libesedb_internal_table_t *internal_table = NULL; |
1157 | 9 | static char *function = "libesedb_table_get_column"; |
1158 | 9 | int template_table_number_of_columns = 0; |
1159 | | |
1160 | 9 | if( table == NULL ) |
1161 | 0 | { |
1162 | 0 | libcerror_error_set( |
1163 | 0 | error, |
1164 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1165 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1166 | 0 | "%s: invalid table.", |
1167 | 0 | function ); |
1168 | |
|
1169 | 0 | return( -1 ); |
1170 | 0 | } |
1171 | 9 | internal_table = (libesedb_internal_table_t *) table; |
1172 | | |
1173 | 9 | if( column == NULL ) |
1174 | 0 | { |
1175 | 0 | libcerror_error_set( |
1176 | 0 | error, |
1177 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1178 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1179 | 0 | "%s: invalid column.", |
1180 | 0 | function ); |
1181 | |
|
1182 | 0 | return( -1 ); |
1183 | 0 | } |
1184 | 9 | if( *column != NULL ) |
1185 | 0 | { |
1186 | 0 | libcerror_error_set( |
1187 | 0 | error, |
1188 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1189 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1190 | 0 | "%s: invalid column value already set.", |
1191 | 0 | function ); |
1192 | |
|
1193 | 0 | return( -1 ); |
1194 | 0 | } |
1195 | 9 | if( ( flags & ~( LIBESEDB_GET_COLUMN_FLAG_IGNORE_TEMPLATE_TABLE ) ) != 0 ) |
1196 | 0 | { |
1197 | 0 | libcerror_error_set( |
1198 | 0 | error, |
1199 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1200 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1201 | 0 | "%s: unsupported flags.", |
1202 | 0 | function ); |
1203 | |
|
1204 | 0 | return( -1 ); |
1205 | 0 | } |
1206 | 9 | if( ( flags & LIBESEDB_GET_COLUMN_FLAG_IGNORE_TEMPLATE_TABLE ) == 0 ) |
1207 | 9 | { |
1208 | 9 | if( internal_table->template_table_definition != NULL ) |
1209 | 0 | { |
1210 | 0 | if( libesedb_table_definition_get_number_of_column_catalog_definitions( |
1211 | 0 | internal_table->template_table_definition, |
1212 | 0 | &template_table_number_of_columns, |
1213 | 0 | error ) != 1 ) |
1214 | 0 | { |
1215 | 0 | libcerror_error_set( |
1216 | 0 | error, |
1217 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1218 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1219 | 0 | "%s: unable to retrieve number of columns from template table.", |
1220 | 0 | function ); |
1221 | |
|
1222 | 0 | return( -1 ); |
1223 | 0 | } |
1224 | 0 | } |
1225 | 9 | } |
1226 | 9 | if( column_entry < template_table_number_of_columns ) |
1227 | 0 | { |
1228 | 0 | if( libesedb_table_definition_get_column_catalog_definition_by_index( |
1229 | 0 | internal_table->template_table_definition, |
1230 | 0 | column_entry, |
1231 | 0 | &column_catalog_definition, |
1232 | 0 | error ) != 1 ) |
1233 | 0 | { |
1234 | 0 | libcerror_error_set( |
1235 | 0 | error, |
1236 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1237 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1238 | 0 | "%s: unable to retrieve column catalog definition from template table.", |
1239 | 0 | function ); |
1240 | |
|
1241 | 0 | return( -1 ); |
1242 | 0 | } |
1243 | 0 | } |
1244 | 9 | else |
1245 | 9 | { |
1246 | 9 | if( libesedb_table_definition_get_column_catalog_definition_by_index( |
1247 | 9 | internal_table->table_definition, |
1248 | 9 | column_entry - template_table_number_of_columns, |
1249 | 9 | &column_catalog_definition, |
1250 | 9 | error ) != 1 ) |
1251 | 0 | { |
1252 | 0 | libcerror_error_set( |
1253 | 0 | error, |
1254 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1255 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1256 | 0 | "%s: unable to retrieve column catalog definition from table.", |
1257 | 0 | function ); |
1258 | |
|
1259 | 0 | return( -1 ); |
1260 | 0 | } |
1261 | 9 | } |
1262 | 9 | if( column_catalog_definition == NULL ) |
1263 | 0 | { |
1264 | 0 | libcerror_error_set( |
1265 | 0 | error, |
1266 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1267 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1268 | 0 | "%s: missing column catalog definition.", |
1269 | 0 | function ); |
1270 | |
|
1271 | 0 | return( -1 ); |
1272 | 0 | } |
1273 | 9 | if( libesedb_column_initialize( |
1274 | 9 | column, |
1275 | 9 | internal_table->io_handle, |
1276 | 9 | column_catalog_definition, |
1277 | 9 | error ) != 1 ) |
1278 | 0 | { |
1279 | 0 | libcerror_error_set( |
1280 | 0 | error, |
1281 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1282 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1283 | 0 | "%s: unable to create column.", |
1284 | 0 | function ); |
1285 | |
|
1286 | 0 | return( -1 ); |
1287 | 0 | } |
1288 | 9 | return( 1 ); |
1289 | 9 | } |
1290 | | |
1291 | | /* Retrieves the number of indexes |
1292 | | * Returns 1 if successful or -1 on error |
1293 | | */ |
1294 | | int libesedb_table_get_number_of_indexes( |
1295 | | libesedb_table_t *table, |
1296 | | int *number_of_indexes, |
1297 | | libcerror_error_t **error ) |
1298 | 0 | { |
1299 | 0 | libesedb_internal_table_t *internal_table = NULL; |
1300 | 0 | static char *function = "libesedb_table_get_number_of_indexes"; |
1301 | |
|
1302 | 0 | if( table == NULL ) |
1303 | 0 | { |
1304 | 0 | libcerror_error_set( |
1305 | 0 | error, |
1306 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1307 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1308 | 0 | "%s: invalid table.", |
1309 | 0 | function ); |
1310 | |
|
1311 | 0 | return( -1 ); |
1312 | 0 | } |
1313 | 0 | internal_table = (libesedb_internal_table_t *) table; |
1314 | |
|
1315 | 0 | if( libesedb_table_definition_get_number_of_index_catalog_definitions( |
1316 | 0 | internal_table->table_definition, |
1317 | 0 | number_of_indexes, |
1318 | 0 | error ) != 1 ) |
1319 | 0 | { |
1320 | 0 | libcerror_error_set( |
1321 | 0 | error, |
1322 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1323 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1324 | 0 | "%s: unable to retrieve number of indexes.", |
1325 | 0 | function ); |
1326 | |
|
1327 | 0 | return( -1 ); |
1328 | 0 | } |
1329 | 0 | return( 1 ); |
1330 | 0 | } |
1331 | | |
1332 | | /* Retrieves a specific index |
1333 | | * Returns 1 if successful or -1 on error |
1334 | | */ |
1335 | | int libesedb_table_get_index( |
1336 | | libesedb_table_t *table, |
1337 | | int index_entry, |
1338 | | libesedb_index_t **index, |
1339 | | libcerror_error_t **error ) |
1340 | 0 | { |
1341 | 0 | libesedb_internal_table_t *internal_table = NULL; |
1342 | 0 | libesedb_catalog_definition_t *index_catalog_definition = NULL; |
1343 | 0 | static char *function = "libesedb_table_get_index"; |
1344 | |
|
1345 | 0 | if( table == NULL ) |
1346 | 0 | { |
1347 | 0 | libcerror_error_set( |
1348 | 0 | error, |
1349 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1350 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1351 | 0 | "%s: invalid table.", |
1352 | 0 | function ); |
1353 | |
|
1354 | 0 | return( -1 ); |
1355 | 0 | } |
1356 | 0 | internal_table = (libesedb_internal_table_t *) table; |
1357 | |
|
1358 | 0 | if( index == NULL ) |
1359 | 0 | { |
1360 | 0 | libcerror_error_set( |
1361 | 0 | error, |
1362 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1363 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1364 | 0 | "%s: invalid index.", |
1365 | 0 | function ); |
1366 | |
|
1367 | 0 | return( -1 ); |
1368 | 0 | } |
1369 | 0 | if( *index != NULL ) |
1370 | 0 | { |
1371 | 0 | libcerror_error_set( |
1372 | 0 | error, |
1373 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1374 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1375 | 0 | "%s: invalid index value already set.", |
1376 | 0 | function ); |
1377 | |
|
1378 | 0 | return( -1 ); |
1379 | 0 | } |
1380 | 0 | if( libesedb_table_definition_get_index_catalog_definition_by_index( |
1381 | 0 | internal_table->table_definition, |
1382 | 0 | index_entry, |
1383 | 0 | &index_catalog_definition, |
1384 | 0 | error ) != 1 ) |
1385 | 0 | { |
1386 | 0 | libcerror_error_set( |
1387 | 0 | error, |
1388 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1389 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1390 | 0 | "%s: unable to retrieve index catalog definition.", |
1391 | 0 | function ); |
1392 | |
|
1393 | 0 | return( -1 ); |
1394 | 0 | } |
1395 | 0 | if( libesedb_index_initialize( |
1396 | 0 | index, |
1397 | 0 | internal_table->file_io_handle, |
1398 | 0 | internal_table->io_handle, |
1399 | 0 | internal_table->table_definition, |
1400 | 0 | internal_table->template_table_definition, |
1401 | 0 | index_catalog_definition, |
1402 | 0 | internal_table->pages_vector, |
1403 | 0 | internal_table->pages_cache, |
1404 | 0 | internal_table->long_values_pages_vector, |
1405 | 0 | internal_table->long_values_pages_cache, |
1406 | 0 | internal_table->table_page_tree, |
1407 | 0 | internal_table->long_values_page_tree, |
1408 | 0 | error ) != 1 ) |
1409 | 0 | { |
1410 | 0 | libcerror_error_set( |
1411 | 0 | error, |
1412 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1413 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1414 | 0 | "%s: unable to create index.", |
1415 | 0 | function ); |
1416 | |
|
1417 | 0 | return( -1 ); |
1418 | 0 | } |
1419 | 0 | return( 1 ); |
1420 | 0 | } |
1421 | | |
1422 | | /* Retrieves the number of records in the table |
1423 | | * Returns 1 if successful or -1 on error |
1424 | | */ |
1425 | | int libesedb_table_get_number_of_records( |
1426 | | libesedb_table_t *table, |
1427 | | int *number_of_records, |
1428 | | libcerror_error_t **error ) |
1429 | 0 | { |
1430 | 0 | libesedb_internal_table_t *internal_table = NULL; |
1431 | 0 | static char *function = "libesedb_table_get_number_of_records"; |
1432 | |
|
1433 | 0 | if( table == NULL ) |
1434 | 0 | { |
1435 | 0 | libcerror_error_set( |
1436 | 0 | error, |
1437 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1438 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1439 | 0 | "%s: invalid table.", |
1440 | 0 | function ); |
1441 | |
|
1442 | 0 | return( -1 ); |
1443 | 0 | } |
1444 | 0 | internal_table = (libesedb_internal_table_t *) table; |
1445 | |
|
1446 | 0 | if( libesedb_page_tree_get_number_of_leaf_values( |
1447 | 0 | internal_table->table_page_tree, |
1448 | 0 | internal_table->file_io_handle, |
1449 | 0 | number_of_records, |
1450 | 0 | error ) != 1 ) |
1451 | 0 | { |
1452 | 0 | libcerror_error_set( |
1453 | 0 | error, |
1454 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1455 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1456 | 0 | "%s: unable to retrieve number of leaf values from table page tree.", |
1457 | 0 | function ); |
1458 | |
|
1459 | 0 | return( -1 ); |
1460 | 0 | } |
1461 | 0 | return( 1 ); |
1462 | 0 | } |
1463 | | |
1464 | | /* Retrieves a specific record |
1465 | | * Returns 1 if successful or -1 on error |
1466 | | */ |
1467 | | int libesedb_table_get_record( |
1468 | | libesedb_table_t *table, |
1469 | | int record_entry, |
1470 | | libesedb_record_t **record, |
1471 | | libcerror_error_t **error ) |
1472 | 0 | { |
1473 | 0 | libesedb_data_definition_t *record_data_definition = NULL; |
1474 | 0 | libesedb_internal_table_t *internal_table = NULL; |
1475 | 0 | static char *function = "libesedb_table_get_record"; |
1476 | |
|
1477 | 0 | if( table == NULL ) |
1478 | 0 | { |
1479 | 0 | libcerror_error_set( |
1480 | 0 | error, |
1481 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1482 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1483 | 0 | "%s: invalid table.", |
1484 | 0 | function ); |
1485 | |
|
1486 | 0 | return( -1 ); |
1487 | 0 | } |
1488 | 0 | internal_table = (libesedb_internal_table_t *) table; |
1489 | |
|
1490 | 0 | if( record == NULL ) |
1491 | 0 | { |
1492 | 0 | libcerror_error_set( |
1493 | 0 | error, |
1494 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1495 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1496 | 0 | "%s: invalid record.", |
1497 | 0 | function ); |
1498 | |
|
1499 | 0 | return( -1 ); |
1500 | 0 | } |
1501 | 0 | if( *record != NULL ) |
1502 | 0 | { |
1503 | 0 | libcerror_error_set( |
1504 | 0 | error, |
1505 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1506 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1507 | 0 | "%s: invalid record value already set.", |
1508 | 0 | function ); |
1509 | |
|
1510 | 0 | return( -1 ); |
1511 | 0 | } |
1512 | 0 | if( libesedb_page_tree_get_leaf_value_by_index( |
1513 | 0 | internal_table->table_page_tree, |
1514 | 0 | internal_table->file_io_handle, |
1515 | 0 | record_entry, |
1516 | 0 | &record_data_definition, |
1517 | 0 | error ) != 1 ) |
1518 | 0 | { |
1519 | 0 | libcerror_error_set( |
1520 | 0 | error, |
1521 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1522 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1523 | 0 | "%s: unable to retrieve leaf value: %d from table values tree.", |
1524 | 0 | function, |
1525 | 0 | record_entry ); |
1526 | |
|
1527 | 0 | goto on_error; |
1528 | 0 | } |
1529 | 0 | if( libesedb_record_initialize( |
1530 | 0 | record, |
1531 | 0 | internal_table->file_io_handle, |
1532 | 0 | internal_table->io_handle, |
1533 | 0 | internal_table->table_definition, |
1534 | 0 | internal_table->template_table_definition, |
1535 | 0 | internal_table->pages_vector, |
1536 | 0 | internal_table->pages_cache, |
1537 | 0 | internal_table->long_values_pages_vector, |
1538 | 0 | internal_table->long_values_pages_cache, |
1539 | 0 | record_data_definition, |
1540 | 0 | internal_table->long_values_page_tree, |
1541 | 0 | error ) != 1 ) |
1542 | 0 | { |
1543 | 0 | libcerror_error_set( |
1544 | 0 | error, |
1545 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1546 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1547 | 0 | "%s: unable to create record: %d.", |
1548 | 0 | function, |
1549 | 0 | record_entry ); |
1550 | |
|
1551 | 0 | goto on_error; |
1552 | 0 | } |
1553 | 0 | return( 1 ); |
1554 | | |
1555 | 0 | on_error: |
1556 | 0 | if( record_data_definition != NULL ) |
1557 | 0 | { |
1558 | 0 | libesedb_data_definition_free( |
1559 | 0 | &record_data_definition, |
1560 | | NULL ); |
1561 | 0 | } |
1562 | 0 | return( -1 ); |
1563 | 0 | } |
1564 | | |