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