/src/libregf/libregf/libregf_value_item.c
Line | Count | Source |
1 | | /* |
2 | | * Value item 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 "libregf_data_block_key.h" |
27 | | #include "libregf_data_block_stream.h" |
28 | | #include "libregf_debug.h" |
29 | | #include "libregf_definitions.h" |
30 | | #include "libregf_hive_bin_cell.h" |
31 | | #include "libregf_hive_bins_list.h" |
32 | | #include "libregf_libbfio.h" |
33 | | #include "libregf_libcerror.h" |
34 | | #include "libregf_libcnotify.h" |
35 | | #include "libregf_libfcache.h" |
36 | | #include "libregf_libfdata.h" |
37 | | #include "libregf_libuna.h" |
38 | | #include "libregf_multi_string.h" |
39 | | #include "libregf_unused.h" |
40 | | #include "libregf_value_item.h" |
41 | | #include "libregf_value_key.h" |
42 | | |
43 | | #include "regf_cell_values.h" |
44 | | |
45 | | /* Creates value item |
46 | | * Make sure the value value_item is referencing, is set to NULL |
47 | | * Returns 1 if successful or -1 on error |
48 | | */ |
49 | | int libregf_value_item_initialize( |
50 | | libregf_value_item_t **value_item, |
51 | | libcerror_error_t **error ) |
52 | 42.0k | { |
53 | 42.0k | static char *function = "libregf_value_item_initialize"; |
54 | | |
55 | 42.0k | if( value_item == NULL ) |
56 | 0 | { |
57 | 0 | libcerror_error_set( |
58 | 0 | error, |
59 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
60 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
61 | 0 | "%s: invalid value item.", |
62 | 0 | function ); |
63 | |
|
64 | 0 | return( -1 ); |
65 | 0 | } |
66 | 42.0k | if( *value_item != NULL ) |
67 | 0 | { |
68 | 0 | libcerror_error_set( |
69 | 0 | error, |
70 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
71 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
72 | 0 | "%s: invalid value item value already set.", |
73 | 0 | function ); |
74 | |
|
75 | 0 | return( -1 ); |
76 | 0 | } |
77 | 42.0k | *value_item = memory_allocate_structure( |
78 | 42.0k | libregf_value_item_t ); |
79 | | |
80 | 42.0k | if( *value_item == NULL ) |
81 | 0 | { |
82 | 0 | libcerror_error_set( |
83 | 0 | error, |
84 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
85 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
86 | 0 | "%s: unable to create value item.", |
87 | 0 | function ); |
88 | |
|
89 | 0 | goto on_error; |
90 | 0 | } |
91 | 42.0k | if( memory_set( |
92 | 42.0k | *value_item, |
93 | 42.0k | 0, |
94 | 42.0k | sizeof( libregf_value_item_t ) ) == NULL ) |
95 | 0 | { |
96 | 0 | libcerror_error_set( |
97 | 0 | error, |
98 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
99 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
100 | 0 | "%s: unable to clear value item.", |
101 | 0 | function ); |
102 | |
|
103 | 0 | goto on_error; |
104 | 0 | } |
105 | 42.0k | return( 1 ); |
106 | | |
107 | 0 | on_error: |
108 | 0 | if( *value_item != NULL ) |
109 | 0 | { |
110 | 0 | memory_free( |
111 | 0 | *value_item ); |
112 | |
|
113 | 0 | *value_item = NULL; |
114 | 0 | } |
115 | 0 | return( -1 ); |
116 | 42.0k | } |
117 | | |
118 | | /* Frees value item |
119 | | * Returns 1 if successful or -1 on error |
120 | | */ |
121 | | int libregf_value_item_free( |
122 | | libregf_value_item_t **value_item, |
123 | | libcerror_error_t **error ) |
124 | 42.0k | { |
125 | 42.0k | static char *function = "libregf_value_item_free"; |
126 | 42.0k | int result = 1; |
127 | | |
128 | 42.0k | if( value_item == NULL ) |
129 | 0 | { |
130 | 0 | libcerror_error_set( |
131 | 0 | error, |
132 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
133 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
134 | 0 | "%s: invalid value item.", |
135 | 0 | function ); |
136 | |
|
137 | 0 | return( -1 ); |
138 | 0 | } |
139 | 42.0k | if( *value_item != NULL ) |
140 | 42.0k | { |
141 | 42.0k | if( ( *value_item )->value_key != NULL ) |
142 | 24.2k | { |
143 | 24.2k | if( libregf_value_key_free( |
144 | 24.2k | &( ( *value_item )->value_key ), |
145 | 24.2k | error ) != 1 ) |
146 | 0 | { |
147 | 0 | libcerror_error_set( |
148 | 0 | error, |
149 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
150 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
151 | 0 | "%s: unable to free value key.", |
152 | 0 | function ); |
153 | |
|
154 | 0 | result = -1; |
155 | 0 | } |
156 | 24.2k | } |
157 | 42.0k | if( ( *value_item )->data_buffer != NULL ) |
158 | 2.57k | { |
159 | 2.57k | memory_free( |
160 | 2.57k | ( *value_item )->data_buffer ); |
161 | 2.57k | } |
162 | 42.0k | if( ( *value_item )->data_stream != NULL ) |
163 | 28 | { |
164 | 28 | if( libfdata_stream_free( |
165 | 28 | &( ( *value_item )->data_stream ), |
166 | 28 | error ) != 1 ) |
167 | 0 | { |
168 | 0 | libcerror_error_set( |
169 | 0 | error, |
170 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
171 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
172 | 0 | "%s: unable to free data stream.", |
173 | 0 | function ); |
174 | |
|
175 | 0 | result = -1; |
176 | 0 | } |
177 | 28 | } |
178 | 42.0k | memory_free( |
179 | 42.0k | *value_item ); |
180 | | |
181 | 42.0k | *value_item = NULL; |
182 | 42.0k | } |
183 | 42.0k | return( result ); |
184 | 42.0k | } |
185 | | |
186 | | /* Clones (duplicates) the value item |
187 | | * Returns 1 if successful or -1 on error |
188 | | */ |
189 | | int libregf_value_item_clone( |
190 | | libregf_value_item_t **destination_value_item, |
191 | | libregf_value_item_t *source_value_item, |
192 | | libcerror_error_t **error ) |
193 | 11.7k | { |
194 | 11.7k | static char *function = "libregf_value_item_clone"; |
195 | | |
196 | 11.7k | if( destination_value_item == NULL ) |
197 | 0 | { |
198 | 0 | libcerror_error_set( |
199 | 0 | error, |
200 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
201 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
202 | 0 | "%s: invalid destination value item.", |
203 | 0 | function ); |
204 | |
|
205 | 0 | return( -1 ); |
206 | 0 | } |
207 | 11.7k | if( *destination_value_item != NULL ) |
208 | 0 | { |
209 | 0 | libcerror_error_set( |
210 | 0 | error, |
211 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
212 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
213 | 0 | "%s: destination value item already set.", |
214 | 0 | function ); |
215 | |
|
216 | 0 | return( -1 ); |
217 | 0 | } |
218 | 11.7k | if( source_value_item == NULL ) |
219 | 0 | { |
220 | 0 | *destination_value_item = NULL; |
221 | |
|
222 | 0 | return( 1 ); |
223 | 0 | } |
224 | 11.7k | if( libregf_value_item_initialize( |
225 | 11.7k | destination_value_item, |
226 | 11.7k | error ) != 1 ) |
227 | 0 | { |
228 | 0 | libcerror_error_set( |
229 | 0 | error, |
230 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
231 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
232 | 0 | "%s: unable to create destination value item.", |
233 | 0 | function ); |
234 | |
|
235 | 0 | goto on_error; |
236 | 0 | } |
237 | 11.7k | if( libregf_value_key_clone( |
238 | 11.7k | &( ( *destination_value_item )->value_key ), |
239 | 11.7k | source_value_item->value_key, |
240 | 11.7k | error ) != 1 ) |
241 | 0 | { |
242 | 0 | libcerror_error_set( |
243 | 0 | error, |
244 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
245 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
246 | 0 | "%s: unable to clone value key.", |
247 | 0 | function ); |
248 | |
|
249 | 0 | goto on_error; |
250 | 0 | } |
251 | 11.7k | if( source_value_item->data_buffer != NULL ) |
252 | 1.28k | { |
253 | 1.28k | if( ( source_value_item->data_buffer_size == 0 ) |
254 | 1.28k | || ( source_value_item->data_buffer_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
255 | 0 | { |
256 | 0 | libcerror_error_set( |
257 | 0 | error, |
258 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
259 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
260 | 0 | "%s: invalid source value item - invalid data buffer size value out of bounds.", |
261 | 0 | function ); |
262 | |
|
263 | 0 | goto on_error; |
264 | 0 | } |
265 | 1.28k | ( *destination_value_item )->data_buffer = (uint8_t *) memory_allocate( |
266 | 1.28k | sizeof( uint8_t ) * source_value_item->data_buffer_size ); |
267 | | |
268 | 1.28k | if( ( *destination_value_item )->data_buffer == NULL ) |
269 | 0 | { |
270 | 0 | libcerror_error_set( |
271 | 0 | error, |
272 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
273 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
274 | 0 | "%s: unable to create value data buffer.", |
275 | 0 | function ); |
276 | |
|
277 | 0 | goto on_error; |
278 | 0 | } |
279 | 1.28k | if( memory_copy( |
280 | 1.28k | ( *destination_value_item )->data_buffer, |
281 | 1.28k | source_value_item->data_buffer, |
282 | 1.28k | (size_t) source_value_item->data_buffer_size ) == NULL ) |
283 | 0 | { |
284 | 0 | libcerror_error_set( |
285 | 0 | error, |
286 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
287 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
288 | 0 | "%s: unable to copy value data buffer.", |
289 | 0 | function ); |
290 | |
|
291 | 0 | goto on_error; |
292 | 0 | } |
293 | 1.28k | ( *destination_value_item )->data_buffer_size = source_value_item->data_buffer_size; |
294 | 1.28k | } |
295 | 11.7k | if( source_value_item->data_stream != NULL ) |
296 | 16 | { |
297 | 16 | if( libfdata_stream_clone( |
298 | 16 | &( ( *destination_value_item )->data_stream ), |
299 | 16 | source_value_item->data_stream, |
300 | 16 | error ) != 1 ) |
301 | 0 | { |
302 | 0 | libcerror_error_set( |
303 | 0 | error, |
304 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
305 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
306 | 0 | "%s: unable to clone data stream.", |
307 | 0 | function ); |
308 | |
|
309 | 0 | goto on_error; |
310 | 0 | } |
311 | 16 | } |
312 | 11.7k | ( *destination_value_item )->data_type = source_value_item->data_type; |
313 | 11.7k | ( *destination_value_item )->item_flags = source_value_item->item_flags; |
314 | | |
315 | 11.7k | return( 1 ); |
316 | | |
317 | 0 | on_error: |
318 | 0 | libregf_value_item_free( |
319 | 0 | destination_value_item, |
320 | 0 | NULL ); |
321 | |
|
322 | 0 | return( -1 ); |
323 | 11.7k | } |
324 | | |
325 | | /* Reads a value key |
326 | | * Returns 1 if successful or -1 on error |
327 | | */ |
328 | | int libregf_value_item_read_value_key( |
329 | | libregf_value_item_t *value_item, |
330 | | libbfio_handle_t *file_io_handle, |
331 | | libregf_hive_bins_list_t *hive_bins_list, |
332 | | uint32_t value_key_offset, |
333 | | libcerror_error_t **error ) |
334 | 30.3k | { |
335 | 30.3k | libregf_hive_bin_cell_t *hive_bin_cell = NULL; |
336 | 30.3k | static char *function = "libregf_value_item_read_value_key"; |
337 | 30.3k | size_t value_key_data_size = 0; |
338 | 30.3k | int hive_bin_index = 0; |
339 | 30.3k | int result = 0; |
340 | | |
341 | 30.3k | if( value_item == NULL ) |
342 | 0 | { |
343 | 0 | libcerror_error_set( |
344 | 0 | error, |
345 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
346 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
347 | 0 | "%s: invalid value item.", |
348 | 0 | function ); |
349 | |
|
350 | 0 | return( -1 ); |
351 | 0 | } |
352 | 30.3k | if( value_item->value_key != NULL ) |
353 | 0 | { |
354 | 0 | libcerror_error_set( |
355 | 0 | error, |
356 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
357 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
358 | 0 | "%s: invalid value item - value key value already set.", |
359 | 0 | function ); |
360 | |
|
361 | 0 | return( -1 ); |
362 | 0 | } |
363 | 30.3k | if( hive_bins_list == NULL ) |
364 | 0 | { |
365 | 0 | libcerror_error_set( |
366 | 0 | error, |
367 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
368 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
369 | 0 | "%s: invalid hive bins list.", |
370 | 0 | function ); |
371 | |
|
372 | 0 | return( -1 ); |
373 | 0 | } |
374 | 30.3k | if( hive_bins_list->io_handle == NULL ) |
375 | 0 | { |
376 | 0 | libcerror_error_set( |
377 | 0 | error, |
378 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
379 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
380 | 0 | "%s: invalid hive bins list - missing IO handle.", |
381 | 0 | function ); |
382 | |
|
383 | 0 | return( -1 ); |
384 | 0 | } |
385 | 30.3k | value_key_data_size = sizeof( regf_value_key_t ); |
386 | | |
387 | 30.3k | if( ( hive_bins_list->io_handle->major_version == 1 ) |
388 | 15.1k | && ( hive_bins_list->io_handle->minor_version <= 1 ) ) |
389 | 0 | { |
390 | 0 | value_key_data_size += 4; |
391 | 0 | } |
392 | 30.3k | if( ( value_key_offset == 0 ) |
393 | 22.5k | || ( value_key_offset == 0xffffffffUL ) ) |
394 | 7.73k | { |
395 | 7.73k | libcerror_error_set( |
396 | 7.73k | error, |
397 | 7.73k | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
398 | 7.73k | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
399 | 7.73k | "%s: invalid value key offset.", |
400 | 7.73k | function ); |
401 | | |
402 | 7.73k | return( -1 ); |
403 | 7.73k | } |
404 | 22.5k | if( libregf_hive_bins_list_get_cell_at_offset( |
405 | 22.5k | hive_bins_list, |
406 | 22.5k | file_io_handle, |
407 | 22.5k | value_key_offset, |
408 | 22.5k | &hive_bin_cell, |
409 | 22.5k | error ) != 1 ) |
410 | 9.29k | { |
411 | 9.29k | libcerror_error_set( |
412 | 9.29k | error, |
413 | 9.29k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
414 | 9.29k | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
415 | 9.29k | "%s: unable to retrieve hive bin at offset: %" PRIu32 " (0x%08" PRIx32 ").", |
416 | 9.29k | function, |
417 | 9.29k | value_key_offset, |
418 | 9.29k | value_key_offset ); |
419 | | |
420 | 9.29k | goto on_error; |
421 | 9.29k | } |
422 | 13.2k | if( hive_bin_cell->size < value_key_data_size ) |
423 | 41 | { |
424 | | #if defined( HAVE_DEBUG_OUTPUT ) |
425 | | if( libcnotify_verbose != 0 ) |
426 | | { |
427 | | libcnotify_printf( |
428 | | "%s: invalid hive bin cell size value too small.\n", |
429 | | function ); |
430 | | } |
431 | | #endif |
432 | 41 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
433 | | |
434 | 41 | return( 1 ); |
435 | 41 | } |
436 | 13.2k | if( libregf_value_key_initialize( |
437 | 13.2k | &( value_item->value_key ), |
438 | 13.2k | error ) != 1 ) |
439 | 0 | { |
440 | 0 | libcerror_error_set( |
441 | 0 | error, |
442 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
443 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
444 | 0 | "%s: unable to create value key.", |
445 | 0 | function ); |
446 | |
|
447 | 0 | goto on_error; |
448 | 0 | } |
449 | | /* TODO pass value name hash */ |
450 | 13.2k | result = libregf_value_key_read_data( |
451 | 13.2k | value_item->value_key, |
452 | 13.2k | hive_bins_list->io_handle, |
453 | 13.2k | hive_bin_cell->data, |
454 | 13.2k | hive_bin_cell->size, |
455 | 13.2k | 0, |
456 | 13.2k | error ); |
457 | | |
458 | 13.2k | if( result == -1 ) |
459 | 374 | { |
460 | 374 | libcerror_error_set( |
461 | 374 | error, |
462 | 374 | LIBCERROR_ERROR_DOMAIN_IO, |
463 | 374 | LIBCERROR_IO_ERROR_READ_FAILED, |
464 | 374 | "%s: unable to read value key at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
465 | 374 | function, |
466 | 374 | value_key_offset, |
467 | 374 | value_key_offset ); |
468 | | |
469 | 374 | goto on_error; |
470 | 374 | } |
471 | 12.8k | else if( result == 0 ) |
472 | 10.9k | { |
473 | | #if defined( HAVE_DEBUG_OUTPUT ) |
474 | | if( libcnotify_verbose != 0 ) |
475 | | { |
476 | | libcnotify_printf( |
477 | | "%s: unsupported value key signature.\n", |
478 | | function ); |
479 | | } |
480 | | #endif |
481 | 10.9k | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
482 | | |
483 | 10.9k | return( 1 ); |
484 | 10.9k | } |
485 | | /* TODO |
486 | | if( value_item->name_size > hive_bin_cell->size ) |
487 | | { |
488 | | #if defined( HAVE_DEBUG_OUTPUT ) |
489 | | if( libcnotify_verbose != 0 ) |
490 | | { |
491 | | libcnotify_printf( |
492 | | "%s: invalid value name size value out of bounds.\n", |
493 | | function ); |
494 | | } |
495 | | #endif |
496 | | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
497 | | |
498 | | return( 1 ); |
499 | | } |
500 | | */ |
501 | | |
502 | 1.91k | if( value_item->value_key->data_in_key != 0 ) |
503 | 157 | { |
504 | | /* TODO |
505 | | if( value_key->data_size > 4 ) |
506 | | { |
507 | | #if defined( HAVE_DEBUG_OUTPUT ) |
508 | | if( libcnotify_verbose != 0 ) |
509 | | { |
510 | | libcnotify_printf( |
511 | | "%s: invalid data size value out of bounds.\n", |
512 | | function ); |
513 | | } |
514 | | #endif |
515 | | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
516 | | |
517 | | return( 1 ); |
518 | | } |
519 | | */ |
520 | 157 | value_item->data_buffer = value_item->value_key->data; |
521 | 157 | value_item->data_buffer_size = value_item->value_key->data_size; |
522 | 157 | value_item->data_type = LIBREGF_VALUE_ITEM_DATA_TYPE_BUFFER; |
523 | | |
524 | 157 | value_item->value_key->data = NULL; |
525 | 157 | value_item->value_key->data_size = 0; |
526 | 157 | } |
527 | 1.75k | else |
528 | 1.75k | { |
529 | 1.75k | result = libregf_hive_bins_list_get_index_at_offset( |
530 | 1.75k | hive_bins_list, |
531 | 1.75k | (off64_t) value_item->value_key->data_offset, |
532 | 1.75k | &hive_bin_index, |
533 | 1.75k | error ); |
534 | | |
535 | 1.75k | if( result == -1 ) |
536 | 0 | { |
537 | 0 | libcerror_error_set( |
538 | 0 | error, |
539 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
540 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
541 | 0 | "%s: unable to determine hive bin value index for data offset: %" PRIu32 " (0x%08" PRIx32 ").", |
542 | 0 | function, |
543 | 0 | value_item->value_key->data_offset, |
544 | 0 | value_item->value_key->data_offset ); |
545 | |
|
546 | 0 | goto on_error; |
547 | 0 | } |
548 | 1.75k | else if( result == 0 ) |
549 | 194 | { |
550 | 194 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
551 | 194 | } |
552 | 1.56k | else |
553 | 1.56k | { |
554 | 1.56k | if( libregf_value_item_read_value_data( |
555 | 1.56k | value_item, |
556 | 1.56k | file_io_handle, |
557 | 1.56k | hive_bins_list, |
558 | 1.56k | value_item->value_key->data_offset, |
559 | 1.56k | value_item->value_key->data_size, |
560 | 1.56k | error ) != 1 ) |
561 | 307 | { |
562 | 307 | libcerror_error_set( |
563 | 307 | error, |
564 | 307 | LIBCERROR_ERROR_DOMAIN_IO, |
565 | 307 | LIBCERROR_IO_ERROR_READ_FAILED, |
566 | 307 | "%s: unable to read value data at offset: %" PRIu32 " (0x%08" PRIx32 ").", |
567 | 307 | function, |
568 | 307 | value_item->value_key->data_offset, |
569 | 307 | value_item->value_key->data_offset ); |
570 | | |
571 | 307 | goto on_error; |
572 | 307 | } |
573 | 1.56k | } |
574 | 1.75k | } |
575 | 1.60k | return( 1 ); |
576 | | |
577 | 9.97k | on_error: |
578 | 9.97k | if( value_item->data_buffer != NULL ) |
579 | 0 | { |
580 | 0 | memory_free( |
581 | 0 | value_item->data_buffer ); |
582 | |
|
583 | 0 | value_item->data_buffer = NULL; |
584 | 0 | } |
585 | 9.97k | value_item->data_buffer_size = 0; |
586 | | |
587 | 9.97k | if( value_item->value_key != NULL ) |
588 | 681 | { |
589 | 681 | libregf_value_key_free( |
590 | 681 | &( value_item->value_key ), |
591 | 681 | NULL ); |
592 | 681 | } |
593 | 9.97k | return( -1 ); |
594 | 1.91k | } |
595 | | |
596 | | /* Reads value data |
597 | | * Returns 1 if successful or -1 on error |
598 | | */ |
599 | | int libregf_value_item_read_value_data( |
600 | | libregf_value_item_t *value_item, |
601 | | libbfio_handle_t *file_io_handle, |
602 | | libregf_hive_bins_list_t *hive_bins_list, |
603 | | uint32_t value_data_offset, |
604 | | uint32_t value_data_size, |
605 | | libcerror_error_t **error ) |
606 | 1.56k | { |
607 | 1.56k | libregf_data_block_key_t *data_block_key = NULL; |
608 | 1.56k | libregf_hive_bin_cell_t *hive_bin_cell = NULL; |
609 | 1.56k | static char *function = "libregf_value_item_read_value_data"; |
610 | 1.56k | size_t data_offset = 0; |
611 | 1.56k | size_t utf16_string_size = 0; |
612 | 1.56k | uint32_t calculated_value_data_size = 0; |
613 | 1.56k | uint32_t value_type = 0; |
614 | 1.56k | int hive_bin_index = 0; |
615 | 1.56k | int result = 0; |
616 | | |
617 | 1.56k | if( value_item == NULL ) |
618 | 0 | { |
619 | 0 | libcerror_error_set( |
620 | 0 | error, |
621 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
622 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
623 | 0 | "%s: invalid value item.", |
624 | 0 | function ); |
625 | |
|
626 | 0 | return( -1 ); |
627 | 0 | } |
628 | 1.56k | if( hive_bins_list == NULL ) |
629 | 0 | { |
630 | 0 | libcerror_error_set( |
631 | 0 | error, |
632 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
633 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
634 | 0 | "%s: invalid hive bins list.", |
635 | 0 | function ); |
636 | |
|
637 | 0 | return( -1 ); |
638 | 0 | } |
639 | 1.56k | if( hive_bins_list->io_handle == NULL ) |
640 | 0 | { |
641 | 0 | libcerror_error_set( |
642 | 0 | error, |
643 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
644 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
645 | 0 | "%s: invalid hive bins list - missing IO handle.", |
646 | 0 | function ); |
647 | |
|
648 | 0 | return( -1 ); |
649 | 0 | } |
650 | 1.56k | if( ( value_data_offset == 0 ) |
651 | 1.53k | || ( value_data_offset == 0xffffffffUL ) ) |
652 | 27 | { |
653 | 27 | libcerror_error_set( |
654 | 27 | error, |
655 | 27 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
656 | 27 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
657 | 27 | "%s: invalid value data offset.", |
658 | 27 | function ); |
659 | | |
660 | 27 | return( -1 ); |
661 | 27 | } |
662 | 1.53k | if( libregf_hive_bins_list_get_cell_at_offset( |
663 | 1.53k | hive_bins_list, |
664 | 1.53k | file_io_handle, |
665 | 1.53k | value_data_offset, |
666 | 1.53k | &hive_bin_cell, |
667 | 1.53k | error ) != 1 ) |
668 | 138 | { |
669 | 138 | libcerror_error_set( |
670 | 138 | error, |
671 | 138 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
672 | 138 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
673 | 138 | "%s: unable to retrieve hive bin at offset: %" PRIu32 ".", |
674 | 138 | function, |
675 | 138 | value_data_offset ); |
676 | | |
677 | 138 | goto on_error; |
678 | 138 | } |
679 | | /* As of version 1.5 large value data is stored in a data block |
680 | | */ |
681 | 1.39k | if( ( value_data_size > 16344 ) |
682 | 445 | && ( hive_bins_list->io_handle->major_version >= 1 ) |
683 | 444 | && ( hive_bins_list->io_handle->minor_version >= 5 ) ) |
684 | 238 | { |
685 | 238 | if( libregf_data_block_key_initialize( |
686 | 238 | &data_block_key, |
687 | 238 | error ) != 1 ) |
688 | 0 | { |
689 | 0 | libcerror_error_set( |
690 | 0 | error, |
691 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
692 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
693 | 0 | "%s: unable to create data block key.", |
694 | 0 | function ); |
695 | |
|
696 | 0 | goto on_error; |
697 | 0 | } |
698 | 238 | result = libregf_data_block_key_read_data( |
699 | 238 | data_block_key, |
700 | 238 | hive_bin_cell->data, |
701 | 238 | hive_bin_cell->size, |
702 | 238 | error ); |
703 | | |
704 | 238 | if( result == -1 ) |
705 | 98 | { |
706 | 98 | libcerror_error_set( |
707 | 98 | error, |
708 | 98 | LIBCERROR_ERROR_DOMAIN_IO, |
709 | 98 | LIBCERROR_IO_ERROR_READ_FAILED, |
710 | 98 | "%s: unable to read data block key at offset: %" PRIu32 " (0x%08" PRIx32 ").", |
711 | 98 | function, |
712 | 98 | value_data_offset, |
713 | 98 | value_data_offset ); |
714 | | |
715 | 98 | goto on_error; |
716 | 98 | } |
717 | 140 | result = libregf_hive_bins_list_get_index_at_offset( |
718 | 140 | hive_bins_list, |
719 | 140 | (off64_t) data_block_key->data_block_list_offset, |
720 | 140 | &hive_bin_index, |
721 | 140 | error ); |
722 | | |
723 | 140 | if( result == -1 ) |
724 | 0 | { |
725 | 0 | libcerror_error_set( |
726 | 0 | error, |
727 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
728 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
729 | 0 | "%s: unable to determine if data block list offset is valid.", |
730 | 0 | function ); |
731 | |
|
732 | 0 | goto on_error; |
733 | 0 | } |
734 | 140 | else if( result == 0 ) |
735 | 21 | { |
736 | 21 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
737 | 21 | } |
738 | 119 | else |
739 | 119 | { |
740 | 119 | if( libregf_value_item_read_data_block_list( |
741 | 119 | value_item, |
742 | 119 | file_io_handle, |
743 | 119 | hive_bins_list, |
744 | 119 | data_block_key->data_block_list_offset, |
745 | 119 | data_block_key->number_of_segments, |
746 | 119 | value_data_size, |
747 | 119 | error ) == -1 ) |
748 | 44 | { |
749 | 44 | libcerror_error_set( |
750 | 44 | error, |
751 | 44 | LIBCERROR_ERROR_DOMAIN_IO, |
752 | 44 | LIBCERROR_IO_ERROR_READ_FAILED, |
753 | 44 | "%s: unable to read data block list at offset: %" PRIu32 ".", |
754 | 44 | function, |
755 | 44 | data_block_key->data_block_list_offset ); |
756 | | |
757 | 44 | goto on_error; |
758 | 44 | } |
759 | | /* TODO: Check if number of segments stored in the data block key matches the calculated */ |
760 | 119 | } |
761 | 96 | if( libregf_data_block_key_free( |
762 | 96 | &data_block_key, |
763 | 96 | error ) != 1 ) |
764 | 0 | { |
765 | 0 | libcerror_error_set( |
766 | 0 | error, |
767 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
768 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
769 | 0 | "%s: unable to free data block key.", |
770 | 0 | function ); |
771 | |
|
772 | 0 | goto on_error; |
773 | 0 | } |
774 | 96 | } |
775 | 1.15k | else |
776 | 1.15k | { |
777 | | #if defined( HAVE_DEBUG_OUTPUT ) |
778 | | if( libcnotify_verbose != 0 ) |
779 | | { |
780 | | libcnotify_printf( |
781 | | "%s: data:\n", |
782 | | function ); |
783 | | libcnotify_print_data( |
784 | | hive_bin_cell->data, |
785 | | hive_bin_cell->size, |
786 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
787 | | } |
788 | | #endif |
789 | 1.15k | if( ( hive_bins_list->io_handle->major_version == 1 ) |
790 | 1.06k | && ( hive_bins_list->io_handle->minor_version <= 1 ) ) |
791 | 0 | { |
792 | 0 | data_offset = 4; |
793 | 0 | } |
794 | 1.15k | if( value_data_size > hive_bin_cell->size ) |
795 | 269 | { |
796 | | #if defined( HAVE_DEBUG_OUTPUT ) |
797 | | if( libcnotify_verbose != 0 ) |
798 | | { |
799 | | libcnotify_printf( |
800 | | "%s: value data size: %" PRIu32 " exceeds hive bin cell size: %" PRIzd ".\n", |
801 | | function, |
802 | | value_data_size, |
803 | | hive_bin_cell->size ); |
804 | | } |
805 | | #endif |
806 | 269 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
807 | | |
808 | 269 | if( hive_bin_cell->size > (uint32_t) INT32_MAX ) |
809 | 0 | { |
810 | 0 | libcerror_error_set( |
811 | 0 | error, |
812 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
813 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
814 | 0 | "%s: invalid hive bin cell size value out of bounds.", |
815 | 0 | function ); |
816 | |
|
817 | 0 | goto on_error; |
818 | 0 | } |
819 | 269 | value_data_size = (uint32_t) hive_bin_cell->size; |
820 | 269 | } |
821 | 1.15k | if( libregf_value_key_get_value_type( |
822 | 1.15k | value_item->value_key, |
823 | 1.15k | &value_type, |
824 | 1.15k | error ) != 1 ) |
825 | 0 | { |
826 | 0 | libcerror_error_set( |
827 | 0 | error, |
828 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
829 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
830 | 0 | "%s: unable to retrieve value type.", |
831 | 0 | function ); |
832 | |
|
833 | 0 | goto on_error; |
834 | 0 | } |
835 | 1.15k | if( ( value_type == LIBREGF_VALUE_TYPE_STRING ) |
836 | 761 | || ( value_type == LIBREGF_VALUE_TYPE_EXPANDABLE_STRING ) ) |
837 | 932 | { |
838 | 932 | calculated_value_data_size = data_offset; |
839 | | |
840 | 28.2k | while( ( calculated_value_data_size + 2 ) <= (uint32_t) hive_bin_cell->size ) |
841 | 28.2k | { |
842 | 28.2k | if( ( hive_bin_cell->data[ calculated_value_data_size ] == 0 ) |
843 | 1.78k | && ( hive_bin_cell->data[ calculated_value_data_size + 1 ] == 0 ) ) |
844 | 895 | { |
845 | 895 | calculated_value_data_size += 2; |
846 | | |
847 | 895 | break; |
848 | 895 | } |
849 | 27.3k | calculated_value_data_size += 2; |
850 | 27.3k | } |
851 | 932 | calculated_value_data_size -= data_offset; |
852 | | |
853 | 932 | if( calculated_value_data_size != value_data_size ) |
854 | 223 | { |
855 | | /* Check if the calculated string is sane |
856 | | */ |
857 | 223 | result = libuna_utf16_string_size_from_utf16_stream( |
858 | 223 | &( hive_bin_cell->data[ data_offset ] ), |
859 | 223 | calculated_value_data_size, |
860 | 223 | LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, |
861 | 223 | &utf16_string_size, |
862 | 223 | NULL ); |
863 | | |
864 | 223 | if( result != 1 ) |
865 | 0 | { |
866 | 0 | calculated_value_data_size = value_data_size; |
867 | 0 | } |
868 | 223 | } |
869 | | #if defined( HAVE_DEBUG_OUTPUT ) |
870 | | if( calculated_value_data_size != value_data_size ) |
871 | | { |
872 | | if( libcnotify_verbose != 0 ) |
873 | | { |
874 | | libcnotify_printf( |
875 | | "%s: mismatch in value data size (calculated: %" PRIu32 ", stored: %" PRIu32 ").\n", |
876 | | function, |
877 | | calculated_value_data_size, |
878 | | value_data_size ); |
879 | | } |
880 | | } |
881 | | #endif |
882 | 932 | if( calculated_value_data_size < value_data_size ) |
883 | 170 | { |
884 | 170 | value_data_size = calculated_value_data_size; |
885 | 170 | } |
886 | 932 | } |
887 | | /* TODO what about a maximum of 1 MiB ? */ |
888 | | |
889 | 1.15k | value_item->data_type = LIBREGF_VALUE_ITEM_DATA_TYPE_BUFFER; |
890 | | |
891 | 1.15k | if( value_data_size > 0 ) |
892 | 1.13k | { |
893 | 1.13k | if( value_data_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) |
894 | 0 | { |
895 | 0 | libcerror_error_set( |
896 | 0 | error, |
897 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
898 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
899 | 0 | "%s: invalid value data size value exceeds maximum allocation size.", |
900 | 0 | function ); |
901 | |
|
902 | 0 | goto on_error; |
903 | 0 | } |
904 | 1.13k | value_item->data_buffer = (uint8_t *) memory_allocate( |
905 | 1.13k | sizeof( uint8_t ) * (size_t) value_data_size ); |
906 | | |
907 | 1.13k | if( value_item->data_buffer == NULL ) |
908 | 0 | { |
909 | 0 | libcerror_error_set( |
910 | 0 | error, |
911 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
912 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
913 | 0 | "%s: unable to create data buffer.", |
914 | 0 | function ); |
915 | |
|
916 | 0 | goto on_error; |
917 | 0 | } |
918 | 1.13k | value_item->data_buffer_size = (size_t) value_data_size; |
919 | | |
920 | 1.13k | if( memory_copy( |
921 | 1.13k | value_item->data_buffer, |
922 | 1.13k | &( hive_bin_cell->data[ data_offset ] ), |
923 | 1.13k | value_data_size ) == NULL ) |
924 | 0 | { |
925 | 0 | libcerror_error_set( |
926 | 0 | error, |
927 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
928 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
929 | 0 | "%s: unable to copy data buffer.", |
930 | 0 | function ); |
931 | |
|
932 | 0 | goto on_error; |
933 | 0 | } |
934 | | #if defined( HAVE_DEBUG_OUTPUT ) |
935 | | data_offset += value_data_size; |
936 | | #endif |
937 | 1.13k | } |
938 | | #if defined( HAVE_DEBUG_OUTPUT ) |
939 | | if( libcnotify_verbose != 0 ) |
940 | | { |
941 | | if( data_offset < hive_bin_cell->size ) |
942 | | { |
943 | | libcnotify_printf( |
944 | | "%s: padding:\n", |
945 | | function ); |
946 | | libcnotify_print_data( |
947 | | &( hive_bin_cell->data[ data_offset ] ), |
948 | | hive_bin_cell->size - data_offset, |
949 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
950 | | } |
951 | | } |
952 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
953 | 1.15k | } |
954 | 1.25k | return( 1 ); |
955 | | |
956 | 280 | on_error: |
957 | 280 | if( value_item->data_buffer != NULL ) |
958 | 0 | { |
959 | 0 | memory_free( |
960 | 0 | value_item->data_buffer ); |
961 | |
|
962 | 0 | value_item->data_buffer = NULL; |
963 | 0 | } |
964 | 280 | if( data_block_key != NULL ) |
965 | 142 | { |
966 | 142 | libregf_data_block_key_free( |
967 | 142 | &data_block_key, |
968 | 142 | NULL ); |
969 | 142 | } |
970 | 280 | return( -1 ); |
971 | 1.39k | } |
972 | | |
973 | | /* Reads a data block (segments) list cell value |
974 | | * Returns 1 if successful, 0 if not or -1 on error |
975 | | */ |
976 | | int libregf_value_item_read_data_block_list( |
977 | | libregf_value_item_t *value_item, |
978 | | libbfio_handle_t *file_io_handle, |
979 | | libregf_hive_bins_list_t *hive_bins_list, |
980 | | uint32_t data_block_list_offset, |
981 | | uint16_t number_of_segments, |
982 | | uint32_t value_data_size, |
983 | | libcerror_error_t **error ) |
984 | 119 | { |
985 | 119 | libregf_hive_bin_cell_t *hive_bin_cell = NULL; |
986 | 119 | uint8_t *list_data = NULL; |
987 | 119 | static char *function = "libregf_value_item_read_data_block_list"; |
988 | 119 | size_t data_offset = 0; |
989 | 119 | size_t list_data_size = 0; |
990 | 119 | uint32_t calculated_value_data_size = 0; |
991 | 119 | uint32_t element_offset = 0; |
992 | 119 | uint32_t segment_offset = 0; |
993 | 119 | uint32_t segment_size = 0; |
994 | 119 | uint16_t element_iterator = 0; |
995 | | |
996 | 119 | if( value_item == NULL ) |
997 | 0 | { |
998 | 0 | libcerror_error_set( |
999 | 0 | error, |
1000 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1001 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1002 | 0 | "%s: invalid value item.", |
1003 | 0 | function ); |
1004 | |
|
1005 | 0 | return( -1 ); |
1006 | 0 | } |
1007 | 119 | if( hive_bins_list == NULL ) |
1008 | 0 | { |
1009 | 0 | libcerror_error_set( |
1010 | 0 | error, |
1011 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1012 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1013 | 0 | "%s: invalid hive bins list.", |
1014 | 0 | function ); |
1015 | |
|
1016 | 0 | return( -1 ); |
1017 | 0 | } |
1018 | 119 | if( hive_bins_list->io_handle == NULL ) |
1019 | 0 | { |
1020 | 0 | libcerror_error_set( |
1021 | 0 | error, |
1022 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1023 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1024 | 0 | "%s: invalid hive bins list - missing IO handle.", |
1025 | 0 | function ); |
1026 | |
|
1027 | 0 | return( -1 ); |
1028 | 0 | } |
1029 | 119 | if( ( data_block_list_offset == 0 ) |
1030 | 98 | || ( data_block_list_offset == 0xffffffffUL ) ) |
1031 | 21 | { |
1032 | 21 | libcerror_error_set( |
1033 | 21 | error, |
1034 | 21 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1035 | 21 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
1036 | 21 | "%s: invalid data block list offset.", |
1037 | 21 | function ); |
1038 | | |
1039 | 21 | return( -1 ); |
1040 | 21 | } |
1041 | 98 | if( libregf_hive_bins_list_get_cell_at_offset( |
1042 | 98 | hive_bins_list, |
1043 | 98 | file_io_handle, |
1044 | 98 | data_block_list_offset, |
1045 | 98 | &hive_bin_cell, |
1046 | 98 | error ) != 1 ) |
1047 | 30 | { |
1048 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1049 | | if( libcnotify_verbose != 0 ) |
1050 | | { |
1051 | | libcnotify_printf( |
1052 | | "%s: unable to retrieve hive bin cell at offset: %" PRIu32 ".\n", |
1053 | | function, |
1054 | | data_block_list_offset ); |
1055 | | } |
1056 | | #endif |
1057 | 30 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
1058 | | |
1059 | 30 | return( 0 ); |
1060 | 30 | } |
1061 | 68 | if( hive_bin_cell == NULL ) |
1062 | 0 | { |
1063 | 0 | libcerror_error_set( |
1064 | 0 | error, |
1065 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1066 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1067 | 0 | "%s: missing hive bins cell.", |
1068 | 0 | function ); |
1069 | |
|
1070 | 0 | return( -1 ); |
1071 | 0 | } |
1072 | 68 | list_data_size = (size_t) hive_bin_cell->size; |
1073 | | |
1074 | 68 | if( ( list_data_size == 0 ) |
1075 | 68 | || ( list_data_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
1076 | 0 | { |
1077 | 0 | libcerror_error_set( |
1078 | 0 | error, |
1079 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1080 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1081 | 0 | "%s: invalid list data size value out of bounds.", |
1082 | 0 | function ); |
1083 | |
|
1084 | 0 | goto on_error; |
1085 | 0 | } |
1086 | | /* Make a local copy to prevent the hive bin cell data from being cached out |
1087 | | */ |
1088 | 68 | list_data = (uint8_t *) memory_allocate( |
1089 | 68 | sizeof( uint8_t ) * list_data_size ); |
1090 | | |
1091 | 68 | if( list_data == NULL ) |
1092 | 0 | { |
1093 | 0 | libcerror_error_set( |
1094 | 0 | error, |
1095 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1096 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1097 | 0 | "%s: unable to create list data.", |
1098 | 0 | function ); |
1099 | |
|
1100 | 0 | goto on_error; |
1101 | 0 | } |
1102 | 68 | if( memory_copy( |
1103 | 68 | list_data, |
1104 | 68 | hive_bin_cell->data, |
1105 | 68 | list_data_size ) == NULL ) |
1106 | 0 | { |
1107 | 0 | libcerror_error_set( |
1108 | 0 | error, |
1109 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1110 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1111 | 0 | "%s: unable to copy list data.", |
1112 | 0 | function ); |
1113 | |
|
1114 | 0 | goto on_error; |
1115 | 0 | } |
1116 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1117 | | if( libcnotify_verbose != 0 ) |
1118 | | { |
1119 | | libcnotify_printf( |
1120 | | "%s: data:\n", |
1121 | | function ); |
1122 | | libcnotify_print_data( |
1123 | | list_data, |
1124 | | list_data_size, |
1125 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
1126 | | } |
1127 | | #endif |
1128 | 68 | if( (size_t) number_of_segments > ( list_data_size / 4 ) ) |
1129 | 23 | { |
1130 | 23 | libcerror_error_set( |
1131 | 23 | error, |
1132 | 23 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1133 | 23 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1134 | 23 | "%s: invalid cell size value too small to contain number of values.", |
1135 | 23 | function ); |
1136 | | |
1137 | 23 | goto on_error; |
1138 | 23 | } |
1139 | 45 | value_item->data_type = LIBREGF_VALUE_ITEM_DATA_TYPE_BLOCK; |
1140 | | |
1141 | 45 | if( libfdata_stream_initialize( |
1142 | 45 | &( value_item->data_stream ), |
1143 | 45 | NULL, |
1144 | 45 | NULL, |
1145 | 45 | NULL, |
1146 | 45 | NULL, |
1147 | 45 | (ssize_t (*)(intptr_t *, intptr_t *, int, int, uint8_t *, size_t, uint32_t, uint8_t, libcerror_error_t **)) &libregf_data_block_stream_read_segment_data, |
1148 | 45 | NULL, |
1149 | 45 | (off64_t (*)(intptr_t *, intptr_t *, int, int, off64_t, libcerror_error_t **)) &libregf_data_block_stream_seek_segment_offset, |
1150 | 45 | 0, |
1151 | 45 | error ) != 1 ) |
1152 | 0 | { |
1153 | 0 | libcerror_error_set( |
1154 | 0 | error, |
1155 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1156 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1157 | 0 | "%s: unable to create value data stream.", |
1158 | 0 | function ); |
1159 | |
|
1160 | 0 | goto on_error; |
1161 | 0 | } |
1162 | 45 | if( number_of_segments > 0 ) |
1163 | 40 | { |
1164 | 40 | if( libfdata_stream_resize( |
1165 | 40 | value_item->data_stream, |
1166 | 40 | (int) number_of_segments, |
1167 | 40 | error ) != 1 ) |
1168 | 0 | { |
1169 | 0 | libcerror_error_set( |
1170 | 0 | error, |
1171 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1172 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
1173 | 0 | "%s: unable to resize value data stream.", |
1174 | 0 | function ); |
1175 | |
|
1176 | 0 | goto on_error; |
1177 | 0 | } |
1178 | 40 | for( element_iterator = 0; |
1179 | 114 | element_iterator < number_of_segments; |
1180 | 74 | element_iterator++ ) |
1181 | 107 | { |
1182 | 107 | byte_stream_copy_to_uint32_little_endian( |
1183 | 107 | &( list_data[ data_offset ] ), |
1184 | 107 | element_offset ); |
1185 | | |
1186 | 107 | data_offset += 4; |
1187 | | |
1188 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1189 | | if( libcnotify_verbose != 0 ) |
1190 | | { |
1191 | | libcnotify_printf( |
1192 | | "%s: element: %03" PRIu16 " offset\t\t\t: 0x%08" PRIx32 "\n", |
1193 | | function, |
1194 | | element_iterator, |
1195 | | element_offset ); |
1196 | | } |
1197 | | #endif |
1198 | | /* Determine the size of the segment by retrieving the corresponding hive bin cell |
1199 | | */ |
1200 | 107 | if( libregf_hive_bins_list_get_cell_at_offset( |
1201 | 107 | hive_bins_list, |
1202 | 107 | file_io_handle, |
1203 | 107 | element_offset, |
1204 | 107 | &hive_bin_cell, |
1205 | 107 | error ) != 1 ) |
1206 | 33 | { |
1207 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1208 | | if( libcnotify_verbose != 0 ) |
1209 | | { |
1210 | | libcnotify_printf( |
1211 | | "%s: unable to retrieve data segment: %" PRIu16 " hive bin cell at offset: %" PRIu32 ".\n", |
1212 | | function, |
1213 | | element_iterator, |
1214 | | element_offset ); |
1215 | | } |
1216 | | #endif |
1217 | 33 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
1218 | | |
1219 | | /* TODO return partial stream or 0-byte the missing data ? */ |
1220 | 33 | libfdata_stream_free( |
1221 | 33 | &( value_item->data_stream ), |
1222 | 33 | NULL ); |
1223 | | |
1224 | 33 | memory_free( |
1225 | 33 | list_data ); |
1226 | | |
1227 | 33 | return( 0 ); |
1228 | 33 | } |
1229 | 74 | segment_offset = (uint32_t) ( hive_bins_list->io_handle->hive_bins_list_offset + 4 + element_offset ); |
1230 | 74 | segment_size = hive_bin_cell->size - 4; |
1231 | | |
1232 | 74 | if( segment_size > 16344 ) |
1233 | 0 | { |
1234 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1235 | | if( libcnotify_verbose != 0 ) |
1236 | | { |
1237 | | libcnotify_printf( |
1238 | | "%s: data segment: %" PRIu16 " size: %" PRIu32 " exceeds maximum.\n", |
1239 | | function, |
1240 | | element_iterator, |
1241 | | segment_size ); |
1242 | | } |
1243 | | #endif |
1244 | 0 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
1245 | |
|
1246 | 0 | segment_size = 16344; |
1247 | 0 | } |
1248 | 74 | if( ( calculated_value_data_size + segment_size ) > value_data_size ) |
1249 | 0 | { |
1250 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1251 | | if( libcnotify_verbose != 0 ) |
1252 | | { |
1253 | | libcnotify_printf( |
1254 | | "%s: mismatch in value data size (calculated: %" PRIu32 ", stored: %" PRIu32 ").\n", |
1255 | | function, |
1256 | | calculated_value_data_size + segment_size, |
1257 | | value_data_size ); |
1258 | | } |
1259 | | #endif |
1260 | 0 | segment_size = value_data_size - calculated_value_data_size; |
1261 | 0 | } |
1262 | | /* Point the stream directly to the data |
1263 | | */ |
1264 | 74 | if( libfdata_stream_set_segment_by_index( |
1265 | 74 | value_item->data_stream, |
1266 | 74 | (int) element_iterator, |
1267 | 74 | 0, |
1268 | 74 | (off64_t) segment_offset, |
1269 | 74 | (size64_t) segment_size, |
1270 | 74 | 0, |
1271 | 74 | error ) != 1 ) |
1272 | 0 | { |
1273 | 0 | libcerror_error_set( |
1274 | 0 | error, |
1275 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1276 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
1277 | 0 | "%s: unable to set value data stream segment: %" PRIu16 ".", |
1278 | 0 | function, |
1279 | 0 | element_iterator ); |
1280 | |
|
1281 | 0 | goto on_error; |
1282 | 0 | } |
1283 | 74 | calculated_value_data_size += segment_size; |
1284 | 74 | } |
1285 | 40 | } |
1286 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1287 | | if( libcnotify_verbose != 0 ) |
1288 | | { |
1289 | | if( data_offset < list_data_size ) |
1290 | | { |
1291 | | libcnotify_printf( |
1292 | | "%s: padding:\n", |
1293 | | function ); |
1294 | | libcnotify_print_data( |
1295 | | &( list_data[ data_offset ] ), |
1296 | | list_data_size - data_offset, |
1297 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
1298 | | } |
1299 | | else |
1300 | | { |
1301 | | libcnotify_printf( |
1302 | | "\n" ); |
1303 | | } |
1304 | | } |
1305 | | #endif |
1306 | 12 | memory_free( |
1307 | 12 | list_data ); |
1308 | | |
1309 | 12 | return( 1 ); |
1310 | | |
1311 | 23 | on_error: |
1312 | 23 | if( value_item->data_stream != NULL ) |
1313 | 0 | { |
1314 | 0 | libfdata_stream_free( |
1315 | 0 | &( value_item->data_stream ), |
1316 | 0 | NULL ); |
1317 | 0 | } |
1318 | 23 | if( list_data != NULL ) |
1319 | 23 | { |
1320 | 23 | memory_free( |
1321 | 23 | list_data ); |
1322 | 23 | } |
1323 | 23 | return( -1 ); |
1324 | 45 | } |
1325 | | |
1326 | | /* Reads a value |
1327 | | * Returns 1 if successful or -1 on error |
1328 | | */ |
1329 | | int libregf_value_item_read_element_data( |
1330 | | libregf_hive_bins_list_t *hive_bins_list, |
1331 | | libbfio_handle_t *file_io_handle, |
1332 | | libfdata_list_element_t *list_element, |
1333 | | libfdata_cache_t *cache, |
1334 | | int data_range_file_index LIBREGF_ATTRIBUTE_UNUSED, |
1335 | | off64_t data_range_offset, |
1336 | | size64_t data_range_size LIBREGF_ATTRIBUTE_UNUSED, |
1337 | | uint32_t data_range_flags LIBREGF_ATTRIBUTE_UNUSED, |
1338 | | uint8_t read_flags LIBREGF_ATTRIBUTE_UNUSED, |
1339 | | libcerror_error_t **error ) |
1340 | 30.3k | { |
1341 | 30.3k | libregf_value_item_t *value_item = NULL; |
1342 | 30.3k | static char *function = "libregf_value_item_read_element_data"; |
1343 | | |
1344 | 30.3k | LIBREGF_UNREFERENCED_PARAMETER( data_range_file_index ) |
1345 | 30.3k | LIBREGF_UNREFERENCED_PARAMETER( data_range_size ) |
1346 | 30.3k | LIBREGF_UNREFERENCED_PARAMETER( data_range_flags ) |
1347 | 30.3k | LIBREGF_UNREFERENCED_PARAMETER( read_flags ) |
1348 | | |
1349 | 30.3k | if( hive_bins_list == NULL ) |
1350 | 0 | { |
1351 | 0 | libcerror_error_set( |
1352 | 0 | error, |
1353 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1354 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1355 | 0 | "%s: invalid hive bins list.", |
1356 | 0 | function ); |
1357 | |
|
1358 | 0 | return( -1 ); |
1359 | 0 | } |
1360 | 30.3k | if( hive_bins_list->io_handle == NULL ) |
1361 | 0 | { |
1362 | 0 | libcerror_error_set( |
1363 | 0 | error, |
1364 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1365 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1366 | 0 | "%s: invalid hive bins list - missing IO handle.", |
1367 | 0 | function ); |
1368 | |
|
1369 | 0 | return( -1 ); |
1370 | 0 | } |
1371 | 30.3k | if( data_range_offset > (off64_t) UINT32_MAX ) |
1372 | 0 | { |
1373 | 0 | libcerror_error_set( |
1374 | 0 | error, |
1375 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1376 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1377 | 0 | "%s: invalid data range offset value out of bounds.", |
1378 | 0 | function ); |
1379 | |
|
1380 | 0 | goto on_error; |
1381 | 0 | } |
1382 | 30.3k | if( libregf_value_item_initialize( |
1383 | 30.3k | &value_item, |
1384 | 30.3k | error ) != 1 ) |
1385 | 0 | { |
1386 | 0 | libcerror_error_set( |
1387 | 0 | error, |
1388 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1389 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1390 | 0 | "%s: unable to create value item.", |
1391 | 0 | function ); |
1392 | |
|
1393 | 0 | goto on_error; |
1394 | 0 | } |
1395 | 30.3k | if( libregf_value_item_read_value_key( |
1396 | 30.3k | value_item, |
1397 | 30.3k | file_io_handle, |
1398 | 30.3k | hive_bins_list, |
1399 | 30.3k | (uint32_t) data_range_offset, |
1400 | 30.3k | error ) != 1 ) |
1401 | 17.7k | { |
1402 | 17.7k | libcerror_error_set( |
1403 | 17.7k | error, |
1404 | 17.7k | LIBCERROR_ERROR_DOMAIN_IO, |
1405 | 17.7k | LIBCERROR_IO_ERROR_READ_FAILED, |
1406 | 17.7k | "%s: unable to read value key at offset: %" PRIi64 ".", |
1407 | 17.7k | function, |
1408 | 17.7k | data_range_offset ); |
1409 | | |
1410 | 17.7k | goto on_error; |
1411 | 17.7k | } |
1412 | 12.5k | if( ( value_item->item_flags & LIBREGF_ITEM_FLAG_IS_CORRUPTED ) != 0 ) |
1413 | 11.5k | { |
1414 | 11.5k | hive_bins_list->io_handle->flags |= LIBREGF_IO_HANDLE_FLAG_IS_CORRUPTED; |
1415 | 11.5k | } |
1416 | 12.5k | if( libfdata_list_element_set_element_value( |
1417 | 12.5k | list_element, |
1418 | 12.5k | (intptr_t *) file_io_handle, |
1419 | 12.5k | cache, |
1420 | 12.5k | (intptr_t *) value_item, |
1421 | 12.5k | (int (*)(intptr_t **, libcerror_error_t **)) &libregf_value_item_free, |
1422 | 12.5k | LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED, |
1423 | 12.5k | error ) != 1 ) |
1424 | 0 | { |
1425 | 0 | libcerror_error_set( |
1426 | 0 | error, |
1427 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1428 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1429 | 0 | "%s: unable to set value item as element value.", |
1430 | 0 | function ); |
1431 | |
|
1432 | 0 | goto on_error; |
1433 | 0 | } |
1434 | 12.5k | return( 1 ); |
1435 | | |
1436 | 17.7k | on_error: |
1437 | 17.7k | if( value_item != NULL ) |
1438 | 17.7k | { |
1439 | 17.7k | libregf_value_item_free( |
1440 | 17.7k | &value_item, |
1441 | 17.7k | NULL ); |
1442 | 17.7k | } |
1443 | 17.7k | return( -1 ); |
1444 | 12.5k | } |
1445 | | |
1446 | | /* Determine if the value corrupted |
1447 | | * Returns 1 if corrupted, 0 if not or -1 on error |
1448 | | */ |
1449 | | int libregf_value_item_is_corrupted( |
1450 | | libregf_value_item_t *value_item, |
1451 | | libcerror_error_t **error ) |
1452 | 11.4k | { |
1453 | 11.4k | static char *function = "libregf_value_item_is_corrupted"; |
1454 | | |
1455 | 11.4k | if( value_item == NULL ) |
1456 | 0 | { |
1457 | 0 | libcerror_error_set( |
1458 | 0 | error, |
1459 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1460 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1461 | 0 | "%s: invalid value item.", |
1462 | 0 | function ); |
1463 | |
|
1464 | 0 | return( -1 ); |
1465 | 0 | } |
1466 | 11.4k | if( ( value_item->item_flags & LIBREGF_ITEM_FLAG_IS_CORRUPTED ) != 0 ) |
1467 | 10.3k | { |
1468 | 10.3k | return( 1 ); |
1469 | 10.3k | } |
1470 | 1.02k | return( 0 ); |
1471 | 11.4k | } |
1472 | | |
1473 | | /* Retrieves the value name size |
1474 | | * Returns 1 if successful or -1 on error |
1475 | | */ |
1476 | | int libregf_value_item_get_name_size( |
1477 | | libregf_value_item_t *value_item, |
1478 | | size_t *name_size, |
1479 | | libcerror_error_t **error ) |
1480 | 11.4k | { |
1481 | 11.4k | static char *function = "libregf_value_item_get_name_size"; |
1482 | | |
1483 | 11.4k | if( value_item == NULL ) |
1484 | 0 | { |
1485 | 0 | libcerror_error_set( |
1486 | 0 | error, |
1487 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1488 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1489 | 0 | "%s: invalid value item.", |
1490 | 0 | function ); |
1491 | |
|
1492 | 0 | return( -1 ); |
1493 | 0 | } |
1494 | 11.4k | if( libregf_value_key_get_name_size( |
1495 | 11.4k | value_item->value_key, |
1496 | 11.4k | name_size, |
1497 | 11.4k | error ) != 1 ) |
1498 | 40 | { |
1499 | 40 | libcerror_error_set( |
1500 | 40 | error, |
1501 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1502 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1503 | 40 | "%s: unable to retrieve name size.", |
1504 | 40 | function ); |
1505 | | |
1506 | 40 | return( -1 ); |
1507 | 40 | } |
1508 | 11.3k | return( 1 ); |
1509 | 11.4k | } |
1510 | | |
1511 | | /* Retrieves the value name |
1512 | | * Returns 1 if successful or -1 on error |
1513 | | */ |
1514 | | int libregf_value_item_get_name( |
1515 | | libregf_value_item_t *value_item, |
1516 | | uint8_t *name, |
1517 | | size_t name_size, |
1518 | | libcerror_error_t **error ) |
1519 | 1.30k | { |
1520 | 1.30k | static char *function = "libregf_value_item_get_name"; |
1521 | | |
1522 | 1.30k | if( value_item == NULL ) |
1523 | 0 | { |
1524 | 0 | libcerror_error_set( |
1525 | 0 | error, |
1526 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1527 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1528 | 0 | "%s: invalid value item.", |
1529 | 0 | function ); |
1530 | |
|
1531 | 0 | return( -1 ); |
1532 | 0 | } |
1533 | 1.30k | if( libregf_value_key_get_name( |
1534 | 1.30k | value_item->value_key, |
1535 | 1.30k | name, |
1536 | 1.30k | name_size, |
1537 | 1.30k | error ) != 1 ) |
1538 | 0 | { |
1539 | 0 | libcerror_error_set( |
1540 | 0 | error, |
1541 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1542 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1543 | 0 | "%s: unable to retrieve name.", |
1544 | 0 | function ); |
1545 | |
|
1546 | 0 | return( -1 ); |
1547 | 0 | } |
1548 | 1.30k | return( 1 ); |
1549 | 1.30k | } |
1550 | | |
1551 | | /* Retrieves the UTF-8 string size of the value name |
1552 | | * The returned size includes the end of string character |
1553 | | * Returns 1 if successful or -1 on error |
1554 | | */ |
1555 | | int libregf_value_item_get_utf8_name_size( |
1556 | | libregf_value_item_t *value_item, |
1557 | | size_t *utf8_name_size, |
1558 | | int ascii_codepage, |
1559 | | libcerror_error_t **error ) |
1560 | 11.4k | { |
1561 | 11.4k | static char *function = "libregf_value_item_get_utf8_name_size"; |
1562 | | |
1563 | 11.4k | if( value_item == NULL ) |
1564 | 0 | { |
1565 | 0 | libcerror_error_set( |
1566 | 0 | error, |
1567 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1568 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1569 | 0 | "%s: invalid value item.", |
1570 | 0 | function ); |
1571 | |
|
1572 | 0 | return( -1 ); |
1573 | 0 | } |
1574 | 11.4k | if( libregf_value_key_get_utf8_name_size( |
1575 | 11.4k | value_item->value_key, |
1576 | 11.4k | utf8_name_size, |
1577 | 11.4k | ascii_codepage, |
1578 | 11.4k | error ) != 1 ) |
1579 | 40 | { |
1580 | 40 | libcerror_error_set( |
1581 | 40 | error, |
1582 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1583 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1584 | 40 | "%s: unable to retrieve UTF-8 name size.", |
1585 | 40 | function ); |
1586 | | |
1587 | 40 | return( -1 ); |
1588 | 40 | } |
1589 | 11.3k | return( 1 ); |
1590 | 11.4k | } |
1591 | | |
1592 | | /* Retrieves the UTF-8 string value of the value name |
1593 | | * The function uses a codepage if necessary, it uses the codepage set for the library |
1594 | | * The size should include the end of string character |
1595 | | * Returns 1 if successful or -1 on error |
1596 | | */ |
1597 | | int libregf_value_item_get_utf8_name( |
1598 | | libregf_value_item_t *value_item, |
1599 | | uint8_t *utf8_name, |
1600 | | size_t utf8_name_size, |
1601 | | int ascii_codepage, |
1602 | | libcerror_error_t **error ) |
1603 | 1.30k | { |
1604 | 1.30k | static char *function = "libregf_value_item_get_utf8_name"; |
1605 | | |
1606 | 1.30k | if( value_item == NULL ) |
1607 | 0 | { |
1608 | 0 | libcerror_error_set( |
1609 | 0 | error, |
1610 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1611 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1612 | 0 | "%s: invalid value item.", |
1613 | 0 | function ); |
1614 | |
|
1615 | 0 | return( -1 ); |
1616 | 0 | } |
1617 | 1.30k | if( libregf_value_key_get_utf8_name( |
1618 | 1.30k | value_item->value_key, |
1619 | 1.30k | utf8_name, |
1620 | 1.30k | utf8_name_size, |
1621 | 1.30k | ascii_codepage, |
1622 | 1.30k | error ) != 1 ) |
1623 | 0 | { |
1624 | 0 | libcerror_error_set( |
1625 | 0 | error, |
1626 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1627 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1628 | 0 | "%s: unable to retrieve UTF-8 name.", |
1629 | 0 | function ); |
1630 | |
|
1631 | 0 | return( -1 ); |
1632 | 0 | } |
1633 | 1.30k | return( 1 ); |
1634 | 1.30k | } |
1635 | | |
1636 | | /* Retrieves the UTF-16 string size of the value name |
1637 | | * The returned size includes the end of string character |
1638 | | * Returns 1 if successful or -1 on error |
1639 | | */ |
1640 | | int libregf_value_item_get_utf16_name_size( |
1641 | | libregf_value_item_t *value_item, |
1642 | | size_t *utf16_name_size, |
1643 | | int ascii_codepage, |
1644 | | libcerror_error_t **error ) |
1645 | 11.4k | { |
1646 | 11.4k | static char *function = "libregf_value_item_get_utf16_name_size"; |
1647 | | |
1648 | 11.4k | if( value_item == NULL ) |
1649 | 0 | { |
1650 | 0 | libcerror_error_set( |
1651 | 0 | error, |
1652 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1653 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1654 | 0 | "%s: invalid value item.", |
1655 | 0 | function ); |
1656 | |
|
1657 | 0 | return( -1 ); |
1658 | 0 | } |
1659 | 11.4k | if( libregf_value_key_get_utf16_name_size( |
1660 | 11.4k | value_item->value_key, |
1661 | 11.4k | utf16_name_size, |
1662 | 11.4k | ascii_codepage, |
1663 | 11.4k | error ) != 1 ) |
1664 | 40 | { |
1665 | 40 | libcerror_error_set( |
1666 | 40 | error, |
1667 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1668 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1669 | 40 | "%s: unable to retrieve UTF-16 name size.", |
1670 | 40 | function ); |
1671 | | |
1672 | 40 | return( -1 ); |
1673 | 40 | } |
1674 | 11.3k | return( 1 ); |
1675 | 11.4k | } |
1676 | | |
1677 | | /* Retrieves the UTF-16 string value of the value name |
1678 | | * The function uses a codepage if necessary, it uses the codepage set for the library |
1679 | | * The size should include the end of string character |
1680 | | * Returns 1 if successful or -1 on error |
1681 | | */ |
1682 | | int libregf_value_item_get_utf16_name( |
1683 | | libregf_value_item_t *value_item, |
1684 | | uint16_t *utf16_name, |
1685 | | size_t utf16_name_size, |
1686 | | int ascii_codepage, |
1687 | | libcerror_error_t **error ) |
1688 | 1.30k | { |
1689 | 1.30k | static char *function = "libregf_value_item_get_utf16_name"; |
1690 | | |
1691 | 1.30k | if( value_item == NULL ) |
1692 | 0 | { |
1693 | 0 | libcerror_error_set( |
1694 | 0 | error, |
1695 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1696 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1697 | 0 | "%s: invalid value item.", |
1698 | 0 | function ); |
1699 | |
|
1700 | 0 | return( -1 ); |
1701 | 0 | } |
1702 | 1.30k | if( libregf_value_key_get_utf16_name( |
1703 | 1.30k | value_item->value_key, |
1704 | 1.30k | utf16_name, |
1705 | 1.30k | utf16_name_size, |
1706 | 1.30k | ascii_codepage, |
1707 | 1.30k | error ) != 1 ) |
1708 | 0 | { |
1709 | 0 | libcerror_error_set( |
1710 | 0 | error, |
1711 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1712 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1713 | 0 | "%s: unable to retrieve UTF-16 name.", |
1714 | 0 | function ); |
1715 | |
|
1716 | 0 | return( -1 ); |
1717 | 0 | } |
1718 | 1.30k | return( 1 ); |
1719 | 1.30k | } |
1720 | | |
1721 | | /* Compares the value name with UTF-8 string |
1722 | | * Returns 1 if the names match, 0 if not or -1 on error |
1723 | | */ |
1724 | | int libregf_value_item_compare_name_with_utf8_string( |
1725 | | libregf_value_item_t *value_item, |
1726 | | uint32_t name_hash, |
1727 | | const uint8_t *utf8_string, |
1728 | | size_t utf8_string_length, |
1729 | | int ascii_codepage, |
1730 | | libcerror_error_t **error ) |
1731 | 880 | { |
1732 | 880 | static char *function = "libregf_value_item_compare_name_with_utf8_string"; |
1733 | 880 | int result = 0; |
1734 | | |
1735 | 880 | if( value_item == NULL ) |
1736 | 0 | { |
1737 | 0 | libcerror_error_set( |
1738 | 0 | error, |
1739 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1740 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1741 | 0 | "%s: invalid value item.", |
1742 | 0 | function ); |
1743 | |
|
1744 | 0 | return( -1 ); |
1745 | 0 | } |
1746 | 880 | result = libregf_value_key_compare_name_with_utf8_string( |
1747 | 880 | value_item->value_key, |
1748 | 880 | name_hash, |
1749 | 880 | utf8_string, |
1750 | 880 | utf8_string_length, |
1751 | 880 | ascii_codepage, |
1752 | 880 | error ); |
1753 | | |
1754 | 880 | if( result == -1 ) |
1755 | 9 | { |
1756 | 9 | libcerror_error_set( |
1757 | 9 | error, |
1758 | 9 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1759 | 9 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
1760 | 9 | "%s: unable to compare name with UTF-8 string.", |
1761 | 9 | function ); |
1762 | | |
1763 | 9 | return( -1 ); |
1764 | 9 | } |
1765 | 871 | return( result ); |
1766 | 880 | } |
1767 | | |
1768 | | /* Compares the value name with UTF-16 string |
1769 | | * Returns 1 if the names match, 0 if not or -1 on error |
1770 | | */ |
1771 | | int libregf_value_item_compare_name_with_utf16_string( |
1772 | | libregf_value_item_t *value_item, |
1773 | | uint32_t name_hash, |
1774 | | const uint16_t *utf16_string, |
1775 | | size_t utf16_string_length, |
1776 | | int ascii_codepage, |
1777 | | libcerror_error_t **error ) |
1778 | 1.76k | { |
1779 | 1.76k | static char *function = "libregf_value_item_compare_name_with_utf16_string"; |
1780 | 1.76k | int result = 0; |
1781 | | |
1782 | 1.76k | if( value_item == NULL ) |
1783 | 0 | { |
1784 | 0 | libcerror_error_set( |
1785 | 0 | error, |
1786 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1787 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1788 | 0 | "%s: invalid value item.", |
1789 | 0 | function ); |
1790 | |
|
1791 | 0 | return( -1 ); |
1792 | 0 | } |
1793 | 1.76k | result = libregf_value_key_compare_name_with_utf16_string( |
1794 | 1.76k | value_item->value_key, |
1795 | 1.76k | name_hash, |
1796 | 1.76k | utf16_string, |
1797 | 1.76k | utf16_string_length, |
1798 | 1.76k | ascii_codepage, |
1799 | 1.76k | error ); |
1800 | | |
1801 | 1.76k | if( result == -1 ) |
1802 | 2 | { |
1803 | 2 | libcerror_error_set( |
1804 | 2 | error, |
1805 | 2 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1806 | 2 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
1807 | 2 | "%s: unable to compare name with UTF-16 string.", |
1808 | 2 | function ); |
1809 | | |
1810 | 2 | return( -1 ); |
1811 | 2 | } |
1812 | 1.76k | return( result ); |
1813 | 1.76k | } |
1814 | | |
1815 | | /* Retrieves the value type |
1816 | | * Returns 1 if successful or -1 on error |
1817 | | */ |
1818 | | int libregf_value_item_get_value_type( |
1819 | | libregf_value_item_t *value_item, |
1820 | | uint32_t *data_type, |
1821 | | libcerror_error_t **error ) |
1822 | 0 | { |
1823 | 0 | static char *function = "libregf_value_item_get_value_type"; |
1824 | |
|
1825 | 0 | if( value_item == NULL ) |
1826 | 0 | { |
1827 | 0 | libcerror_error_set( |
1828 | 0 | error, |
1829 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1830 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1831 | 0 | "%s: invalid value item.", |
1832 | 0 | function ); |
1833 | |
|
1834 | 0 | return( -1 ); |
1835 | 0 | } |
1836 | 0 | if( libregf_value_key_get_value_type( |
1837 | 0 | value_item->value_key, |
1838 | 0 | data_type, |
1839 | 0 | error ) != 1 ) |
1840 | 0 | { |
1841 | 0 | libcerror_error_set( |
1842 | 0 | error, |
1843 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1844 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1845 | 0 | "%s: unable to retrieve value type.", |
1846 | 0 | function ); |
1847 | |
|
1848 | 0 | return( -1 ); |
1849 | 0 | } |
1850 | 0 | return( 1 ); |
1851 | 0 | } |
1852 | | |
1853 | | /* Retrieves the data size |
1854 | | * Returns 1 if successful or -1 on error |
1855 | | */ |
1856 | | int libregf_value_item_get_data_size( |
1857 | | libregf_value_item_t *value_item, |
1858 | | size_t *data_size, |
1859 | | libcerror_error_t **error ) |
1860 | 11.4k | { |
1861 | 11.4k | static char *function = "libregf_value_item_get_data_size"; |
1862 | 11.4k | size64_t value_data_size = 0; |
1863 | | |
1864 | 11.4k | if( value_item == NULL ) |
1865 | 0 | { |
1866 | 0 | libcerror_error_set( |
1867 | 0 | error, |
1868 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1869 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1870 | 0 | "%s: invalid value item.", |
1871 | 0 | function ); |
1872 | |
|
1873 | 0 | return( -1 ); |
1874 | 0 | } |
1875 | 11.4k | if( ( value_item->data_type != 0 ) |
1876 | 1.41k | && ( value_item->data_type != LIBREGF_VALUE_ITEM_DATA_TYPE_BUFFER ) |
1877 | 60 | && ( value_item->data_type != LIBREGF_VALUE_ITEM_DATA_TYPE_BLOCK ) ) |
1878 | 0 | { |
1879 | 0 | libcerror_error_set( |
1880 | 0 | error, |
1881 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1882 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1883 | 0 | "%s: unsupported value item data type: 0x%02" PRIx8 ".", |
1884 | 0 | function, |
1885 | 0 | value_item->data_type ); |
1886 | |
|
1887 | 0 | return( -1 ); |
1888 | 0 | } |
1889 | 11.4k | if( data_size == NULL ) |
1890 | 0 | { |
1891 | 0 | libcerror_error_set( |
1892 | 0 | error, |
1893 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1894 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1895 | 0 | "%s: invalid data size.", |
1896 | 0 | function ); |
1897 | |
|
1898 | 0 | return( -1 ); |
1899 | 0 | } |
1900 | 11.4k | if( ( value_item->data_type == LIBREGF_VALUE_ITEM_DATA_TYPE_BLOCK ) |
1901 | 60 | && ( value_item->data_buffer == NULL ) ) |
1902 | 57 | { |
1903 | 57 | if( libfdata_stream_get_size( |
1904 | 57 | value_item->data_stream, |
1905 | 57 | &value_data_size, |
1906 | 57 | error ) != 1 ) |
1907 | 39 | { |
1908 | 39 | libcerror_error_set( |
1909 | 39 | error, |
1910 | 39 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1911 | 39 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1912 | 39 | "%s: unable to retrieve size from data stream.", |
1913 | 39 | function ); |
1914 | | |
1915 | 39 | return( -1 ); |
1916 | 39 | } |
1917 | 18 | if( value_data_size > (size64_t) SSIZE_MAX ) |
1918 | 0 | { |
1919 | 0 | libcerror_error_set( |
1920 | 0 | error, |
1921 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1922 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1923 | 0 | "%s: invalid stream data size value out of bounds.", |
1924 | 0 | function ); |
1925 | |
|
1926 | 0 | return( -1 ); |
1927 | 0 | } |
1928 | 18 | } |
1929 | 11.4k | else if( value_item->data_type != 0 ) |
1930 | 1.35k | { |
1931 | 1.35k | value_data_size = value_item->data_buffer_size; |
1932 | 1.35k | } |
1933 | 11.4k | *data_size = (size_t) value_data_size; |
1934 | | |
1935 | 11.4k | return( 1 ); |
1936 | 11.4k | } |
1937 | | |
1938 | | /* Retrieves the data |
1939 | | * Returns 1 if successful or -1 on error |
1940 | | */ |
1941 | | int libregf_value_item_get_data( |
1942 | | libregf_value_item_t *value_item, |
1943 | | libbfio_handle_t *file_io_handle, |
1944 | | uint8_t **data, |
1945 | | size_t *data_size, |
1946 | | libcerror_error_t **error ) |
1947 | 5.41k | { |
1948 | 5.41k | static char *function = "libregf_value_item_get_data"; |
1949 | 5.41k | size64_t stream_data_size = 0; |
1950 | 5.41k | ssize_t read_count = 0; |
1951 | | |
1952 | 5.41k | if( value_item == NULL ) |
1953 | 0 | { |
1954 | 0 | libcerror_error_set( |
1955 | 0 | error, |
1956 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1957 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1958 | 0 | "%s: invalid value item.", |
1959 | 0 | function ); |
1960 | |
|
1961 | 0 | return( -1 ); |
1962 | 0 | } |
1963 | 5.41k | if( ( value_item->data_type != 0 ) |
1964 | 5.17k | && ( value_item->data_type != LIBREGF_VALUE_ITEM_DATA_TYPE_BUFFER ) |
1965 | 98 | && ( value_item->data_type != LIBREGF_VALUE_ITEM_DATA_TYPE_BLOCK ) ) |
1966 | 0 | { |
1967 | 0 | libcerror_error_set( |
1968 | 0 | error, |
1969 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1970 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
1971 | 0 | "%s: unsupported value item data type: 0x%02" PRIx8 ".", |
1972 | 0 | function, |
1973 | 0 | value_item->data_type ); |
1974 | |
|
1975 | 0 | return( -1 ); |
1976 | 0 | } |
1977 | 5.41k | if( data == NULL ) |
1978 | 0 | { |
1979 | 0 | libcerror_error_set( |
1980 | 0 | error, |
1981 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1982 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1983 | 0 | "%s: invalid data.", |
1984 | 0 | function ); |
1985 | |
|
1986 | 0 | return( -1 ); |
1987 | 0 | } |
1988 | 5.41k | if( data_size == NULL ) |
1989 | 0 | { |
1990 | 0 | libcerror_error_set( |
1991 | 0 | error, |
1992 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1993 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1994 | 0 | "%s: invalid data size.", |
1995 | 0 | function ); |
1996 | |
|
1997 | 0 | return( -1 ); |
1998 | 0 | } |
1999 | 5.41k | if( ( value_item->data_type == LIBREGF_VALUE_ITEM_DATA_TYPE_BLOCK ) |
2000 | 98 | && ( value_item->data_buffer == NULL ) ) |
2001 | 75 | { |
2002 | 75 | if( libfdata_stream_get_size( |
2003 | 75 | value_item->data_stream, |
2004 | 75 | &stream_data_size, |
2005 | 75 | error ) != 1 ) |
2006 | 58 | { |
2007 | 58 | libcerror_error_set( |
2008 | 58 | error, |
2009 | 58 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2010 | 58 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2011 | 58 | "%s: unable to retrieve size from data stream.", |
2012 | 58 | function ); |
2013 | | |
2014 | 58 | goto on_error; |
2015 | 58 | } |
2016 | 17 | if( ( stream_data_size == 0 ) |
2017 | 9 | || ( stream_data_size > (size64_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
2018 | 8 | { |
2019 | 8 | libcerror_error_set( |
2020 | 8 | error, |
2021 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2022 | 8 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2023 | 8 | "%s: invalid stream data size value out of bounds.", |
2024 | 8 | function ); |
2025 | | |
2026 | 8 | goto on_error; |
2027 | 8 | } |
2028 | | /* Cache the whole stream this should not happen very often "normal" files |
2029 | | */ |
2030 | 9 | value_item->data_buffer = (uint8_t *) memory_allocate( |
2031 | 9 | sizeof( uint8_t ) * (size_t) stream_data_size ); |
2032 | | |
2033 | 9 | if( value_item->data_buffer == NULL ) |
2034 | 0 | { |
2035 | 0 | libcerror_error_set( |
2036 | 0 | error, |
2037 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2038 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
2039 | 0 | "%s: unable to create data buffer.", |
2040 | 0 | function ); |
2041 | |
|
2042 | 0 | goto on_error; |
2043 | 0 | } |
2044 | 9 | value_item->data_buffer_size = (size_t) stream_data_size; |
2045 | | |
2046 | 9 | read_count = libfdata_stream_read_buffer_at_offset( |
2047 | 9 | value_item->data_stream, |
2048 | 9 | (intptr_t *) file_io_handle, |
2049 | 9 | value_item->data_buffer, |
2050 | 9 | value_item->data_buffer_size, |
2051 | 9 | 0, |
2052 | 9 | 0, |
2053 | 9 | error ); |
2054 | | |
2055 | 9 | if( read_count != (ssize_t) value_item->data_buffer_size ) |
2056 | 0 | { |
2057 | 0 | libcerror_error_set( |
2058 | 0 | error, |
2059 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2060 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2061 | 0 | "%s: unable to read data from data stream at offset: 0 (0x00000000).", |
2062 | 0 | function ); |
2063 | |
|
2064 | 0 | goto on_error; |
2065 | 0 | } |
2066 | 9 | } |
2067 | 5.35k | if( value_item->data_type != 0 ) |
2068 | 5.11k | { |
2069 | 5.11k | *data = value_item->data_buffer; |
2070 | 5.11k | *data_size = value_item->data_buffer_size; |
2071 | 5.11k | } |
2072 | 240 | else |
2073 | 240 | { |
2074 | 240 | *data = NULL; |
2075 | 240 | *data_size = 0; |
2076 | 240 | } |
2077 | 5.35k | return( 1 ); |
2078 | | |
2079 | 66 | on_error: |
2080 | 66 | if( value_item->data_buffer != NULL ) |
2081 | 0 | { |
2082 | 0 | memory_free( |
2083 | 0 | value_item->data_buffer ); |
2084 | |
|
2085 | 0 | value_item->data_buffer = NULL; |
2086 | 0 | } |
2087 | 66 | value_item->data_buffer_size = 0; |
2088 | | |
2089 | 66 | return( -1 ); |
2090 | 5.41k | } |
2091 | | |
2092 | | /* Retrieves the 32-bit value |
2093 | | * Returns 1 if successful or -1 on error |
2094 | | */ |
2095 | | int libregf_value_item_get_value_32bit( |
2096 | | libregf_value_item_t *value_item, |
2097 | | libbfio_handle_t *file_io_handle, |
2098 | | uint32_t *value_32bit, |
2099 | | libcerror_error_t **error ) |
2100 | 0 | { |
2101 | 0 | uint8_t *value_data = NULL; |
2102 | 0 | static char *function = "libregf_value_item_get_value_32bit"; |
2103 | 0 | size_t value_data_size = 0; |
2104 | 0 | uint32_t value_type = 0; |
2105 | |
|
2106 | 0 | if( value_item == NULL ) |
2107 | 0 | { |
2108 | 0 | libcerror_error_set( |
2109 | 0 | error, |
2110 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2111 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2112 | 0 | "%s: invalid value item.", |
2113 | 0 | function ); |
2114 | |
|
2115 | 0 | return( -1 ); |
2116 | 0 | } |
2117 | 0 | if( value_32bit == NULL ) |
2118 | 0 | { |
2119 | 0 | libcerror_error_set( |
2120 | 0 | error, |
2121 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2122 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2123 | 0 | "%s: invalid value 32-bit.", |
2124 | 0 | function ); |
2125 | |
|
2126 | 0 | return( -1 ); |
2127 | 0 | } |
2128 | 0 | if( libregf_value_key_get_value_type( |
2129 | 0 | value_item->value_key, |
2130 | 0 | &value_type, |
2131 | 0 | error ) != 1 ) |
2132 | 0 | { |
2133 | 0 | libcerror_error_set( |
2134 | 0 | error, |
2135 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2136 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2137 | 0 | "%s: unable to retrieve value type.", |
2138 | 0 | function ); |
2139 | |
|
2140 | 0 | return( -1 ); |
2141 | 0 | } |
2142 | 0 | if( ( value_type != LIBREGF_VALUE_TYPE_INTEGER_32BIT_BIG_ENDIAN ) |
2143 | 0 | && ( value_type != LIBREGF_VALUE_TYPE_INTEGER_32BIT_LITTLE_ENDIAN ) ) |
2144 | 0 | { |
2145 | 0 | libcerror_error_set( |
2146 | 0 | error, |
2147 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2148 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2149 | 0 | "%s: unsupported 32-bit integer value type: 0x%04" PRIx32 ".", |
2150 | 0 | function, |
2151 | 0 | value_type ); |
2152 | |
|
2153 | 0 | return( -1 ); |
2154 | 0 | } |
2155 | 0 | if( libregf_value_item_get_data( |
2156 | 0 | value_item, |
2157 | 0 | file_io_handle, |
2158 | 0 | &value_data, |
2159 | 0 | &value_data_size, |
2160 | 0 | error ) != 1 ) |
2161 | 0 | { |
2162 | 0 | libcerror_error_set( |
2163 | 0 | error, |
2164 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2165 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2166 | 0 | "%s: unable to retrieve value data.", |
2167 | 0 | function ); |
2168 | |
|
2169 | 0 | return( -1 ); |
2170 | 0 | } |
2171 | 0 | if( value_data_size < 4 ) |
2172 | 0 | { |
2173 | 0 | libcerror_error_set( |
2174 | 0 | error, |
2175 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2176 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2177 | 0 | "%s: invalid value data size value out of bounds.", |
2178 | 0 | function ); |
2179 | |
|
2180 | 0 | return( -1 ); |
2181 | 0 | } |
2182 | 0 | else if( value_data_size > 4 ) |
2183 | 0 | { |
2184 | 0 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
2185 | 0 | } |
2186 | 0 | if( value_type == LIBREGF_VALUE_TYPE_INTEGER_32BIT_BIG_ENDIAN ) |
2187 | 0 | { |
2188 | 0 | byte_stream_copy_to_uint32_big_endian( |
2189 | 0 | value_data, |
2190 | 0 | *value_32bit ); |
2191 | 0 | } |
2192 | 0 | else |
2193 | 0 | { |
2194 | 0 | byte_stream_copy_to_uint32_little_endian( |
2195 | 0 | value_data, |
2196 | 0 | *value_32bit ); |
2197 | 0 | } |
2198 | 0 | return( 1 ); |
2199 | 0 | } |
2200 | | |
2201 | | /* Retrieves the 64-bit value |
2202 | | * Returns 1 if successful or -1 on error |
2203 | | */ |
2204 | | int libregf_value_item_get_value_64bit( |
2205 | | libregf_value_item_t *value_item, |
2206 | | libbfio_handle_t *file_io_handle, |
2207 | | uint64_t *value_64bit, |
2208 | | libcerror_error_t **error ) |
2209 | 0 | { |
2210 | 0 | uint8_t *value_data = NULL; |
2211 | 0 | static char *function = "libregf_value_item_get_value_64bit"; |
2212 | 0 | size_t value_data_size = 0; |
2213 | 0 | uint32_t value_type = 0; |
2214 | |
|
2215 | 0 | if( value_item == NULL ) |
2216 | 0 | { |
2217 | 0 | libcerror_error_set( |
2218 | 0 | error, |
2219 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2220 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2221 | 0 | "%s: invalid value item.", |
2222 | 0 | function ); |
2223 | |
|
2224 | 0 | return( -1 ); |
2225 | 0 | } |
2226 | 0 | if( value_64bit == NULL ) |
2227 | 0 | { |
2228 | 0 | libcerror_error_set( |
2229 | 0 | error, |
2230 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2231 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2232 | 0 | "%s: invalid value 64-bit.", |
2233 | 0 | function ); |
2234 | |
|
2235 | 0 | return( -1 ); |
2236 | 0 | } |
2237 | 0 | if( libregf_value_key_get_value_type( |
2238 | 0 | value_item->value_key, |
2239 | 0 | &value_type, |
2240 | 0 | error ) != 1 ) |
2241 | 0 | { |
2242 | 0 | libcerror_error_set( |
2243 | 0 | error, |
2244 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2245 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2246 | 0 | "%s: unable to retrieve value type.", |
2247 | 0 | function ); |
2248 | |
|
2249 | 0 | return( -1 ); |
2250 | 0 | } |
2251 | 0 | if( value_type != LIBREGF_VALUE_TYPE_INTEGER_64BIT_LITTLE_ENDIAN ) |
2252 | 0 | { |
2253 | 0 | libcerror_error_set( |
2254 | 0 | error, |
2255 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2256 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2257 | 0 | "%s: unsupported 64-bit integer value type: 0x%04" PRIx32 ".", |
2258 | 0 | function, |
2259 | 0 | value_type ); |
2260 | |
|
2261 | 0 | return( -1 ); |
2262 | 0 | } |
2263 | 0 | if( libregf_value_item_get_data( |
2264 | 0 | value_item, |
2265 | 0 | file_io_handle, |
2266 | 0 | &value_data, |
2267 | 0 | &value_data_size, |
2268 | 0 | error ) != 1 ) |
2269 | 0 | { |
2270 | 0 | libcerror_error_set( |
2271 | 0 | error, |
2272 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2273 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2274 | 0 | "%s: unable to retrieve value data.", |
2275 | 0 | function ); |
2276 | |
|
2277 | 0 | return( -1 ); |
2278 | 0 | } |
2279 | 0 | if( value_data_size < 8 ) |
2280 | 0 | { |
2281 | 0 | libcerror_error_set( |
2282 | 0 | error, |
2283 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2284 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2285 | 0 | "%s: invalid value data size value out of bounds.", |
2286 | 0 | function ); |
2287 | |
|
2288 | 0 | return( -1 ); |
2289 | 0 | } |
2290 | 0 | else if( value_data_size > 8 ) |
2291 | 0 | { |
2292 | 0 | value_item->item_flags |= LIBREGF_ITEM_FLAG_IS_CORRUPTED; |
2293 | 0 | } |
2294 | 0 | byte_stream_copy_to_uint64_little_endian( |
2295 | 0 | value_data, |
2296 | 0 | *value_64bit ); |
2297 | |
|
2298 | 0 | return( 1 ); |
2299 | 0 | } |
2300 | | |
2301 | | /* Retrieves the UTF-8 string size |
2302 | | * This function uses UTF-8 RFC 2279 (or 6-byte UTF-8) to support characters outside Unicode |
2303 | | * The returned size includes the end of string character |
2304 | | * Returns 1 if successful or -1 on error |
2305 | | */ |
2306 | | int libregf_value_item_get_value_utf8_string_size( |
2307 | | libregf_value_item_t *value_item, |
2308 | | libbfio_handle_t *file_io_handle, |
2309 | | size_t *utf8_string_size, |
2310 | | libcerror_error_t **error ) |
2311 | 11.4k | { |
2312 | 11.4k | uint8_t *value_data = NULL; |
2313 | 11.4k | static char *function = "libregf_value_item_get_value_utf8_string_size"; |
2314 | 11.4k | size_t value_data_size = 0; |
2315 | 11.4k | uint32_t value_type = 0; |
2316 | | |
2317 | 11.4k | if( value_item == NULL ) |
2318 | 0 | { |
2319 | 0 | libcerror_error_set( |
2320 | 0 | error, |
2321 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2322 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2323 | 0 | "%s: invalid value item.", |
2324 | 0 | function ); |
2325 | |
|
2326 | 0 | return( -1 ); |
2327 | 0 | } |
2328 | 11.4k | if( libregf_value_key_get_value_type( |
2329 | 11.4k | value_item->value_key, |
2330 | 11.4k | &value_type, |
2331 | 11.4k | error ) != 1 ) |
2332 | 40 | { |
2333 | 40 | libcerror_error_set( |
2334 | 40 | error, |
2335 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2336 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2337 | 40 | "%s: unable to retrieve value type.", |
2338 | 40 | function ); |
2339 | | |
2340 | 40 | return( -1 ); |
2341 | 40 | } |
2342 | 11.3k | if( ( value_type != LIBREGF_VALUE_TYPE_STRING ) |
2343 | 10.8k | && ( value_type != LIBREGF_VALUE_TYPE_EXPANDABLE_STRING ) |
2344 | 10.3k | && ( value_type != LIBREGF_VALUE_TYPE_SYMBOLIC_LINK ) ) |
2345 | 10.3k | { |
2346 | 10.3k | libcerror_error_set( |
2347 | 10.3k | error, |
2348 | 10.3k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2349 | 10.3k | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2350 | 10.3k | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
2351 | 10.3k | function, |
2352 | 10.3k | value_type ); |
2353 | | |
2354 | 10.3k | return( -1 ); |
2355 | 10.3k | } |
2356 | 1.07k | if( libregf_value_item_get_data( |
2357 | 1.07k | value_item, |
2358 | 1.07k | file_io_handle, |
2359 | 1.07k | &value_data, |
2360 | 1.07k | &value_data_size, |
2361 | 1.07k | error ) != 1 ) |
2362 | 33 | { |
2363 | 33 | libcerror_error_set( |
2364 | 33 | error, |
2365 | 33 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2366 | 33 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2367 | 33 | "%s: unable to retrieve value data.", |
2368 | 33 | function ); |
2369 | | |
2370 | 33 | return( -1 ); |
2371 | 33 | } |
2372 | 1.04k | if( value_data_size == 0 ) |
2373 | 124 | { |
2374 | 124 | if( utf8_string_size == NULL ) |
2375 | 0 | { |
2376 | 0 | libcerror_error_set( |
2377 | 0 | error, |
2378 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2379 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2380 | 0 | "%s: invalid UTF-8 string size.", |
2381 | 0 | function ); |
2382 | |
|
2383 | 0 | return( -1 ); |
2384 | 0 | } |
2385 | 124 | *utf8_string_size = 0; |
2386 | 124 | } |
2387 | 921 | else |
2388 | 921 | { |
2389 | 921 | if( libuna_utf8_string_size_from_utf16_stream( |
2390 | 921 | value_data, |
2391 | 921 | value_data_size, |
2392 | 921 | LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, |
2393 | 921 | utf8_string_size, |
2394 | 921 | error ) != 1 ) |
2395 | 20 | { |
2396 | 20 | libcerror_error_set( |
2397 | 20 | error, |
2398 | 20 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2399 | 20 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2400 | 20 | "%s: unable to determine UTF-8 string size.", |
2401 | 20 | function ); |
2402 | | |
2403 | 20 | return( -1 ); |
2404 | 20 | } |
2405 | 921 | } |
2406 | 1.02k | return( 1 ); |
2407 | 1.04k | } |
2408 | | |
2409 | | /* Retrieves the UTF-8 string value |
2410 | | * This function uses UTF-8 RFC 2279 (or 6-byte UTF-8) to support characters outside Unicode |
2411 | | * The function uses a codepage if necessary, it uses the codepage set for the library |
2412 | | * The size should include the end of string character |
2413 | | * Returns 1 if successful or -1 on error |
2414 | | */ |
2415 | | int libregf_value_item_get_value_utf8_string( |
2416 | | libregf_value_item_t *value_item, |
2417 | | libbfio_handle_t *file_io_handle, |
2418 | | uint8_t *utf8_string, |
2419 | | size_t utf8_string_size, |
2420 | | libcerror_error_t **error ) |
2421 | 901 | { |
2422 | 901 | uint8_t *value_data = NULL; |
2423 | 901 | static char *function = "libregf_value_item_get_value_utf8_string"; |
2424 | 901 | size_t value_data_size = 0; |
2425 | 901 | uint32_t value_type = 0; |
2426 | | |
2427 | 901 | if( value_item == NULL ) |
2428 | 0 | { |
2429 | 0 | libcerror_error_set( |
2430 | 0 | error, |
2431 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2432 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2433 | 0 | "%s: invalid value item.", |
2434 | 0 | function ); |
2435 | |
|
2436 | 0 | return( -1 ); |
2437 | 0 | } |
2438 | 901 | if( libregf_value_key_get_value_type( |
2439 | 901 | value_item->value_key, |
2440 | 901 | &value_type, |
2441 | 901 | error ) != 1 ) |
2442 | 0 | { |
2443 | 0 | libcerror_error_set( |
2444 | 0 | error, |
2445 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2446 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2447 | 0 | "%s: unable to retrieve value type.", |
2448 | 0 | function ); |
2449 | |
|
2450 | 0 | return( -1 ); |
2451 | 0 | } |
2452 | 901 | if( ( value_type != LIBREGF_VALUE_TYPE_STRING ) |
2453 | 470 | && ( value_type != LIBREGF_VALUE_TYPE_EXPANDABLE_STRING ) |
2454 | 4 | && ( value_type != LIBREGF_VALUE_TYPE_SYMBOLIC_LINK ) ) |
2455 | 0 | { |
2456 | 0 | libcerror_error_set( |
2457 | 0 | error, |
2458 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2459 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2460 | 0 | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
2461 | 0 | function, |
2462 | 0 | value_type ); |
2463 | |
|
2464 | 0 | return( -1 ); |
2465 | 0 | } |
2466 | 901 | if( libregf_value_item_get_data( |
2467 | 901 | value_item, |
2468 | 901 | file_io_handle, |
2469 | 901 | &value_data, |
2470 | 901 | &value_data_size, |
2471 | 901 | error ) != 1 ) |
2472 | 0 | { |
2473 | 0 | libcerror_error_set( |
2474 | 0 | error, |
2475 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2476 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2477 | 0 | "%s: unable to retrieve value data.", |
2478 | 0 | function ); |
2479 | |
|
2480 | 0 | return( -1 ); |
2481 | 0 | } |
2482 | 901 | if( libuna_utf8_string_copy_from_utf16_stream( |
2483 | 901 | utf8_string, |
2484 | 901 | utf8_string_size, |
2485 | 901 | value_data, |
2486 | 901 | value_data_size, |
2487 | 901 | LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, |
2488 | 901 | error ) != 1 ) |
2489 | 0 | { |
2490 | 0 | libcerror_error_set( |
2491 | 0 | error, |
2492 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2493 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2494 | 0 | "%s: unable to set UTF-8 string.", |
2495 | 0 | function ); |
2496 | |
|
2497 | 0 | return( -1 ); |
2498 | 0 | } |
2499 | 901 | return( 1 ); |
2500 | 901 | } |
2501 | | |
2502 | | /* Retrieves the UTF-16 string size at a specific value from the referenced value |
2503 | | * This function uses UCS-2 (with surrogates) to support characters outside Unicode |
2504 | | * The returned size includes the end of string character |
2505 | | * Returns 1 if successful or -1 on error |
2506 | | */ |
2507 | | int libregf_value_item_get_value_utf16_string_size( |
2508 | | libregf_value_item_t *value_item, |
2509 | | libbfio_handle_t *file_io_handle, |
2510 | | size_t *utf16_string_size, |
2511 | | libcerror_error_t **error ) |
2512 | 11.4k | { |
2513 | 11.4k | uint8_t *value_data = NULL; |
2514 | 11.4k | static char *function = "libregf_value_item_get_value_utf16_string_size"; |
2515 | 11.4k | size_t value_data_size = 0; |
2516 | 11.4k | uint32_t value_type = 0; |
2517 | | |
2518 | 11.4k | if( value_item == NULL ) |
2519 | 0 | { |
2520 | 0 | libcerror_error_set( |
2521 | 0 | error, |
2522 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2523 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2524 | 0 | "%s: invalid value item.", |
2525 | 0 | function ); |
2526 | |
|
2527 | 0 | return( -1 ); |
2528 | 0 | } |
2529 | 11.4k | if( libregf_value_key_get_value_type( |
2530 | 11.4k | value_item->value_key, |
2531 | 11.4k | &value_type, |
2532 | 11.4k | error ) != 1 ) |
2533 | 40 | { |
2534 | 40 | libcerror_error_set( |
2535 | 40 | error, |
2536 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2537 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2538 | 40 | "%s: unable to retrieve value type.", |
2539 | 40 | function ); |
2540 | | |
2541 | 40 | return( -1 ); |
2542 | 40 | } |
2543 | 11.3k | if( ( value_type != LIBREGF_VALUE_TYPE_STRING ) |
2544 | 10.8k | && ( value_type != LIBREGF_VALUE_TYPE_EXPANDABLE_STRING ) |
2545 | 10.3k | && ( value_type != LIBREGF_VALUE_TYPE_SYMBOLIC_LINK ) ) |
2546 | 10.3k | { |
2547 | 10.3k | libcerror_error_set( |
2548 | 10.3k | error, |
2549 | 10.3k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2550 | 10.3k | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2551 | 10.3k | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
2552 | 10.3k | function, |
2553 | 10.3k | value_type ); |
2554 | | |
2555 | 10.3k | return( -1 ); |
2556 | 10.3k | } |
2557 | 1.07k | if( libregf_value_item_get_data( |
2558 | 1.07k | value_item, |
2559 | 1.07k | file_io_handle, |
2560 | 1.07k | &value_data, |
2561 | 1.07k | &value_data_size, |
2562 | 1.07k | error ) != 1 ) |
2563 | 33 | { |
2564 | 33 | libcerror_error_set( |
2565 | 33 | error, |
2566 | 33 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2567 | 33 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2568 | 33 | "%s: unable to retrieve value data.", |
2569 | 33 | function ); |
2570 | | |
2571 | 33 | return( -1 ); |
2572 | 33 | } |
2573 | 1.04k | if( value_data_size == 0 ) |
2574 | 124 | { |
2575 | 124 | if( utf16_string_size == NULL ) |
2576 | 0 | { |
2577 | 0 | libcerror_error_set( |
2578 | 0 | error, |
2579 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2580 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2581 | 0 | "%s: invalid UTF-16 string size.", |
2582 | 0 | function ); |
2583 | |
|
2584 | 0 | return( -1 ); |
2585 | 0 | } |
2586 | 124 | *utf16_string_size = 0; |
2587 | 124 | } |
2588 | 921 | else |
2589 | 921 | { |
2590 | 921 | if( libuna_utf16_string_size_from_utf16_stream( |
2591 | 921 | value_data, |
2592 | 921 | value_data_size, |
2593 | 921 | LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, |
2594 | 921 | utf16_string_size, |
2595 | 921 | error ) != 1 ) |
2596 | 20 | { |
2597 | 20 | libcerror_error_set( |
2598 | 20 | error, |
2599 | 20 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2600 | 20 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2601 | 20 | "%s: unable to determine UTF-16 string size.", |
2602 | 20 | function ); |
2603 | | |
2604 | 20 | return( -1 ); |
2605 | 20 | } |
2606 | 921 | } |
2607 | 1.02k | return( 1 ); |
2608 | 1.04k | } |
2609 | | |
2610 | | /* Retrieves the UTF-16 string value |
2611 | | * This function uses UCS-2 (with surrogates) to support characters outside Unicode |
2612 | | * The function uses a codepage if necessary, it uses the codepage set for the library |
2613 | | * The size should include the end of string character |
2614 | | * Returns 1 if successful or -1 on error |
2615 | | */ |
2616 | | int libregf_value_item_get_value_utf16_string( |
2617 | | libregf_value_item_t *value_item, |
2618 | | libbfio_handle_t *file_io_handle, |
2619 | | uint16_t *utf16_string, |
2620 | | size_t utf16_string_size, |
2621 | | libcerror_error_t **error ) |
2622 | 901 | { |
2623 | 901 | uint8_t *value_data = NULL; |
2624 | 901 | static char *function = "libregf_value_item_get_value_utf16_string"; |
2625 | 901 | size_t value_data_size = 0; |
2626 | 901 | uint32_t value_type = 0; |
2627 | | |
2628 | 901 | if( value_item == NULL ) |
2629 | 0 | { |
2630 | 0 | libcerror_error_set( |
2631 | 0 | error, |
2632 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2633 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2634 | 0 | "%s: invalid value item.", |
2635 | 0 | function ); |
2636 | |
|
2637 | 0 | return( -1 ); |
2638 | 0 | } |
2639 | 901 | if( libregf_value_key_get_value_type( |
2640 | 901 | value_item->value_key, |
2641 | 901 | &value_type, |
2642 | 901 | error ) != 1 ) |
2643 | 0 | { |
2644 | 0 | libcerror_error_set( |
2645 | 0 | error, |
2646 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2647 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2648 | 0 | "%s: unable to retrieve value type.", |
2649 | 0 | function ); |
2650 | |
|
2651 | 0 | return( -1 ); |
2652 | 0 | } |
2653 | 901 | if( ( value_type != LIBREGF_VALUE_TYPE_STRING ) |
2654 | 470 | && ( value_type != LIBREGF_VALUE_TYPE_EXPANDABLE_STRING ) |
2655 | 4 | && ( value_type != LIBREGF_VALUE_TYPE_SYMBOLIC_LINK ) ) |
2656 | 0 | { |
2657 | 0 | libcerror_error_set( |
2658 | 0 | error, |
2659 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2660 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2661 | 0 | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
2662 | 0 | function, |
2663 | 0 | value_type ); |
2664 | |
|
2665 | 0 | return( -1 ); |
2666 | 0 | } |
2667 | 901 | if( libregf_value_item_get_data( |
2668 | 901 | value_item, |
2669 | 901 | file_io_handle, |
2670 | 901 | &value_data, |
2671 | 901 | &value_data_size, |
2672 | 901 | error ) != 1 ) |
2673 | 0 | { |
2674 | 0 | libcerror_error_set( |
2675 | 0 | error, |
2676 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2677 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2678 | 0 | "%s: unable to retrieve value data.", |
2679 | 0 | function ); |
2680 | |
|
2681 | 0 | return( -1 ); |
2682 | 0 | } |
2683 | 901 | if( libuna_utf16_string_copy_from_utf16_stream( |
2684 | 901 | utf16_string, |
2685 | 901 | utf16_string_size, |
2686 | 901 | value_data, |
2687 | 901 | value_data_size, |
2688 | 901 | LIBUNA_ENDIAN_LITTLE | LIBUNA_UTF16_STREAM_ALLOW_UNPAIRED_SURROGATE, |
2689 | 901 | error ) != 1 ) |
2690 | 0 | { |
2691 | 0 | libcerror_error_set( |
2692 | 0 | error, |
2693 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
2694 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
2695 | 0 | "%s: unable to set UTF-16 string.", |
2696 | 0 | function ); |
2697 | |
|
2698 | 0 | return( -1 ); |
2699 | 0 | } |
2700 | 901 | return( 1 ); |
2701 | 901 | } |
2702 | | |
2703 | | /* Retrieves the binary data size |
2704 | | * Returns 1 if successful or -1 on error |
2705 | | */ |
2706 | | int libregf_value_item_get_value_binary_data_size( |
2707 | | libregf_value_item_t *value_item, |
2708 | | size_t *binary_data_size, |
2709 | | libcerror_error_t **error ) |
2710 | 11.4k | { |
2711 | 11.4k | static char *function = "libregf_value_item_get_value_binary_data_size"; |
2712 | 11.4k | uint32_t value_type = 0; |
2713 | | |
2714 | 11.4k | if( value_item == NULL ) |
2715 | 0 | { |
2716 | 0 | libcerror_error_set( |
2717 | 0 | error, |
2718 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2719 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2720 | 0 | "%s: invalid value item.", |
2721 | 0 | function ); |
2722 | |
|
2723 | 0 | return( -1 ); |
2724 | 0 | } |
2725 | 11.4k | if( libregf_value_key_get_value_type( |
2726 | 11.4k | value_item->value_key, |
2727 | 11.4k | &value_type, |
2728 | 11.4k | error ) != 1 ) |
2729 | 40 | { |
2730 | 40 | libcerror_error_set( |
2731 | 40 | error, |
2732 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2733 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2734 | 40 | "%s: unable to retrieve value type.", |
2735 | 40 | function ); |
2736 | | |
2737 | 40 | return( -1 ); |
2738 | 40 | } |
2739 | 11.3k | if( value_type != LIBREGF_VALUE_TYPE_BINARY_DATA ) |
2740 | 11.3k | { |
2741 | 11.3k | libcerror_error_set( |
2742 | 11.3k | error, |
2743 | 11.3k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2744 | 11.3k | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2745 | 11.3k | "%s: unsupported binary data value type: 0x%04" PRIx32 ".", |
2746 | 11.3k | function, |
2747 | 11.3k | value_type ); |
2748 | | |
2749 | 11.3k | return( -1 ); |
2750 | 11.3k | } |
2751 | 52 | if( libregf_value_item_get_data_size( |
2752 | 52 | value_item, |
2753 | 52 | binary_data_size, |
2754 | 52 | error ) != 1 ) |
2755 | 3 | { |
2756 | 3 | libcerror_error_set( |
2757 | 3 | error, |
2758 | 3 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2759 | 3 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2760 | 3 | "%s: unable to retrieve value data size.", |
2761 | 3 | function ); |
2762 | | |
2763 | 3 | return( -1 ); |
2764 | 3 | } |
2765 | 49 | return( 1 ); |
2766 | 52 | } |
2767 | | |
2768 | | /* Retrieves the binary data value |
2769 | | * Returns 1 if successful or -1 on error |
2770 | | */ |
2771 | | int libregf_value_item_get_value_binary_data( |
2772 | | libregf_value_item_t *value_item, |
2773 | | libbfio_handle_t *file_io_handle, |
2774 | | uint8_t *binary_data, |
2775 | | size_t binary_data_size, |
2776 | | libcerror_error_t **error ) |
2777 | 25 | { |
2778 | 25 | uint8_t *value_data = NULL; |
2779 | 25 | static char *function = "libregf_value_item_get_value_binary_data"; |
2780 | 25 | size_t value_data_size = 0; |
2781 | 25 | uint32_t value_type = 0; |
2782 | | |
2783 | 25 | if( value_item == NULL ) |
2784 | 0 | { |
2785 | 0 | libcerror_error_set( |
2786 | 0 | error, |
2787 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2788 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2789 | 0 | "%s: invalid value item.", |
2790 | 0 | function ); |
2791 | |
|
2792 | 0 | return( -1 ); |
2793 | 0 | } |
2794 | 25 | if( binary_data == NULL ) |
2795 | 0 | { |
2796 | 0 | libcerror_error_set( |
2797 | 0 | error, |
2798 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2799 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2800 | 0 | "%s: invalid binary data.", |
2801 | 0 | function ); |
2802 | |
|
2803 | 0 | return( -1 ); |
2804 | 0 | } |
2805 | 25 | if( binary_data_size > (size_t) SSIZE_MAX ) |
2806 | 0 | { |
2807 | 0 | libcerror_error_set( |
2808 | 0 | error, |
2809 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2810 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
2811 | 0 | "%s: invalid binary data size value exceeds maximum.", |
2812 | 0 | function ); |
2813 | |
|
2814 | 0 | return( -1 ); |
2815 | 0 | } |
2816 | 25 | if( libregf_value_key_get_value_type( |
2817 | 25 | value_item->value_key, |
2818 | 25 | &value_type, |
2819 | 25 | error ) != 1 ) |
2820 | 0 | { |
2821 | 0 | libcerror_error_set( |
2822 | 0 | error, |
2823 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2824 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2825 | 0 | "%s: unable to retrieve value type.", |
2826 | 0 | function ); |
2827 | |
|
2828 | 0 | return( -1 ); |
2829 | 0 | } |
2830 | 25 | if( value_type != LIBREGF_VALUE_TYPE_BINARY_DATA ) |
2831 | 0 | { |
2832 | 0 | libcerror_error_set( |
2833 | 0 | error, |
2834 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2835 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2836 | 0 | "%s: unsupported binary data value type: 0x%04" PRIx32 ".", |
2837 | 0 | function, |
2838 | 0 | value_type ); |
2839 | |
|
2840 | 0 | return( -1 ); |
2841 | 0 | } |
2842 | | /* TODO optimize to read directly from block or stream */ |
2843 | 25 | if( libregf_value_item_get_data( |
2844 | 25 | value_item, |
2845 | 25 | file_io_handle, |
2846 | 25 | &value_data, |
2847 | 25 | &value_data_size, |
2848 | 25 | error ) != 1 ) |
2849 | 0 | { |
2850 | 0 | libcerror_error_set( |
2851 | 0 | error, |
2852 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2853 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2854 | 0 | "%s: unable to retrieve value data.", |
2855 | 0 | function ); |
2856 | |
|
2857 | 0 | return( -1 ); |
2858 | 0 | } |
2859 | 25 | if( value_data == NULL ) |
2860 | 0 | { |
2861 | 0 | libcerror_error_set( |
2862 | 0 | error, |
2863 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2864 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2865 | 0 | "%s: missing value data.", |
2866 | 0 | function ); |
2867 | |
|
2868 | 0 | return( -1 ); |
2869 | 0 | } |
2870 | 25 | if( binary_data_size < value_data_size ) |
2871 | 0 | { |
2872 | 0 | libcerror_error_set( |
2873 | 0 | error, |
2874 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2875 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
2876 | 0 | "%s: binary data is too small.", |
2877 | 0 | function ); |
2878 | |
|
2879 | 0 | return( -1 ); |
2880 | 0 | } |
2881 | 25 | if( memory_copy( |
2882 | 25 | binary_data, |
2883 | 25 | value_data, |
2884 | 25 | value_data_size ) == NULL ) |
2885 | 0 | { |
2886 | 0 | libcerror_error_set( |
2887 | 0 | error, |
2888 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2889 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
2890 | 0 | "%s: unable to set binary data.", |
2891 | 0 | function ); |
2892 | |
|
2893 | 0 | return( -1 ); |
2894 | 0 | } |
2895 | 25 | return( 1 ); |
2896 | 25 | } |
2897 | | |
2898 | | /* Retrieves the multi string value |
2899 | | * Creates a new multi string |
2900 | | * Returns 1 if successful or -1 on error |
2901 | | */ |
2902 | | int libregf_value_item_get_value_multi_string( |
2903 | | libregf_value_item_t *value_item, |
2904 | | libbfio_handle_t *file_io_handle, |
2905 | | libregf_multi_string_t **multi_string, |
2906 | | libcerror_error_t **error ) |
2907 | 11.4k | { |
2908 | 11.4k | uint8_t *value_data = NULL; |
2909 | 11.4k | static char *function = "libregf_value_item_get_value_multi_string"; |
2910 | 11.4k | size_t value_data_size = 0; |
2911 | 11.4k | uint32_t value_type = 0; |
2912 | | |
2913 | 11.4k | if( value_item == NULL ) |
2914 | 0 | { |
2915 | 0 | libcerror_error_set( |
2916 | 0 | error, |
2917 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2918 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2919 | 0 | "%s: invalid value item.", |
2920 | 0 | function ); |
2921 | |
|
2922 | 0 | return( -1 ); |
2923 | 0 | } |
2924 | 11.4k | if( multi_string == NULL ) |
2925 | 0 | { |
2926 | 0 | libcerror_error_set( |
2927 | 0 | error, |
2928 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2929 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2930 | 0 | "%s: invalid multi string.", |
2931 | 0 | function ); |
2932 | |
|
2933 | 0 | return( -1 ); |
2934 | 0 | } |
2935 | 11.4k | if( libregf_value_key_get_value_type( |
2936 | 11.4k | value_item->value_key, |
2937 | 11.4k | &value_type, |
2938 | 11.4k | error ) != 1 ) |
2939 | 40 | { |
2940 | 40 | libcerror_error_set( |
2941 | 40 | error, |
2942 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2943 | 40 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2944 | 40 | "%s: unable to retrieve value type.", |
2945 | 40 | function ); |
2946 | | |
2947 | 40 | goto on_error; |
2948 | 40 | } |
2949 | 11.3k | if( value_type != LIBREGF_VALUE_TYPE_MULTI_VALUE_STRING ) |
2950 | 11.2k | { |
2951 | 11.2k | libcerror_error_set( |
2952 | 11.2k | error, |
2953 | 11.2k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2954 | 11.2k | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
2955 | 11.2k | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
2956 | 11.2k | function, |
2957 | 11.2k | value_type ); |
2958 | | |
2959 | 11.2k | goto on_error; |
2960 | 11.2k | } |
2961 | 145 | if( libregf_value_item_get_data( |
2962 | 145 | value_item, |
2963 | 145 | file_io_handle, |
2964 | 145 | &value_data, |
2965 | 145 | &value_data_size, |
2966 | 145 | error ) != 1 ) |
2967 | 0 | { |
2968 | 0 | libcerror_error_set( |
2969 | 0 | error, |
2970 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2971 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2972 | 0 | "%s: unable to retrieve value data.", |
2973 | 0 | function ); |
2974 | |
|
2975 | 0 | goto on_error; |
2976 | 0 | } |
2977 | 145 | if( libregf_multi_string_initialize( |
2978 | 145 | multi_string, |
2979 | 145 | error ) != 1 ) |
2980 | 0 | { |
2981 | 0 | libcerror_error_set( |
2982 | 0 | error, |
2983 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2984 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2985 | 0 | "%s: unable to create multi string.", |
2986 | 0 | function ); |
2987 | |
|
2988 | 0 | goto on_error; |
2989 | 0 | } |
2990 | 145 | if( libregf_internal_multi_string_read_data( |
2991 | 145 | (libregf_internal_multi_string_t *) *multi_string, |
2992 | 145 | value_data, |
2993 | 145 | value_data_size, |
2994 | 145 | error ) != 1 ) |
2995 | 33 | { |
2996 | 33 | libcerror_error_set( |
2997 | 33 | error, |
2998 | 33 | LIBCERROR_ERROR_DOMAIN_IO, |
2999 | 33 | LIBCERROR_IO_ERROR_READ_FAILED, |
3000 | 33 | "%s: unable to read multi string from value data.", |
3001 | 33 | function ); |
3002 | | |
3003 | 33 | goto on_error; |
3004 | 33 | } |
3005 | 112 | return( 1 ); |
3006 | | |
3007 | 11.3k | on_error: |
3008 | 11.3k | if( *multi_string != NULL ) |
3009 | 33 | { |
3010 | 33 | libregf_multi_string_free( |
3011 | 33 | multi_string, |
3012 | | NULL ); |
3013 | 33 | } |
3014 | 11.3k | return( -1 ); |
3015 | 145 | } |
3016 | | |