/src/libesedb/libesedb/libesedb_column.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Column 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_column.h" |
28 | | #include "libesedb_definitions.h" |
29 | | #include "libesedb_io_handle.h" |
30 | | #include "libesedb_libcerror.h" |
31 | | #include "libesedb_types.h" |
32 | | |
33 | | /* Creates a column |
34 | | * Make sure the value column is referencing, is set to NULL |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libesedb_column_initialize( |
38 | | libesedb_column_t **column, |
39 | | libesedb_io_handle_t *io_handle, |
40 | | libesedb_catalog_definition_t *catalog_definition, |
41 | | libcerror_error_t **error ) |
42 | 3 | { |
43 | 3 | libesedb_internal_column_t *internal_column = NULL; |
44 | 3 | static char *function = "libesedb_column_initialize"; |
45 | | |
46 | 3 | if( column == NULL ) |
47 | 0 | { |
48 | 0 | libcerror_error_set( |
49 | 0 | error, |
50 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
51 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
52 | 0 | "%s: invalid column.", |
53 | 0 | function ); |
54 | |
|
55 | 0 | return( -1 ); |
56 | 0 | } |
57 | 3 | if( *column != NULL ) |
58 | 0 | { |
59 | 0 | libcerror_error_set( |
60 | 0 | error, |
61 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
62 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
63 | 0 | "%s: invalid column value already set.", |
64 | 0 | function ); |
65 | |
|
66 | 0 | return( -1 ); |
67 | 0 | } |
68 | 3 | if( io_handle == NULL ) |
69 | 0 | { |
70 | 0 | libcerror_error_set( |
71 | 0 | error, |
72 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
73 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
74 | 0 | "%s: invalid IO handle.", |
75 | 0 | function ); |
76 | |
|
77 | 0 | return( -1 ); |
78 | 0 | } |
79 | 3 | if( catalog_definition == NULL ) |
80 | 0 | { |
81 | 0 | libcerror_error_set( |
82 | 0 | error, |
83 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
84 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
85 | 0 | "%s: invalid catalog definition.", |
86 | 0 | function ); |
87 | |
|
88 | 0 | return( -1 ); |
89 | 0 | } |
90 | 3 | internal_column = memory_allocate_structure( |
91 | 3 | libesedb_internal_column_t ); |
92 | | |
93 | 3 | if( internal_column == NULL ) |
94 | 0 | { |
95 | 0 | libcerror_error_set( |
96 | 0 | error, |
97 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
98 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
99 | 0 | "%s: unable to create column.", |
100 | 0 | function ); |
101 | |
|
102 | 0 | goto on_error; |
103 | 0 | } |
104 | 3 | if( memory_set( |
105 | 3 | internal_column, |
106 | 3 | 0, |
107 | 3 | sizeof( libesedb_internal_column_t ) ) == NULL ) |
108 | 0 | { |
109 | 0 | libcerror_error_set( |
110 | 0 | error, |
111 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
112 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
113 | 0 | "%s: unable to clear column.", |
114 | 0 | function ); |
115 | |
|
116 | 0 | goto on_error; |
117 | 0 | } |
118 | 3 | internal_column->io_handle = io_handle; |
119 | 3 | internal_column->catalog_definition = catalog_definition; |
120 | | |
121 | 3 | *column = (libesedb_column_t *) internal_column; |
122 | | |
123 | 3 | return( 1 ); |
124 | | |
125 | 0 | on_error: |
126 | 0 | if( internal_column != NULL ) |
127 | 0 | { |
128 | 0 | memory_free( |
129 | 0 | internal_column ); |
130 | 0 | } |
131 | 0 | return( -1 ); |
132 | 3 | } |
133 | | |
134 | | /* Frees a column |
135 | | * Returns 1 if successful or -1 on error |
136 | | */ |
137 | | int libesedb_column_free( |
138 | | libesedb_column_t **column, |
139 | | libcerror_error_t **error ) |
140 | 3 | { |
141 | 3 | libesedb_internal_column_t *internal_column = NULL; |
142 | 3 | static char *function = "libesedb_column_free"; |
143 | 3 | int result = 1; |
144 | | |
145 | 3 | if( column == NULL ) |
146 | 0 | { |
147 | 0 | libcerror_error_set( |
148 | 0 | error, |
149 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
150 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
151 | 0 | "%s: invalid column.", |
152 | 0 | function ); |
153 | |
|
154 | 0 | return( -1 ); |
155 | 0 | } |
156 | 3 | if( *column != NULL ) |
157 | 3 | { |
158 | 3 | internal_column = (libesedb_internal_column_t *) *column; |
159 | 3 | *column = NULL; |
160 | | |
161 | | /* The io_handle and catalog_definition references |
162 | | * are freed elsewhere |
163 | | */ |
164 | 3 | memory_free( |
165 | 3 | internal_column ); |
166 | 3 | } |
167 | 3 | return( result ); |
168 | 3 | } |
169 | | |
170 | | /* Retrieves the column identifier |
171 | | * Returns 1 if successful or -1 on error |
172 | | */ |
173 | | int libesedb_column_get_identifier( |
174 | | libesedb_column_t *column, |
175 | | uint32_t *identifier, |
176 | | libcerror_error_t **error ) |
177 | 0 | { |
178 | 0 | libesedb_internal_column_t *internal_column = NULL; |
179 | 0 | static char *function = "libesedb_column_get_identifier"; |
180 | |
|
181 | 0 | if( column == NULL ) |
182 | 0 | { |
183 | 0 | libcerror_error_set( |
184 | 0 | error, |
185 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
186 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
187 | 0 | "%s: invalid column.", |
188 | 0 | function ); |
189 | |
|
190 | 0 | return( -1 ); |
191 | 0 | } |
192 | 0 | internal_column = (libesedb_internal_column_t *) column; |
193 | |
|
194 | 0 | if( libesedb_catalog_definition_get_identifier( |
195 | 0 | internal_column->catalog_definition, |
196 | 0 | identifier, |
197 | 0 | error ) != 1 ) |
198 | 0 | { |
199 | 0 | libcerror_error_set( |
200 | 0 | error, |
201 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
202 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
203 | 0 | "%s: unable to retrieve catalog definition identifier.", |
204 | 0 | function ); |
205 | |
|
206 | 0 | return( -1 ); |
207 | 0 | } |
208 | 0 | return( 1 ); |
209 | 0 | } |
210 | | |
211 | | /* Retrieves the column type |
212 | | * Returns 1 if successful or -1 on error |
213 | | */ |
214 | | int libesedb_column_get_type( |
215 | | libesedb_column_t *column, |
216 | | uint32_t *type, |
217 | | libcerror_error_t **error ) |
218 | 0 | { |
219 | 0 | libesedb_internal_column_t *internal_column = NULL; |
220 | 0 | static char *function = "libesedb_column_get_type"; |
221 | |
|
222 | 0 | if( column == NULL ) |
223 | 0 | { |
224 | 0 | libcerror_error_set( |
225 | 0 | error, |
226 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
227 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
228 | 0 | "%s: invalid column.", |
229 | 0 | function ); |
230 | |
|
231 | 0 | return( -1 ); |
232 | 0 | } |
233 | 0 | internal_column = (libesedb_internal_column_t *) column; |
234 | |
|
235 | 0 | if( libesedb_catalog_definition_get_column_type( |
236 | 0 | internal_column->catalog_definition, |
237 | 0 | type, |
238 | 0 | error ) != 1 ) |
239 | 0 | { |
240 | 0 | libcerror_error_set( |
241 | 0 | error, |
242 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
243 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
244 | 0 | "%s: unable to retrieve catalog definition column type.", |
245 | 0 | function ); |
246 | |
|
247 | 0 | return( -1 ); |
248 | 0 | } |
249 | 0 | return( 1 ); |
250 | 0 | } |
251 | | |
252 | | /* Retrieves the size of the UTF-8 encoded string of the column name |
253 | | * The returned size includes the end of string character |
254 | | * Returns 1 if successful or -1 on error |
255 | | */ |
256 | | int libesedb_column_get_utf8_name_size( |
257 | | libesedb_column_t *column, |
258 | | size_t *utf8_string_size, |
259 | | libcerror_error_t **error ) |
260 | 0 | { |
261 | 0 | libesedb_internal_column_t *internal_column = NULL; |
262 | 0 | static char *function = "libesedb_column_get_utf8_name_size"; |
263 | |
|
264 | 0 | if( column == NULL ) |
265 | 0 | { |
266 | 0 | libcerror_error_set( |
267 | 0 | error, |
268 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
269 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
270 | 0 | "%s: invalid column.", |
271 | 0 | function ); |
272 | |
|
273 | 0 | return( -1 ); |
274 | 0 | } |
275 | 0 | internal_column = (libesedb_internal_column_t *) column; |
276 | |
|
277 | 0 | if( internal_column->io_handle == NULL ) |
278 | 0 | { |
279 | 0 | libcerror_error_set( |
280 | 0 | error, |
281 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
282 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
283 | 0 | "%s: invalid column - missing IO handle.", |
284 | 0 | function ); |
285 | |
|
286 | 0 | return( -1 ); |
287 | 0 | } |
288 | 0 | if( libesedb_catalog_definition_get_utf8_name_size( |
289 | 0 | internal_column->catalog_definition, |
290 | 0 | utf8_string_size, |
291 | 0 | internal_column->io_handle->ascii_codepage, |
292 | 0 | error ) != 1 ) |
293 | 0 | { |
294 | 0 | libcerror_error_set( |
295 | 0 | error, |
296 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
297 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
298 | 0 | "%s: unable to retrieve UTF-8 string size.", |
299 | 0 | function ); |
300 | |
|
301 | 0 | return( -1 ); |
302 | 0 | } |
303 | 0 | return( 1 ); |
304 | 0 | } |
305 | | |
306 | | /* Retrieves the UTF-8 encoded string of the column name |
307 | | * The size should include the end of string character |
308 | | * Returns 1 if successful or -1 on error |
309 | | */ |
310 | | int libesedb_column_get_utf8_name( |
311 | | libesedb_column_t *column, |
312 | | uint8_t *utf8_string, |
313 | | size_t utf8_string_size, |
314 | | libcerror_error_t **error ) |
315 | 0 | { |
316 | 0 | libesedb_internal_column_t *internal_column = NULL; |
317 | 0 | static char *function = "libesedb_column_get_utf8_name"; |
318 | |
|
319 | 0 | if( column == NULL ) |
320 | 0 | { |
321 | 0 | libcerror_error_set( |
322 | 0 | error, |
323 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
324 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
325 | 0 | "%s: invalid column.", |
326 | 0 | function ); |
327 | |
|
328 | 0 | return( -1 ); |
329 | 0 | } |
330 | 0 | internal_column = (libesedb_internal_column_t *) column; |
331 | |
|
332 | 0 | if( internal_column->io_handle == NULL ) |
333 | 0 | { |
334 | 0 | libcerror_error_set( |
335 | 0 | error, |
336 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
337 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
338 | 0 | "%s: invalid column - missing IO handle.", |
339 | 0 | function ); |
340 | |
|
341 | 0 | return( -1 ); |
342 | 0 | } |
343 | 0 | if( libesedb_catalog_definition_get_utf8_name( |
344 | 0 | internal_column->catalog_definition, |
345 | 0 | utf8_string, |
346 | 0 | utf8_string_size, |
347 | 0 | internal_column->io_handle->ascii_codepage, |
348 | 0 | error ) != 1 ) |
349 | 0 | { |
350 | 0 | libcerror_error_set( |
351 | 0 | error, |
352 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
353 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
354 | 0 | "%s: unable to retrieve UTF-8 string.", |
355 | 0 | function ); |
356 | |
|
357 | 0 | return( -1 ); |
358 | 0 | } |
359 | 0 | return( 1 ); |
360 | 0 | } |
361 | | |
362 | | /* Retrieves the size of the UTF-16 encoded string of the column name |
363 | | * The returned size includes the end of string character |
364 | | * Returns 1 if successful or -1 on error |
365 | | */ |
366 | | int libesedb_column_get_utf16_name_size( |
367 | | libesedb_column_t *column, |
368 | | size_t *utf16_string_size, |
369 | | libcerror_error_t **error ) |
370 | 0 | { |
371 | 0 | libesedb_internal_column_t *internal_column = NULL; |
372 | 0 | static char *function = "libesedb_column_get_utf16_name_size"; |
373 | |
|
374 | 0 | if( column == NULL ) |
375 | 0 | { |
376 | 0 | libcerror_error_set( |
377 | 0 | error, |
378 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
379 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
380 | 0 | "%s: invalid column.", |
381 | 0 | function ); |
382 | |
|
383 | 0 | return( -1 ); |
384 | 0 | } |
385 | 0 | internal_column = (libesedb_internal_column_t *) column; |
386 | |
|
387 | 0 | if( internal_column->io_handle == NULL ) |
388 | 0 | { |
389 | 0 | libcerror_error_set( |
390 | 0 | error, |
391 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
392 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
393 | 0 | "%s: invalid column - missing IO handle.", |
394 | 0 | function ); |
395 | |
|
396 | 0 | return( -1 ); |
397 | 0 | } |
398 | 0 | if( libesedb_catalog_definition_get_utf16_name_size( |
399 | 0 | internal_column->catalog_definition, |
400 | 0 | utf16_string_size, |
401 | 0 | internal_column->io_handle->ascii_codepage, |
402 | 0 | error ) != 1 ) |
403 | 0 | { |
404 | 0 | libcerror_error_set( |
405 | 0 | error, |
406 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
407 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
408 | 0 | "%s: unable to retrieve UTF-16 string size.", |
409 | 0 | function ); |
410 | |
|
411 | 0 | return( -1 ); |
412 | 0 | } |
413 | 0 | return( 1 ); |
414 | 0 | } |
415 | | |
416 | | /* Retrieves the UTF-16 encoded string of the column name |
417 | | * The size should include the end of string character |
418 | | * Returns 1 if successful or -1 on error |
419 | | */ |
420 | | int libesedb_column_get_utf16_name( |
421 | | libesedb_column_t *column, |
422 | | uint16_t *utf16_string, |
423 | | size_t utf16_string_size, |
424 | | libcerror_error_t **error ) |
425 | 0 | { |
426 | 0 | libesedb_internal_column_t *internal_column = NULL; |
427 | 0 | static char *function = "libesedb_column_get_utf16_name"; |
428 | |
|
429 | 0 | if( column == NULL ) |
430 | 0 | { |
431 | 0 | libcerror_error_set( |
432 | 0 | error, |
433 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
434 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
435 | 0 | "%s: invalid column.", |
436 | 0 | function ); |
437 | |
|
438 | 0 | return( -1 ); |
439 | 0 | } |
440 | 0 | internal_column = (libesedb_internal_column_t *) column; |
441 | |
|
442 | 0 | if( internal_column->io_handle == NULL ) |
443 | 0 | { |
444 | 0 | libcerror_error_set( |
445 | 0 | error, |
446 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
447 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
448 | 0 | "%s: invalid column - missing IO handle.", |
449 | 0 | function ); |
450 | |
|
451 | 0 | return( -1 ); |
452 | 0 | } |
453 | 0 | if( libesedb_catalog_definition_get_utf16_name( |
454 | 0 | internal_column->catalog_definition, |
455 | 0 | utf16_string, |
456 | 0 | utf16_string_size, |
457 | 0 | internal_column->io_handle->ascii_codepage, |
458 | 0 | error ) != 1 ) |
459 | 0 | { |
460 | 0 | libcerror_error_set( |
461 | 0 | error, |
462 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
463 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
464 | 0 | "%s: unable to retrieve UTF-16 string.", |
465 | 0 | function ); |
466 | |
|
467 | 0 | return( -1 ); |
468 | 0 | } |
469 | 0 | return( 1 ); |
470 | 0 | } |
471 | | |