/src/libesedb/libesedb/libesedb_long_value.c
Line | Count | Source |
1 | | /* |
2 | | * Long value 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 <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libesedb_compression.h" |
28 | | #include "libesedb_data_segment.h" |
29 | | #include "libesedb_definitions.h" |
30 | | #include "libesedb_libbfio.h" |
31 | | #include "libesedb_libcerror.h" |
32 | | #include "libesedb_libcnotify.h" |
33 | | #include "libesedb_libfcache.h" |
34 | | #include "libesedb_libfdata.h" |
35 | | #include "libesedb_libfvalue.h" |
36 | | #include "libesedb_long_value.h" |
37 | | #include "libesedb_record_value.h" |
38 | | |
39 | | /* Creates a long value |
40 | | * Make sure the value long_value is referencing, is set to NULL |
41 | | * Returns 1 if successful or -1 on error |
42 | | */ |
43 | | int libesedb_long_value_initialize( |
44 | | libesedb_long_value_t **long_value, |
45 | | libbfio_handle_t *file_io_handle, |
46 | | libesedb_io_handle_t *io_handle, |
47 | | libesedb_catalog_definition_t *column_catalog_definition, |
48 | | libfdata_list_t *data_segments_list, |
49 | | libcerror_error_t **error ) |
50 | 0 | { |
51 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
52 | 0 | static char *function = "libesedb_long_value_initialize"; |
53 | |
|
54 | 0 | if( long_value == NULL ) |
55 | 0 | { |
56 | 0 | libcerror_error_set( |
57 | 0 | error, |
58 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
59 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
60 | 0 | "%s: invalid long value.", |
61 | 0 | function ); |
62 | |
|
63 | 0 | return( -1 ); |
64 | 0 | } |
65 | 0 | if( *long_value != NULL ) |
66 | 0 | { |
67 | 0 | libcerror_error_set( |
68 | 0 | error, |
69 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
70 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
71 | 0 | "%s: invalid long value value already set.", |
72 | 0 | function ); |
73 | |
|
74 | 0 | return( -1 ); |
75 | 0 | } |
76 | 0 | if( column_catalog_definition == NULL ) |
77 | 0 | { |
78 | 0 | libcerror_error_set( |
79 | 0 | error, |
80 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
81 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
82 | 0 | "%s: invalid column catalog definition.", |
83 | 0 | function ); |
84 | |
|
85 | 0 | return( -1 ); |
86 | 0 | } |
87 | 0 | if( data_segments_list == NULL ) |
88 | 0 | { |
89 | 0 | libcerror_error_set( |
90 | 0 | error, |
91 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
92 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
93 | 0 | "%s: invalid data segments list.", |
94 | 0 | function ); |
95 | |
|
96 | 0 | return( -1 ); |
97 | 0 | } |
98 | 0 | internal_long_value = memory_allocate_structure( |
99 | 0 | libesedb_internal_long_value_t ); |
100 | |
|
101 | 0 | if( internal_long_value == NULL ) |
102 | 0 | { |
103 | 0 | libcerror_error_set( |
104 | 0 | error, |
105 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
106 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
107 | 0 | "%s: unable to create long value.", |
108 | 0 | function ); |
109 | |
|
110 | 0 | goto on_error; |
111 | 0 | } |
112 | 0 | if( memory_set( |
113 | 0 | internal_long_value, |
114 | 0 | 0, |
115 | 0 | sizeof( libesedb_internal_long_value_t ) ) == NULL ) |
116 | 0 | { |
117 | 0 | libcerror_error_set( |
118 | 0 | error, |
119 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
120 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
121 | 0 | "%s: unable to clear long value.", |
122 | 0 | function ); |
123 | |
|
124 | 0 | memory_free( |
125 | 0 | internal_long_value ); |
126 | |
|
127 | 0 | return( -1 ); |
128 | 0 | } |
129 | 0 | if( libfcache_cache_initialize( |
130 | 0 | &( internal_long_value->data_segments_cache ), |
131 | 0 | LIBESEDB_MAXIMUM_CACHE_ENTRIES_LONG_VALUES_DATA, |
132 | 0 | error ) != 1 ) |
133 | 0 | { |
134 | 0 | libcerror_error_set( |
135 | 0 | error, |
136 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
137 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
138 | 0 | "%s: unable to create data segments cache.", |
139 | 0 | function ); |
140 | |
|
141 | 0 | goto on_error; |
142 | 0 | } |
143 | 0 | internal_long_value->file_io_handle = file_io_handle; |
144 | 0 | internal_long_value->io_handle = io_handle; |
145 | 0 | internal_long_value->column_catalog_definition = column_catalog_definition; |
146 | 0 | internal_long_value->data_segments_list = data_segments_list; |
147 | |
|
148 | 0 | *long_value = (libesedb_long_value_t *) internal_long_value; |
149 | |
|
150 | 0 | return( 1 ); |
151 | | |
152 | 0 | on_error: |
153 | 0 | if( internal_long_value != NULL ) |
154 | 0 | { |
155 | 0 | if( internal_long_value->data_segments_cache != NULL ) |
156 | 0 | { |
157 | 0 | libfcache_cache_free( |
158 | 0 | &( internal_long_value->data_segments_cache ), |
159 | 0 | NULL ); |
160 | 0 | } |
161 | 0 | memory_free( |
162 | 0 | internal_long_value ); |
163 | 0 | } |
164 | 0 | return( -1 ); |
165 | 0 | } |
166 | | |
167 | | /* Frees a long value |
168 | | * Returns 1 if successful or -1 on error |
169 | | */ |
170 | | int libesedb_long_value_free( |
171 | | libesedb_long_value_t **long_value, |
172 | | libcerror_error_t **error ) |
173 | 0 | { |
174 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
175 | 0 | static char *function = "libesedb_long_value_free"; |
176 | 0 | int result = 1; |
177 | |
|
178 | 0 | if( long_value == NULL ) |
179 | 0 | { |
180 | 0 | libcerror_error_set( |
181 | 0 | error, |
182 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
183 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
184 | 0 | "%s: invalid long value.", |
185 | 0 | function ); |
186 | |
|
187 | 0 | return( -1 ); |
188 | 0 | } |
189 | 0 | if( *long_value != NULL ) |
190 | 0 | { |
191 | 0 | internal_long_value = (libesedb_internal_long_value_t *) *long_value; |
192 | 0 | *long_value = NULL; |
193 | | |
194 | | /* The file_io_handle and io_handle references are freed elsewhere |
195 | | */ |
196 | 0 | if( libfdata_list_free( |
197 | 0 | &( internal_long_value->data_segments_list ), |
198 | 0 | error ) != 1 ) |
199 | 0 | { |
200 | 0 | libcerror_error_set( |
201 | 0 | error, |
202 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
203 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
204 | 0 | "%s: unable to free data segments list.", |
205 | 0 | function ); |
206 | |
|
207 | 0 | result = -1; |
208 | 0 | } |
209 | 0 | if( libfcache_cache_free( |
210 | 0 | &( internal_long_value->data_segments_cache ), |
211 | 0 | error ) != 1 ) |
212 | 0 | { |
213 | 0 | libcerror_error_set( |
214 | 0 | error, |
215 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
216 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
217 | 0 | "%s: unable to free data segments cache.", |
218 | 0 | function ); |
219 | |
|
220 | 0 | result = -1; |
221 | 0 | } |
222 | 0 | if( internal_long_value->record_value != NULL ) |
223 | 0 | { |
224 | 0 | if( libfvalue_value_free( |
225 | 0 | &( internal_long_value->record_value ), |
226 | 0 | error ) != 1 ) |
227 | 0 | { |
228 | 0 | libcerror_error_set( |
229 | 0 | error, |
230 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
231 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
232 | 0 | "%s: unable to free record value.", |
233 | 0 | function ); |
234 | |
|
235 | 0 | result = -1; |
236 | 0 | } |
237 | 0 | } |
238 | 0 | memory_free( |
239 | 0 | internal_long_value ); |
240 | 0 | } |
241 | 0 | return( result ); |
242 | 0 | } |
243 | | |
244 | | /* Retrieve the data size |
245 | | * If the long value is compressed this will return the uncompressed data size |
246 | | * Returns 1 if successful or -1 on error |
247 | | */ |
248 | | int libesedb_long_value_get_data_size( |
249 | | libesedb_long_value_t *long_value, |
250 | | size64_t *data_size, |
251 | | libcerror_error_t **error ) |
252 | 0 | { |
253 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
254 | 0 | libfvalue_value_t *record_value = NULL; |
255 | 0 | static char *function = "libesedb_long_value_get_data_size"; |
256 | 0 | size_t safe_data_size = 0; |
257 | 0 | int result = 0; |
258 | |
|
259 | 0 | if( long_value == NULL ) |
260 | 0 | { |
261 | 0 | libcerror_error_set( |
262 | 0 | error, |
263 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
264 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
265 | 0 | "%s: invalid long value.", |
266 | 0 | function ); |
267 | |
|
268 | 0 | return( -1 ); |
269 | 0 | } |
270 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
271 | |
|
272 | 0 | if( data_size == NULL ) |
273 | 0 | { |
274 | 0 | libcerror_error_set( |
275 | 0 | error, |
276 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
277 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
278 | 0 | "%s: invalid data size.", |
279 | 0 | function ); |
280 | |
|
281 | 0 | return( -1 ); |
282 | 0 | } |
283 | 0 | if( libesedb_long_value_get_record_value( |
284 | 0 | internal_long_value, |
285 | 0 | &record_value, |
286 | 0 | error ) != 1 ) |
287 | 0 | { |
288 | 0 | libcerror_error_set( |
289 | 0 | error, |
290 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
291 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
292 | 0 | "%s: unable to retrieve record value.", |
293 | 0 | function ); |
294 | |
|
295 | 0 | return( -1 ); |
296 | 0 | } |
297 | 0 | result = libfvalue_value_has_data( |
298 | 0 | record_value, |
299 | 0 | error ); |
300 | |
|
301 | 0 | if( result == -1 ) |
302 | 0 | { |
303 | 0 | libcerror_error_set( |
304 | 0 | error, |
305 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
306 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
307 | 0 | "%s: unable to determine if record value has data.", |
308 | 0 | function ); |
309 | |
|
310 | 0 | return( -1 ); |
311 | 0 | } |
312 | 0 | else if( result != 0 ) |
313 | 0 | { |
314 | 0 | result = libfvalue_value_get_data_size( |
315 | 0 | record_value, |
316 | 0 | &safe_data_size, |
317 | 0 | error ); |
318 | |
|
319 | 0 | if( result != 1 ) |
320 | 0 | { |
321 | 0 | libcerror_error_set( |
322 | 0 | error, |
323 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
324 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
325 | 0 | "%s: unable to retrieve data size from record value.", |
326 | 0 | function ); |
327 | |
|
328 | 0 | return( -1 ); |
329 | 0 | } |
330 | 0 | } |
331 | 0 | *data_size = safe_data_size; |
332 | |
|
333 | 0 | return( 1 ); |
334 | 0 | } |
335 | | |
336 | | /* Retrieve the data |
337 | | * If the long value is compressed this will return the uncompressed data |
338 | | * Returns 1 if successful or -1 on error |
339 | | */ |
340 | | int libesedb_long_value_get_data( |
341 | | libesedb_long_value_t *long_value, |
342 | | uint8_t *data, |
343 | | size_t data_size, |
344 | | libcerror_error_t **error ) |
345 | 0 | { |
346 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
347 | 0 | libfvalue_value_t *record_value = NULL; |
348 | 0 | static char *function = "libesedb_long_value_get_data"; |
349 | 0 | int result = 0; |
350 | |
|
351 | 0 | if( long_value == NULL ) |
352 | 0 | { |
353 | 0 | libcerror_error_set( |
354 | 0 | error, |
355 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
356 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
357 | 0 | "%s: invalid long value.", |
358 | 0 | function ); |
359 | |
|
360 | 0 | return( -1 ); |
361 | 0 | } |
362 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
363 | |
|
364 | 0 | if( libesedb_long_value_get_record_value( |
365 | 0 | internal_long_value, |
366 | 0 | &record_value, |
367 | 0 | error ) != 1 ) |
368 | 0 | { |
369 | 0 | libcerror_error_set( |
370 | 0 | error, |
371 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
372 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
373 | 0 | "%s: unable to retrieve record value.", |
374 | 0 | function ); |
375 | |
|
376 | 0 | return( -1 ); |
377 | 0 | } |
378 | 0 | result = libfvalue_value_has_data( |
379 | 0 | record_value, |
380 | 0 | error ); |
381 | |
|
382 | 0 | if( result == -1 ) |
383 | 0 | { |
384 | 0 | libcerror_error_set( |
385 | 0 | error, |
386 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
387 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
388 | 0 | "%s: unable to determine if record value has data.", |
389 | 0 | function ); |
390 | |
|
391 | 0 | return( -1 ); |
392 | 0 | } |
393 | 0 | else if( result != 0 ) |
394 | 0 | { |
395 | 0 | result = libfvalue_value_copy_data( |
396 | 0 | record_value, |
397 | 0 | data, |
398 | 0 | data_size, |
399 | 0 | error ); |
400 | |
|
401 | 0 | if( result != 1 ) |
402 | 0 | { |
403 | 0 | libcerror_error_set( |
404 | 0 | error, |
405 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
406 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
407 | 0 | "%s: unable to copy data from record value.", |
408 | 0 | function ); |
409 | |
|
410 | 0 | return( -1 ); |
411 | 0 | } |
412 | 0 | } |
413 | 0 | return( 1 ); |
414 | 0 | } |
415 | | |
416 | | /* Retrieve the record value |
417 | | * Returns 1 if successful or -1 on error |
418 | | */ |
419 | | int libesedb_long_value_get_record_value( |
420 | | libesedb_internal_long_value_t *internal_long_value, |
421 | | libfvalue_value_t **record_value, |
422 | | libcerror_error_t **error ) |
423 | 0 | { |
424 | 0 | libesedb_data_segment_t *data_segment = NULL; |
425 | 0 | uint8_t *compressed_data = NULL; |
426 | 0 | uint8_t *data = NULL; |
427 | 0 | static char *function = "libesedb_long_value_get_record_value"; |
428 | 0 | size64_t data_size = 0; |
429 | 0 | size_t data_offset = 0; |
430 | 0 | size_t uncompressed_data_size = 0; |
431 | 0 | uint32_t column_type = 0; |
432 | 0 | uint8_t record_value_type = 0; |
433 | 0 | int data_segment_index = 0; |
434 | 0 | int encoding = 0; |
435 | 0 | int long_value_codepage = 0; |
436 | 0 | int number_of_data_segments = 0; |
437 | |
|
438 | 0 | if( internal_long_value == NULL ) |
439 | 0 | { |
440 | 0 | libcerror_error_set( |
441 | 0 | error, |
442 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
443 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
444 | 0 | "%s: invalid long value.", |
445 | 0 | function ); |
446 | |
|
447 | 0 | return( -1 ); |
448 | 0 | } |
449 | 0 | if( internal_long_value->io_handle == NULL ) |
450 | 0 | { |
451 | 0 | libcerror_error_set( |
452 | 0 | error, |
453 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
454 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
455 | 0 | "%s: invalid long value - missing IO handle.", |
456 | 0 | function ); |
457 | |
|
458 | 0 | return( -1 ); |
459 | 0 | } |
460 | 0 | if( record_value == NULL ) |
461 | 0 | { |
462 | 0 | libcerror_error_set( |
463 | 0 | error, |
464 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
465 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
466 | 0 | "%s: invalid record value.", |
467 | 0 | function ); |
468 | |
|
469 | 0 | return( -1 ); |
470 | 0 | } |
471 | 0 | if( internal_long_value->record_value == NULL ) |
472 | 0 | { |
473 | 0 | if( libesedb_catalog_definition_get_column_type( |
474 | 0 | internal_long_value->column_catalog_definition, |
475 | 0 | &column_type, |
476 | 0 | error ) != 1 ) |
477 | 0 | { |
478 | 0 | libcerror_error_set( |
479 | 0 | error, |
480 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
481 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
482 | 0 | "%s: unable to retrieve catalog definition column type.", |
483 | 0 | function ); |
484 | |
|
485 | 0 | goto on_error; |
486 | 0 | } |
487 | 0 | switch( column_type ) |
488 | 0 | { |
489 | 0 | case LIBESEDB_COLUMN_TYPE_BINARY_DATA: |
490 | 0 | case LIBESEDB_COLUMN_TYPE_LARGE_BINARY_DATA: |
491 | 0 | record_value_type = LIBFVALUE_VALUE_TYPE_BINARY_DATA; |
492 | 0 | break; |
493 | | |
494 | 0 | case LIBESEDB_COLUMN_TYPE_TEXT: |
495 | 0 | case LIBESEDB_COLUMN_TYPE_LARGE_TEXT: |
496 | 0 | record_value_type = LIBFVALUE_VALUE_TYPE_STRING_BYTE_STREAM; |
497 | 0 | break; |
498 | | |
499 | 0 | default: |
500 | 0 | libcerror_error_set( |
501 | 0 | error, |
502 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
503 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
504 | 0 | "%s: unsupported column type: %" PRIu32 ".", |
505 | 0 | function, |
506 | 0 | column_type ); |
507 | |
|
508 | 0 | goto on_error; |
509 | 0 | } |
510 | 0 | if( libfdata_list_get_size( |
511 | 0 | internal_long_value->data_segments_list, |
512 | 0 | &data_size, |
513 | 0 | error ) != 1 ) |
514 | 0 | { |
515 | 0 | libcerror_error_set( |
516 | 0 | error, |
517 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
518 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
519 | 0 | "%s: unable to retrieve size from data segments list.", |
520 | 0 | function ); |
521 | |
|
522 | 0 | goto on_error; |
523 | 0 | } |
524 | 0 | if( ( data_size == 0 ) |
525 | 0 | || ( data_size > (size64_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
526 | 0 | { |
527 | 0 | libcerror_error_set( |
528 | 0 | error, |
529 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
530 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
531 | 0 | "%s: invalid data size value out of bounds.", |
532 | 0 | function ); |
533 | |
|
534 | 0 | goto on_error; |
535 | 0 | } |
536 | 0 | data = (uint8_t *) memory_allocate( |
537 | 0 | (size_t) data_size ); |
538 | |
|
539 | 0 | if( data == NULL ) |
540 | 0 | { |
541 | 0 | libcerror_error_set( |
542 | 0 | error, |
543 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
544 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
545 | 0 | "%s: unable to create data.", |
546 | 0 | function ); |
547 | |
|
548 | 0 | goto on_error; |
549 | 0 | } |
550 | 0 | if( memory_set( |
551 | 0 | data, |
552 | 0 | 0, |
553 | 0 | (size_t) data_size ) == NULL ) |
554 | 0 | { |
555 | 0 | libcerror_error_set( |
556 | 0 | error, |
557 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
558 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
559 | 0 | "%s: unable to clear data.", |
560 | 0 | function ); |
561 | |
|
562 | 0 | goto on_error; |
563 | 0 | } |
564 | 0 | if( libfdata_list_get_number_of_elements( |
565 | 0 | internal_long_value->data_segments_list, |
566 | 0 | &number_of_data_segments, |
567 | 0 | error ) != 1 ) |
568 | 0 | { |
569 | 0 | libcerror_error_set( |
570 | 0 | error, |
571 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
572 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
573 | 0 | "%s: unable to retrieve number of elements from data segments list.", |
574 | 0 | function ); |
575 | |
|
576 | 0 | goto on_error; |
577 | 0 | } |
578 | 0 | for( data_segment_index = 0; |
579 | 0 | data_segment_index < number_of_data_segments; |
580 | 0 | data_segment_index++ ) |
581 | 0 | { |
582 | 0 | if( libfdata_list_get_element_value_by_index( |
583 | 0 | internal_long_value->data_segments_list, |
584 | 0 | (intptr_t *) internal_long_value->file_io_handle, |
585 | 0 | (libfdata_cache_t *) internal_long_value->data_segments_cache, |
586 | 0 | data_segment_index, |
587 | 0 | (intptr_t **) &data_segment, |
588 | 0 | 0, |
589 | 0 | error ) != 1 ) |
590 | 0 | { |
591 | 0 | libcerror_error_set( |
592 | 0 | error, |
593 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
594 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
595 | 0 | "%s: unable to retrieve data segment: %d.", |
596 | 0 | function, |
597 | 0 | data_segment_index ); |
598 | |
|
599 | 0 | goto on_error; |
600 | 0 | } |
601 | 0 | if( data_segment == NULL ) |
602 | 0 | { |
603 | 0 | libcerror_error_set( |
604 | 0 | error, |
605 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
606 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
607 | 0 | "%s: missing data segment: %d.", |
608 | 0 | function, |
609 | 0 | data_segment_index ); |
610 | |
|
611 | 0 | goto on_error; |
612 | 0 | } |
613 | 0 | if( data_segment->data == NULL ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
619 | 0 | "%s: invalid data segment: %d - missing data.", |
620 | 0 | function, |
621 | 0 | data_segment_index ); |
622 | |
|
623 | 0 | goto on_error; |
624 | 0 | } |
625 | 0 | if( ( data_segment->data_size > 1 ) |
626 | 0 | && ( data_segment->data[ 0 ] == 0x18 ) ) |
627 | 0 | { |
628 | 0 | if( libesedb_compression_lzxpress_decompress_get_size( |
629 | 0 | data_segment->data, |
630 | 0 | data_segment->data_size, |
631 | 0 | (size_t *) &uncompressed_data_size, |
632 | 0 | error ) != 1 ) |
633 | 0 | { |
634 | 0 | libcerror_error_set( |
635 | 0 | error, |
636 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
637 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
638 | 0 | "%s: unable retrieve uncompressed data segment: %d size.", |
639 | 0 | function, |
640 | 0 | data_segment_index ); |
641 | |
|
642 | 0 | goto on_error; |
643 | 0 | } |
644 | 0 | if( ( uncompressed_data_size == 0 ) |
645 | 0 | || ( uncompressed_data_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
646 | 0 | { |
647 | 0 | libcerror_error_set( |
648 | 0 | error, |
649 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
650 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
651 | 0 | "%s: invalid uncompressed data segment: %d size value out of bounds.", |
652 | 0 | function, |
653 | 0 | data_segment_index ); |
654 | |
|
655 | 0 | goto on_error; |
656 | 0 | } |
657 | 0 | if( libesedb_compression_lzxpress_decompress( |
658 | 0 | data_segment->data, |
659 | 0 | data_segment->data_size, |
660 | 0 | &( data[ data_offset ] ), |
661 | 0 | uncompressed_data_size, |
662 | 0 | error ) != 1 ) |
663 | 0 | { |
664 | 0 | libcerror_error_set( |
665 | 0 | error, |
666 | 0 | LIBCERROR_ERROR_DOMAIN_COMPRESSION, |
667 | 0 | LIBCERROR_COMPRESSION_ERROR_DECOMPRESS_FAILED, |
668 | 0 | "%s: unable to decompress data segment: %d.", |
669 | 0 | function, |
670 | 0 | data_segment_index ); |
671 | |
|
672 | 0 | goto on_error; |
673 | 0 | } |
674 | 0 | data_offset += uncompressed_data_size; |
675 | 0 | } |
676 | 0 | else |
677 | 0 | { |
678 | 0 | if( memory_copy( |
679 | 0 | &( data[ data_offset ] ), |
680 | 0 | data_segment->data, |
681 | 0 | data_segment->data_size ) == NULL ) |
682 | 0 | { |
683 | 0 | libcerror_error_set( |
684 | 0 | error, |
685 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
686 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
687 | 0 | "%s: unable to copy data.", |
688 | 0 | function ); |
689 | |
|
690 | 0 | goto on_error; |
691 | 0 | } |
692 | 0 | data_offset += data_segment->data_size; |
693 | 0 | } |
694 | 0 | } |
695 | 0 | if( ( column_type == LIBESEDB_COLUMN_TYPE_TEXT ) |
696 | 0 | || ( column_type == LIBESEDB_COLUMN_TYPE_LARGE_TEXT ) ) |
697 | 0 | { |
698 | 0 | long_value_codepage = (int) internal_long_value->column_catalog_definition->codepage; |
699 | | |
700 | | /* If the codepage is not set use the default codepage |
701 | | */ |
702 | 0 | if( long_value_codepage == 0 ) |
703 | 0 | { |
704 | 0 | long_value_codepage = internal_long_value->io_handle->ascii_codepage; |
705 | 0 | } |
706 | 0 | encoding = long_value_codepage; |
707 | 0 | } |
708 | 0 | else |
709 | 0 | { |
710 | 0 | encoding = LIBFVALUE_ENDIAN_LITTLE; |
711 | 0 | } |
712 | 0 | if( libfvalue_value_type_initialize( |
713 | 0 | &( internal_long_value->record_value ), |
714 | 0 | record_value_type, |
715 | 0 | error ) != 1 ) |
716 | 0 | { |
717 | 0 | libcerror_error_set( |
718 | 0 | error, |
719 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
720 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
721 | 0 | "%s: unable to create record value.", |
722 | 0 | function ); |
723 | |
|
724 | 0 | goto on_error; |
725 | 0 | } |
726 | 0 | if( libfvalue_value_set_data( |
727 | 0 | internal_long_value->record_value, |
728 | 0 | data, |
729 | 0 | (size_t) data_size, |
730 | 0 | encoding, |
731 | 0 | LIBFVALUE_VALUE_DATA_FLAG_MANAGED | LIBFVALUE_VALUE_DATA_FLAG_CLONE_BY_REFERENCE, |
732 | 0 | error ) != 1 ) |
733 | 0 | { |
734 | 0 | libcerror_error_set( |
735 | 0 | error, |
736 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
737 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
738 | 0 | "%s: unable to set data in record value.", |
739 | 0 | function ); |
740 | |
|
741 | 0 | goto on_error; |
742 | 0 | } |
743 | | /* The record value takes over management of data |
744 | | */ |
745 | | #if defined( __clang_analyzer__ ) |
746 | | free( data ); |
747 | | #endif |
748 | 0 | data = NULL; |
749 | 0 | } |
750 | 0 | *record_value = internal_long_value->record_value; |
751 | |
|
752 | 0 | return( 1 ); |
753 | | |
754 | 0 | on_error: |
755 | 0 | if( internal_long_value->record_value != NULL ) |
756 | 0 | { |
757 | 0 | libfvalue_value_free( |
758 | 0 | &( internal_long_value->record_value ), |
759 | 0 | NULL ); |
760 | 0 | } |
761 | 0 | if( compressed_data != NULL ) |
762 | 0 | { |
763 | 0 | memory_free( |
764 | 0 | compressed_data ); |
765 | 0 | } |
766 | 0 | if( data != NULL ) |
767 | 0 | { |
768 | 0 | memory_free( |
769 | 0 | data ); |
770 | 0 | } |
771 | 0 | return( -1 ); |
772 | 0 | } |
773 | | |
774 | | /* Retrieve the number of data segments |
775 | | * Returns 1 if successful or -1 on error |
776 | | */ |
777 | | int libesedb_long_value_get_number_of_data_segments( |
778 | | libesedb_long_value_t *long_value, |
779 | | int *number_of_data_segments, |
780 | | libcerror_error_t **error ) |
781 | 0 | { |
782 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
783 | 0 | static char *function = "libesedb_long_value_get_number_of_data_segments"; |
784 | |
|
785 | 0 | if( long_value == NULL ) |
786 | 0 | { |
787 | 0 | libcerror_error_set( |
788 | 0 | error, |
789 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
790 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
791 | 0 | "%s: invalid long value.", |
792 | 0 | function ); |
793 | |
|
794 | 0 | return( -1 ); |
795 | 0 | } |
796 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
797 | |
|
798 | 0 | if( libfdata_list_get_number_of_elements( |
799 | 0 | internal_long_value->data_segments_list, |
800 | 0 | number_of_data_segments, |
801 | 0 | error ) != 1 ) |
802 | 0 | { |
803 | 0 | libcerror_error_set( |
804 | 0 | error, |
805 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
806 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
807 | 0 | "%s: unable to retrieve number of elements from data segments list.", |
808 | 0 | function ); |
809 | |
|
810 | 0 | return( -1 ); |
811 | 0 | } |
812 | 0 | return( 1 ); |
813 | 0 | } |
814 | | |
815 | | /* Retrieve the data segment size |
816 | | * If the long value is compressed this will return the compressed data segment size |
817 | | * Returns 1 if successful or -1 on error |
818 | | */ |
819 | | int libesedb_long_value_get_data_segment_size( |
820 | | libesedb_long_value_t *long_value, |
821 | | int data_segment_index, |
822 | | size_t *data_size, |
823 | | libcerror_error_t **error ) |
824 | 0 | { |
825 | 0 | libesedb_data_segment_t *data_segment = NULL; |
826 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
827 | 0 | static char *function = "libesedb_long_value_get_data_segment_size"; |
828 | |
|
829 | 0 | if( long_value == NULL ) |
830 | 0 | { |
831 | 0 | libcerror_error_set( |
832 | 0 | error, |
833 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
834 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
835 | 0 | "%s: invalid long value.", |
836 | 0 | function ); |
837 | |
|
838 | 0 | return( -1 ); |
839 | 0 | } |
840 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
841 | |
|
842 | 0 | if( libfdata_list_get_element_value_by_index( |
843 | 0 | internal_long_value->data_segments_list, |
844 | 0 | (intptr_t *) internal_long_value->file_io_handle, |
845 | 0 | (libfdata_cache_t *) internal_long_value->data_segments_cache, |
846 | 0 | data_segment_index, |
847 | 0 | (intptr_t **) &data_segment, |
848 | 0 | 0, |
849 | 0 | error ) != 1 ) |
850 | 0 | { |
851 | 0 | libcerror_error_set( |
852 | 0 | error, |
853 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
854 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
855 | 0 | "%s: unable to retrieve data segment: %d.", |
856 | 0 | function, |
857 | 0 | data_segment_index ); |
858 | |
|
859 | 0 | return( -1 ); |
860 | 0 | } |
861 | 0 | if( libesedb_data_segment_get_data_size( |
862 | 0 | data_segment, |
863 | 0 | data_size, |
864 | 0 | error ) != 1 ) |
865 | 0 | { |
866 | 0 | libcerror_error_set( |
867 | 0 | error, |
868 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
869 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
870 | 0 | "%s: unable to retrieve data segment: %d data size.", |
871 | 0 | function, |
872 | 0 | data_segment_index ); |
873 | |
|
874 | 0 | return( -1 ); |
875 | 0 | } |
876 | 0 | return( 1 ); |
877 | 0 | } |
878 | | |
879 | | /* Retrieve the data segment |
880 | | * If the long value is compressed this will return the compressed data segment |
881 | | * Returns 1 if successful or -1 on error |
882 | | */ |
883 | | int libesedb_long_value_get_data_segment( |
884 | | libesedb_long_value_t *long_value, |
885 | | int data_segment_index, |
886 | | uint8_t *data, |
887 | | size_t data_size, |
888 | | libcerror_error_t **error ) |
889 | 0 | { |
890 | 0 | libesedb_data_segment_t *data_segment = NULL; |
891 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
892 | 0 | static char *function = "libesedb_long_value_get_data_segment"; |
893 | |
|
894 | 0 | if( long_value == NULL ) |
895 | 0 | { |
896 | 0 | libcerror_error_set( |
897 | 0 | error, |
898 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
899 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
900 | 0 | "%s: invalid long value.", |
901 | 0 | function ); |
902 | |
|
903 | 0 | return( -1 ); |
904 | 0 | } |
905 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
906 | | |
907 | | /* TODO return uncompressed data */ |
908 | 0 | if( libfdata_list_get_element_value_by_index( |
909 | 0 | internal_long_value->data_segments_list, |
910 | 0 | (intptr_t *) internal_long_value->file_io_handle, |
911 | 0 | (libfdata_cache_t *) internal_long_value->data_segments_cache, |
912 | 0 | data_segment_index, |
913 | 0 | (intptr_t **) &data_segment, |
914 | 0 | 0, |
915 | 0 | error ) != 1 ) |
916 | 0 | { |
917 | 0 | libcerror_error_set( |
918 | 0 | error, |
919 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
920 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
921 | 0 | "%s: unable to retrieve data segment: %d.", |
922 | 0 | function, |
923 | 0 | data_segment_index ); |
924 | |
|
925 | 0 | return( -1 ); |
926 | 0 | } |
927 | 0 | if( libesedb_data_segment_get_data( |
928 | 0 | data_segment, |
929 | 0 | data, |
930 | 0 | data_size, |
931 | 0 | error ) != 1 ) |
932 | 0 | { |
933 | 0 | libcerror_error_set( |
934 | 0 | error, |
935 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
936 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
937 | 0 | "%s: unable to retrieve data segment: %d data.", |
938 | 0 | function, |
939 | 0 | data_segment_index ); |
940 | |
|
941 | 0 | return( -1 ); |
942 | 0 | } |
943 | 0 | return( 1 ); |
944 | 0 | } |
945 | | |
946 | | /* Retrieves the size of the data as an UTF-8 encoded string |
947 | | * The returned size includes the end of string character |
948 | | * Returns 1 if successful, 0 if value is NULL or -1 on error |
949 | | */ |
950 | | int libesedb_long_value_get_utf8_string_size( |
951 | | libesedb_long_value_t *long_value, |
952 | | size_t *utf8_string_size, |
953 | | libcerror_error_t **error ) |
954 | 0 | { |
955 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
956 | 0 | libfvalue_value_t *record_value = NULL; |
957 | 0 | static char *function = "libesedb_long_value_get_utf8_string_size"; |
958 | 0 | uint32_t column_type = 0; |
959 | 0 | int result = 0; |
960 | |
|
961 | 0 | if( long_value == NULL ) |
962 | 0 | { |
963 | 0 | libcerror_error_set( |
964 | 0 | error, |
965 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
966 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
967 | 0 | "%s: invalid long value.", |
968 | 0 | function ); |
969 | |
|
970 | 0 | return( -1 ); |
971 | 0 | } |
972 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
973 | |
|
974 | 0 | if( libesedb_catalog_definition_get_column_type( |
975 | 0 | internal_long_value->column_catalog_definition, |
976 | 0 | &column_type, |
977 | 0 | error ) != 1 ) |
978 | 0 | { |
979 | 0 | libcerror_error_set( |
980 | 0 | error, |
981 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
982 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
983 | 0 | "%s: unable to retrieve catalog definition column type.", |
984 | 0 | function ); |
985 | |
|
986 | 0 | return( -1 ); |
987 | 0 | } |
988 | 0 | if( ( column_type != LIBESEDB_COLUMN_TYPE_TEXT ) |
989 | 0 | && ( column_type != LIBESEDB_COLUMN_TYPE_LARGE_TEXT ) ) |
990 | 0 | { |
991 | 0 | libcerror_error_set( |
992 | 0 | error, |
993 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
994 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
995 | 0 | "%s: unsupported column type: %" PRIu32 ".", |
996 | 0 | function, |
997 | 0 | column_type ); |
998 | |
|
999 | 0 | return( -1 ); |
1000 | 0 | } |
1001 | 0 | if( libesedb_long_value_get_record_value( |
1002 | 0 | internal_long_value, |
1003 | 0 | &record_value, |
1004 | 0 | error ) != 1 ) |
1005 | 0 | { |
1006 | 0 | libcerror_error_set( |
1007 | 0 | error, |
1008 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1009 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1010 | 0 | "%s: unable to retrieve record value.", |
1011 | 0 | function ); |
1012 | |
|
1013 | 0 | return( -1 ); |
1014 | 0 | } |
1015 | 0 | result = libfvalue_value_has_data( |
1016 | 0 | record_value, |
1017 | 0 | error ); |
1018 | |
|
1019 | 0 | if( result == -1 ) |
1020 | 0 | { |
1021 | 0 | libcerror_error_set( |
1022 | 0 | error, |
1023 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1024 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1025 | 0 | "%s: unable to determine if record value has data.", |
1026 | 0 | function ); |
1027 | |
|
1028 | 0 | return( -1 ); |
1029 | 0 | } |
1030 | 0 | else if( result != 0 ) |
1031 | 0 | { |
1032 | 0 | result = libfvalue_value_get_utf8_string_size( |
1033 | 0 | record_value, |
1034 | 0 | 0, |
1035 | 0 | utf8_string_size, |
1036 | 0 | error ); |
1037 | |
|
1038 | 0 | if( result != 1 ) |
1039 | 0 | { |
1040 | 0 | libcerror_error_set( |
1041 | 0 | error, |
1042 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1043 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1044 | 0 | "%s: unable retrieve UTF-8 string size.", |
1045 | 0 | function ); |
1046 | |
|
1047 | 0 | return( -1 ); |
1048 | 0 | } |
1049 | 0 | } |
1050 | 0 | return( result ); |
1051 | 0 | } |
1052 | | |
1053 | | /* Retrieves the data as an UTF-8 encoded string |
1054 | | * The function uses the codepage in the column definition if necessary |
1055 | | * The size should include the end of string character |
1056 | | * Returns 1 if successful, 0 if value is NULL or -1 on error |
1057 | | */ |
1058 | | int libesedb_long_value_get_utf8_string( |
1059 | | libesedb_long_value_t *long_value, |
1060 | | uint8_t *utf8_string, |
1061 | | size_t utf8_string_size, |
1062 | | libcerror_error_t **error ) |
1063 | 0 | { |
1064 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
1065 | 0 | libfvalue_value_t *record_value = NULL; |
1066 | 0 | static char *function = "libesedb_long_value_get_utf8_string"; |
1067 | 0 | uint32_t column_type = 0; |
1068 | 0 | int result = 0; |
1069 | |
|
1070 | 0 | if( long_value == NULL ) |
1071 | 0 | { |
1072 | 0 | libcerror_error_set( |
1073 | 0 | error, |
1074 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1075 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1076 | 0 | "%s: invalid long value.", |
1077 | 0 | function ); |
1078 | |
|
1079 | 0 | return( -1 ); |
1080 | 0 | } |
1081 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
1082 | |
|
1083 | 0 | if( libesedb_catalog_definition_get_column_type( |
1084 | 0 | internal_long_value->column_catalog_definition, |
1085 | 0 | &column_type, |
1086 | 0 | error ) != 1 ) |
1087 | 0 | { |
1088 | 0 | libcerror_error_set( |
1089 | 0 | error, |
1090 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1091 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1092 | 0 | "%s: unable to retrieve catalog definition column type.", |
1093 | 0 | function ); |
1094 | |
|
1095 | 0 | return( -1 ); |
1096 | 0 | } |
1097 | 0 | if( ( column_type != LIBESEDB_COLUMN_TYPE_TEXT ) |
1098 | 0 | && ( column_type != LIBESEDB_COLUMN_TYPE_LARGE_TEXT ) ) |
1099 | 0 | { |
1100 | 0 | libcerror_error_set( |
1101 | 0 | error, |
1102 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1103 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1104 | 0 | "%s: unsupported column type: %" PRIu32 ".", |
1105 | 0 | function, |
1106 | 0 | column_type ); |
1107 | |
|
1108 | 0 | return( -1 ); |
1109 | 0 | } |
1110 | 0 | if( libesedb_long_value_get_record_value( |
1111 | 0 | internal_long_value, |
1112 | 0 | &record_value, |
1113 | 0 | error ) != 1 ) |
1114 | 0 | { |
1115 | 0 | libcerror_error_set( |
1116 | 0 | error, |
1117 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1118 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1119 | 0 | "%s: unable to retrieve record value.", |
1120 | 0 | function ); |
1121 | |
|
1122 | 0 | return( -1 ); |
1123 | 0 | } |
1124 | 0 | result = libfvalue_value_has_data( |
1125 | 0 | record_value, |
1126 | 0 | error ); |
1127 | |
|
1128 | 0 | if( result == -1 ) |
1129 | 0 | { |
1130 | 0 | libcerror_error_set( |
1131 | 0 | error, |
1132 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1133 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1134 | 0 | "%s: unable to determine if record value has data.", |
1135 | 0 | function ); |
1136 | |
|
1137 | 0 | return( -1 ); |
1138 | 0 | } |
1139 | 0 | else if( result != 0 ) |
1140 | 0 | { |
1141 | 0 | result = libfvalue_value_copy_to_utf8_string( |
1142 | 0 | record_value, |
1143 | 0 | 0, |
1144 | 0 | utf8_string, |
1145 | 0 | utf8_string_size, |
1146 | 0 | error ); |
1147 | |
|
1148 | 0 | if( result != 1 ) |
1149 | 0 | { |
1150 | 0 | libcerror_error_set( |
1151 | 0 | error, |
1152 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1153 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1154 | 0 | "%s: unable to copy value to UTF-8 string.", |
1155 | 0 | function ); |
1156 | |
|
1157 | 0 | return( -1 ); |
1158 | 0 | } |
1159 | 0 | } |
1160 | 0 | return( result ); |
1161 | 0 | } |
1162 | | |
1163 | | /* Retrieves the size of the data as an UTF-16 encoded string |
1164 | | * The returned size includes the end of string character |
1165 | | * Returns 1 if successful, 0 if value is NULL or -1 on error |
1166 | | */ |
1167 | | int libesedb_long_value_get_utf16_string_size( |
1168 | | libesedb_long_value_t *long_value, |
1169 | | size_t *utf16_string_size, |
1170 | | libcerror_error_t **error ) |
1171 | 0 | { |
1172 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
1173 | 0 | libfvalue_value_t *record_value = NULL; |
1174 | 0 | static char *function = "libesedb_long_value_get_utf16_string_size"; |
1175 | 0 | uint32_t column_type = 0; |
1176 | 0 | int result = 0; |
1177 | |
|
1178 | 0 | if( long_value == NULL ) |
1179 | 0 | { |
1180 | 0 | libcerror_error_set( |
1181 | 0 | error, |
1182 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1183 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1184 | 0 | "%s: invalid long value.", |
1185 | 0 | function ); |
1186 | |
|
1187 | 0 | return( -1 ); |
1188 | 0 | } |
1189 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
1190 | |
|
1191 | 0 | if( libesedb_catalog_definition_get_column_type( |
1192 | 0 | internal_long_value->column_catalog_definition, |
1193 | 0 | &column_type, |
1194 | 0 | error ) != 1 ) |
1195 | 0 | { |
1196 | 0 | libcerror_error_set( |
1197 | 0 | error, |
1198 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1199 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1200 | 0 | "%s: unable to retrieve catalog definition column type.", |
1201 | 0 | function ); |
1202 | |
|
1203 | 0 | return( -1 ); |
1204 | 0 | } |
1205 | 0 | if( ( column_type != LIBESEDB_COLUMN_TYPE_TEXT ) |
1206 | 0 | && ( column_type != LIBESEDB_COLUMN_TYPE_LARGE_TEXT ) ) |
1207 | 0 | { |
1208 | 0 | libcerror_error_set( |
1209 | 0 | error, |
1210 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1211 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1212 | 0 | "%s: unsupported column type: %" PRIu32 ".", |
1213 | 0 | function, |
1214 | 0 | column_type ); |
1215 | |
|
1216 | 0 | return( -1 ); |
1217 | 0 | } |
1218 | 0 | if( libesedb_long_value_get_record_value( |
1219 | 0 | internal_long_value, |
1220 | 0 | &record_value, |
1221 | 0 | error ) != 1 ) |
1222 | 0 | { |
1223 | 0 | libcerror_error_set( |
1224 | 0 | error, |
1225 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1226 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1227 | 0 | "%s: unable to retrieve record value.", |
1228 | 0 | function ); |
1229 | |
|
1230 | 0 | return( -1 ); |
1231 | 0 | } |
1232 | 0 | result = libfvalue_value_has_data( |
1233 | 0 | record_value, |
1234 | 0 | error ); |
1235 | |
|
1236 | 0 | if( result == -1 ) |
1237 | 0 | { |
1238 | 0 | libcerror_error_set( |
1239 | 0 | error, |
1240 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1241 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1242 | 0 | "%s: unable to determine if record value has data.", |
1243 | 0 | function ); |
1244 | |
|
1245 | 0 | return( -1 ); |
1246 | 0 | } |
1247 | 0 | else if( result != 0 ) |
1248 | 0 | { |
1249 | 0 | result = libfvalue_value_get_utf16_string_size( |
1250 | 0 | record_value, |
1251 | 0 | 0, |
1252 | 0 | utf16_string_size, |
1253 | 0 | error ); |
1254 | |
|
1255 | 0 | if( result != 1 ) |
1256 | 0 | { |
1257 | 0 | libcerror_error_set( |
1258 | 0 | error, |
1259 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1260 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1261 | 0 | "%s: unable retrieve UTF-16 string size.", |
1262 | 0 | function ); |
1263 | |
|
1264 | 0 | return( -1 ); |
1265 | 0 | } |
1266 | 0 | } |
1267 | 0 | return( result ); |
1268 | 0 | } |
1269 | | |
1270 | | /* Retrieves the data as an UTF-16 encoded string |
1271 | | * The function uses the codepage in the column definition if necessary |
1272 | | * The size should include the end of string character |
1273 | | * Returns 1 if successful, 0 if value is NULL or -1 on error |
1274 | | */ |
1275 | | int libesedb_long_value_get_utf16_string( |
1276 | | libesedb_long_value_t *long_value, |
1277 | | uint16_t *utf16_string, |
1278 | | size_t utf16_string_size, |
1279 | | libcerror_error_t **error ) |
1280 | 0 | { |
1281 | 0 | libesedb_internal_long_value_t *internal_long_value = NULL; |
1282 | 0 | libfvalue_value_t *record_value = NULL; |
1283 | 0 | static char *function = "libesedb_long_value_get_utf16_string"; |
1284 | 0 | uint32_t column_type = 0; |
1285 | 0 | int result = 0; |
1286 | |
|
1287 | 0 | if( long_value == NULL ) |
1288 | 0 | { |
1289 | 0 | libcerror_error_set( |
1290 | 0 | error, |
1291 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1292 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1293 | 0 | "%s: invalid long value.", |
1294 | 0 | function ); |
1295 | |
|
1296 | 0 | return( -1 ); |
1297 | 0 | } |
1298 | 0 | internal_long_value = (libesedb_internal_long_value_t *) long_value; |
1299 | |
|
1300 | 0 | if( libesedb_catalog_definition_get_column_type( |
1301 | 0 | internal_long_value->column_catalog_definition, |
1302 | 0 | &column_type, |
1303 | 0 | error ) != 1 ) |
1304 | 0 | { |
1305 | 0 | libcerror_error_set( |
1306 | 0 | error, |
1307 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1308 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1309 | 0 | "%s: unable to retrieve catalog definition column type.", |
1310 | 0 | function ); |
1311 | |
|
1312 | 0 | return( -1 ); |
1313 | 0 | } |
1314 | 0 | if( ( column_type != LIBESEDB_COLUMN_TYPE_TEXT ) |
1315 | 0 | && ( column_type != LIBESEDB_COLUMN_TYPE_LARGE_TEXT ) ) |
1316 | 0 | { |
1317 | 0 | libcerror_error_set( |
1318 | 0 | error, |
1319 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1320 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1321 | 0 | "%s: unsupported column type: %" PRIu32 ".", |
1322 | 0 | function, |
1323 | 0 | column_type ); |
1324 | |
|
1325 | 0 | return( -1 ); |
1326 | 0 | } |
1327 | 0 | if( libesedb_long_value_get_record_value( |
1328 | 0 | internal_long_value, |
1329 | 0 | &record_value, |
1330 | 0 | error ) != 1 ) |
1331 | 0 | { |
1332 | 0 | libcerror_error_set( |
1333 | 0 | error, |
1334 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1335 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1336 | 0 | "%s: unable to retrieve record value.", |
1337 | 0 | function ); |
1338 | |
|
1339 | 0 | return( -1 ); |
1340 | 0 | } |
1341 | 0 | result = libfvalue_value_has_data( |
1342 | 0 | record_value, |
1343 | 0 | error ); |
1344 | |
|
1345 | 0 | if( result == -1 ) |
1346 | 0 | { |
1347 | 0 | libcerror_error_set( |
1348 | 0 | error, |
1349 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1350 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1351 | 0 | "%s: unable to determine if record value has data.", |
1352 | 0 | function ); |
1353 | |
|
1354 | 0 | return( -1 ); |
1355 | 0 | } |
1356 | 0 | else if( result != 0 ) |
1357 | 0 | { |
1358 | 0 | result = libfvalue_value_copy_to_utf16_string( |
1359 | 0 | record_value, |
1360 | 0 | 0, |
1361 | 0 | utf16_string, |
1362 | 0 | utf16_string_size, |
1363 | 0 | error ); |
1364 | |
|
1365 | 0 | if( result != 1 ) |
1366 | 0 | { |
1367 | 0 | libcerror_error_set( |
1368 | 0 | error, |
1369 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1370 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1371 | 0 | "%s: unable to copy value to UTF-16 string.", |
1372 | 0 | function ); |
1373 | |
|
1374 | 0 | return( -1 ); |
1375 | 0 | } |
1376 | 0 | } |
1377 | 0 | return( result ); |
1378 | 0 | } |
1379 | | |