/src/libsmraw/libfvalue/libfvalue_value.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Value functions |
3 | | * |
4 | | * Copyright (C) 2010-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <file_stream.h> |
24 | | #include <memory.h> |
25 | | #include <narrow_string.h> |
26 | | #include <system_string.h> |
27 | | #include <types.h> |
28 | | #include <wide_string.h> |
29 | | |
30 | | #include "libfvalue_data_handle.h" |
31 | | #include "libfvalue_definitions.h" |
32 | | #include "libfvalue_libcdata.h" |
33 | | #include "libfvalue_libcerror.h" |
34 | | #include "libfvalue_libcnotify.h" |
35 | | #include "libfvalue_types.h" |
36 | | #include "libfvalue_value.h" |
37 | | |
38 | | /* Creates a value |
39 | | * Make sure the value value is referencing, is set to NULL |
40 | | * Returns 1 if successful or -1 on error |
41 | | */ |
42 | | int libfvalue_value_initialize( |
43 | | libfvalue_value_t **value, |
44 | | const char *type_string, |
45 | | const char *type_description, |
46 | | libfvalue_data_handle_t *data_handle, |
47 | | int (*initialize_instance)( |
48 | | intptr_t **instance, |
49 | | libcerror_error_t **error ), |
50 | | int (*free_instance)( |
51 | | intptr_t **instance, |
52 | | libcerror_error_t **error ), |
53 | | int (*clone_instance)( |
54 | | intptr_t **destination_instance, |
55 | | intptr_t *source_instance, |
56 | | libcerror_error_t **error ), |
57 | | int (*copy_from_byte_stream)( |
58 | | intptr_t *instance, |
59 | | const uint8_t *byte_stream, |
60 | | size_t byte_stream_size, |
61 | | int encoding, |
62 | | libcerror_error_t **error ), |
63 | | int (*copy_to_byte_stream)( |
64 | | intptr_t *instance, |
65 | | uint8_t *byte_stream, |
66 | | size_t byte_stream_size, |
67 | | int encoding, |
68 | | libcerror_error_t **error ), |
69 | | int (*copy_from_integer)( |
70 | | intptr_t *instance, |
71 | | uint64_t integer_value, |
72 | | size_t integer_value_size, |
73 | | libcerror_error_t **error ), |
74 | | int (*copy_to_integer)( |
75 | | intptr_t *instance, |
76 | | uint64_t *integer_value, |
77 | | size_t *integer_value_size, |
78 | | libcerror_error_t **error ), |
79 | | int (*copy_from_floating_point)( |
80 | | intptr_t *instance, |
81 | | double floating_point_value, |
82 | | size_t floating_point_value_size, |
83 | | libcerror_error_t **error ), |
84 | | int (*copy_to_floating_point)( |
85 | | intptr_t *instance, |
86 | | double *floating_point_value, |
87 | | size_t *floating_point_value_size, |
88 | | libcerror_error_t **error ), |
89 | | int (*copy_from_utf8_string_with_index)( |
90 | | intptr_t *instance, |
91 | | const uint8_t *utf8_string, |
92 | | size_t utf8_string_length, |
93 | | size_t *utf8_string_index, |
94 | | uint32_t string_format_flags, |
95 | | libcerror_error_t **error ), |
96 | | int (*get_utf8_string_size)( |
97 | | intptr_t *instance, |
98 | | size_t *utf8_string_size, |
99 | | uint32_t string_format_flags, |
100 | | libcerror_error_t **error ), |
101 | | int (*copy_to_utf8_string_with_index)( |
102 | | intptr_t *instance, |
103 | | uint8_t *utf8_string, |
104 | | size_t utf8_string_size, |
105 | | size_t *utf8_string_index, |
106 | | uint32_t string_format_flags, |
107 | | libcerror_error_t **error ), |
108 | | int (*copy_from_utf16_string_with_index)( |
109 | | intptr_t *instance, |
110 | | const uint16_t *utf16_string, |
111 | | size_t utf16_string_length, |
112 | | size_t *utf16_string_index, |
113 | | uint32_t string_format_flags, |
114 | | libcerror_error_t **error ), |
115 | | int (*get_utf16_string_size)( |
116 | | intptr_t *instance, |
117 | | size_t *utf16_string_size, |
118 | | uint32_t string_format_flags, |
119 | | libcerror_error_t **error ), |
120 | | int (*copy_to_utf16_string_with_index)( |
121 | | intptr_t *instance, |
122 | | uint16_t *utf16_string, |
123 | | size_t utf16_string_size, |
124 | | size_t *utf16_string_index, |
125 | | uint32_t string_format_flags, |
126 | | libcerror_error_t **error ), |
127 | | int (*copy_from_utf32_string_with_index)( |
128 | | intptr_t *instance, |
129 | | const uint32_t *utf32_string, |
130 | | size_t utf32_string_length, |
131 | | size_t *utf32_string_index, |
132 | | uint32_t string_format_flags, |
133 | | libcerror_error_t **error ), |
134 | | int (*get_utf32_string_size)( |
135 | | intptr_t *instance, |
136 | | size_t *utf32_string_size, |
137 | | uint32_t string_format_flags, |
138 | | libcerror_error_t **error ), |
139 | | int (*copy_to_utf32_string_with_index)( |
140 | | intptr_t *instance, |
141 | | uint32_t *utf32_string, |
142 | | size_t utf32_string_size, |
143 | | size_t *utf32_string_index, |
144 | | uint32_t string_format_flags, |
145 | | libcerror_error_t **error ), |
146 | | uint8_t flags, |
147 | | libcerror_error_t **error ) |
148 | 0 | { |
149 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
150 | 0 | static char *function = "libfvalue_value_initialize"; |
151 | |
|
152 | 0 | if( value == NULL ) |
153 | 0 | { |
154 | 0 | libcerror_error_set( |
155 | 0 | error, |
156 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
157 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
158 | 0 | "%s: invalid value.", |
159 | 0 | function ); |
160 | |
|
161 | 0 | return( -1 ); |
162 | 0 | } |
163 | 0 | if( *value != NULL ) |
164 | 0 | { |
165 | 0 | libcerror_error_set( |
166 | 0 | error, |
167 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
168 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
169 | 0 | "%s: invalid value value already set.", |
170 | 0 | function ); |
171 | |
|
172 | 0 | return( -1 ); |
173 | 0 | } |
174 | 0 | if( type_string == NULL ) |
175 | 0 | { |
176 | 0 | libcerror_error_set( |
177 | 0 | error, |
178 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
179 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
180 | 0 | "%s: invalid type string", |
181 | 0 | function ); |
182 | |
|
183 | 0 | return( -1 ); |
184 | 0 | } |
185 | 0 | internal_value = memory_allocate_structure( |
186 | 0 | libfvalue_internal_value_t ); |
187 | |
|
188 | 0 | if( internal_value == NULL ) |
189 | 0 | { |
190 | 0 | libcerror_error_set( |
191 | 0 | error, |
192 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
193 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
194 | 0 | "%s: unable to create value.", |
195 | 0 | function ); |
196 | |
|
197 | 0 | goto on_error; |
198 | 0 | } |
199 | 0 | if( memory_set( |
200 | 0 | internal_value, |
201 | 0 | 0, |
202 | 0 | sizeof( libfvalue_internal_value_t ) ) == NULL ) |
203 | 0 | { |
204 | 0 | libcerror_error_set( |
205 | 0 | error, |
206 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
207 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
208 | 0 | "%s: unable to clear value.", |
209 | 0 | function ); |
210 | |
|
211 | 0 | memory_free( |
212 | 0 | internal_value ); |
213 | |
|
214 | 0 | return( -1 ); |
215 | 0 | } |
216 | 0 | if( free_instance != NULL ) |
217 | 0 | { |
218 | 0 | if( libcdata_array_initialize( |
219 | 0 | &( internal_value->value_instances ), |
220 | 0 | 1, |
221 | 0 | error ) != 1 ) |
222 | 0 | { |
223 | 0 | libcerror_error_set( |
224 | 0 | error, |
225 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
226 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
227 | 0 | "%s: unable to create value instances array.", |
228 | 0 | function ); |
229 | |
|
230 | 0 | goto on_error; |
231 | 0 | } |
232 | 0 | } |
233 | 0 | if( data_handle == NULL ) |
234 | 0 | { |
235 | | /* TODO add read function ? */ |
236 | 0 | if( libfvalue_data_handle_initialize( |
237 | 0 | &( internal_value->data_handle ), |
238 | 0 | NULL, |
239 | 0 | error ) != 1 ) |
240 | 0 | { |
241 | 0 | libcerror_error_set( |
242 | 0 | error, |
243 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
244 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
245 | 0 | "%s: unable to create data handle.", |
246 | 0 | function ); |
247 | |
|
248 | 0 | goto on_error; |
249 | 0 | } |
250 | 0 | internal_value->flags |= LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED; |
251 | 0 | } |
252 | 0 | else |
253 | 0 | { |
254 | 0 | internal_value->data_handle = data_handle; |
255 | 0 | } |
256 | 0 | internal_value->type_string = type_string; |
257 | 0 | internal_value->type_description = type_description; |
258 | |
|
259 | 0 | internal_value->initialize_instance = initialize_instance; |
260 | 0 | internal_value->free_instance = free_instance; |
261 | 0 | internal_value->clone_instance = clone_instance; |
262 | |
|
263 | 0 | internal_value->copy_from_byte_stream = copy_from_byte_stream; |
264 | 0 | internal_value->copy_to_byte_stream = copy_to_byte_stream; |
265 | |
|
266 | 0 | internal_value->copy_from_integer = copy_from_integer; |
267 | 0 | internal_value->copy_to_integer = copy_to_integer; |
268 | |
|
269 | 0 | internal_value->copy_from_floating_point = copy_from_floating_point; |
270 | 0 | internal_value->copy_to_floating_point = copy_to_floating_point; |
271 | |
|
272 | 0 | internal_value->copy_from_utf8_string_with_index = copy_from_utf8_string_with_index; |
273 | 0 | internal_value->get_utf8_string_size = get_utf8_string_size; |
274 | 0 | internal_value->copy_to_utf8_string_with_index = copy_to_utf8_string_with_index; |
275 | |
|
276 | 0 | internal_value->copy_from_utf16_string_with_index = copy_from_utf16_string_with_index; |
277 | 0 | internal_value->get_utf16_string_size = get_utf16_string_size; |
278 | 0 | internal_value->copy_to_utf16_string_with_index = copy_to_utf16_string_with_index; |
279 | |
|
280 | 0 | internal_value->copy_from_utf32_string_with_index = copy_from_utf32_string_with_index; |
281 | 0 | internal_value->get_utf32_string_size = get_utf32_string_size; |
282 | 0 | internal_value->copy_to_utf32_string_with_index = copy_to_utf32_string_with_index; |
283 | |
|
284 | 0 | internal_value->flags |= flags; |
285 | |
|
286 | 0 | *value = (libfvalue_value_t *) internal_value; |
287 | |
|
288 | 0 | return( 1 ); |
289 | | |
290 | 0 | on_error: |
291 | 0 | if( internal_value != NULL ) |
292 | 0 | { |
293 | 0 | if( internal_value->value_instances != NULL ) |
294 | 0 | { |
295 | 0 | libcdata_array_free( |
296 | 0 | &( internal_value->value_instances ), |
297 | 0 | NULL, |
298 | 0 | NULL ); |
299 | 0 | } |
300 | 0 | memory_free( |
301 | 0 | internal_value ); |
302 | 0 | } |
303 | 0 | return( -1 ); |
304 | 0 | } |
305 | | |
306 | | /* Frees a value |
307 | | * Returns 1 if successful or -1 on error |
308 | | */ |
309 | | int libfvalue_value_free( |
310 | | libfvalue_value_t **value, |
311 | | libcerror_error_t **error ) |
312 | 0 | { |
313 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
314 | 0 | static char *function = "libfvalue_value_free"; |
315 | 0 | int result = 1; |
316 | |
|
317 | 0 | if( value == NULL ) |
318 | 0 | { |
319 | 0 | libcerror_error_set( |
320 | 0 | error, |
321 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
322 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
323 | 0 | "%s: invalid value.", |
324 | 0 | function ); |
325 | |
|
326 | 0 | return( -1 ); |
327 | 0 | } |
328 | 0 | if( *value != NULL ) |
329 | 0 | { |
330 | 0 | if( libfvalue_value_clear( |
331 | 0 | *value, |
332 | 0 | error ) != 1 ) |
333 | 0 | { |
334 | 0 | libcerror_error_set( |
335 | 0 | error, |
336 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
337 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
338 | 0 | "%s: unable to free data handle.", |
339 | 0 | function ); |
340 | |
|
341 | 0 | result = -1; |
342 | 0 | } |
343 | 0 | internal_value = (libfvalue_internal_value_t *) *value; |
344 | 0 | *value = NULL; |
345 | |
|
346 | 0 | if( internal_value->value_instances != NULL ) |
347 | 0 | { |
348 | 0 | if( libcdata_array_free( |
349 | 0 | &( internal_value->value_instances ), |
350 | 0 | internal_value->free_instance, |
351 | 0 | error ) != 1 ) |
352 | 0 | { |
353 | 0 | libcerror_error_set( |
354 | 0 | error, |
355 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
356 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
357 | 0 | "%s: unable to free value instances array.", |
358 | 0 | function ); |
359 | |
|
360 | 0 | result = -1; |
361 | 0 | } |
362 | 0 | } |
363 | 0 | if( ( internal_value->flags & LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED ) != 0 ) |
364 | 0 | { |
365 | 0 | if( libfvalue_data_handle_free( |
366 | 0 | &( internal_value->data_handle ), |
367 | 0 | error ) != 1 ) |
368 | 0 | { |
369 | 0 | libcerror_error_set( |
370 | 0 | error, |
371 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
372 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
373 | 0 | "%s: unable to free data handle.", |
374 | 0 | function ); |
375 | |
|
376 | 0 | result = -1; |
377 | 0 | } |
378 | 0 | internal_value->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED ); |
379 | 0 | } |
380 | 0 | memory_free( |
381 | 0 | internal_value ); |
382 | 0 | } |
383 | 0 | return( result ); |
384 | 0 | } |
385 | | |
386 | | /* Clones a value |
387 | | * Returns 1 if successful or -1 on error |
388 | | */ |
389 | | int libfvalue_value_clone( |
390 | | libfvalue_value_t **destination_value, |
391 | | libfvalue_value_t *source_value, |
392 | | libcerror_error_t **error ) |
393 | 0 | { |
394 | 0 | libfvalue_internal_value_t *internal_source_value = NULL; |
395 | 0 | libfvalue_data_handle_t *destination_data_handle = NULL; |
396 | 0 | static char *function = "libfvalue_value_clone"; |
397 | |
|
398 | 0 | if( destination_value == NULL ) |
399 | 0 | { |
400 | 0 | libcerror_error_set( |
401 | 0 | error, |
402 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
403 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
404 | 0 | "%s: invalid destination value.", |
405 | 0 | function ); |
406 | |
|
407 | 0 | return( -1 ); |
408 | 0 | } |
409 | 0 | if( *destination_value != NULL ) |
410 | 0 | { |
411 | 0 | libcerror_error_set( |
412 | 0 | error, |
413 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
414 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
415 | 0 | "%s: destination value already set.", |
416 | 0 | function ); |
417 | |
|
418 | 0 | return( -1 ); |
419 | 0 | } |
420 | 0 | if( source_value == NULL ) |
421 | 0 | { |
422 | 0 | *destination_value = NULL; |
423 | |
|
424 | 0 | return( 1 ); |
425 | 0 | } |
426 | 0 | internal_source_value = (libfvalue_internal_value_t *) source_value; |
427 | |
|
428 | 0 | if( libfvalue_data_handle_clone( |
429 | 0 | &destination_data_handle, |
430 | 0 | internal_source_value->data_handle, |
431 | 0 | error ) != 1 ) |
432 | 0 | { |
433 | 0 | libcerror_error_set( |
434 | 0 | error, |
435 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
436 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
437 | 0 | "%s: unable to create destination data handle.", |
438 | 0 | function ); |
439 | |
|
440 | 0 | goto on_error; |
441 | 0 | } |
442 | 0 | if( libfvalue_value_initialize( |
443 | 0 | destination_value, |
444 | 0 | internal_source_value->type_string, |
445 | 0 | internal_source_value->type_description, |
446 | 0 | destination_data_handle, |
447 | 0 | internal_source_value->initialize_instance, |
448 | 0 | internal_source_value->free_instance, |
449 | 0 | internal_source_value->clone_instance, |
450 | 0 | internal_source_value->copy_from_byte_stream, |
451 | 0 | internal_source_value->copy_to_byte_stream, |
452 | 0 | internal_source_value->copy_from_integer, |
453 | 0 | internal_source_value->copy_to_integer, |
454 | 0 | internal_source_value->copy_from_floating_point, |
455 | 0 | internal_source_value->copy_to_floating_point, |
456 | 0 | internal_source_value->copy_from_utf8_string_with_index, |
457 | 0 | internal_source_value->get_utf8_string_size, |
458 | 0 | internal_source_value->copy_to_utf8_string_with_index, |
459 | 0 | internal_source_value->copy_from_utf16_string_with_index, |
460 | 0 | internal_source_value->get_utf16_string_size, |
461 | 0 | internal_source_value->copy_to_utf16_string_with_index, |
462 | 0 | internal_source_value->copy_from_utf32_string_with_index, |
463 | 0 | internal_source_value->get_utf32_string_size, |
464 | 0 | internal_source_value->copy_to_utf32_string_with_index, |
465 | 0 | internal_source_value->flags | LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED, |
466 | 0 | error ) != 1 ) |
467 | 0 | { |
468 | 0 | libcerror_error_set( |
469 | 0 | error, |
470 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
471 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
472 | 0 | "%s: unable to create destination value.", |
473 | 0 | function ); |
474 | |
|
475 | 0 | goto on_error; |
476 | 0 | } |
477 | 0 | if( *destination_value == NULL ) |
478 | 0 | { |
479 | 0 | libcerror_error_set( |
480 | 0 | error, |
481 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
482 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
483 | 0 | "%s: missing destination value.", |
484 | 0 | function ); |
485 | |
|
486 | 0 | goto on_error; |
487 | 0 | } |
488 | 0 | destination_data_handle = NULL; |
489 | |
|
490 | 0 | if( internal_source_value->identifier != NULL ) |
491 | 0 | { |
492 | 0 | if( libfvalue_value_set_identifier( |
493 | 0 | *destination_value, |
494 | 0 | internal_source_value->identifier, |
495 | 0 | internal_source_value->identifier_size, |
496 | 0 | LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED, |
497 | 0 | error ) != 1 ) |
498 | 0 | { |
499 | 0 | libcerror_error_set( |
500 | 0 | error, |
501 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
502 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
503 | 0 | "%s: unable to set identifier in destination value.", |
504 | 0 | function ); |
505 | |
|
506 | 0 | goto on_error; |
507 | 0 | } |
508 | 0 | } |
509 | | /* The value instances are not cloned and are re-created on demand |
510 | | */ |
511 | 0 | return( 1 ); |
512 | | |
513 | 0 | on_error: |
514 | 0 | if( destination_data_handle != NULL ) |
515 | 0 | { |
516 | 0 | libfvalue_data_handle_free( |
517 | 0 | &destination_data_handle, |
518 | 0 | NULL ); |
519 | 0 | } |
520 | 0 | if( *destination_value != NULL ) |
521 | 0 | { |
522 | 0 | libfvalue_value_free( |
523 | 0 | destination_value, |
524 | 0 | NULL ); |
525 | 0 | } |
526 | 0 | return( -1 ); |
527 | 0 | } |
528 | | |
529 | | /* Clears a value |
530 | | * Returns 1 if successful or -1 on error |
531 | | */ |
532 | | int libfvalue_value_clear( |
533 | | libfvalue_value_t *value, |
534 | | libcerror_error_t **error ) |
535 | 0 | { |
536 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
537 | 0 | static char *function = "libfvalue_value_clear"; |
538 | |
|
539 | 0 | if( value == NULL ) |
540 | 0 | { |
541 | 0 | libcerror_error_set( |
542 | 0 | error, |
543 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
544 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
545 | 0 | "%s: invalid value.", |
546 | 0 | function ); |
547 | |
|
548 | 0 | return( -1 ); |
549 | 0 | } |
550 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
551 | |
|
552 | 0 | if( ( internal_value->flags & LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED ) != 0 ) |
553 | 0 | { |
554 | 0 | if( internal_value->identifier != NULL ) |
555 | 0 | { |
556 | 0 | memory_free( |
557 | 0 | internal_value->identifier ); |
558 | 0 | } |
559 | 0 | internal_value->flags &= ~( LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED ); |
560 | 0 | } |
561 | 0 | if( libfvalue_data_handle_clear( |
562 | 0 | internal_value->data_handle, |
563 | 0 | error ) != 1 ) |
564 | 0 | { |
565 | 0 | libcerror_error_set( |
566 | 0 | error, |
567 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
568 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
569 | 0 | "%s: unable to clear data handle.", |
570 | 0 | function ); |
571 | |
|
572 | 0 | return( -1 ); |
573 | 0 | } |
574 | 0 | if( internal_value->value_instances != NULL ) |
575 | 0 | { |
576 | 0 | if( internal_value->free_instance == NULL ) |
577 | 0 | { |
578 | 0 | libcerror_error_set( |
579 | 0 | error, |
580 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
581 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
582 | 0 | "%s: invalid value - missing free instance function.", |
583 | 0 | function ); |
584 | |
|
585 | 0 | return( -1 ); |
586 | 0 | } |
587 | 0 | if( libcdata_array_empty( |
588 | 0 | internal_value->value_instances, |
589 | 0 | internal_value->free_instance, |
590 | 0 | error ) != 1 ) |
591 | 0 | { |
592 | 0 | libcerror_error_set( |
593 | 0 | error, |
594 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
595 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
596 | 0 | "%s: unable to empty value instances array.", |
597 | 0 | function ); |
598 | |
|
599 | 0 | return( -1 ); |
600 | 0 | } |
601 | 0 | } |
602 | 0 | return( 1 ); |
603 | 0 | } |
604 | | |
605 | | /* Retrieves the value type |
606 | | * Returns 1 if successful or -1 on error |
607 | | */ |
608 | | int libfvalue_value_get_type( |
609 | | libfvalue_value_t *value, |
610 | | int *value_type, |
611 | | libcerror_error_t **error ) |
612 | 0 | { |
613 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
614 | 0 | static char *function = "libfvalue_value_get_type"; |
615 | |
|
616 | 0 | if( value == NULL ) |
617 | 0 | { |
618 | 0 | libcerror_error_set( |
619 | 0 | error, |
620 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
621 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
622 | 0 | "%s: invalid value.", |
623 | 0 | function ); |
624 | |
|
625 | 0 | return( -1 ); |
626 | 0 | } |
627 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
628 | |
|
629 | 0 | if( value_type == NULL ) |
630 | 0 | { |
631 | 0 | libcerror_error_set( |
632 | 0 | error, |
633 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
634 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
635 | 0 | "%s: invalid value type.", |
636 | 0 | function ); |
637 | |
|
638 | 0 | return( -1 ); |
639 | 0 | } |
640 | 0 | *value_type = internal_value->type; |
641 | |
|
642 | 0 | return( 1 ); |
643 | 0 | } |
644 | | |
645 | | /* Compares two index values |
646 | | * Returns LIBCDATA_COMPARE_LESS, LIBCDATA_COMPARE_EQUAL, LIBCDATA_COMPARE_GREATER if successful or -1 on error |
647 | | */ |
648 | | int libfvalue_compare_identifier( |
649 | | intptr_t *first_value, |
650 | | intptr_t *second_value, |
651 | | libcerror_error_t **error ) |
652 | 0 | { |
653 | 0 | libfvalue_internal_value_t *internal_first_value = NULL; |
654 | 0 | libfvalue_internal_value_t *internal_second_value = NULL; |
655 | 0 | static char *function = "libfvalue_compare_identifier"; |
656 | 0 | size_t compare_size = 0; |
657 | 0 | int result = 0; |
658 | |
|
659 | 0 | if( first_value == NULL ) |
660 | 0 | { |
661 | 0 | libcerror_error_set( |
662 | 0 | error, |
663 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
664 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
665 | 0 | "%s: invalid first value.", |
666 | 0 | function ); |
667 | |
|
668 | 0 | return( -1 ); |
669 | 0 | } |
670 | 0 | internal_first_value = (libfvalue_internal_value_t *) first_value; |
671 | |
|
672 | 0 | if( second_value == NULL ) |
673 | 0 | { |
674 | 0 | libcerror_error_set( |
675 | 0 | error, |
676 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
677 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
678 | 0 | "%s: invalid second value.", |
679 | 0 | function ); |
680 | |
|
681 | 0 | return( -1 ); |
682 | 0 | } |
683 | 0 | internal_second_value = (libfvalue_internal_value_t *) second_value; |
684 | |
|
685 | 0 | if( internal_first_value->identifier == NULL ) |
686 | 0 | { |
687 | 0 | libcerror_error_set( |
688 | 0 | error, |
689 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
690 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
691 | 0 | "%s: invalid first value - missing identifier.", |
692 | 0 | function ); |
693 | |
|
694 | 0 | return( -1 ); |
695 | 0 | } |
696 | 0 | if( internal_second_value->identifier == NULL ) |
697 | 0 | { |
698 | 0 | libcerror_error_set( |
699 | 0 | error, |
700 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
701 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
702 | 0 | "%s: invalid second value - missing identifier.", |
703 | 0 | function ); |
704 | |
|
705 | 0 | return( -1 ); |
706 | 0 | } |
707 | 0 | if( internal_first_value->identifier_size <= internal_second_value->identifier_size ) |
708 | 0 | { |
709 | 0 | compare_size = internal_first_value->identifier_size; |
710 | 0 | } |
711 | 0 | else |
712 | 0 | { |
713 | 0 | compare_size = internal_second_value->identifier_size; |
714 | 0 | } |
715 | 0 | result = memory_compare( |
716 | 0 | internal_first_value->identifier, |
717 | 0 | internal_second_value->identifier, |
718 | 0 | compare_size ); |
719 | |
|
720 | 0 | if( result < 0 ) |
721 | 0 | { |
722 | 0 | return( LIBCDATA_COMPARE_LESS ); |
723 | 0 | } |
724 | 0 | else if( result > 0 ) |
725 | 0 | { |
726 | 0 | return( LIBCDATA_COMPARE_GREATER ); |
727 | 0 | } |
728 | 0 | if( internal_first_value->identifier_size < internal_second_value->identifier_size ) |
729 | 0 | { |
730 | 0 | return( LIBCDATA_COMPARE_LESS ); |
731 | 0 | } |
732 | 0 | else if( internal_first_value->identifier_size > internal_second_value->identifier_size ) |
733 | 0 | { |
734 | 0 | return( LIBCDATA_COMPARE_GREATER ); |
735 | 0 | } |
736 | 0 | return( LIBCDATA_COMPARE_EQUAL ); |
737 | 0 | } |
738 | | |
739 | | /* Retrieves the identifier |
740 | | * Returns 1 if successful or -1 on error |
741 | | */ |
742 | | int libfvalue_value_get_identifier( |
743 | | libfvalue_value_t *value, |
744 | | uint8_t **identifier, |
745 | | size_t *identifier_size, |
746 | | libcerror_error_t **error ) |
747 | 0 | { |
748 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
749 | 0 | static char *function = "libfvalue_value_get_identifier"; |
750 | |
|
751 | 0 | if( value == NULL ) |
752 | 0 | { |
753 | 0 | libcerror_error_set( |
754 | 0 | error, |
755 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
756 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
757 | 0 | "%s: invalid value.", |
758 | 0 | function ); |
759 | |
|
760 | 0 | return( -1 ); |
761 | 0 | } |
762 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
763 | |
|
764 | 0 | if( identifier == 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 identifier.", |
771 | 0 | function ); |
772 | |
|
773 | 0 | return( -1 ); |
774 | 0 | } |
775 | 0 | if( identifier_size == NULL ) |
776 | 0 | { |
777 | 0 | libcerror_error_set( |
778 | 0 | error, |
779 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
780 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
781 | 0 | "%s: invalid identifier size.", |
782 | 0 | function ); |
783 | |
|
784 | 0 | return( -1 ); |
785 | 0 | } |
786 | 0 | *identifier = internal_value->identifier; |
787 | 0 | *identifier_size = internal_value->identifier_size; |
788 | |
|
789 | 0 | return( 1 ); |
790 | 0 | } |
791 | | |
792 | | /* Sets the identifier |
793 | | * Returns 1 if successful or -1 on error |
794 | | */ |
795 | | int libfvalue_value_set_identifier( |
796 | | libfvalue_value_t *value, |
797 | | const uint8_t *identifier, |
798 | | size_t identifier_size, |
799 | | uint8_t flags, |
800 | | libcerror_error_t **error ) |
801 | 0 | { |
802 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
803 | 0 | static char *function = "libfvalue_value_set_identifier"; |
804 | 0 | uint8_t supported_flags = 0; |
805 | |
|
806 | 0 | if( value == NULL ) |
807 | 0 | { |
808 | 0 | libcerror_error_set( |
809 | 0 | error, |
810 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
811 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
812 | 0 | "%s: invalid value.", |
813 | 0 | function ); |
814 | |
|
815 | 0 | return( -1 ); |
816 | 0 | } |
817 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
818 | |
|
819 | 0 | if( internal_value->identifier != NULL ) |
820 | 0 | { |
821 | 0 | libcerror_error_set( |
822 | 0 | error, |
823 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
824 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
825 | 0 | "%s: invalid value - identifier already set.", |
826 | 0 | function ); |
827 | |
|
828 | 0 | return( -1 ); |
829 | 0 | } |
830 | 0 | if( identifier == NULL ) |
831 | 0 | { |
832 | 0 | libcerror_error_set( |
833 | 0 | error, |
834 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
835 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
836 | 0 | "%s: invalid identifier.", |
837 | 0 | function ); |
838 | |
|
839 | 0 | return( -1 ); |
840 | 0 | } |
841 | 0 | if( ( identifier_size == 0 ) |
842 | 0 | || ( identifier_size > (size_t) SSIZE_MAX ) ) |
843 | 0 | { |
844 | 0 | libcerror_error_set( |
845 | 0 | error, |
846 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
847 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
848 | 0 | "%s: invalid identifier length value out of bounds.", |
849 | 0 | function ); |
850 | |
|
851 | 0 | return( -1 ); |
852 | 0 | } |
853 | 0 | supported_flags = LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED |
854 | 0 | | LIBFVALUE_VALUE_IDENTIFIER_FLAG_CLONE_BY_REFERENCE; |
855 | |
|
856 | 0 | if( ( flags & ~( supported_flags ) ) != 0 ) |
857 | 0 | { |
858 | 0 | libcerror_error_set( |
859 | 0 | error, |
860 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
861 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
862 | 0 | "%s: unsupported flags: 0x%02" PRIx8 ".", |
863 | 0 | function, |
864 | 0 | flags ); |
865 | |
|
866 | 0 | return( -1 ); |
867 | 0 | } |
868 | 0 | if( ( internal_value->flags & LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED ) != 0 ) |
869 | 0 | { |
870 | 0 | if( internal_value->identifier != NULL ) |
871 | 0 | { |
872 | 0 | memory_free( |
873 | 0 | internal_value->identifier ); |
874 | |
|
875 | 0 | internal_value->identifier = NULL; |
876 | 0 | internal_value->identifier_size = 0; |
877 | 0 | } |
878 | 0 | internal_value->flags &= ~( LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED ); |
879 | 0 | } |
880 | 0 | if( ( flags & LIBFVALUE_VALUE_IDENTIFIER_FLAG_CLONE_BY_REFERENCE ) != 0 ) |
881 | 0 | { |
882 | 0 | internal_value->identifier = (uint8_t *) identifier; |
883 | |
|
884 | 0 | if( ( flags & LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED ) != 0 ) |
885 | 0 | { |
886 | 0 | internal_value->flags |= LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED; |
887 | 0 | } |
888 | 0 | } |
889 | 0 | else |
890 | 0 | { |
891 | 0 | internal_value->identifier = (uint8_t *) memory_allocate( |
892 | 0 | sizeof( uint8_t ) * identifier_size ); |
893 | |
|
894 | 0 | if( internal_value->identifier == NULL ) |
895 | 0 | { |
896 | 0 | libcerror_error_set( |
897 | 0 | error, |
898 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
899 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
900 | 0 | "%s: unable to create identifier.", |
901 | 0 | function ); |
902 | |
|
903 | 0 | goto on_error; |
904 | 0 | } |
905 | 0 | if( memory_copy( |
906 | 0 | internal_value->identifier, |
907 | 0 | identifier, |
908 | 0 | identifier_size ) == NULL ) |
909 | 0 | { |
910 | 0 | libcerror_error_set( |
911 | 0 | error, |
912 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
913 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
914 | 0 | "%s: unable to copy identifier.", |
915 | 0 | function ); |
916 | |
|
917 | 0 | goto on_error; |
918 | 0 | } |
919 | 0 | internal_value->flags |= LIBFVALUE_VALUE_FLAG_IDENTIFIER_MANAGED; |
920 | 0 | } |
921 | 0 | internal_value->identifier_size = identifier_size; |
922 | |
|
923 | 0 | return( 1 ); |
924 | | |
925 | 0 | on_error: |
926 | 0 | if( internal_value->identifier != NULL ) |
927 | 0 | { |
928 | 0 | memory_free( |
929 | 0 | internal_value->identifier ); |
930 | |
|
931 | 0 | internal_value->identifier = NULL; |
932 | 0 | } |
933 | 0 | return( -1 ); |
934 | 0 | } |
935 | | |
936 | | /* Retrieves the value data flags |
937 | | * Returns 1 if successful or -1 on error |
938 | | */ |
939 | | int libfvalue_value_get_data_flags( |
940 | | libfvalue_value_t *value, |
941 | | uint32_t *data_flags, |
942 | | libcerror_error_t **error ) |
943 | 0 | { |
944 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
945 | 0 | static char *function = "libfvalue_value_get_data_flags"; |
946 | |
|
947 | 0 | if( value == NULL ) |
948 | 0 | { |
949 | 0 | libcerror_error_set( |
950 | 0 | error, |
951 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
952 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
953 | 0 | "%s: invalid value.", |
954 | 0 | function ); |
955 | |
|
956 | 0 | return( -1 ); |
957 | 0 | } |
958 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
959 | |
|
960 | 0 | if( libfvalue_data_handle_get_data_flags( |
961 | 0 | internal_value->data_handle, |
962 | 0 | data_flags, |
963 | 0 | error ) != 1 ) |
964 | 0 | { |
965 | 0 | libcerror_error_set( |
966 | 0 | error, |
967 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
968 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
969 | 0 | "%s: unable to retrieve data flags from data handle.", |
970 | 0 | function ); |
971 | |
|
972 | 0 | return( -1 ); |
973 | 0 | } |
974 | 0 | return( 1 ); |
975 | 0 | } |
976 | | |
977 | | /* Sets the value data flags |
978 | | * Returns 1 if successful or -1 on error |
979 | | */ |
980 | | int libfvalue_value_set_data_flags( |
981 | | libfvalue_value_t *value, |
982 | | uint32_t data_flags, |
983 | | libcerror_error_t **error ) |
984 | 0 | { |
985 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
986 | 0 | static char *function = "libfvalue_value_set_data_flags"; |
987 | |
|
988 | 0 | if( value == NULL ) |
989 | 0 | { |
990 | 0 | libcerror_error_set( |
991 | 0 | error, |
992 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
993 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
994 | 0 | "%s: invalid value.", |
995 | 0 | function ); |
996 | |
|
997 | 0 | return( -1 ); |
998 | 0 | } |
999 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1000 | |
|
1001 | 0 | if( libfvalue_data_handle_set_data_flags( |
1002 | 0 | internal_value->data_handle, |
1003 | 0 | data_flags, |
1004 | 0 | error ) != 1 ) |
1005 | 0 | { |
1006 | 0 | libcerror_error_set( |
1007 | 0 | error, |
1008 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1009 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1010 | 0 | "%s: unable to set data flags in data handle.", |
1011 | 0 | function ); |
1012 | |
|
1013 | 0 | return( -1 ); |
1014 | 0 | } |
1015 | 0 | return( 1 ); |
1016 | 0 | } |
1017 | | |
1018 | | /* Determines if the value has data |
1019 | | * Returns 1 if the value has data, 0 if not or -1 on error |
1020 | | */ |
1021 | | int libfvalue_value_has_data( |
1022 | | libfvalue_value_t *value, |
1023 | | libcerror_error_t **error ) |
1024 | 0 | { |
1025 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1026 | 0 | uint8_t *data = NULL; |
1027 | 0 | static char *function = "libfvalue_value_has_data"; |
1028 | 0 | size_t data_size = 0; |
1029 | 0 | int encoding = 0; |
1030 | |
|
1031 | 0 | if( value == NULL ) |
1032 | 0 | { |
1033 | 0 | libcerror_error_set( |
1034 | 0 | error, |
1035 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1036 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1037 | 0 | "%s: invalid value.", |
1038 | 0 | function ); |
1039 | |
|
1040 | 0 | return( -1 ); |
1041 | 0 | } |
1042 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1043 | |
|
1044 | 0 | if( libfvalue_data_handle_get_data( |
1045 | 0 | internal_value->data_handle, |
1046 | 0 | &data, |
1047 | 0 | &data_size, |
1048 | 0 | &encoding, |
1049 | 0 | error ) != 1 ) |
1050 | 0 | { |
1051 | 0 | libcerror_error_set( |
1052 | 0 | error, |
1053 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1054 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1055 | 0 | "%s: unable to retrieve data from data handle.", |
1056 | 0 | function ); |
1057 | |
|
1058 | 0 | return( -1 ); |
1059 | 0 | } |
1060 | 0 | if( data == NULL ) |
1061 | 0 | { |
1062 | 0 | return( 0 ); |
1063 | 0 | } |
1064 | 0 | return( 1 ); |
1065 | 0 | } |
1066 | | |
1067 | | /* Initializes the data |
1068 | | * Returns 1 if successful or -1 on error |
1069 | | */ |
1070 | | int libfvalue_value_initialize_data( |
1071 | | libfvalue_value_t *value, |
1072 | | size_t data_size, |
1073 | | libcerror_error_t **error ) |
1074 | 0 | { |
1075 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1076 | 0 | uint8_t *data = NULL; |
1077 | 0 | static char *function = "libfvalue_value_initialize_data"; |
1078 | 0 | int result = 0; |
1079 | |
|
1080 | 0 | if( value == NULL ) |
1081 | 0 | { |
1082 | 0 | libcerror_error_set( |
1083 | 0 | error, |
1084 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1085 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1086 | 0 | "%s: invalid value.", |
1087 | 0 | function ); |
1088 | |
|
1089 | 0 | return( -1 ); |
1090 | 0 | } |
1091 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1092 | |
|
1093 | 0 | if( ( data_size == 0 ) |
1094 | 0 | || ( data_size > (size_t) SSIZE_MAX ) ) |
1095 | 0 | { |
1096 | 0 | libcerror_error_set( |
1097 | 0 | error, |
1098 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1099 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1100 | 0 | "%s: invalid data size value out of bounds.", |
1101 | 0 | function ); |
1102 | |
|
1103 | 0 | return( -1 ); |
1104 | 0 | } |
1105 | 0 | result = libfvalue_value_has_data( |
1106 | 0 | value, |
1107 | 0 | error ); |
1108 | |
|
1109 | 0 | if( result == -1 ) |
1110 | 0 | { |
1111 | 0 | libcerror_error_set( |
1112 | 0 | error, |
1113 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1114 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1115 | 0 | "%s: unable to determine if value has data.", |
1116 | 0 | function ); |
1117 | |
|
1118 | 0 | return( -1 ); |
1119 | 0 | } |
1120 | 0 | else if( result != 0 ) |
1121 | 0 | { |
1122 | 0 | libcerror_error_set( |
1123 | 0 | error, |
1124 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1125 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1126 | 0 | "%s: invalid value data already set.", |
1127 | 0 | function ); |
1128 | |
|
1129 | 0 | return( -1 ); |
1130 | 0 | } |
1131 | 0 | data = (uint8_t *) memory_allocate( |
1132 | 0 | sizeof( uint8_t ) * data_size ); |
1133 | |
|
1134 | 0 | if( data == NULL ) |
1135 | 0 | { |
1136 | 0 | libcerror_error_set( |
1137 | 0 | error, |
1138 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1139 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1140 | 0 | "%s: unable to create data.", |
1141 | 0 | function ); |
1142 | |
|
1143 | 0 | goto on_error; |
1144 | 0 | } |
1145 | 0 | if( libfvalue_data_handle_set_data( |
1146 | 0 | internal_value->data_handle, |
1147 | 0 | data, |
1148 | 0 | data_size, |
1149 | 0 | LIBFVALUE_ENDIAN_NATIVE, |
1150 | 0 | LIBFVALUE_VALUE_DATA_FLAG_MANAGED | LIBFVALUE_VALUE_DATA_FLAG_CLONE_BY_REFERENCE, |
1151 | 0 | error ) != 1 ) |
1152 | 0 | { |
1153 | 0 | libcerror_error_set( |
1154 | 0 | error, |
1155 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1156 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1157 | 0 | "%s: unable to set data in data handle.", |
1158 | 0 | function ); |
1159 | |
|
1160 | 0 | goto on_error; |
1161 | 0 | } |
1162 | 0 | return( 1 ); |
1163 | | |
1164 | 0 | on_error: |
1165 | 0 | if( data != NULL ) |
1166 | 0 | { |
1167 | 0 | memory_free( |
1168 | 0 | data ); |
1169 | 0 | } |
1170 | 0 | return( -1 ); |
1171 | 0 | } |
1172 | | |
1173 | | /* Retrieves the data size |
1174 | | * Returns 1 if successful or -1 on error |
1175 | | */ |
1176 | | int libfvalue_value_get_data_size( |
1177 | | libfvalue_value_t *value, |
1178 | | size_t *data_size, |
1179 | | libcerror_error_t **error ) |
1180 | 0 | { |
1181 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1182 | 0 | uint8_t *data = NULL; |
1183 | 0 | static char *function = "libfvalue_value_get_data_size"; |
1184 | 0 | int encoding = 0; |
1185 | |
|
1186 | 0 | if( value == NULL ) |
1187 | 0 | { |
1188 | 0 | libcerror_error_set( |
1189 | 0 | error, |
1190 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1191 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1192 | 0 | "%s: invalid value.", |
1193 | 0 | function ); |
1194 | |
|
1195 | 0 | return( -1 ); |
1196 | 0 | } |
1197 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1198 | |
|
1199 | 0 | if( libfvalue_data_handle_get_data( |
1200 | 0 | internal_value->data_handle, |
1201 | 0 | &data, |
1202 | 0 | data_size, |
1203 | 0 | &encoding, |
1204 | 0 | error ) != 1 ) |
1205 | 0 | { |
1206 | 0 | libcerror_error_set( |
1207 | 0 | error, |
1208 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1209 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1210 | 0 | "%s: unable to retrieve data from data handle.", |
1211 | 0 | function ); |
1212 | |
|
1213 | 0 | return( -1 ); |
1214 | 0 | } |
1215 | 0 | if( data == NULL ) |
1216 | 0 | { |
1217 | 0 | if( data_size == NULL ) |
1218 | 0 | { |
1219 | 0 | libcerror_error_set( |
1220 | 0 | error, |
1221 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1222 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1223 | 0 | "%s: invalid data size.", |
1224 | 0 | function ); |
1225 | |
|
1226 | 0 | return( -1 ); |
1227 | 0 | } |
1228 | 0 | *data_size = 0; |
1229 | 0 | } |
1230 | 0 | return( 1 ); |
1231 | 0 | } |
1232 | | |
1233 | | /* Retrieves the data |
1234 | | * Returns 1 if successful or -1 on error |
1235 | | */ |
1236 | | int libfvalue_value_get_data( |
1237 | | libfvalue_value_t *value, |
1238 | | uint8_t **data, |
1239 | | size_t *data_size, |
1240 | | int *encoding, |
1241 | | libcerror_error_t **error ) |
1242 | 0 | { |
1243 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1244 | 0 | static char *function = "libfvalue_value_get_data"; |
1245 | |
|
1246 | 0 | if( value == NULL ) |
1247 | 0 | { |
1248 | 0 | libcerror_error_set( |
1249 | 0 | error, |
1250 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1251 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1252 | 0 | "%s: invalid value.", |
1253 | 0 | function ); |
1254 | |
|
1255 | 0 | return( -1 ); |
1256 | 0 | } |
1257 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1258 | |
|
1259 | 0 | if( libfvalue_data_handle_get_data( |
1260 | 0 | internal_value->data_handle, |
1261 | 0 | data, |
1262 | 0 | data_size, |
1263 | 0 | encoding, |
1264 | 0 | error ) != 1 ) |
1265 | 0 | { |
1266 | 0 | libcerror_error_set( |
1267 | 0 | error, |
1268 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1269 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1270 | 0 | "%s: unable to retrieve data from data handle.", |
1271 | 0 | function ); |
1272 | |
|
1273 | 0 | return( -1 ); |
1274 | 0 | } |
1275 | 0 | return( 1 ); |
1276 | 0 | } |
1277 | | |
1278 | | /* Sets the data |
1279 | | * Returns 1 if successful or -1 on error |
1280 | | */ |
1281 | | int libfvalue_value_set_data( |
1282 | | libfvalue_value_t *value, |
1283 | | const uint8_t *data, |
1284 | | size_t data_size, |
1285 | | int encoding, |
1286 | | uint8_t flags, |
1287 | | libcerror_error_t **error ) |
1288 | 0 | { |
1289 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1290 | 0 | static char *function = "libfvalue_value_set_data"; |
1291 | |
|
1292 | 0 | if( value == NULL ) |
1293 | 0 | { |
1294 | 0 | libcerror_error_set( |
1295 | 0 | error, |
1296 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1297 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1298 | 0 | "%s: invalid value.", |
1299 | 0 | function ); |
1300 | |
|
1301 | 0 | return( -1 ); |
1302 | 0 | } |
1303 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1304 | |
|
1305 | 0 | if( libfvalue_data_handle_set_data( |
1306 | 0 | internal_value->data_handle, |
1307 | 0 | data, |
1308 | 0 | data_size, |
1309 | 0 | encoding, |
1310 | 0 | flags, |
1311 | 0 | error ) != 1 ) |
1312 | 0 | { |
1313 | 0 | libcerror_error_set( |
1314 | 0 | error, |
1315 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1316 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1317 | 0 | "%s: unable to set data in data handle.", |
1318 | 0 | function ); |
1319 | |
|
1320 | 0 | return( -1 ); |
1321 | 0 | } |
1322 | 0 | return( 1 ); |
1323 | 0 | } |
1324 | | |
1325 | | /* Copies the data |
1326 | | * Returns 1 if successful or -1 on error |
1327 | | */ |
1328 | | int libfvalue_value_copy_data( |
1329 | | libfvalue_value_t *value, |
1330 | | uint8_t *data, |
1331 | | size_t data_size, |
1332 | | libcerror_error_t **error ) |
1333 | 0 | { |
1334 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1335 | 0 | uint8_t *data_handle_data = NULL; |
1336 | 0 | static char *function = "libfvalue_value_copy_data"; |
1337 | 0 | size_t data_handle_data_size = 0; |
1338 | 0 | int encoding = 0; |
1339 | |
|
1340 | 0 | if( value == NULL ) |
1341 | 0 | { |
1342 | 0 | libcerror_error_set( |
1343 | 0 | error, |
1344 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1345 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1346 | 0 | "%s: invalid value.", |
1347 | 0 | function ); |
1348 | |
|
1349 | 0 | return( -1 ); |
1350 | 0 | } |
1351 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1352 | |
|
1353 | 0 | if( data == NULL ) |
1354 | 0 | { |
1355 | 0 | libcerror_error_set( |
1356 | 0 | error, |
1357 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1358 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1359 | 0 | "%s: invalid data.", |
1360 | 0 | function ); |
1361 | |
|
1362 | 0 | return( -1 ); |
1363 | 0 | } |
1364 | 0 | if( data_size > (size_t) SSIZE_MAX ) |
1365 | 0 | { |
1366 | 0 | libcerror_error_set( |
1367 | 0 | error, |
1368 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1369 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
1370 | 0 | "%s: invalid data size value exceeds maximum.", |
1371 | 0 | function ); |
1372 | |
|
1373 | 0 | return( -1 ); |
1374 | 0 | } |
1375 | 0 | if( libfvalue_data_handle_get_data( |
1376 | 0 | internal_value->data_handle, |
1377 | 0 | &data_handle_data, |
1378 | 0 | &data_handle_data_size, |
1379 | 0 | &encoding, |
1380 | 0 | error ) != 1 ) |
1381 | 0 | { |
1382 | 0 | libcerror_error_set( |
1383 | 0 | error, |
1384 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1385 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1386 | 0 | "%s: unable to retrieve data from data handle.", |
1387 | 0 | function ); |
1388 | |
|
1389 | 0 | return( -1 ); |
1390 | 0 | } |
1391 | 0 | if( ( data_handle_data == NULL ) |
1392 | 0 | || ( data_handle_data_size == 0 ) ) |
1393 | 0 | { |
1394 | 0 | libcerror_error_set( |
1395 | 0 | error, |
1396 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1397 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1398 | 0 | "%s: missing data in data handle.", |
1399 | 0 | function ); |
1400 | |
|
1401 | 0 | return( -1 ); |
1402 | 0 | } |
1403 | 0 | if( data_handle_data_size > data_size ) |
1404 | 0 | { |
1405 | 0 | libcerror_error_set( |
1406 | 0 | error, |
1407 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1408 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1409 | 0 | "%s: invalid data size value too small.", |
1410 | 0 | function ); |
1411 | |
|
1412 | 0 | return( -1 ); |
1413 | 0 | } |
1414 | 0 | if( memory_copy( |
1415 | 0 | data, |
1416 | 0 | data_handle_data, |
1417 | 0 | data_handle_data_size ) == NULL ) |
1418 | 0 | { |
1419 | 0 | libcerror_error_set( |
1420 | 0 | error, |
1421 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1422 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1423 | 0 | "%s: unable to copy data.", |
1424 | 0 | function ); |
1425 | |
|
1426 | 0 | return( -1 ); |
1427 | 0 | } |
1428 | 0 | return( 1 ); |
1429 | 0 | } |
1430 | | |
1431 | | /* Retrieves the format flags |
1432 | | * Returns 1 if successful or -1 on error |
1433 | | */ |
1434 | | int libfvalue_value_get_format_flags( |
1435 | | libfvalue_value_t *value, |
1436 | | uint32_t *format_flags, |
1437 | | libcerror_error_t **error ) |
1438 | 0 | { |
1439 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1440 | 0 | static char *function = "libfvalue_value_get_format_flags"; |
1441 | |
|
1442 | 0 | if( value == NULL ) |
1443 | 0 | { |
1444 | 0 | libcerror_error_set( |
1445 | 0 | error, |
1446 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1447 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1448 | 0 | "%s: invalid value.", |
1449 | 0 | function ); |
1450 | |
|
1451 | 0 | return( -1 ); |
1452 | 0 | } |
1453 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1454 | |
|
1455 | 0 | if( format_flags == 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 format flags.", |
1462 | 0 | function ); |
1463 | |
|
1464 | 0 | return( -1 ); |
1465 | 0 | } |
1466 | 0 | *format_flags = internal_value->format_flags; |
1467 | |
|
1468 | 0 | return( 1 ); |
1469 | 0 | } |
1470 | | |
1471 | | /* Sets the format flags |
1472 | | * Returns 1 if successful or -1 on error |
1473 | | */ |
1474 | | int libfvalue_value_set_format_flags( |
1475 | | libfvalue_value_t *value, |
1476 | | uint32_t format_flags, |
1477 | | libcerror_error_t **error ) |
1478 | 0 | { |
1479 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1480 | 0 | static char *function = "libfvalue_value_set_format_flags"; |
1481 | |
|
1482 | 0 | if( value == NULL ) |
1483 | 0 | { |
1484 | 0 | libcerror_error_set( |
1485 | 0 | error, |
1486 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1487 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1488 | 0 | "%s: invalid value.", |
1489 | 0 | function ); |
1490 | |
|
1491 | 0 | return( -1 ); |
1492 | 0 | } |
1493 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1494 | |
|
1495 | 0 | internal_value->format_flags = format_flags; |
1496 | |
|
1497 | 0 | return( 1 ); |
1498 | 0 | } |
1499 | | |
1500 | | /* Value instance functions |
1501 | | */ |
1502 | | |
1503 | | /* Retrieves the value instance |
1504 | | * The value instance is created if it does not exist |
1505 | | * Returns 1 if successful or -1 on error |
1506 | | */ |
1507 | | int libfvalue_value_get_value_instance_by_index( |
1508 | | libfvalue_value_t *value, |
1509 | | int value_entry_index, |
1510 | | intptr_t **value_instance, |
1511 | | libcerror_error_t **error ) |
1512 | 0 | { |
1513 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1514 | 0 | uint8_t *value_entry_data = NULL; |
1515 | 0 | static char *function = "libfvalue_value_get_value_instance_by_index"; |
1516 | 0 | size_t value_entry_data_size = 0; |
1517 | 0 | int encoding = 0; |
1518 | 0 | int result = 0; |
1519 | |
|
1520 | 0 | if( value == NULL ) |
1521 | 0 | { |
1522 | 0 | libcerror_error_set( |
1523 | 0 | error, |
1524 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1525 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1526 | 0 | "%s: invalid value.", |
1527 | 0 | function ); |
1528 | |
|
1529 | 0 | return( -1 ); |
1530 | 0 | } |
1531 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1532 | |
|
1533 | 0 | if( internal_value->initialize_instance == NULL ) |
1534 | 0 | { |
1535 | 0 | libcerror_error_set( |
1536 | 0 | error, |
1537 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1538 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1539 | 0 | "%s: invalid value - missing initialize instance function.", |
1540 | 0 | function ); |
1541 | |
|
1542 | 0 | return( -1 ); |
1543 | 0 | } |
1544 | 0 | if( internal_value->value_instances != NULL ) |
1545 | 0 | { |
1546 | 0 | if( internal_value->free_instance == NULL ) |
1547 | 0 | { |
1548 | 0 | libcerror_error_set( |
1549 | 0 | error, |
1550 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1551 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1552 | 0 | "%s: invalid value - missing free instance function.", |
1553 | 0 | function ); |
1554 | |
|
1555 | 0 | return( -1 ); |
1556 | 0 | } |
1557 | 0 | if( internal_value->copy_from_byte_stream == NULL ) |
1558 | 0 | { |
1559 | 0 | libcerror_error_set( |
1560 | 0 | error, |
1561 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1562 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1563 | 0 | "%s: invalid value - missing free copy from byte stream function.", |
1564 | 0 | function ); |
1565 | |
|
1566 | 0 | return( -1 ); |
1567 | 0 | } |
1568 | 0 | } |
1569 | 0 | if( value_instance == NULL ) |
1570 | 0 | { |
1571 | 0 | libcerror_error_set( |
1572 | 0 | error, |
1573 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1574 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1575 | 0 | "%s: invalid value instance.", |
1576 | 0 | function ); |
1577 | |
|
1578 | 0 | return( -1 ); |
1579 | 0 | } |
1580 | 0 | if( *value_instance != NULL ) |
1581 | 0 | { |
1582 | 0 | libcerror_error_set( |
1583 | 0 | error, |
1584 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1585 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1586 | 0 | "%s: invalid value instance value already set.", |
1587 | 0 | function ); |
1588 | |
|
1589 | 0 | return( -1 ); |
1590 | 0 | } |
1591 | 0 | if( libcdata_array_get_entry_by_index( |
1592 | 0 | internal_value->value_instances, |
1593 | 0 | value_entry_index, |
1594 | 0 | value_instance, |
1595 | 0 | error ) != 1 ) |
1596 | 0 | { |
1597 | 0 | libcerror_error_set( |
1598 | 0 | error, |
1599 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1600 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1601 | 0 | "%s: unable to retrieve entry: %d from values instances array.", |
1602 | 0 | function, |
1603 | 0 | value_entry_index ); |
1604 | |
|
1605 | 0 | goto on_error; |
1606 | 0 | } |
1607 | 0 | if( *value_instance == NULL ) |
1608 | 0 | { |
1609 | 0 | result = libfvalue_value_get_entry_data( |
1610 | 0 | value, |
1611 | 0 | value_entry_index, |
1612 | 0 | &value_entry_data, |
1613 | 0 | &value_entry_data_size, |
1614 | 0 | &encoding, |
1615 | 0 | error ); |
1616 | |
|
1617 | 0 | if( result == -1 ) |
1618 | 0 | { |
1619 | 0 | libcerror_error_set( |
1620 | 0 | error, |
1621 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1622 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1623 | 0 | "%s: unable to retrieve entry data: %d.", |
1624 | 0 | function, |
1625 | 0 | value_entry_index ); |
1626 | |
|
1627 | 0 | goto on_error; |
1628 | 0 | } |
1629 | 0 | else if( result != 0 ) |
1630 | 0 | { |
1631 | 0 | if( internal_value->initialize_instance( |
1632 | 0 | value_instance, |
1633 | 0 | error ) != 1 ) |
1634 | 0 | { |
1635 | 0 | libcerror_error_set( |
1636 | 0 | error, |
1637 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1638 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1639 | 0 | "%s: unable to create value instance.", |
1640 | 0 | function ); |
1641 | |
|
1642 | 0 | goto on_error; |
1643 | 0 | } |
1644 | 0 | if( internal_value->copy_from_byte_stream( |
1645 | 0 | *value_instance, |
1646 | 0 | value_entry_data, |
1647 | 0 | value_entry_data_size, |
1648 | 0 | encoding, |
1649 | 0 | error ) != 1 ) |
1650 | 0 | { |
1651 | 0 | libcerror_error_set( |
1652 | 0 | error, |
1653 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1654 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1655 | 0 | "%s: unable to copy value instance from byte stream.", |
1656 | 0 | function ); |
1657 | |
|
1658 | 0 | goto on_error; |
1659 | 0 | } |
1660 | 0 | } |
1661 | 0 | else |
1662 | 0 | { |
1663 | 0 | *value_instance = NULL; |
1664 | 0 | } |
1665 | 0 | if( libcdata_array_set_entry_by_index( |
1666 | 0 | internal_value->value_instances, |
1667 | 0 | value_entry_index, |
1668 | 0 | *value_instance, |
1669 | 0 | error ) != 1 ) |
1670 | 0 | { |
1671 | 0 | libcerror_error_set( |
1672 | 0 | error, |
1673 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1674 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1675 | 0 | "%s: unable to set entry: %d in values instances array.", |
1676 | 0 | function, |
1677 | 0 | value_entry_index ); |
1678 | |
|
1679 | 0 | goto on_error; |
1680 | 0 | } |
1681 | 0 | } |
1682 | 0 | return( 1 ); |
1683 | | |
1684 | 0 | on_error: |
1685 | 0 | if( *value_instance != NULL ) |
1686 | 0 | { |
1687 | 0 | internal_value->free_instance( |
1688 | 0 | value_instance, |
1689 | 0 | NULL ); |
1690 | 0 | } |
1691 | 0 | return( -1 ); |
1692 | 0 | } |
1693 | | |
1694 | | /* Value entry functions |
1695 | | */ |
1696 | | |
1697 | | /* Retrieves the number of values entries |
1698 | | * Returns 1 if successful or -1 on error |
1699 | | */ |
1700 | | int libfvalue_value_get_number_of_value_entries( |
1701 | | libfvalue_value_t *value, |
1702 | | int *number_of_value_entries, |
1703 | | libcerror_error_t **error ) |
1704 | 0 | { |
1705 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1706 | 0 | static char *function = "libfvalue_value_get_number_of_value_entries"; |
1707 | 0 | int safe_number_of_value_entries = 0; |
1708 | 0 | int result = 0; |
1709 | |
|
1710 | 0 | if( value == NULL ) |
1711 | 0 | { |
1712 | 0 | libcerror_error_set( |
1713 | 0 | error, |
1714 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1715 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1716 | 0 | "%s: invalid value.", |
1717 | 0 | function ); |
1718 | |
|
1719 | 0 | return( -1 ); |
1720 | 0 | } |
1721 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1722 | |
|
1723 | 0 | if( number_of_value_entries == NULL ) |
1724 | 0 | { |
1725 | 0 | libcerror_error_set( |
1726 | 0 | error, |
1727 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1728 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1729 | 0 | "%s: invalid number of value entries.", |
1730 | 0 | function ); |
1731 | |
|
1732 | 0 | return( -1 ); |
1733 | 0 | } |
1734 | 0 | result = libfvalue_value_has_data( |
1735 | 0 | value, |
1736 | 0 | error ); |
1737 | |
|
1738 | 0 | if( result == -1 ) |
1739 | 0 | { |
1740 | 0 | libcerror_error_set( |
1741 | 0 | error, |
1742 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1743 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1744 | 0 | "%s: unable to determine if value has data.", |
1745 | 0 | function ); |
1746 | |
|
1747 | 0 | return( -1 ); |
1748 | 0 | } |
1749 | 0 | else if( result != 0 ) |
1750 | 0 | { |
1751 | 0 | if( libfvalue_data_handle_get_number_of_value_entries( |
1752 | 0 | internal_value->data_handle, |
1753 | 0 | &safe_number_of_value_entries, |
1754 | 0 | error ) != 1 ) |
1755 | 0 | { |
1756 | 0 | libcerror_error_set( |
1757 | 0 | error, |
1758 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1759 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1760 | 0 | "%s: unable to retrieve number of value entries from data handle.", |
1761 | 0 | function ); |
1762 | |
|
1763 | 0 | return( -1 ); |
1764 | 0 | } |
1765 | 0 | } |
1766 | 0 | else if( internal_value->value_instances != NULL ) |
1767 | 0 | { |
1768 | 0 | if( libcdata_array_get_number_of_entries( |
1769 | 0 | internal_value->value_instances, |
1770 | 0 | &safe_number_of_value_entries, |
1771 | 0 | error ) != 1 ) |
1772 | 0 | { |
1773 | 0 | libcerror_error_set( |
1774 | 0 | error, |
1775 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1776 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1777 | 0 | "%s: unable to retrieve number of entries from values instances array.", |
1778 | 0 | function ); |
1779 | |
|
1780 | 0 | return( -1 ); |
1781 | 0 | } |
1782 | 0 | } |
1783 | 0 | if( safe_number_of_value_entries < 0 ) |
1784 | 0 | { |
1785 | 0 | libcerror_error_set( |
1786 | 0 | error, |
1787 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1788 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1789 | 0 | "%s: invalid number of value entries value out of bounds.", |
1790 | 0 | function ); |
1791 | |
|
1792 | 0 | return( -1 ); |
1793 | 0 | } |
1794 | 0 | *number_of_value_entries = safe_number_of_value_entries; |
1795 | |
|
1796 | 0 | return( 1 ); |
1797 | 0 | } |
1798 | | |
1799 | | /* Retrieves the entry |
1800 | | * Returns 1 if successful, 0 if the value has no data or -1 on error |
1801 | | */ |
1802 | | int libfvalue_value_get_entry( |
1803 | | libfvalue_value_t *value, |
1804 | | int value_entry_index, |
1805 | | size_t *entry_data_offset, |
1806 | | size_t *entry_data_size, |
1807 | | libcerror_error_t **error ) |
1808 | 0 | { |
1809 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1810 | 0 | static char *function = "libfvalue_value_get_entry"; |
1811 | 0 | int result = 0; |
1812 | |
|
1813 | 0 | if( value == NULL ) |
1814 | 0 | { |
1815 | 0 | libcerror_error_set( |
1816 | 0 | error, |
1817 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1818 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1819 | 0 | "%s: invalid value.", |
1820 | 0 | function ); |
1821 | |
|
1822 | 0 | return( -1 ); |
1823 | 0 | } |
1824 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1825 | |
|
1826 | 0 | if( entry_data_offset == NULL ) |
1827 | 0 | { |
1828 | 0 | libcerror_error_set( |
1829 | 0 | error, |
1830 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1831 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1832 | 0 | "%s: invalid entry data offset.", |
1833 | 0 | function ); |
1834 | |
|
1835 | 0 | return( -1 ); |
1836 | 0 | } |
1837 | 0 | if( entry_data_size == NULL ) |
1838 | 0 | { |
1839 | 0 | libcerror_error_set( |
1840 | 0 | error, |
1841 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1842 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1843 | 0 | "%s: invalid entry data size.", |
1844 | 0 | function ); |
1845 | |
|
1846 | 0 | return( -1 ); |
1847 | 0 | } |
1848 | 0 | result = libfvalue_value_has_data( |
1849 | 0 | value, |
1850 | 0 | error ); |
1851 | |
|
1852 | 0 | if( result == -1 ) |
1853 | 0 | { |
1854 | 0 | libcerror_error_set( |
1855 | 0 | error, |
1856 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1857 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1858 | 0 | "%s: unable to determine if value has data.", |
1859 | 0 | function ); |
1860 | |
|
1861 | 0 | return( -1 ); |
1862 | 0 | } |
1863 | 0 | else if( result != 0 ) |
1864 | 0 | { |
1865 | 0 | if( libfvalue_data_handle_get_value_entry( |
1866 | 0 | internal_value->data_handle, |
1867 | 0 | value_entry_index, |
1868 | 0 | entry_data_offset, |
1869 | 0 | entry_data_size, |
1870 | 0 | error ) != 1 ) |
1871 | 0 | { |
1872 | 0 | libcerror_error_set( |
1873 | 0 | error, |
1874 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1875 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1876 | 0 | "%s: unable to retrieve entry: %d from data handle.", |
1877 | 0 | function, |
1878 | 0 | value_entry_index ); |
1879 | |
|
1880 | 0 | return( -1 ); |
1881 | 0 | } |
1882 | 0 | if( *entry_data_size == 0 ) |
1883 | 0 | { |
1884 | 0 | result = 0; |
1885 | 0 | } |
1886 | 0 | } |
1887 | 0 | if( result == 0 ) |
1888 | 0 | { |
1889 | 0 | *entry_data_offset = 0; |
1890 | 0 | *entry_data_size = 0; |
1891 | 0 | } |
1892 | 0 | return( result ); |
1893 | 0 | } |
1894 | | |
1895 | | /* Sets the entry |
1896 | | * Returns 1 if successful or -1 on error |
1897 | | */ |
1898 | | int libfvalue_value_set_entry( |
1899 | | libfvalue_value_t *value, |
1900 | | int value_entry_index, |
1901 | | size_t entry_data_offset, |
1902 | | size_t entry_data_size, |
1903 | | libcerror_error_t **error ) |
1904 | 0 | { |
1905 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
1906 | 0 | intptr_t *value_instance = NULL; |
1907 | 0 | static char *function = "libfvalue_value_set_entry"; |
1908 | |
|
1909 | 0 | if( value == NULL ) |
1910 | 0 | { |
1911 | 0 | libcerror_error_set( |
1912 | 0 | error, |
1913 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1914 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1915 | 0 | "%s: invalid value.", |
1916 | 0 | function ); |
1917 | |
|
1918 | 0 | return( -1 ); |
1919 | 0 | } |
1920 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
1921 | |
|
1922 | 0 | if( internal_value->free_instance == NULL ) |
1923 | 0 | { |
1924 | 0 | libcerror_error_set( |
1925 | 0 | error, |
1926 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1927 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1928 | 0 | "%s: invalid value - missing free instance function.", |
1929 | 0 | function ); |
1930 | |
|
1931 | 0 | return( -1 ); |
1932 | 0 | } |
1933 | 0 | if( libcdata_array_get_entry_by_index( |
1934 | 0 | internal_value->value_instances, |
1935 | 0 | value_entry_index, |
1936 | 0 | &value_instance, |
1937 | 0 | error ) != 1 ) |
1938 | 0 | { |
1939 | 0 | libcerror_error_set( |
1940 | 0 | error, |
1941 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1942 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1943 | 0 | "%s: unable to retrieve entry: %d from values instances array.", |
1944 | 0 | function, |
1945 | 0 | value_entry_index ); |
1946 | |
|
1947 | 0 | return( -1 ); |
1948 | 0 | } |
1949 | 0 | if( value_instance != NULL ) |
1950 | 0 | { |
1951 | 0 | if( libcdata_array_set_entry_by_index( |
1952 | 0 | internal_value->value_instances, |
1953 | 0 | value_entry_index, |
1954 | 0 | NULL, |
1955 | 0 | error ) != 1 ) |
1956 | 0 | { |
1957 | 0 | libcerror_error_set( |
1958 | 0 | error, |
1959 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1960 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1961 | 0 | "%s: unable to set entry: %d in values instances array.", |
1962 | 0 | function, |
1963 | 0 | value_entry_index ); |
1964 | |
|
1965 | 0 | return( -1 ); |
1966 | 0 | } |
1967 | 0 | if( internal_value->free_instance( |
1968 | 0 | &value_instance, |
1969 | 0 | error ) != 1 ) |
1970 | 0 | { |
1971 | 0 | libcerror_error_set( |
1972 | 0 | error, |
1973 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1974 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
1975 | 0 | "%s: unable to free value instance: %d.", |
1976 | 0 | function, |
1977 | 0 | value_entry_index ); |
1978 | |
|
1979 | 0 | return( -1 ); |
1980 | 0 | } |
1981 | 0 | } |
1982 | 0 | if( libfvalue_data_handle_set_value_entry( |
1983 | 0 | internal_value->data_handle, |
1984 | 0 | value_entry_index, |
1985 | 0 | entry_data_offset, |
1986 | 0 | entry_data_size, |
1987 | 0 | error ) != 1 ) |
1988 | 0 | { |
1989 | 0 | libcerror_error_set( |
1990 | 0 | error, |
1991 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1992 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1993 | 0 | "%s: unable to set entry: %d in data handle.", |
1994 | 0 | function, |
1995 | 0 | value_entry_index ); |
1996 | |
|
1997 | 0 | return( -1 ); |
1998 | 0 | } |
1999 | 0 | return( 1 ); |
2000 | 0 | } |
2001 | | |
2002 | | /* Appends the entry |
2003 | | * Returns 1 if successful or -1 on error |
2004 | | */ |
2005 | | int libfvalue_value_append_entry( |
2006 | | libfvalue_value_t *value, |
2007 | | int *value_entry_index, |
2008 | | size_t entry_data_offset, |
2009 | | size_t entry_data_size, |
2010 | | libcerror_error_t **error ) |
2011 | 0 | { |
2012 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2013 | 0 | intptr_t *value_instance = NULL; |
2014 | 0 | static char *function = "libfvalue_value_append_entry"; |
2015 | 0 | int entry_index = 0; |
2016 | 0 | int number_of_value_entries = 0; |
2017 | |
|
2018 | 0 | if( value == NULL ) |
2019 | 0 | { |
2020 | 0 | libcerror_error_set( |
2021 | 0 | error, |
2022 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2023 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2024 | 0 | "%s: invalid value.", |
2025 | 0 | function ); |
2026 | |
|
2027 | 0 | return( -1 ); |
2028 | 0 | } |
2029 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2030 | |
|
2031 | 0 | if( internal_value->free_instance == NULL ) |
2032 | 0 | { |
2033 | 0 | libcerror_error_set( |
2034 | 0 | error, |
2035 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2036 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2037 | 0 | "%s: invalid value - missing free instance function.", |
2038 | 0 | function ); |
2039 | |
|
2040 | 0 | return( -1 ); |
2041 | 0 | } |
2042 | 0 | if( value_entry_index == NULL ) |
2043 | 0 | { |
2044 | 0 | libcerror_error_set( |
2045 | 0 | error, |
2046 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2047 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2048 | 0 | "%s: invalid value entry index.", |
2049 | 0 | function ); |
2050 | |
|
2051 | 0 | return( -1 ); |
2052 | 0 | } |
2053 | 0 | if( libfvalue_data_handle_get_number_of_value_entries( |
2054 | 0 | internal_value->data_handle, |
2055 | 0 | &number_of_value_entries, |
2056 | 0 | error ) != 1 ) |
2057 | 0 | { |
2058 | 0 | libcerror_error_set( |
2059 | 0 | error, |
2060 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2061 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2062 | 0 | "%s: unable to retrieve number of value entries from data handle.", |
2063 | 0 | function ); |
2064 | |
|
2065 | 0 | return( -1 ); |
2066 | 0 | } |
2067 | | /* Since the data handle can reallocate the buffer used to store the data |
2068 | | * and the value instances reference this data make sure that no stale |
2069 | | * value instances are kept around. |
2070 | | */ |
2071 | 0 | for( entry_index = 0; |
2072 | 0 | entry_index < number_of_value_entries; |
2073 | 0 | entry_index += 1 ) |
2074 | 0 | { |
2075 | 0 | if( libcdata_array_get_entry_by_index( |
2076 | 0 | internal_value->value_instances, |
2077 | 0 | entry_index, |
2078 | 0 | &value_instance, |
2079 | 0 | error ) != 1 ) |
2080 | 0 | { |
2081 | 0 | libcerror_error_set( |
2082 | 0 | error, |
2083 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2084 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2085 | 0 | "%s: unable to retrieve entry: %d from values instances array.", |
2086 | 0 | function, |
2087 | 0 | entry_index ); |
2088 | |
|
2089 | 0 | return( -1 ); |
2090 | 0 | } |
2091 | 0 | if( value_instance != NULL ) |
2092 | 0 | { |
2093 | 0 | if( libcdata_array_set_entry_by_index( |
2094 | 0 | internal_value->value_instances, |
2095 | 0 | entry_index, |
2096 | 0 | NULL, |
2097 | 0 | error ) != 1 ) |
2098 | 0 | { |
2099 | 0 | libcerror_error_set( |
2100 | 0 | error, |
2101 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2102 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2103 | 0 | "%s: unable to set entry: %d in values instances array.", |
2104 | 0 | function, |
2105 | 0 | entry_index ); |
2106 | |
|
2107 | 0 | return( -1 ); |
2108 | 0 | } |
2109 | 0 | if( internal_value->free_instance( |
2110 | 0 | &value_instance, |
2111 | 0 | error ) != 1 ) |
2112 | 0 | { |
2113 | 0 | libcerror_error_set( |
2114 | 0 | error, |
2115 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2116 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2117 | 0 | "%s: unable to free value instance: %d.", |
2118 | 0 | function, |
2119 | 0 | entry_index ); |
2120 | |
|
2121 | 0 | return( -1 ); |
2122 | 0 | } |
2123 | 0 | } |
2124 | 0 | } |
2125 | 0 | if( libcdata_array_resize( |
2126 | 0 | internal_value->value_instances, |
2127 | 0 | number_of_value_entries + 1, |
2128 | 0 | internal_value->free_instance, |
2129 | 0 | error ) != 1 ) |
2130 | 0 | { |
2131 | 0 | libcerror_error_set( |
2132 | 0 | error, |
2133 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2134 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2135 | 0 | "%s: unable to resize value instances array.", |
2136 | 0 | function ); |
2137 | |
|
2138 | 0 | return( -1 ); |
2139 | 0 | } |
2140 | 0 | if( libfvalue_data_handle_append_value_entry( |
2141 | 0 | internal_value->data_handle, |
2142 | 0 | value_entry_index, |
2143 | 0 | entry_data_offset, |
2144 | 0 | entry_data_size, |
2145 | 0 | error ) != 1 ) |
2146 | 0 | { |
2147 | 0 | libcerror_error_set( |
2148 | 0 | error, |
2149 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2150 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2151 | 0 | "%s: unable to append entry to data handle.", |
2152 | 0 | function ); |
2153 | |
|
2154 | 0 | return( -1 ); |
2155 | 0 | } |
2156 | 0 | return( 1 ); |
2157 | 0 | } |
2158 | | |
2159 | | /* Retrieves the entry data |
2160 | | * Returns 1 if successful, 0 if the value has no data or -1 on error |
2161 | | */ |
2162 | | int libfvalue_value_get_entry_data( |
2163 | | libfvalue_value_t *value, |
2164 | | int value_entry_index, |
2165 | | uint8_t **entry_data, |
2166 | | size_t *entry_data_size, |
2167 | | int *encoding, |
2168 | | libcerror_error_t **error ) |
2169 | 0 | { |
2170 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2171 | 0 | static char *function = "libfvalue_value_get_entry_data"; |
2172 | 0 | int result = 0; |
2173 | |
|
2174 | 0 | if( value == NULL ) |
2175 | 0 | { |
2176 | 0 | libcerror_error_set( |
2177 | 0 | error, |
2178 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2179 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2180 | 0 | "%s: invalid value.", |
2181 | 0 | function ); |
2182 | |
|
2183 | 0 | return( -1 ); |
2184 | 0 | } |
2185 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2186 | |
|
2187 | 0 | if( entry_data == NULL ) |
2188 | 0 | { |
2189 | 0 | libcerror_error_set( |
2190 | 0 | error, |
2191 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2192 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2193 | 0 | "%s: invalid entry data.", |
2194 | 0 | function ); |
2195 | |
|
2196 | 0 | return( -1 ); |
2197 | 0 | } |
2198 | 0 | if( entry_data_size == NULL ) |
2199 | 0 | { |
2200 | 0 | libcerror_error_set( |
2201 | 0 | error, |
2202 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2203 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2204 | 0 | "%s: invalid entry data size.", |
2205 | 0 | function ); |
2206 | |
|
2207 | 0 | return( -1 ); |
2208 | 0 | } |
2209 | 0 | if( encoding == NULL ) |
2210 | 0 | { |
2211 | 0 | libcerror_error_set( |
2212 | 0 | error, |
2213 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2214 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2215 | 0 | "%s: invalid encoding.", |
2216 | 0 | function ); |
2217 | |
|
2218 | 0 | return( -1 ); |
2219 | 0 | } |
2220 | 0 | result = libfvalue_value_has_data( |
2221 | 0 | value, |
2222 | 0 | error ); |
2223 | |
|
2224 | 0 | if( result == -1 ) |
2225 | 0 | { |
2226 | 0 | libcerror_error_set( |
2227 | 0 | error, |
2228 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2229 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2230 | 0 | "%s: unable to determine if value has data.", |
2231 | 0 | function ); |
2232 | |
|
2233 | 0 | return( -1 ); |
2234 | 0 | } |
2235 | 0 | else if( result != 0 ) |
2236 | 0 | { |
2237 | 0 | if( libfvalue_data_handle_get_value_entry_data( |
2238 | 0 | internal_value->data_handle, |
2239 | 0 | value_entry_index, |
2240 | 0 | entry_data, |
2241 | 0 | entry_data_size, |
2242 | 0 | encoding, |
2243 | 0 | error ) != 1 ) |
2244 | 0 | { |
2245 | 0 | libcerror_error_set( |
2246 | 0 | error, |
2247 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2248 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2249 | 0 | "%s: unable to retrieve entry: %d data from data handle.", |
2250 | 0 | function, |
2251 | 0 | value_entry_index ); |
2252 | |
|
2253 | 0 | return( -1 ); |
2254 | 0 | } |
2255 | 0 | if( ( *entry_data == NULL ) |
2256 | 0 | || ( *entry_data_size == 0 ) ) |
2257 | 0 | { |
2258 | 0 | result = 0; |
2259 | 0 | } |
2260 | 0 | } |
2261 | 0 | if( result == 0 ) |
2262 | 0 | { |
2263 | 0 | *entry_data = NULL; |
2264 | 0 | *entry_data_size = 0; |
2265 | 0 | } |
2266 | 0 | return( result ); |
2267 | 0 | } |
2268 | | |
2269 | | /* Sets the entry data |
2270 | | * Returns 1 if successful or -1 on error |
2271 | | */ |
2272 | | int libfvalue_value_set_entry_data( |
2273 | | libfvalue_value_t *value, |
2274 | | int value_entry_index, |
2275 | | const uint8_t *entry_data, |
2276 | | size_t entry_data_size, |
2277 | | int encoding, |
2278 | | libcerror_error_t **error ) |
2279 | 0 | { |
2280 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2281 | 0 | intptr_t *value_instance = NULL; |
2282 | 0 | static char *function = "libfvalue_value_set_entry_data"; |
2283 | |
|
2284 | 0 | if( value == NULL ) |
2285 | 0 | { |
2286 | 0 | libcerror_error_set( |
2287 | 0 | error, |
2288 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2289 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2290 | 0 | "%s: invalid value.", |
2291 | 0 | function ); |
2292 | |
|
2293 | 0 | return( -1 ); |
2294 | 0 | } |
2295 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2296 | |
|
2297 | 0 | if( internal_value->free_instance == NULL ) |
2298 | 0 | { |
2299 | 0 | libcerror_error_set( |
2300 | 0 | error, |
2301 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2302 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2303 | 0 | "%s: invalid value - missing free instance function.", |
2304 | 0 | function ); |
2305 | |
|
2306 | 0 | return( -1 ); |
2307 | 0 | } |
2308 | 0 | if( libcdata_array_get_entry_by_index( |
2309 | 0 | internal_value->value_instances, |
2310 | 0 | value_entry_index, |
2311 | 0 | &value_instance, |
2312 | 0 | error ) != 1 ) |
2313 | 0 | { |
2314 | 0 | libcerror_error_set( |
2315 | 0 | error, |
2316 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2317 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2318 | 0 | "%s: unable to retrieve entry: %d from values instances array.", |
2319 | 0 | function, |
2320 | 0 | value_entry_index ); |
2321 | |
|
2322 | 0 | return( -1 ); |
2323 | 0 | } |
2324 | 0 | if( value_instance != NULL ) |
2325 | 0 | { |
2326 | 0 | if( libcdata_array_set_entry_by_index( |
2327 | 0 | internal_value->value_instances, |
2328 | 0 | value_entry_index, |
2329 | 0 | NULL, |
2330 | 0 | error ) != 1 ) |
2331 | 0 | { |
2332 | 0 | libcerror_error_set( |
2333 | 0 | error, |
2334 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2335 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2336 | 0 | "%s: unable to set entry: %d data in values instances array.", |
2337 | 0 | function, |
2338 | 0 | value_entry_index ); |
2339 | |
|
2340 | 0 | return( -1 ); |
2341 | 0 | } |
2342 | 0 | if( internal_value->free_instance( |
2343 | 0 | &value_instance, |
2344 | 0 | error ) != 1 ) |
2345 | 0 | { |
2346 | 0 | libcerror_error_set( |
2347 | 0 | error, |
2348 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2349 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2350 | 0 | "%s: unable to free value instance: %d.", |
2351 | 0 | function, |
2352 | 0 | value_entry_index ); |
2353 | |
|
2354 | 0 | return( -1 ); |
2355 | 0 | } |
2356 | 0 | } |
2357 | 0 | if( libfvalue_data_handle_set_value_entry_data( |
2358 | 0 | internal_value->data_handle, |
2359 | 0 | value_entry_index, |
2360 | 0 | entry_data, |
2361 | 0 | entry_data_size, |
2362 | 0 | encoding, |
2363 | 0 | error ) != 1 ) |
2364 | 0 | { |
2365 | 0 | libcerror_error_set( |
2366 | 0 | error, |
2367 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2368 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2369 | 0 | "%s: unable to set entry: %d in data handle.", |
2370 | 0 | function, |
2371 | 0 | value_entry_index ); |
2372 | |
|
2373 | 0 | return( -1 ); |
2374 | 0 | } |
2375 | 0 | return( 1 ); |
2376 | 0 | } |
2377 | | |
2378 | | /* Appends the entry data |
2379 | | * Returns 1 if successful or -1 on error |
2380 | | */ |
2381 | | int libfvalue_value_append_entry_data( |
2382 | | libfvalue_value_t *value, |
2383 | | int *value_entry_index, |
2384 | | const uint8_t *entry_data, |
2385 | | size_t entry_data_size, |
2386 | | int encoding, |
2387 | | libcerror_error_t **error ) |
2388 | 0 | { |
2389 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2390 | 0 | intptr_t *value_instance = NULL; |
2391 | 0 | static char *function = "libfvalue_value_append_entry_data"; |
2392 | 0 | int number_of_value_entries = 0; |
2393 | |
|
2394 | 0 | if( value == NULL ) |
2395 | 0 | { |
2396 | 0 | libcerror_error_set( |
2397 | 0 | error, |
2398 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2399 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2400 | 0 | "%s: invalid value.", |
2401 | 0 | function ); |
2402 | |
|
2403 | 0 | return( -1 ); |
2404 | 0 | } |
2405 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2406 | |
|
2407 | 0 | if( internal_value->free_instance == NULL ) |
2408 | 0 | { |
2409 | 0 | libcerror_error_set( |
2410 | 0 | error, |
2411 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2412 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2413 | 0 | "%s: invalid value - missing free instance function.", |
2414 | 0 | function ); |
2415 | |
|
2416 | 0 | return( -1 ); |
2417 | 0 | } |
2418 | 0 | if( value_entry_index == NULL ) |
2419 | 0 | { |
2420 | 0 | libcerror_error_set( |
2421 | 0 | error, |
2422 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2423 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2424 | 0 | "%s: invalid value entry index.", |
2425 | 0 | function ); |
2426 | |
|
2427 | 0 | return( -1 ); |
2428 | 0 | } |
2429 | 0 | if( libfvalue_data_handle_get_number_of_value_entries( |
2430 | 0 | internal_value->data_handle, |
2431 | 0 | &number_of_value_entries, |
2432 | 0 | error ) != 1 ) |
2433 | 0 | { |
2434 | 0 | libcerror_error_set( |
2435 | 0 | error, |
2436 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2437 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2438 | 0 | "%s: unable to retrieve number of value entries from data handle.", |
2439 | 0 | function ); |
2440 | |
|
2441 | 0 | return( -1 ); |
2442 | 0 | } |
2443 | | /* Since the data handle can reallocate the buffer used to store the data |
2444 | | * and the value instances reference this data make sure that no stale |
2445 | | * value instances are kept around. |
2446 | | */ |
2447 | 0 | for( *value_entry_index = 0; |
2448 | 0 | *value_entry_index < number_of_value_entries; |
2449 | 0 | *value_entry_index += 1 ) |
2450 | 0 | { |
2451 | 0 | if( libcdata_array_get_entry_by_index( |
2452 | 0 | internal_value->value_instances, |
2453 | 0 | *value_entry_index, |
2454 | 0 | &value_instance, |
2455 | 0 | error ) != 1 ) |
2456 | 0 | { |
2457 | 0 | libcerror_error_set( |
2458 | 0 | error, |
2459 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2460 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2461 | 0 | "%s: unable to retrieve entry: %d from values instances array.", |
2462 | 0 | function, |
2463 | 0 | *value_entry_index ); |
2464 | |
|
2465 | 0 | return( -1 ); |
2466 | 0 | } |
2467 | 0 | if( value_instance != NULL ) |
2468 | 0 | { |
2469 | 0 | if( libcdata_array_set_entry_by_index( |
2470 | 0 | internal_value->value_instances, |
2471 | 0 | *value_entry_index, |
2472 | 0 | NULL, |
2473 | 0 | error ) != 1 ) |
2474 | 0 | { |
2475 | 0 | libcerror_error_set( |
2476 | 0 | error, |
2477 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2478 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2479 | 0 | "%s: unable to set entry: %d in values instances array.", |
2480 | 0 | function, |
2481 | 0 | *value_entry_index ); |
2482 | |
|
2483 | 0 | return( -1 ); |
2484 | 0 | } |
2485 | 0 | if( internal_value->free_instance( |
2486 | 0 | &value_instance, |
2487 | 0 | error ) != 1 ) |
2488 | 0 | { |
2489 | 0 | libcerror_error_set( |
2490 | 0 | error, |
2491 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2492 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2493 | 0 | "%s: unable to free value instance: %d.", |
2494 | 0 | function, |
2495 | 0 | *value_entry_index ); |
2496 | |
|
2497 | 0 | return( -1 ); |
2498 | 0 | } |
2499 | 0 | } |
2500 | 0 | } |
2501 | 0 | if( libcdata_array_resize( |
2502 | 0 | internal_value->value_instances, |
2503 | 0 | number_of_value_entries + 1, |
2504 | 0 | internal_value->free_instance, |
2505 | 0 | error ) != 1 ) |
2506 | 0 | { |
2507 | 0 | libcerror_error_set( |
2508 | 0 | error, |
2509 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2510 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2511 | 0 | "%s: unable to resize value instances array.", |
2512 | 0 | function ); |
2513 | |
|
2514 | 0 | return( -1 ); |
2515 | 0 | } |
2516 | 0 | if( libfvalue_data_handle_append_value_entry_data( |
2517 | 0 | internal_value->data_handle, |
2518 | 0 | value_entry_index, |
2519 | 0 | entry_data, |
2520 | 0 | entry_data_size, |
2521 | 0 | encoding, |
2522 | 0 | error ) != 1 ) |
2523 | 0 | { |
2524 | 0 | libcerror_error_set( |
2525 | 0 | error, |
2526 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2527 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2528 | 0 | "%s: unable to append entry to data handle.", |
2529 | 0 | function ); |
2530 | |
|
2531 | 0 | return( -1 ); |
2532 | 0 | } |
2533 | 0 | return( 1 ); |
2534 | 0 | } |
2535 | | |
2536 | | /* Copies the entry data |
2537 | | * Returns 1 if successful, 0 if the value has no data or -1 on error |
2538 | | */ |
2539 | | int libfvalue_value_copy_entry_data( |
2540 | | libfvalue_value_t *value, |
2541 | | int value_entry_index, |
2542 | | uint8_t *entry_data, |
2543 | | size_t entry_data_size, |
2544 | | int *encoding, |
2545 | | libcerror_error_t **error ) |
2546 | 0 | { |
2547 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2548 | 0 | uint8_t *value_entry_data = NULL; |
2549 | 0 | static char *function = "libfvalue_value_copy_entry_data"; |
2550 | 0 | size_t value_entry_data_size = 0; |
2551 | 0 | int result = 0; |
2552 | |
|
2553 | 0 | if( value == NULL ) |
2554 | 0 | { |
2555 | 0 | libcerror_error_set( |
2556 | 0 | error, |
2557 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2558 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2559 | 0 | "%s: invalid value.", |
2560 | 0 | function ); |
2561 | |
|
2562 | 0 | return( -1 ); |
2563 | 0 | } |
2564 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2565 | |
|
2566 | 0 | if( entry_data == NULL ) |
2567 | 0 | { |
2568 | 0 | libcerror_error_set( |
2569 | 0 | error, |
2570 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2571 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2572 | 0 | "%s: invalid entry data.", |
2573 | 0 | function ); |
2574 | |
|
2575 | 0 | return( -1 ); |
2576 | 0 | } |
2577 | 0 | if( entry_data_size > (size_t) SSIZE_MAX ) |
2578 | 0 | { |
2579 | 0 | libcerror_error_set( |
2580 | 0 | error, |
2581 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2582 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
2583 | 0 | "%s: invalid entry data size value exceeds maximum.", |
2584 | 0 | function ); |
2585 | |
|
2586 | 0 | return( -1 ); |
2587 | 0 | } |
2588 | 0 | result = libfvalue_value_has_data( |
2589 | 0 | value, |
2590 | 0 | error ); |
2591 | |
|
2592 | 0 | if( result == -1 ) |
2593 | 0 | { |
2594 | 0 | libcerror_error_set( |
2595 | 0 | error, |
2596 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2597 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2598 | 0 | "%s: unable to determine if value has data.", |
2599 | 0 | function ); |
2600 | |
|
2601 | 0 | return( -1 ); |
2602 | 0 | } |
2603 | 0 | else if( result != 0 ) |
2604 | 0 | { |
2605 | 0 | if( libfvalue_data_handle_get_value_entry_data( |
2606 | 0 | internal_value->data_handle, |
2607 | 0 | value_entry_index, |
2608 | 0 | &value_entry_data, |
2609 | 0 | &value_entry_data_size, |
2610 | 0 | encoding, |
2611 | 0 | error ) != 1 ) |
2612 | 0 | { |
2613 | 0 | libcerror_error_set( |
2614 | 0 | error, |
2615 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2616 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2617 | 0 | "%s: unable to retrieve entry: %d data from data handle.", |
2618 | 0 | function, |
2619 | 0 | value_entry_index ); |
2620 | |
|
2621 | 0 | return( -1 ); |
2622 | 0 | } |
2623 | 0 | if( ( value_entry_data == NULL ) |
2624 | 0 | || ( value_entry_data_size == 0 ) ) |
2625 | 0 | { |
2626 | 0 | result = 0; |
2627 | 0 | } |
2628 | 0 | } |
2629 | 0 | if( result != 0 ) |
2630 | 0 | { |
2631 | 0 | if( entry_data_size < value_entry_data_size ) |
2632 | 0 | { |
2633 | 0 | libcerror_error_set( |
2634 | 0 | error, |
2635 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2636 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
2637 | 0 | "%s: invalid entry: %d data size value out of bounds.", |
2638 | 0 | function, |
2639 | 0 | value_entry_index ); |
2640 | |
|
2641 | 0 | return( -1 ); |
2642 | 0 | } |
2643 | 0 | if( memory_copy( |
2644 | 0 | entry_data, |
2645 | 0 | value_entry_data, |
2646 | 0 | value_entry_data_size ) == NULL ) |
2647 | 0 | { |
2648 | 0 | libcerror_error_set( |
2649 | 0 | error, |
2650 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2651 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
2652 | 0 | "%s: unable to copy entry: %d data.", |
2653 | 0 | function, |
2654 | 0 | value_entry_index ); |
2655 | |
|
2656 | 0 | return( -1 ); |
2657 | 0 | } |
2658 | 0 | } |
2659 | 0 | return( result ); |
2660 | 0 | } |
2661 | | |
2662 | | /* Boolean value functions |
2663 | | */ |
2664 | | |
2665 | | /* Copies the value data from a boolean value |
2666 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
2667 | | */ |
2668 | | int libfvalue_value_copy_from_boolean( |
2669 | | libfvalue_value_t *value, |
2670 | | int value_entry_index, |
2671 | | uint8_t value_boolean, |
2672 | | libcerror_error_t **error ) |
2673 | 0 | { |
2674 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2675 | 0 | intptr_t *value_instance = NULL; |
2676 | 0 | static char *function = "libfvalue_value_copy_from_boolean"; |
2677 | 0 | int result = 0; |
2678 | |
|
2679 | 0 | if( value == NULL ) |
2680 | 0 | { |
2681 | 0 | libcerror_error_set( |
2682 | 0 | error, |
2683 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2684 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2685 | 0 | "%s: invalid value.", |
2686 | 0 | function ); |
2687 | |
|
2688 | 0 | return( -1 ); |
2689 | 0 | } |
2690 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2691 | |
|
2692 | 0 | if( internal_value->copy_from_integer != NULL ) |
2693 | 0 | { |
2694 | 0 | if( libfvalue_value_get_value_instance_by_index( |
2695 | 0 | value, |
2696 | 0 | value_entry_index, |
2697 | 0 | &value_instance, |
2698 | 0 | error ) != 1 ) |
2699 | 0 | { |
2700 | 0 | libcerror_error_set( |
2701 | 0 | error, |
2702 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2703 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2704 | 0 | "%s: unable to retrieve value instance: %d.", |
2705 | 0 | function, |
2706 | 0 | value_entry_index ); |
2707 | |
|
2708 | 0 | return( -1 ); |
2709 | 0 | } |
2710 | 0 | if( value_instance != NULL ) |
2711 | 0 | { |
2712 | 0 | if( internal_value->copy_from_integer( |
2713 | 0 | value_instance, |
2714 | 0 | (uint64_t) value_boolean, |
2715 | 0 | 1, |
2716 | 0 | error ) != 1 ) |
2717 | 0 | { |
2718 | 0 | libcerror_error_set( |
2719 | 0 | error, |
2720 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2721 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
2722 | 0 | "%s: unable to copy instance from boolean.", |
2723 | 0 | function ); |
2724 | |
|
2725 | 0 | return( -1 ); |
2726 | 0 | } |
2727 | 0 | result = 1; |
2728 | 0 | } |
2729 | 0 | } |
2730 | 0 | return( result ); |
2731 | 0 | } |
2732 | | |
2733 | | /* Copies the value data to a boolean value |
2734 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
2735 | | */ |
2736 | | int libfvalue_value_copy_to_boolean( |
2737 | | libfvalue_value_t *value, |
2738 | | int value_entry_index, |
2739 | | uint8_t *value_boolean, |
2740 | | libcerror_error_t **error ) |
2741 | 0 | { |
2742 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2743 | 0 | intptr_t *value_instance = NULL; |
2744 | 0 | static char *function = "libfvalue_value_copy_to_boolean"; |
2745 | 0 | size_t integer_value_size = 0; |
2746 | 0 | uint64_t integer_value = 0; |
2747 | 0 | int result = 0; |
2748 | |
|
2749 | 0 | if( value == NULL ) |
2750 | 0 | { |
2751 | 0 | libcerror_error_set( |
2752 | 0 | error, |
2753 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2754 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2755 | 0 | "%s: invalid value.", |
2756 | 0 | function ); |
2757 | |
|
2758 | 0 | return( -1 ); |
2759 | 0 | } |
2760 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2761 | |
|
2762 | 0 | if( value_boolean == NULL ) |
2763 | 0 | { |
2764 | 0 | libcerror_error_set( |
2765 | 0 | error, |
2766 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2767 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2768 | 0 | "%s: missing value boolean.", |
2769 | 0 | function ); |
2770 | |
|
2771 | 0 | return( -1 ); |
2772 | 0 | } |
2773 | 0 | if( internal_value->copy_to_integer != NULL ) |
2774 | 0 | { |
2775 | 0 | if( libfvalue_value_get_value_instance_by_index( |
2776 | 0 | value, |
2777 | 0 | value_entry_index, |
2778 | 0 | &value_instance, |
2779 | 0 | error ) != 1 ) |
2780 | 0 | { |
2781 | 0 | libcerror_error_set( |
2782 | 0 | error, |
2783 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2784 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2785 | 0 | "%s: unable to retrieve value instance: %d.", |
2786 | 0 | function, |
2787 | 0 | value_entry_index ); |
2788 | |
|
2789 | 0 | return( -1 ); |
2790 | 0 | } |
2791 | 0 | if( value_instance != NULL ) |
2792 | 0 | { |
2793 | 0 | if( internal_value->copy_to_integer( |
2794 | 0 | value_instance, |
2795 | 0 | &integer_value, |
2796 | 0 | &integer_value_size, |
2797 | 0 | error ) != 1 ) |
2798 | 0 | { |
2799 | 0 | libcerror_error_set( |
2800 | 0 | error, |
2801 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2802 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
2803 | 0 | "%s: unable to copy instance to boolean.", |
2804 | 0 | function ); |
2805 | |
|
2806 | 0 | return( -1 ); |
2807 | 0 | } |
2808 | 0 | if( integer_value != 0 ) |
2809 | 0 | { |
2810 | 0 | *value_boolean = 1; |
2811 | 0 | } |
2812 | 0 | else |
2813 | 0 | { |
2814 | 0 | *value_boolean = 0; |
2815 | 0 | } |
2816 | 0 | result = 1; |
2817 | 0 | } |
2818 | 0 | } |
2819 | 0 | return( result ); |
2820 | 0 | } |
2821 | | |
2822 | | /* Integer value functions |
2823 | | */ |
2824 | | |
2825 | | /* Copies the value data from an 8-bit value |
2826 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
2827 | | */ |
2828 | | int libfvalue_value_copy_from_8bit( |
2829 | | libfvalue_value_t *value, |
2830 | | int value_entry_index, |
2831 | | uint8_t value_8bit, |
2832 | | libcerror_error_t **error ) |
2833 | 0 | { |
2834 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2835 | 0 | intptr_t *value_instance = NULL; |
2836 | 0 | static char *function = "libfvalue_value_copy_from_8bit"; |
2837 | 0 | int result = 0; |
2838 | |
|
2839 | 0 | if( value == NULL ) |
2840 | 0 | { |
2841 | 0 | libcerror_error_set( |
2842 | 0 | error, |
2843 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2844 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2845 | 0 | "%s: invalid value.", |
2846 | 0 | function ); |
2847 | |
|
2848 | 0 | return( -1 ); |
2849 | 0 | } |
2850 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2851 | |
|
2852 | 0 | if( internal_value->copy_from_integer != NULL ) |
2853 | 0 | { |
2854 | 0 | if( libfvalue_value_get_value_instance_by_index( |
2855 | 0 | value, |
2856 | 0 | value_entry_index, |
2857 | 0 | &value_instance, |
2858 | 0 | error ) != 1 ) |
2859 | 0 | { |
2860 | 0 | libcerror_error_set( |
2861 | 0 | error, |
2862 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2863 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2864 | 0 | "%s: unable to retrieve value instance: %d.", |
2865 | 0 | function, |
2866 | 0 | value_entry_index ); |
2867 | |
|
2868 | 0 | return( -1 ); |
2869 | 0 | } |
2870 | 0 | if( value_instance != NULL ) |
2871 | 0 | { |
2872 | 0 | if( internal_value->copy_from_integer( |
2873 | 0 | value_instance, |
2874 | 0 | (uint64_t) value_8bit, |
2875 | 0 | 8, |
2876 | 0 | error ) != 1 ) |
2877 | 0 | { |
2878 | 0 | libcerror_error_set( |
2879 | 0 | error, |
2880 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2881 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
2882 | 0 | "%s: unable to copy instance from 8-bit integer.", |
2883 | 0 | function ); |
2884 | |
|
2885 | 0 | return( -1 ); |
2886 | 0 | } |
2887 | 0 | result = 1; |
2888 | 0 | } |
2889 | 0 | } |
2890 | 0 | return( result ); |
2891 | 0 | } |
2892 | | |
2893 | | /* Copies the value data to an 8-bit value |
2894 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
2895 | | */ |
2896 | | int libfvalue_value_copy_to_8bit( |
2897 | | libfvalue_value_t *value, |
2898 | | int value_entry_index, |
2899 | | uint8_t *value_8bit, |
2900 | | libcerror_error_t **error ) |
2901 | 0 | { |
2902 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2903 | 0 | intptr_t *value_instance = NULL; |
2904 | 0 | static char *function = "libfvalue_value_copy_to_8bit"; |
2905 | 0 | size_t integer_value_size = 0; |
2906 | 0 | uint64_t integer_value = 0; |
2907 | 0 | int result = 0; |
2908 | |
|
2909 | 0 | if( value == NULL ) |
2910 | 0 | { |
2911 | 0 | libcerror_error_set( |
2912 | 0 | error, |
2913 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2914 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2915 | 0 | "%s: invalid value.", |
2916 | 0 | function ); |
2917 | |
|
2918 | 0 | return( -1 ); |
2919 | 0 | } |
2920 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
2921 | |
|
2922 | 0 | if( value_8bit == NULL ) |
2923 | 0 | { |
2924 | 0 | libcerror_error_set( |
2925 | 0 | error, |
2926 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2927 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2928 | 0 | "%s: missing value 8-bit.", |
2929 | 0 | function ); |
2930 | |
|
2931 | 0 | return( -1 ); |
2932 | 0 | } |
2933 | 0 | if( internal_value->copy_to_integer != NULL ) |
2934 | 0 | { |
2935 | 0 | if( libfvalue_value_get_value_instance_by_index( |
2936 | 0 | value, |
2937 | 0 | value_entry_index, |
2938 | 0 | &value_instance, |
2939 | 0 | error ) != 1 ) |
2940 | 0 | { |
2941 | 0 | libcerror_error_set( |
2942 | 0 | error, |
2943 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2944 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2945 | 0 | "%s: unable to retrieve value instance: %d.", |
2946 | 0 | function, |
2947 | 0 | value_entry_index ); |
2948 | |
|
2949 | 0 | return( -1 ); |
2950 | 0 | } |
2951 | 0 | if( value_instance != NULL ) |
2952 | 0 | { |
2953 | 0 | if( internal_value->copy_to_integer( |
2954 | 0 | value_instance, |
2955 | 0 | &integer_value, |
2956 | 0 | &integer_value_size, |
2957 | 0 | error ) != 1 ) |
2958 | 0 | { |
2959 | 0 | libcerror_error_set( |
2960 | 0 | error, |
2961 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2962 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
2963 | 0 | "%s: unable to copy instance to integer value.", |
2964 | 0 | function ); |
2965 | |
|
2966 | 0 | return( -1 ); |
2967 | 0 | } |
2968 | 0 | if( integer_value > (uint64_t) UINT8_MAX ) |
2969 | 0 | { |
2970 | 0 | libcerror_error_set( |
2971 | 0 | error, |
2972 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2973 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2974 | 0 | "%s: integer value out of bounds.", |
2975 | 0 | function ); |
2976 | |
|
2977 | 0 | return( -1 ); |
2978 | 0 | } |
2979 | 0 | *value_8bit = (uint8_t) integer_value; |
2980 | |
|
2981 | 0 | result = 1; |
2982 | 0 | } |
2983 | 0 | } |
2984 | 0 | return( result ); |
2985 | 0 | } |
2986 | | |
2987 | | /* Copies the value data from a 16-bit value |
2988 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
2989 | | */ |
2990 | | int libfvalue_value_copy_from_16bit( |
2991 | | libfvalue_value_t *value, |
2992 | | int value_entry_index, |
2993 | | uint16_t value_16bit, |
2994 | | libcerror_error_t **error ) |
2995 | 0 | { |
2996 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
2997 | 0 | intptr_t *value_instance = NULL; |
2998 | 0 | static char *function = "libfvalue_value_copy_from_16bit"; |
2999 | 0 | int result = 0; |
3000 | |
|
3001 | 0 | if( value == NULL ) |
3002 | 0 | { |
3003 | 0 | libcerror_error_set( |
3004 | 0 | error, |
3005 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3006 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3007 | 0 | "%s: invalid value.", |
3008 | 0 | function ); |
3009 | |
|
3010 | 0 | return( -1 ); |
3011 | 0 | } |
3012 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3013 | |
|
3014 | 0 | if( internal_value->copy_from_integer != NULL ) |
3015 | 0 | { |
3016 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3017 | 0 | value, |
3018 | 0 | value_entry_index, |
3019 | 0 | &value_instance, |
3020 | 0 | error ) != 1 ) |
3021 | 0 | { |
3022 | 0 | libcerror_error_set( |
3023 | 0 | error, |
3024 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3025 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3026 | 0 | "%s: unable to retrieve value instance: %d.", |
3027 | 0 | function, |
3028 | 0 | value_entry_index ); |
3029 | |
|
3030 | 0 | return( -1 ); |
3031 | 0 | } |
3032 | 0 | if( value_instance != NULL ) |
3033 | 0 | { |
3034 | 0 | if( internal_value->copy_from_integer( |
3035 | 0 | value_instance, |
3036 | 0 | (uint64_t) value_16bit, |
3037 | 0 | 16, |
3038 | 0 | error ) != 1 ) |
3039 | 0 | { |
3040 | 0 | libcerror_error_set( |
3041 | 0 | error, |
3042 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3043 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3044 | 0 | "%s: unable to copy instance from 16-bit integer.", |
3045 | 0 | function ); |
3046 | |
|
3047 | 0 | return( -1 ); |
3048 | 0 | } |
3049 | 0 | result = 1; |
3050 | 0 | } |
3051 | 0 | } |
3052 | 0 | return( result ); |
3053 | 0 | } |
3054 | | |
3055 | | /* Copies the value data to a 16-bit value |
3056 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3057 | | */ |
3058 | | int libfvalue_value_copy_to_16bit( |
3059 | | libfvalue_value_t *value, |
3060 | | int value_entry_index, |
3061 | | uint16_t *value_16bit, |
3062 | | libcerror_error_t **error ) |
3063 | 0 | { |
3064 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3065 | 0 | intptr_t *value_instance = NULL; |
3066 | 0 | static char *function = "libfvalue_value_copy_to_16bit"; |
3067 | 0 | size_t integer_value_size = 0; |
3068 | 0 | uint64_t integer_value = 0; |
3069 | 0 | int result = 0; |
3070 | |
|
3071 | 0 | if( value == NULL ) |
3072 | 0 | { |
3073 | 0 | libcerror_error_set( |
3074 | 0 | error, |
3075 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3076 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3077 | 0 | "%s: invalid value.", |
3078 | 0 | function ); |
3079 | |
|
3080 | 0 | return( -1 ); |
3081 | 0 | } |
3082 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3083 | |
|
3084 | 0 | if( value_16bit == NULL ) |
3085 | 0 | { |
3086 | 0 | libcerror_error_set( |
3087 | 0 | error, |
3088 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3089 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3090 | 0 | "%s: missing value 16-bit.", |
3091 | 0 | function ); |
3092 | |
|
3093 | 0 | return( -1 ); |
3094 | 0 | } |
3095 | 0 | if( internal_value->copy_to_integer != NULL ) |
3096 | 0 | { |
3097 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3098 | 0 | value, |
3099 | 0 | value_entry_index, |
3100 | 0 | &value_instance, |
3101 | 0 | error ) != 1 ) |
3102 | 0 | { |
3103 | 0 | libcerror_error_set( |
3104 | 0 | error, |
3105 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3106 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3107 | 0 | "%s: unable to retrieve value instance: %d.", |
3108 | 0 | function, |
3109 | 0 | value_entry_index ); |
3110 | |
|
3111 | 0 | return( -1 ); |
3112 | 0 | } |
3113 | 0 | if( value_instance != NULL ) |
3114 | 0 | { |
3115 | 0 | if( internal_value->copy_to_integer( |
3116 | 0 | value_instance, |
3117 | 0 | &integer_value, |
3118 | 0 | &integer_value_size, |
3119 | 0 | error ) != 1 ) |
3120 | 0 | { |
3121 | 0 | libcerror_error_set( |
3122 | 0 | error, |
3123 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3124 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3125 | 0 | "%s: unable to copy instance to integer value.", |
3126 | 0 | function ); |
3127 | |
|
3128 | 0 | return( -1 ); |
3129 | 0 | } |
3130 | 0 | if( integer_value > (uint64_t) UINT16_MAX ) |
3131 | 0 | { |
3132 | 0 | libcerror_error_set( |
3133 | 0 | error, |
3134 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3135 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3136 | 0 | "%s: integer value out of bounds.", |
3137 | 0 | function ); |
3138 | |
|
3139 | 0 | return( -1 ); |
3140 | 0 | } |
3141 | 0 | *value_16bit = (uint16_t) integer_value; |
3142 | |
|
3143 | 0 | result = 1; |
3144 | 0 | } |
3145 | 0 | } |
3146 | 0 | return( result ); |
3147 | 0 | } |
3148 | | |
3149 | | /* Copies the value data from a 32-bit value |
3150 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3151 | | */ |
3152 | | int libfvalue_value_copy_from_32bit( |
3153 | | libfvalue_value_t *value, |
3154 | | int value_entry_index, |
3155 | | uint32_t value_32bit, |
3156 | | libcerror_error_t **error ) |
3157 | 0 | { |
3158 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3159 | 0 | intptr_t *value_instance = NULL; |
3160 | 0 | static char *function = "libfvalue_value_copy_from_32bit"; |
3161 | 0 | int result = 0; |
3162 | |
|
3163 | 0 | if( value == NULL ) |
3164 | 0 | { |
3165 | 0 | libcerror_error_set( |
3166 | 0 | error, |
3167 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3168 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3169 | 0 | "%s: invalid value.", |
3170 | 0 | function ); |
3171 | |
|
3172 | 0 | return( -1 ); |
3173 | 0 | } |
3174 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3175 | |
|
3176 | 0 | if( internal_value->copy_from_integer != NULL ) |
3177 | 0 | { |
3178 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3179 | 0 | value, |
3180 | 0 | value_entry_index, |
3181 | 0 | &value_instance, |
3182 | 0 | error ) != 1 ) |
3183 | 0 | { |
3184 | 0 | libcerror_error_set( |
3185 | 0 | error, |
3186 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3187 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3188 | 0 | "%s: unable to retrieve value instance: %d.", |
3189 | 0 | function, |
3190 | 0 | value_entry_index ); |
3191 | |
|
3192 | 0 | return( -1 ); |
3193 | 0 | } |
3194 | 0 | if( value_instance != NULL ) |
3195 | 0 | { |
3196 | 0 | if( internal_value->copy_from_integer( |
3197 | 0 | value_instance, |
3198 | 0 | (uint64_t) value_32bit, |
3199 | 0 | 32, |
3200 | 0 | error ) != 1 ) |
3201 | 0 | { |
3202 | 0 | libcerror_error_set( |
3203 | 0 | error, |
3204 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3205 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3206 | 0 | "%s: unable to copy instance from 32-bit integer.", |
3207 | 0 | function ); |
3208 | |
|
3209 | 0 | return( -1 ); |
3210 | 0 | } |
3211 | 0 | result = 1; |
3212 | 0 | } |
3213 | 0 | } |
3214 | 0 | return( result ); |
3215 | 0 | } |
3216 | | |
3217 | | /* Copies the value data to a 32-bit value |
3218 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3219 | | */ |
3220 | | int libfvalue_value_copy_to_32bit( |
3221 | | libfvalue_value_t *value, |
3222 | | int value_entry_index, |
3223 | | uint32_t *value_32bit, |
3224 | | libcerror_error_t **error ) |
3225 | 0 | { |
3226 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3227 | 0 | intptr_t *value_instance = NULL; |
3228 | 0 | static char *function = "libfvalue_value_copy_to_32bit"; |
3229 | 0 | size_t integer_value_size = 0; |
3230 | 0 | uint64_t integer_value = 0; |
3231 | 0 | int result = 0; |
3232 | |
|
3233 | 0 | if( value == NULL ) |
3234 | 0 | { |
3235 | 0 | libcerror_error_set( |
3236 | 0 | error, |
3237 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3238 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3239 | 0 | "%s: invalid value.", |
3240 | 0 | function ); |
3241 | |
|
3242 | 0 | return( -1 ); |
3243 | 0 | } |
3244 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3245 | |
|
3246 | 0 | if( value_32bit == NULL ) |
3247 | 0 | { |
3248 | 0 | libcerror_error_set( |
3249 | 0 | error, |
3250 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3251 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3252 | 0 | "%s: missing value 32-bit.", |
3253 | 0 | function ); |
3254 | |
|
3255 | 0 | return( -1 ); |
3256 | 0 | } |
3257 | 0 | if( internal_value->copy_to_integer != NULL ) |
3258 | 0 | { |
3259 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3260 | 0 | value, |
3261 | 0 | value_entry_index, |
3262 | 0 | &value_instance, |
3263 | 0 | error ) != 1 ) |
3264 | 0 | { |
3265 | 0 | libcerror_error_set( |
3266 | 0 | error, |
3267 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3268 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3269 | 0 | "%s: unable to retrieve value instance: %d.", |
3270 | 0 | function, |
3271 | 0 | value_entry_index ); |
3272 | |
|
3273 | 0 | return( -1 ); |
3274 | 0 | } |
3275 | 0 | if( value_instance != NULL ) |
3276 | 0 | { |
3277 | 0 | if( internal_value->copy_to_integer( |
3278 | 0 | value_instance, |
3279 | 0 | &integer_value, |
3280 | 0 | &integer_value_size, |
3281 | 0 | error ) != 1 ) |
3282 | 0 | { |
3283 | 0 | libcerror_error_set( |
3284 | 0 | error, |
3285 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3286 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3287 | 0 | "%s: unable to copy instance to integer value.", |
3288 | 0 | function ); |
3289 | |
|
3290 | 0 | return( -1 ); |
3291 | 0 | } |
3292 | 0 | if( integer_value > (uint64_t) UINT32_MAX ) |
3293 | 0 | { |
3294 | 0 | libcerror_error_set( |
3295 | 0 | error, |
3296 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3297 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3298 | 0 | "%s: integer value out of bounds.", |
3299 | 0 | function ); |
3300 | |
|
3301 | 0 | return( -1 ); |
3302 | 0 | } |
3303 | 0 | *value_32bit = (uint32_t) integer_value; |
3304 | |
|
3305 | 0 | result = 1; |
3306 | 0 | } |
3307 | 0 | } |
3308 | 0 | return( result ); |
3309 | 0 | } |
3310 | | |
3311 | | /* Copies the value data from a 64-bit value |
3312 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3313 | | */ |
3314 | | int libfvalue_value_copy_from_64bit( |
3315 | | libfvalue_value_t *value, |
3316 | | int value_entry_index, |
3317 | | uint64_t value_64bit, |
3318 | | libcerror_error_t **error ) |
3319 | 0 | { |
3320 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3321 | 0 | intptr_t *value_instance = NULL; |
3322 | 0 | static char *function = "libfvalue_value_copy_from_64bit"; |
3323 | 0 | int result = 0; |
3324 | |
|
3325 | 0 | if( value == NULL ) |
3326 | 0 | { |
3327 | 0 | libcerror_error_set( |
3328 | 0 | error, |
3329 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3330 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3331 | 0 | "%s: invalid value.", |
3332 | 0 | function ); |
3333 | |
|
3334 | 0 | return( -1 ); |
3335 | 0 | } |
3336 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3337 | |
|
3338 | 0 | if( internal_value->copy_from_integer != NULL ) |
3339 | 0 | { |
3340 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3341 | 0 | value, |
3342 | 0 | value_entry_index, |
3343 | 0 | &value_instance, |
3344 | 0 | error ) != 1 ) |
3345 | 0 | { |
3346 | 0 | libcerror_error_set( |
3347 | 0 | error, |
3348 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3349 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3350 | 0 | "%s: unable to retrieve value instance: %d.", |
3351 | 0 | function, |
3352 | 0 | value_entry_index ); |
3353 | |
|
3354 | 0 | return( -1 ); |
3355 | 0 | } |
3356 | 0 | if( value_instance != NULL ) |
3357 | 0 | { |
3358 | 0 | if( internal_value->copy_from_integer( |
3359 | 0 | value_instance, |
3360 | 0 | (uint64_t) value_64bit, |
3361 | 0 | 64, |
3362 | 0 | error ) != 1 ) |
3363 | 0 | { |
3364 | 0 | libcerror_error_set( |
3365 | 0 | error, |
3366 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3367 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3368 | 0 | "%s: unable to copy instance from 64-bit integer.", |
3369 | 0 | function ); |
3370 | |
|
3371 | 0 | return( -1 ); |
3372 | 0 | } |
3373 | 0 | result = 1; |
3374 | 0 | } |
3375 | 0 | } |
3376 | 0 | return( result ); |
3377 | 0 | } |
3378 | | |
3379 | | /* Copies the value data to a 64-bit value |
3380 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3381 | | */ |
3382 | | int libfvalue_value_copy_to_64bit( |
3383 | | libfvalue_value_t *value, |
3384 | | int value_entry_index, |
3385 | | uint64_t *value_64bit, |
3386 | | libcerror_error_t **error ) |
3387 | 0 | { |
3388 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3389 | 0 | intptr_t *value_instance = NULL; |
3390 | 0 | static char *function = "libfvalue_value_copy_to_64bit"; |
3391 | 0 | size_t integer_value_size = 0; |
3392 | 0 | uint64_t integer_value = 0; |
3393 | 0 | int result = 0; |
3394 | |
|
3395 | 0 | if( value == NULL ) |
3396 | 0 | { |
3397 | 0 | libcerror_error_set( |
3398 | 0 | error, |
3399 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3400 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3401 | 0 | "%s: invalid value.", |
3402 | 0 | function ); |
3403 | |
|
3404 | 0 | return( -1 ); |
3405 | 0 | } |
3406 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3407 | |
|
3408 | 0 | if( value_64bit == NULL ) |
3409 | 0 | { |
3410 | 0 | libcerror_error_set( |
3411 | 0 | error, |
3412 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3413 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3414 | 0 | "%s: missing value 64-bit.", |
3415 | 0 | function ); |
3416 | |
|
3417 | 0 | return( -1 ); |
3418 | 0 | } |
3419 | 0 | if( internal_value->copy_to_integer != NULL ) |
3420 | 0 | { |
3421 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3422 | 0 | value, |
3423 | 0 | value_entry_index, |
3424 | 0 | &value_instance, |
3425 | 0 | error ) != 1 ) |
3426 | 0 | { |
3427 | 0 | libcerror_error_set( |
3428 | 0 | error, |
3429 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3430 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3431 | 0 | "%s: unable to retrieve value instance: %d.", |
3432 | 0 | function, |
3433 | 0 | value_entry_index ); |
3434 | |
|
3435 | 0 | return( -1 ); |
3436 | 0 | } |
3437 | 0 | if( value_instance != NULL ) |
3438 | 0 | { |
3439 | 0 | if( internal_value->copy_to_integer( |
3440 | 0 | value_instance, |
3441 | 0 | &integer_value, |
3442 | 0 | &integer_value_size, |
3443 | 0 | error ) != 1 ) |
3444 | 0 | { |
3445 | 0 | libcerror_error_set( |
3446 | 0 | error, |
3447 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3448 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3449 | 0 | "%s: unable to copy instance to integer value.", |
3450 | 0 | function ); |
3451 | |
|
3452 | 0 | return( -1 ); |
3453 | 0 | } |
3454 | 0 | *value_64bit = (uint64_t) integer_value; |
3455 | |
|
3456 | 0 | result = 1; |
3457 | 0 | } |
3458 | 0 | } |
3459 | 0 | return( result ); |
3460 | 0 | } |
3461 | | |
3462 | | /* Floating point value functions |
3463 | | */ |
3464 | | |
3465 | | /* Copies the value data from a float value |
3466 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3467 | | */ |
3468 | | int libfvalue_value_copy_from_float( |
3469 | | libfvalue_value_t *value, |
3470 | | int value_entry_index, |
3471 | | float value_float, |
3472 | | libcerror_error_t **error ) |
3473 | 0 | { |
3474 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3475 | 0 | intptr_t *value_instance = NULL; |
3476 | 0 | static char *function = "libfvalue_value_copy_from_float"; |
3477 | 0 | int result = 0; |
3478 | |
|
3479 | 0 | if( value == NULL ) |
3480 | 0 | { |
3481 | 0 | libcerror_error_set( |
3482 | 0 | error, |
3483 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3484 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3485 | 0 | "%s: invalid value.", |
3486 | 0 | function ); |
3487 | |
|
3488 | 0 | return( -1 ); |
3489 | 0 | } |
3490 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3491 | |
|
3492 | 0 | if( internal_value->copy_from_floating_point != NULL ) |
3493 | 0 | { |
3494 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3495 | 0 | value, |
3496 | 0 | value_entry_index, |
3497 | 0 | &value_instance, |
3498 | 0 | error ) != 1 ) |
3499 | 0 | { |
3500 | 0 | libcerror_error_set( |
3501 | 0 | error, |
3502 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3503 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3504 | 0 | "%s: unable to retrieve value instance: %d.", |
3505 | 0 | function, |
3506 | 0 | value_entry_index ); |
3507 | |
|
3508 | 0 | return( -1 ); |
3509 | 0 | } |
3510 | 0 | if( value_instance != NULL ) |
3511 | 0 | { |
3512 | 0 | if( internal_value->copy_from_floating_point( |
3513 | 0 | value_instance, |
3514 | 0 | (double) value_float, |
3515 | 0 | 32, |
3516 | 0 | error ) != 1 ) |
3517 | 0 | { |
3518 | 0 | libcerror_error_set( |
3519 | 0 | error, |
3520 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3521 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3522 | 0 | "%s: unable to copy instance from 32-bit floating point.", |
3523 | 0 | function ); |
3524 | |
|
3525 | 0 | return( -1 ); |
3526 | 0 | } |
3527 | 0 | result = 1; |
3528 | 0 | } |
3529 | 0 | } |
3530 | 0 | return( result ); |
3531 | 0 | } |
3532 | | |
3533 | | /* Copies the value data to a float value |
3534 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3535 | | */ |
3536 | | int libfvalue_value_copy_to_float( |
3537 | | libfvalue_value_t *value, |
3538 | | int value_entry_index, |
3539 | | float *value_float, |
3540 | | libcerror_error_t **error ) |
3541 | 0 | { |
3542 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3543 | 0 | intptr_t *value_instance = NULL; |
3544 | 0 | static char *function = "libfvalue_value_copy_to_float"; |
3545 | 0 | size_t floating_point_value_size = 0; |
3546 | 0 | double floating_point_value = 0.0; |
3547 | 0 | int result = 0; |
3548 | |
|
3549 | 0 | if( value == NULL ) |
3550 | 0 | { |
3551 | 0 | libcerror_error_set( |
3552 | 0 | error, |
3553 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3554 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3555 | 0 | "%s: invalid value.", |
3556 | 0 | function ); |
3557 | |
|
3558 | 0 | return( -1 ); |
3559 | 0 | } |
3560 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3561 | |
|
3562 | 0 | if( value_float == NULL ) |
3563 | 0 | { |
3564 | 0 | libcerror_error_set( |
3565 | 0 | error, |
3566 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3567 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3568 | 0 | "%s: invalid value float.", |
3569 | 0 | function ); |
3570 | |
|
3571 | 0 | return( -1 ); |
3572 | 0 | } |
3573 | 0 | if( internal_value->copy_to_floating_point != NULL ) |
3574 | 0 | { |
3575 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3576 | 0 | value, |
3577 | 0 | value_entry_index, |
3578 | 0 | &value_instance, |
3579 | 0 | error ) != 1 ) |
3580 | 0 | { |
3581 | 0 | libcerror_error_set( |
3582 | 0 | error, |
3583 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3584 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3585 | 0 | "%s: unable to retrieve value instance: %d.", |
3586 | 0 | function, |
3587 | 0 | value_entry_index ); |
3588 | |
|
3589 | 0 | return( -1 ); |
3590 | 0 | } |
3591 | 0 | if( value_instance != NULL ) |
3592 | 0 | { |
3593 | 0 | if( internal_value->copy_to_floating_point( |
3594 | 0 | value_instance, |
3595 | 0 | &floating_point_value, |
3596 | 0 | &floating_point_value_size, |
3597 | 0 | error ) != 1 ) |
3598 | 0 | { |
3599 | 0 | libcerror_error_set( |
3600 | 0 | error, |
3601 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3602 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3603 | 0 | "%s: unable to copy instance to floating point value.", |
3604 | 0 | function ); |
3605 | |
|
3606 | 0 | return( -1 ); |
3607 | 0 | } |
3608 | 0 | *value_float = (float) floating_point_value; |
3609 | |
|
3610 | 0 | result = 1; |
3611 | 0 | } |
3612 | 0 | } |
3613 | 0 | return( result ); |
3614 | 0 | } |
3615 | | |
3616 | | /* Copies the value data from a double value |
3617 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3618 | | */ |
3619 | | int libfvalue_value_copy_from_double( |
3620 | | libfvalue_value_t *value, |
3621 | | int value_entry_index, |
3622 | | double value_double, |
3623 | | libcerror_error_t **error ) |
3624 | 0 | { |
3625 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3626 | 0 | intptr_t *value_instance = NULL; |
3627 | 0 | static char *function = "libfvalue_value_copy_from_double"; |
3628 | 0 | int result = 0; |
3629 | |
|
3630 | 0 | if( value == NULL ) |
3631 | 0 | { |
3632 | 0 | libcerror_error_set( |
3633 | 0 | error, |
3634 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3635 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3636 | 0 | "%s: invalid value.", |
3637 | 0 | function ); |
3638 | |
|
3639 | 0 | return( -1 ); |
3640 | 0 | } |
3641 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3642 | |
|
3643 | 0 | if( internal_value->copy_from_floating_point != NULL ) |
3644 | 0 | { |
3645 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3646 | 0 | value, |
3647 | 0 | value_entry_index, |
3648 | 0 | &value_instance, |
3649 | 0 | error ) != 1 ) |
3650 | 0 | { |
3651 | 0 | libcerror_error_set( |
3652 | 0 | error, |
3653 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3654 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3655 | 0 | "%s: unable to retrieve value instance: %d.", |
3656 | 0 | function, |
3657 | 0 | value_entry_index ); |
3658 | |
|
3659 | 0 | return( -1 ); |
3660 | 0 | } |
3661 | 0 | if( value_instance != NULL ) |
3662 | 0 | { |
3663 | 0 | if( internal_value->copy_from_floating_point( |
3664 | 0 | value_instance, |
3665 | 0 | (double) value_double, |
3666 | 0 | 64, |
3667 | 0 | error ) != 1 ) |
3668 | 0 | { |
3669 | 0 | libcerror_error_set( |
3670 | 0 | error, |
3671 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3672 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3673 | 0 | "%s: unable to copy instance from 32-bit floating point.", |
3674 | 0 | function ); |
3675 | |
|
3676 | 0 | return( -1 ); |
3677 | 0 | } |
3678 | 0 | result = 1; |
3679 | 0 | } |
3680 | 0 | } |
3681 | 0 | return( result ); |
3682 | 0 | } |
3683 | | |
3684 | | /* Copies the value data to a double value |
3685 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3686 | | */ |
3687 | | int libfvalue_value_copy_to_double( |
3688 | | libfvalue_value_t *value, |
3689 | | int value_entry_index, |
3690 | | double *value_double, |
3691 | | libcerror_error_t **error ) |
3692 | 0 | { |
3693 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3694 | 0 | intptr_t *value_instance = NULL; |
3695 | 0 | static char *function = "libfvalue_value_copy_to_double"; |
3696 | 0 | size_t floating_point_value_size = 0; |
3697 | 0 | double floating_point_value = 0.0; |
3698 | 0 | int result = 0; |
3699 | |
|
3700 | 0 | if( value == NULL ) |
3701 | 0 | { |
3702 | 0 | libcerror_error_set( |
3703 | 0 | error, |
3704 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3705 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3706 | 0 | "%s: invalid value.", |
3707 | 0 | function ); |
3708 | |
|
3709 | 0 | return( -1 ); |
3710 | 0 | } |
3711 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3712 | |
|
3713 | 0 | if( value_double == NULL ) |
3714 | 0 | { |
3715 | 0 | libcerror_error_set( |
3716 | 0 | error, |
3717 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3718 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3719 | 0 | "%s: invalid value double.", |
3720 | 0 | function ); |
3721 | |
|
3722 | 0 | return( -1 ); |
3723 | 0 | } |
3724 | 0 | if( internal_value->copy_to_floating_point != NULL ) |
3725 | 0 | { |
3726 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3727 | 0 | value, |
3728 | 0 | value_entry_index, |
3729 | 0 | &value_instance, |
3730 | 0 | error ) != 1 ) |
3731 | 0 | { |
3732 | 0 | libcerror_error_set( |
3733 | 0 | error, |
3734 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3735 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3736 | 0 | "%s: unable to retrieve value instance: %d.", |
3737 | 0 | function, |
3738 | 0 | value_entry_index ); |
3739 | |
|
3740 | 0 | return( -1 ); |
3741 | 0 | } |
3742 | 0 | if( value_instance != NULL ) |
3743 | 0 | { |
3744 | 0 | if( internal_value->copy_to_floating_point( |
3745 | 0 | value_instance, |
3746 | 0 | &floating_point_value, |
3747 | 0 | &floating_point_value_size, |
3748 | 0 | error ) != 1 ) |
3749 | 0 | { |
3750 | 0 | libcerror_error_set( |
3751 | 0 | error, |
3752 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3753 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3754 | 0 | "%s: unable to copy instance to floating point value.", |
3755 | 0 | function ); |
3756 | |
|
3757 | 0 | return( -1 ); |
3758 | 0 | } |
3759 | 0 | *value_double = (double) floating_point_value; |
3760 | |
|
3761 | 0 | result = 1; |
3762 | 0 | } |
3763 | 0 | } |
3764 | 0 | return( result ); |
3765 | 0 | } |
3766 | | |
3767 | | /* String value functions |
3768 | | */ |
3769 | | |
3770 | | /* Copies the value data from an UTF-8 encoded string |
3771 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3772 | | */ |
3773 | | int libfvalue_value_copy_from_utf8_string( |
3774 | | libfvalue_value_t *value, |
3775 | | int value_entry_index, |
3776 | | const uint8_t *utf8_string, |
3777 | | size_t utf8_string_length, |
3778 | | libcerror_error_t **error ) |
3779 | 0 | { |
3780 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3781 | 0 | intptr_t *value_instance = NULL; |
3782 | 0 | static char *function = "libfvalue_value_copy_from_utf8_string"; |
3783 | 0 | size_t utf8_string_index = 0; |
3784 | 0 | int result = 0; |
3785 | |
|
3786 | 0 | if( value == NULL ) |
3787 | 0 | { |
3788 | 0 | libcerror_error_set( |
3789 | 0 | error, |
3790 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3791 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3792 | 0 | "%s: invalid value.", |
3793 | 0 | function ); |
3794 | |
|
3795 | 0 | return( -1 ); |
3796 | 0 | } |
3797 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3798 | |
|
3799 | 0 | if( internal_value->initialize_instance == NULL ) |
3800 | 0 | { |
3801 | 0 | libcerror_error_set( |
3802 | 0 | error, |
3803 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3804 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3805 | 0 | "%s: invalid value - missing initialize instance function.", |
3806 | 0 | function ); |
3807 | |
|
3808 | 0 | return( -1 ); |
3809 | 0 | } |
3810 | 0 | if( internal_value->free_instance == NULL ) |
3811 | 0 | { |
3812 | 0 | libcerror_error_set( |
3813 | 0 | error, |
3814 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3815 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3816 | 0 | "%s: invalid value - missing free instance function.", |
3817 | 0 | function ); |
3818 | |
|
3819 | 0 | return( -1 ); |
3820 | 0 | } |
3821 | 0 | if( internal_value->copy_from_utf8_string_with_index != NULL ) |
3822 | 0 | { |
3823 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3824 | 0 | value, |
3825 | 0 | value_entry_index, |
3826 | 0 | &value_instance, |
3827 | 0 | error ) != 1 ) |
3828 | 0 | { |
3829 | 0 | libcerror_error_set( |
3830 | 0 | error, |
3831 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3832 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3833 | 0 | "%s: unable to retrieve value instance: %d.", |
3834 | 0 | function, |
3835 | 0 | value_entry_index ); |
3836 | |
|
3837 | 0 | return( -1 ); |
3838 | 0 | } |
3839 | 0 | if( value_instance == NULL ) |
3840 | 0 | { |
3841 | 0 | if( internal_value->initialize_instance( |
3842 | 0 | &value_instance, |
3843 | 0 | error ) != 1 ) |
3844 | 0 | { |
3845 | 0 | libcerror_error_set( |
3846 | 0 | error, |
3847 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3848 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3849 | 0 | "%s: unable to create value instance.", |
3850 | 0 | function ); |
3851 | |
|
3852 | 0 | return( -1 ); |
3853 | 0 | } |
3854 | 0 | if( libcdata_array_set_entry_by_index( |
3855 | 0 | internal_value->value_instances, |
3856 | 0 | value_entry_index, |
3857 | 0 | value_instance, |
3858 | 0 | error ) != 1 ) |
3859 | 0 | { |
3860 | 0 | libcerror_error_set( |
3861 | 0 | error, |
3862 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3863 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3864 | 0 | "%s: unable to set entry: %d in values instances array.", |
3865 | 0 | function, |
3866 | 0 | value_entry_index ); |
3867 | |
|
3868 | 0 | internal_value->free_instance( |
3869 | 0 | &value_instance, |
3870 | 0 | NULL ); |
3871 | |
|
3872 | 0 | return( -1 ); |
3873 | 0 | } |
3874 | 0 | } |
3875 | 0 | if( internal_value->copy_from_utf8_string_with_index( |
3876 | 0 | value_instance, |
3877 | 0 | utf8_string, |
3878 | 0 | utf8_string_length, |
3879 | 0 | &utf8_string_index, |
3880 | 0 | internal_value->format_flags, |
3881 | 0 | error ) != 1 ) |
3882 | 0 | { |
3883 | 0 | libcerror_error_set( |
3884 | 0 | error, |
3885 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3886 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3887 | 0 | "%s: unable to copy instance from UTF-8 string.", |
3888 | 0 | function ); |
3889 | |
|
3890 | 0 | return( -1 ); |
3891 | 0 | } |
3892 | 0 | result = 1; |
3893 | 0 | } |
3894 | 0 | return( result ); |
3895 | 0 | } |
3896 | | |
3897 | | /* Retrieves the size of an UTF-8 encoded string of the value data |
3898 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3899 | | */ |
3900 | | int libfvalue_value_get_utf8_string_size( |
3901 | | libfvalue_value_t *value, |
3902 | | int value_entry_index, |
3903 | | size_t *utf8_string_size, |
3904 | | libcerror_error_t **error ) |
3905 | 0 | { |
3906 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
3907 | 0 | intptr_t *value_instance = NULL; |
3908 | 0 | static char *function = "libfvalue_value_get_utf8_string_size"; |
3909 | 0 | int result = 0; |
3910 | |
|
3911 | 0 | if( value == NULL ) |
3912 | 0 | { |
3913 | 0 | libcerror_error_set( |
3914 | 0 | error, |
3915 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3916 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3917 | 0 | "%s: invalid value.", |
3918 | 0 | function ); |
3919 | |
|
3920 | 0 | return( -1 ); |
3921 | 0 | } |
3922 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
3923 | |
|
3924 | 0 | if( internal_value->get_utf8_string_size != NULL ) |
3925 | 0 | { |
3926 | 0 | if( libfvalue_value_get_value_instance_by_index( |
3927 | 0 | value, |
3928 | 0 | value_entry_index, |
3929 | 0 | &value_instance, |
3930 | 0 | error ) != 1 ) |
3931 | 0 | { |
3932 | 0 | libcerror_error_set( |
3933 | 0 | error, |
3934 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3935 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3936 | 0 | "%s: unable to retrieve value instance: %d.", |
3937 | 0 | function, |
3938 | 0 | value_entry_index ); |
3939 | |
|
3940 | 0 | return( -1 ); |
3941 | 0 | } |
3942 | 0 | if( value_instance != NULL ) |
3943 | 0 | { |
3944 | 0 | if( internal_value->get_utf8_string_size( |
3945 | 0 | value_instance, |
3946 | 0 | utf8_string_size, |
3947 | 0 | internal_value->format_flags, |
3948 | 0 | error ) != 1 ) |
3949 | 0 | { |
3950 | 0 | libcerror_error_set( |
3951 | 0 | error, |
3952 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3953 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3954 | 0 | "%s: unable to determine size UTF-8 string of instance.", |
3955 | 0 | function ); |
3956 | |
|
3957 | 0 | return( -1 ); |
3958 | 0 | } |
3959 | 0 | result = 1; |
3960 | 0 | } |
3961 | 0 | } |
3962 | 0 | return( result ); |
3963 | 0 | } |
3964 | | |
3965 | | /* Copies the value data to an UTF-8 encoded string |
3966 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
3967 | | */ |
3968 | | int libfvalue_value_copy_to_utf8_string( |
3969 | | libfvalue_value_t *value, |
3970 | | int value_entry_index, |
3971 | | uint8_t *utf8_string, |
3972 | | size_t utf8_string_size, |
3973 | | libcerror_error_t **error ) |
3974 | 0 | { |
3975 | 0 | static char *function = "libfvalue_value_copy_to_utf8_string"; |
3976 | 0 | size_t utf8_string_index = 0; |
3977 | 0 | int result = 0; |
3978 | |
|
3979 | 0 | result = libfvalue_value_copy_to_utf8_string_with_index( |
3980 | 0 | value, |
3981 | 0 | value_entry_index, |
3982 | 0 | utf8_string, |
3983 | 0 | utf8_string_size, |
3984 | 0 | &utf8_string_index, |
3985 | 0 | error ); |
3986 | |
|
3987 | 0 | if( result == -1 ) |
3988 | 0 | { |
3989 | 0 | libcerror_error_set( |
3990 | 0 | error, |
3991 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3992 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
3993 | 0 | "%s: unable to copy value: %d to UTF-8 string.", |
3994 | 0 | function, |
3995 | 0 | value_entry_index ); |
3996 | |
|
3997 | 0 | return( -1 ); |
3998 | 0 | } |
3999 | 0 | return( result ); |
4000 | 0 | } |
4001 | | |
4002 | | /* Copies the value data to an UTF-8 encoded string |
4003 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4004 | | */ |
4005 | | int libfvalue_value_copy_to_utf8_string_with_index( |
4006 | | libfvalue_value_t *value, |
4007 | | int value_entry_index, |
4008 | | uint8_t *utf8_string, |
4009 | | size_t utf8_string_size, |
4010 | | size_t *utf8_string_index, |
4011 | | libcerror_error_t **error ) |
4012 | 0 | { |
4013 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4014 | 0 | intptr_t *value_instance = NULL; |
4015 | 0 | static char *function = "libfvalue_value_copy_to_utf8_string_with_index"; |
4016 | 0 | int result = 0; |
4017 | |
|
4018 | 0 | if( value == NULL ) |
4019 | 0 | { |
4020 | 0 | libcerror_error_set( |
4021 | 0 | error, |
4022 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4023 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4024 | 0 | "%s: invalid value.", |
4025 | 0 | function ); |
4026 | |
|
4027 | 0 | return( -1 ); |
4028 | 0 | } |
4029 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4030 | |
|
4031 | 0 | if( internal_value->copy_to_utf8_string_with_index != NULL ) |
4032 | 0 | { |
4033 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4034 | 0 | value, |
4035 | 0 | value_entry_index, |
4036 | 0 | &value_instance, |
4037 | 0 | error ) != 1 ) |
4038 | 0 | { |
4039 | 0 | libcerror_error_set( |
4040 | 0 | error, |
4041 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4042 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4043 | 0 | "%s: unable to retrieve value instance: %d.", |
4044 | 0 | function, |
4045 | 0 | value_entry_index ); |
4046 | |
|
4047 | 0 | return( -1 ); |
4048 | 0 | } |
4049 | 0 | if( value_instance != NULL ) |
4050 | 0 | { |
4051 | 0 | if( internal_value->copy_to_utf8_string_with_index( |
4052 | 0 | value_instance, |
4053 | 0 | utf8_string, |
4054 | 0 | utf8_string_size, |
4055 | 0 | utf8_string_index, |
4056 | 0 | internal_value->format_flags, |
4057 | 0 | error ) != 1 ) |
4058 | 0 | { |
4059 | 0 | libcerror_error_set( |
4060 | 0 | error, |
4061 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4062 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4063 | 0 | "%s: unable to copy instance to UTF-8 string.", |
4064 | 0 | function ); |
4065 | |
|
4066 | 0 | return( -1 ); |
4067 | 0 | } |
4068 | 0 | result = 1; |
4069 | 0 | } |
4070 | 0 | } |
4071 | 0 | return( result ); |
4072 | 0 | } |
4073 | | |
4074 | | /* Copies the value data from an UTF-16 encoded string |
4075 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4076 | | */ |
4077 | | int libfvalue_value_copy_from_utf16_string( |
4078 | | libfvalue_value_t *value, |
4079 | | int value_entry_index, |
4080 | | const uint16_t *utf16_string, |
4081 | | size_t utf16_string_length, |
4082 | | libcerror_error_t **error ) |
4083 | 0 | { |
4084 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4085 | 0 | intptr_t *value_instance = NULL; |
4086 | 0 | static char *function = "libfvalue_value_copy_from_utf16_string"; |
4087 | 0 | size_t utf16_string_index = 0; |
4088 | 0 | int result = 0; |
4089 | |
|
4090 | 0 | if( value == NULL ) |
4091 | 0 | { |
4092 | 0 | libcerror_error_set( |
4093 | 0 | error, |
4094 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4095 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4096 | 0 | "%s: invalid value.", |
4097 | 0 | function ); |
4098 | |
|
4099 | 0 | return( -1 ); |
4100 | 0 | } |
4101 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4102 | |
|
4103 | 0 | if( internal_value->initialize_instance == NULL ) |
4104 | 0 | { |
4105 | 0 | libcerror_error_set( |
4106 | 0 | error, |
4107 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4108 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4109 | 0 | "%s: invalid value - missing initialize instance function.", |
4110 | 0 | function ); |
4111 | |
|
4112 | 0 | return( -1 ); |
4113 | 0 | } |
4114 | 0 | if( internal_value->free_instance == NULL ) |
4115 | 0 | { |
4116 | 0 | libcerror_error_set( |
4117 | 0 | error, |
4118 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4119 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4120 | 0 | "%s: invalid value - missing free instance function.", |
4121 | 0 | function ); |
4122 | |
|
4123 | 0 | return( -1 ); |
4124 | 0 | } |
4125 | 0 | if( internal_value->copy_from_utf16_string_with_index != NULL ) |
4126 | 0 | { |
4127 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4128 | 0 | value, |
4129 | 0 | value_entry_index, |
4130 | 0 | &value_instance, |
4131 | 0 | error ) != 1 ) |
4132 | 0 | { |
4133 | 0 | libcerror_error_set( |
4134 | 0 | error, |
4135 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4136 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4137 | 0 | "%s: unable to retrieve value instance: %d.", |
4138 | 0 | function, |
4139 | 0 | value_entry_index ); |
4140 | |
|
4141 | 0 | return( -1 ); |
4142 | 0 | } |
4143 | 0 | if( value_instance == NULL ) |
4144 | 0 | { |
4145 | 0 | if( internal_value->initialize_instance( |
4146 | 0 | &value_instance, |
4147 | 0 | error ) != 1 ) |
4148 | 0 | { |
4149 | 0 | libcerror_error_set( |
4150 | 0 | error, |
4151 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4152 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4153 | 0 | "%s: unable to create value instance.", |
4154 | 0 | function ); |
4155 | |
|
4156 | 0 | return( -1 ); |
4157 | 0 | } |
4158 | 0 | if( libcdata_array_set_entry_by_index( |
4159 | 0 | internal_value->value_instances, |
4160 | 0 | value_entry_index, |
4161 | 0 | value_instance, |
4162 | 0 | error ) != 1 ) |
4163 | 0 | { |
4164 | 0 | libcerror_error_set( |
4165 | 0 | error, |
4166 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4167 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4168 | 0 | "%s: unable to set entry: %d in values instances array.", |
4169 | 0 | function, |
4170 | 0 | value_entry_index ); |
4171 | |
|
4172 | 0 | internal_value->free_instance( |
4173 | 0 | &value_instance, |
4174 | 0 | NULL ); |
4175 | |
|
4176 | 0 | return( -1 ); |
4177 | 0 | } |
4178 | 0 | } |
4179 | 0 | if( internal_value->copy_from_utf16_string_with_index( |
4180 | 0 | value_instance, |
4181 | 0 | utf16_string, |
4182 | 0 | utf16_string_length, |
4183 | 0 | &utf16_string_index, |
4184 | 0 | internal_value->format_flags, |
4185 | 0 | error ) != 1 ) |
4186 | 0 | { |
4187 | 0 | libcerror_error_set( |
4188 | 0 | error, |
4189 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4190 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4191 | 0 | "%s: unable to copy instance from UTF-16 string.", |
4192 | 0 | function ); |
4193 | |
|
4194 | 0 | return( -1 ); |
4195 | 0 | } |
4196 | 0 | result = 1; |
4197 | 0 | } |
4198 | 0 | return( result ); |
4199 | 0 | } |
4200 | | |
4201 | | /* Retrieves the size of an UTF-16 encoded string of the value data |
4202 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4203 | | */ |
4204 | | int libfvalue_value_get_utf16_string_size( |
4205 | | libfvalue_value_t *value, |
4206 | | int value_entry_index, |
4207 | | size_t *utf16_string_size, |
4208 | | libcerror_error_t **error ) |
4209 | 0 | { |
4210 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4211 | 0 | intptr_t *value_instance = NULL; |
4212 | 0 | static char *function = "libfvalue_value_get_utf16_string_size"; |
4213 | 0 | int result = 0; |
4214 | |
|
4215 | 0 | if( value == NULL ) |
4216 | 0 | { |
4217 | 0 | libcerror_error_set( |
4218 | 0 | error, |
4219 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4220 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4221 | 0 | "%s: invalid value.", |
4222 | 0 | function ); |
4223 | |
|
4224 | 0 | return( -1 ); |
4225 | 0 | } |
4226 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4227 | |
|
4228 | 0 | if( internal_value->get_utf16_string_size != NULL ) |
4229 | 0 | { |
4230 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4231 | 0 | value, |
4232 | 0 | value_entry_index, |
4233 | 0 | &value_instance, |
4234 | 0 | error ) != 1 ) |
4235 | 0 | { |
4236 | 0 | libcerror_error_set( |
4237 | 0 | error, |
4238 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4239 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4240 | 0 | "%s: unable to retrieve value instance: %d.", |
4241 | 0 | function, |
4242 | 0 | value_entry_index ); |
4243 | |
|
4244 | 0 | return( -1 ); |
4245 | 0 | } |
4246 | 0 | if( value_instance != NULL ) |
4247 | 0 | { |
4248 | 0 | if( internal_value->get_utf16_string_size( |
4249 | 0 | value_instance, |
4250 | 0 | utf16_string_size, |
4251 | 0 | internal_value->format_flags, |
4252 | 0 | error ) != 1 ) |
4253 | 0 | { |
4254 | 0 | libcerror_error_set( |
4255 | 0 | error, |
4256 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4257 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4258 | 0 | "%s: unable to determine size UTF-16 string of instance.", |
4259 | 0 | function ); |
4260 | |
|
4261 | 0 | return( -1 ); |
4262 | 0 | } |
4263 | 0 | result = 1; |
4264 | 0 | } |
4265 | 0 | } |
4266 | 0 | return( result ); |
4267 | 0 | } |
4268 | | |
4269 | | /* Copies the value data to an UTF-16 encoded string |
4270 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4271 | | */ |
4272 | | int libfvalue_value_copy_to_utf16_string( |
4273 | | libfvalue_value_t *value, |
4274 | | int value_entry_index, |
4275 | | uint16_t *utf16_string, |
4276 | | size_t utf16_string_size, |
4277 | | libcerror_error_t **error ) |
4278 | 0 | { |
4279 | 0 | static char *function = "libfvalue_value_copy_to_utf16_string"; |
4280 | 0 | size_t utf16_string_index = 0; |
4281 | 0 | int result = 0; |
4282 | |
|
4283 | 0 | result = libfvalue_value_copy_to_utf16_string_with_index( |
4284 | 0 | value, |
4285 | 0 | value_entry_index, |
4286 | 0 | utf16_string, |
4287 | 0 | utf16_string_size, |
4288 | 0 | &utf16_string_index, |
4289 | 0 | error ); |
4290 | |
|
4291 | 0 | if( result == -1 ) |
4292 | 0 | { |
4293 | 0 | libcerror_error_set( |
4294 | 0 | error, |
4295 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4296 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4297 | 0 | "%s: unable to copy value: %d to UTF-16 string.", |
4298 | 0 | function, |
4299 | 0 | value_entry_index ); |
4300 | |
|
4301 | 0 | return( -1 ); |
4302 | 0 | } |
4303 | 0 | return( result ); |
4304 | 0 | } |
4305 | | |
4306 | | /* Copies the value data to an UTF-16 encoded string |
4307 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4308 | | */ |
4309 | | int libfvalue_value_copy_to_utf16_string_with_index( |
4310 | | libfvalue_value_t *value, |
4311 | | int value_entry_index, |
4312 | | uint16_t *utf16_string, |
4313 | | size_t utf16_string_size, |
4314 | | size_t *utf16_string_index, |
4315 | | libcerror_error_t **error ) |
4316 | 0 | { |
4317 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4318 | 0 | intptr_t *value_instance = NULL; |
4319 | 0 | static char *function = "libfvalue_value_copy_to_utf16_string_with_index"; |
4320 | 0 | int result = 0; |
4321 | |
|
4322 | 0 | if( value == NULL ) |
4323 | 0 | { |
4324 | 0 | libcerror_error_set( |
4325 | 0 | error, |
4326 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4327 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4328 | 0 | "%s: invalid value.", |
4329 | 0 | function ); |
4330 | |
|
4331 | 0 | return( -1 ); |
4332 | 0 | } |
4333 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4334 | |
|
4335 | 0 | if( internal_value->copy_to_utf16_string_with_index != NULL ) |
4336 | 0 | { |
4337 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4338 | 0 | value, |
4339 | 0 | value_entry_index, |
4340 | 0 | &value_instance, |
4341 | 0 | error ) != 1 ) |
4342 | 0 | { |
4343 | 0 | libcerror_error_set( |
4344 | 0 | error, |
4345 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4346 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4347 | 0 | "%s: unable to retrieve value instance: %d.", |
4348 | 0 | function, |
4349 | 0 | value_entry_index ); |
4350 | |
|
4351 | 0 | return( -1 ); |
4352 | 0 | } |
4353 | 0 | if( value_instance != NULL ) |
4354 | 0 | { |
4355 | 0 | if( internal_value->copy_to_utf16_string_with_index( |
4356 | 0 | value_instance, |
4357 | 0 | utf16_string, |
4358 | 0 | utf16_string_size, |
4359 | 0 | utf16_string_index, |
4360 | 0 | internal_value->format_flags, |
4361 | 0 | error ) != 1 ) |
4362 | 0 | { |
4363 | 0 | libcerror_error_set( |
4364 | 0 | error, |
4365 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4366 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4367 | 0 | "%s: unable to copy instance to UTF-16 string.", |
4368 | 0 | function ); |
4369 | |
|
4370 | 0 | return( -1 ); |
4371 | 0 | } |
4372 | 0 | result = 1; |
4373 | 0 | } |
4374 | 0 | } |
4375 | 0 | return( result ); |
4376 | 0 | } |
4377 | | |
4378 | | /* Copies the value data from an UTF-32 encoded string |
4379 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4380 | | */ |
4381 | | int libfvalue_value_copy_from_utf32_string( |
4382 | | libfvalue_value_t *value, |
4383 | | int value_entry_index, |
4384 | | const uint32_t *utf32_string, |
4385 | | size_t utf32_string_length, |
4386 | | libcerror_error_t **error ) |
4387 | 0 | { |
4388 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4389 | 0 | intptr_t *value_instance = NULL; |
4390 | 0 | static char *function = "libfvalue_value_copy_from_utf32_string"; |
4391 | 0 | size_t utf32_string_index = 0; |
4392 | 0 | int result = 0; |
4393 | |
|
4394 | 0 | if( value == NULL ) |
4395 | 0 | { |
4396 | 0 | libcerror_error_set( |
4397 | 0 | error, |
4398 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4399 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4400 | 0 | "%s: invalid value.", |
4401 | 0 | function ); |
4402 | |
|
4403 | 0 | return( -1 ); |
4404 | 0 | } |
4405 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4406 | |
|
4407 | 0 | if( internal_value->initialize_instance == NULL ) |
4408 | 0 | { |
4409 | 0 | libcerror_error_set( |
4410 | 0 | error, |
4411 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4412 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4413 | 0 | "%s: invalid value - missing initialize instance function.", |
4414 | 0 | function ); |
4415 | |
|
4416 | 0 | return( -1 ); |
4417 | 0 | } |
4418 | 0 | if( internal_value->free_instance == NULL ) |
4419 | 0 | { |
4420 | 0 | libcerror_error_set( |
4421 | 0 | error, |
4422 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4423 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4424 | 0 | "%s: invalid value - missing free instance function.", |
4425 | 0 | function ); |
4426 | |
|
4427 | 0 | return( -1 ); |
4428 | 0 | } |
4429 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4430 | |
|
4431 | 0 | if( internal_value->copy_from_utf32_string_with_index != NULL ) |
4432 | 0 | { |
4433 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4434 | 0 | value, |
4435 | 0 | value_entry_index, |
4436 | 0 | &value_instance, |
4437 | 0 | error ) != 1 ) |
4438 | 0 | { |
4439 | 0 | libcerror_error_set( |
4440 | 0 | error, |
4441 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4442 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4443 | 0 | "%s: unable to retrieve value instance: %d.", |
4444 | 0 | function, |
4445 | 0 | value_entry_index ); |
4446 | |
|
4447 | 0 | return( -1 ); |
4448 | 0 | } |
4449 | 0 | if( value_instance == NULL ) |
4450 | 0 | { |
4451 | 0 | if( internal_value->initialize_instance( |
4452 | 0 | &value_instance, |
4453 | 0 | error ) != 1 ) |
4454 | 0 | { |
4455 | 0 | libcerror_error_set( |
4456 | 0 | error, |
4457 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4458 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4459 | 0 | "%s: unable to create value instance.", |
4460 | 0 | function ); |
4461 | |
|
4462 | 0 | return( -1 ); |
4463 | 0 | } |
4464 | 0 | if( libcdata_array_set_entry_by_index( |
4465 | 0 | internal_value->value_instances, |
4466 | 0 | value_entry_index, |
4467 | 0 | value_instance, |
4468 | 0 | error ) != 1 ) |
4469 | 0 | { |
4470 | 0 | libcerror_error_set( |
4471 | 0 | error, |
4472 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4473 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4474 | 0 | "%s: unable to set entry: %d in values instances array.", |
4475 | 0 | function, |
4476 | 0 | value_entry_index ); |
4477 | |
|
4478 | 0 | internal_value->free_instance( |
4479 | 0 | &value_instance, |
4480 | 0 | NULL ); |
4481 | |
|
4482 | 0 | return( -1 ); |
4483 | 0 | } |
4484 | 0 | } |
4485 | 0 | if( internal_value->copy_from_utf32_string_with_index( |
4486 | 0 | value_instance, |
4487 | 0 | utf32_string, |
4488 | 0 | utf32_string_length, |
4489 | 0 | &utf32_string_index, |
4490 | 0 | internal_value->format_flags, |
4491 | 0 | error ) != 1 ) |
4492 | 0 | { |
4493 | 0 | libcerror_error_set( |
4494 | 0 | error, |
4495 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4496 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4497 | 0 | "%s: unable to copy instance from UTF-32 string.", |
4498 | 0 | function ); |
4499 | |
|
4500 | 0 | return( -1 ); |
4501 | 0 | } |
4502 | 0 | result = 1; |
4503 | 0 | } |
4504 | 0 | return( result ); |
4505 | 0 | } |
4506 | | |
4507 | | /* Retrieves the size of an UTF-32 encoded string of the value data |
4508 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4509 | | */ |
4510 | | int libfvalue_value_get_utf32_string_size( |
4511 | | libfvalue_value_t *value, |
4512 | | int value_entry_index, |
4513 | | size_t *utf32_string_size, |
4514 | | libcerror_error_t **error ) |
4515 | 0 | { |
4516 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4517 | 0 | intptr_t *value_instance = NULL; |
4518 | 0 | static char *function = "libfvalue_value_get_utf32_string_size"; |
4519 | 0 | int result = 0; |
4520 | |
|
4521 | 0 | if( value == NULL ) |
4522 | 0 | { |
4523 | 0 | libcerror_error_set( |
4524 | 0 | error, |
4525 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4526 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4527 | 0 | "%s: invalid value.", |
4528 | 0 | function ); |
4529 | |
|
4530 | 0 | return( -1 ); |
4531 | 0 | } |
4532 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4533 | |
|
4534 | 0 | if( internal_value->get_utf32_string_size != NULL ) |
4535 | 0 | { |
4536 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4537 | 0 | value, |
4538 | 0 | value_entry_index, |
4539 | 0 | &value_instance, |
4540 | 0 | error ) != 1 ) |
4541 | 0 | { |
4542 | 0 | libcerror_error_set( |
4543 | 0 | error, |
4544 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4545 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4546 | 0 | "%s: unable to retrieve value instance: %d.", |
4547 | 0 | function, |
4548 | 0 | value_entry_index ); |
4549 | |
|
4550 | 0 | return( -1 ); |
4551 | 0 | } |
4552 | 0 | if( value_instance != NULL ) |
4553 | 0 | { |
4554 | 0 | if( internal_value->get_utf32_string_size( |
4555 | 0 | value_instance, |
4556 | 0 | utf32_string_size, |
4557 | 0 | internal_value->format_flags, |
4558 | 0 | error ) != 1 ) |
4559 | 0 | { |
4560 | 0 | libcerror_error_set( |
4561 | 0 | error, |
4562 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4563 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4564 | 0 | "%s: unable to determine size UTF-32 string of instance.", |
4565 | 0 | function ); |
4566 | |
|
4567 | 0 | return( -1 ); |
4568 | 0 | } |
4569 | 0 | result = 1; |
4570 | 0 | } |
4571 | 0 | } |
4572 | 0 | return( result ); |
4573 | 0 | } |
4574 | | |
4575 | | /* Copies the value data to an UTF-32 encoded string |
4576 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4577 | | */ |
4578 | | int libfvalue_value_copy_to_utf32_string( |
4579 | | libfvalue_value_t *value, |
4580 | | int value_entry_index, |
4581 | | uint32_t *utf32_string, |
4582 | | size_t utf32_string_size, |
4583 | | libcerror_error_t **error ) |
4584 | 0 | { |
4585 | 0 | static char *function = "libfvalue_value_copy_to_utf32_string"; |
4586 | 0 | size_t utf32_string_index = 0; |
4587 | 0 | int result = 0; |
4588 | |
|
4589 | 0 | result = libfvalue_value_copy_to_utf32_string_with_index( |
4590 | 0 | value, |
4591 | 0 | value_entry_index, |
4592 | 0 | utf32_string, |
4593 | 0 | utf32_string_size, |
4594 | 0 | &utf32_string_index, |
4595 | 0 | error ); |
4596 | |
|
4597 | 0 | if( result == -1 ) |
4598 | 0 | { |
4599 | 0 | libcerror_error_set( |
4600 | 0 | error, |
4601 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4602 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4603 | 0 | "%s: unable to copy value: %d to UTF-32 string.", |
4604 | 0 | function, |
4605 | 0 | value_entry_index ); |
4606 | |
|
4607 | 0 | return( -1 ); |
4608 | 0 | } |
4609 | 0 | return( result ); |
4610 | 0 | } |
4611 | | |
4612 | | /* Copies the value data to an UTF-32 encoded string |
4613 | | * Returns 1 if successful, 0 if value could not be set or -1 on error |
4614 | | */ |
4615 | | int libfvalue_value_copy_to_utf32_string_with_index( |
4616 | | libfvalue_value_t *value, |
4617 | | int value_entry_index, |
4618 | | uint32_t *utf32_string, |
4619 | | size_t utf32_string_size, |
4620 | | size_t *utf32_string_index, |
4621 | | libcerror_error_t **error ) |
4622 | 0 | { |
4623 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4624 | 0 | intptr_t *value_instance = NULL; |
4625 | 0 | static char *function = "libfvalue_value_copy_to_utf32_string_with_index"; |
4626 | 0 | int result = 0; |
4627 | |
|
4628 | 0 | if( value == NULL ) |
4629 | 0 | { |
4630 | 0 | libcerror_error_set( |
4631 | 0 | error, |
4632 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4633 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4634 | 0 | "%s: invalid value.", |
4635 | 0 | function ); |
4636 | |
|
4637 | 0 | return( -1 ); |
4638 | 0 | } |
4639 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4640 | |
|
4641 | 0 | if( internal_value->copy_to_utf32_string_with_index != NULL ) |
4642 | 0 | { |
4643 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4644 | 0 | value, |
4645 | 0 | value_entry_index, |
4646 | 0 | &value_instance, |
4647 | 0 | error ) != 1 ) |
4648 | 0 | { |
4649 | 0 | libcerror_error_set( |
4650 | 0 | error, |
4651 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4652 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4653 | 0 | "%s: unable to retrieve value instance: %d.", |
4654 | 0 | function, |
4655 | 0 | value_entry_index ); |
4656 | |
|
4657 | 0 | return( -1 ); |
4658 | 0 | } |
4659 | 0 | if( value_instance != NULL ) |
4660 | 0 | { |
4661 | 0 | if( internal_value->copy_to_utf32_string_with_index( |
4662 | 0 | value_instance, |
4663 | 0 | utf32_string, |
4664 | 0 | utf32_string_size, |
4665 | 0 | utf32_string_index, |
4666 | 0 | internal_value->format_flags, |
4667 | 0 | error ) != 1 ) |
4668 | 0 | { |
4669 | 0 | libcerror_error_set( |
4670 | 0 | error, |
4671 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4672 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4673 | 0 | "%s: unable to copy instance to UTF-32 string.", |
4674 | 0 | function ); |
4675 | |
|
4676 | 0 | return( -1 ); |
4677 | 0 | } |
4678 | 0 | result = 1; |
4679 | 0 | } |
4680 | 0 | } |
4681 | 0 | return( result ); |
4682 | 0 | } |
4683 | | |
4684 | | /* Marshalling functions |
4685 | | */ |
4686 | | |
4687 | | #ifdef TODO |
4688 | | |
4689 | | /* Reads the value data from a file stream |
4690 | | * Returns the number of bytes read or -1 on error |
4691 | | */ |
4692 | | ssize_t libfvalue_value_read_from_file_stream( |
4693 | | libfvalue_value_t *value, |
4694 | | FILE *file_stream, |
4695 | | libcerror_error_t **error ) |
4696 | | { |
4697 | | libfvalue_internal_value_t *internal_value = NULL; |
4698 | | static char *function = "libfvalue_value_read_from_file_stream"; |
4699 | | |
4700 | | if( value == NULL ) |
4701 | | { |
4702 | | libcerror_error_set( |
4703 | | error, |
4704 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4705 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4706 | | "%s: invalid value.", |
4707 | | function ); |
4708 | | |
4709 | | return( -1 ); |
4710 | | } |
4711 | | internal_value = (libfvalue_internal_value_t *) value; |
4712 | | |
4713 | | if( internal_value->copy_from_utf8_string_with_index == NULL ) |
4714 | | { |
4715 | | libcerror_error_set( |
4716 | | error, |
4717 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4718 | | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4719 | | "%s: invalid value - missing copy from UTF-8 string function.", |
4720 | | function ); |
4721 | | |
4722 | | return( -1 ); |
4723 | | } |
4724 | | if( file_stream == NULL ) |
4725 | | { |
4726 | | libcerror_error_set( |
4727 | | error, |
4728 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4729 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4730 | | "%s: invalid file stream.", |
4731 | | function ); |
4732 | | |
4733 | | return( -1 ); |
4734 | | } |
4735 | | /* TODO implement function */ |
4736 | | return( -1 ); |
4737 | | } |
4738 | | |
4739 | | #endif /* TODO */ |
4740 | | |
4741 | | /* Writes the value data to a file stream |
4742 | | * Returns the number of bytes written or -1 on error |
4743 | | */ |
4744 | | ssize_t libfvalue_value_write_to_file_stream( |
4745 | | libfvalue_value_t *value, |
4746 | | FILE *file_stream, |
4747 | | libcerror_error_t **error ) |
4748 | 0 | { |
4749 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
4750 | 0 | intptr_t *value_instance = NULL; |
4751 | 0 | uint8_t *value_string = NULL; |
4752 | 0 | static char *function = "libfvalue_value_write_to_file_stream"; |
4753 | 0 | size_t value_string_index = 0; |
4754 | 0 | size_t value_string_size = 0; |
4755 | 0 | ssize_t write_count = 0; |
4756 | 0 | int print_count = 0; |
4757 | 0 | int number_of_value_entries = 0; |
4758 | 0 | int value_entry_index = 0; |
4759 | |
|
4760 | 0 | if( value == NULL ) |
4761 | 0 | { |
4762 | 0 | libcerror_error_set( |
4763 | 0 | error, |
4764 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4765 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4766 | 0 | "%s: invalid value.", |
4767 | 0 | function ); |
4768 | |
|
4769 | 0 | return( -1 ); |
4770 | 0 | } |
4771 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
4772 | |
|
4773 | 0 | if( internal_value->type_string == NULL ) |
4774 | 0 | { |
4775 | 0 | libcerror_error_set( |
4776 | 0 | error, |
4777 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4778 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4779 | 0 | "%s: invalid value - missing type string.", |
4780 | 0 | function ); |
4781 | |
|
4782 | 0 | return( -1 ); |
4783 | 0 | } |
4784 | 0 | if( ( internal_value->identifier == NULL ) |
4785 | 0 | || ( internal_value->identifier[ 0 ] == 0 ) ) |
4786 | 0 | { |
4787 | 0 | libcerror_error_set( |
4788 | 0 | error, |
4789 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4790 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4791 | 0 | "%s: invalid value - missing identifier.", |
4792 | 0 | function ); |
4793 | |
|
4794 | 0 | return( -1 ); |
4795 | 0 | } |
4796 | 0 | if( internal_value->get_utf8_string_size == NULL ) |
4797 | 0 | { |
4798 | 0 | libcerror_error_set( |
4799 | 0 | error, |
4800 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4801 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4802 | 0 | "%s: invalid value - missing get UTF-8 string size function.", |
4803 | 0 | function ); |
4804 | |
|
4805 | 0 | return( -1 ); |
4806 | 0 | } |
4807 | 0 | if( internal_value->copy_to_utf8_string_with_index == NULL ) |
4808 | 0 | { |
4809 | 0 | libcerror_error_set( |
4810 | 0 | error, |
4811 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4812 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4813 | 0 | "%s: invalid value - missing copy to UTF-8 string function.", |
4814 | 0 | function ); |
4815 | |
|
4816 | 0 | return( -1 ); |
4817 | 0 | } |
4818 | 0 | if( file_stream == NULL ) |
4819 | 0 | { |
4820 | 0 | libcerror_error_set( |
4821 | 0 | error, |
4822 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4823 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4824 | 0 | "%s: invalid file stream.", |
4825 | 0 | function ); |
4826 | |
|
4827 | 0 | return( -1 ); |
4828 | 0 | } |
4829 | 0 | if( libfvalue_value_get_number_of_value_entries( |
4830 | 0 | value, |
4831 | 0 | &number_of_value_entries, |
4832 | 0 | error ) != 1 ) |
4833 | 0 | { |
4834 | 0 | libcerror_error_set( |
4835 | 0 | error, |
4836 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4837 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4838 | 0 | "%s: unable to retrieve number of value entries.", |
4839 | 0 | function ); |
4840 | |
|
4841 | 0 | goto on_error; |
4842 | 0 | } |
4843 | 0 | for( value_entry_index = 0; |
4844 | 0 | value_entry_index < number_of_value_entries; |
4845 | 0 | value_entry_index++ ) |
4846 | 0 | { |
4847 | 0 | if( libfvalue_value_get_value_instance_by_index( |
4848 | 0 | value, |
4849 | 0 | value_entry_index, |
4850 | 0 | &value_instance, |
4851 | 0 | error ) != 1 ) |
4852 | 0 | { |
4853 | 0 | libcerror_error_set( |
4854 | 0 | error, |
4855 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4856 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4857 | 0 | "%s: unable to retrieve value instance: %d.", |
4858 | 0 | function, |
4859 | 0 | value_entry_index ); |
4860 | |
|
4861 | 0 | goto on_error; |
4862 | 0 | } |
4863 | 0 | print_count = fprintf( |
4864 | 0 | file_stream, |
4865 | 0 | "<%s type=\"%s\">", |
4866 | 0 | (char *) internal_value->identifier, |
4867 | 0 | internal_value->type_string ); |
4868 | |
|
4869 | 0 | if( print_count < 0 ) |
4870 | 0 | { |
4871 | 0 | libcerror_error_set( |
4872 | 0 | error, |
4873 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4874 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
4875 | 0 | "%s: unable to write to file stream.", |
4876 | 0 | function ); |
4877 | |
|
4878 | 0 | goto on_error; |
4879 | 0 | } |
4880 | 0 | write_count += print_count; |
4881 | |
|
4882 | 0 | if( number_of_value_entries > 1 ) |
4883 | 0 | { |
4884 | 0 | print_count = fprintf( |
4885 | 0 | file_stream, |
4886 | 0 | "<value_entry>" ); |
4887 | |
|
4888 | 0 | if( print_count < 0 ) |
4889 | 0 | { |
4890 | 0 | libcerror_error_set( |
4891 | 0 | error, |
4892 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4893 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
4894 | 0 | "%s: unable to write to file stream.", |
4895 | 0 | function ); |
4896 | |
|
4897 | 0 | goto on_error; |
4898 | 0 | } |
4899 | 0 | write_count += print_count; |
4900 | 0 | } |
4901 | 0 | if( value_instance != NULL ) |
4902 | 0 | { |
4903 | 0 | if( internal_value->get_utf8_string_size( |
4904 | 0 | value_instance, |
4905 | 0 | &value_string_size, |
4906 | 0 | internal_value->format_flags, |
4907 | 0 | error ) != 1 ) |
4908 | 0 | { |
4909 | 0 | libcerror_error_set( |
4910 | 0 | error, |
4911 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4912 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4913 | 0 | "%s: unable to determine size UTF-8 string of instance.", |
4914 | 0 | function ); |
4915 | |
|
4916 | 0 | goto on_error; |
4917 | 0 | } |
4918 | 0 | if( value_string_size > 0 ) |
4919 | 0 | { |
4920 | 0 | value_string = (uint8_t *) memory_allocate( |
4921 | 0 | sizeof( uint8_t ) * value_string_size ); |
4922 | |
|
4923 | 0 | if( value_string == NULL ) |
4924 | 0 | { |
4925 | 0 | libcerror_error_set( |
4926 | 0 | error, |
4927 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
4928 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
4929 | 0 | "%s: unable to value string.", |
4930 | 0 | function ); |
4931 | |
|
4932 | 0 | goto on_error; |
4933 | 0 | } |
4934 | 0 | if( internal_value->copy_to_utf8_string_with_index( |
4935 | 0 | value_instance, |
4936 | 0 | value_string, |
4937 | 0 | value_string_size, |
4938 | 0 | &value_string_index, |
4939 | 0 | internal_value->format_flags, |
4940 | 0 | error ) != 1 ) |
4941 | 0 | { |
4942 | 0 | libcerror_error_set( |
4943 | 0 | error, |
4944 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4945 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
4946 | 0 | "%s: unable to copy instance to UTF-8 string.", |
4947 | 0 | function ); |
4948 | |
|
4949 | 0 | goto on_error; |
4950 | 0 | } |
4951 | 0 | print_count = fprintf( |
4952 | 0 | file_stream, |
4953 | 0 | "%s", |
4954 | 0 | value_string ); |
4955 | |
|
4956 | 0 | if( print_count < 0 ) |
4957 | 0 | { |
4958 | 0 | libcerror_error_set( |
4959 | 0 | error, |
4960 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4961 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
4962 | 0 | "%s: unable to write to file stream.", |
4963 | 0 | function ); |
4964 | |
|
4965 | 0 | goto on_error; |
4966 | 0 | } |
4967 | 0 | write_count += print_count; |
4968 | |
|
4969 | 0 | memory_free( |
4970 | 0 | value_string ); |
4971 | |
|
4972 | 0 | value_string = NULL; |
4973 | 0 | } |
4974 | 0 | } |
4975 | 0 | if( number_of_value_entries > 1 ) |
4976 | 0 | { |
4977 | 0 | print_count = fprintf( |
4978 | 0 | file_stream, |
4979 | 0 | "</value_entry>" ); |
4980 | |
|
4981 | 0 | if( print_count < 0 ) |
4982 | 0 | { |
4983 | 0 | libcerror_error_set( |
4984 | 0 | error, |
4985 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4986 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
4987 | 0 | "%s: unable to write to file stream.", |
4988 | 0 | function ); |
4989 | |
|
4990 | 0 | goto on_error; |
4991 | 0 | } |
4992 | 0 | write_count += print_count; |
4993 | 0 | } |
4994 | 0 | print_count = fprintf( |
4995 | 0 | file_stream, |
4996 | 0 | "</%s>", |
4997 | 0 | (char *) internal_value->identifier ); |
4998 | |
|
4999 | 0 | if( print_count < 0 ) |
5000 | 0 | { |
5001 | 0 | libcerror_error_set( |
5002 | 0 | error, |
5003 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5004 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
5005 | 0 | "%s: unable to write to file stream.", |
5006 | 0 | function ); |
5007 | |
|
5008 | 0 | goto on_error; |
5009 | 0 | } |
5010 | 0 | write_count += print_count; |
5011 | 0 | } |
5012 | 0 | return( write_count ); |
5013 | | |
5014 | 0 | on_error: |
5015 | 0 | if( value_string != NULL ) |
5016 | 0 | { |
5017 | 0 | memory_free( |
5018 | 0 | value_string ); |
5019 | 0 | } |
5020 | 0 | return( -1 ); |
5021 | 0 | } |
5022 | | |
5023 | | /* Prints the value |
5024 | | * Returns 1 if successful or -1 on error |
5025 | | */ |
5026 | | int libfvalue_value_print( |
5027 | | libfvalue_value_t *value, |
5028 | | int value_entry_index, |
5029 | | uint8_t flags, |
5030 | | libcerror_error_t **error ) |
5031 | 0 | { |
5032 | 0 | libfvalue_internal_value_t *internal_value = NULL; |
5033 | 0 | system_character_t *value_string = NULL; |
5034 | 0 | intptr_t *value_instance = NULL; |
5035 | 0 | static char *function = "libfvalue_value_print"; |
5036 | 0 | size_t value_string_index = 0; |
5037 | 0 | size_t value_string_size = 0; |
5038 | 0 | int result = 0; |
5039 | |
|
5040 | 0 | if( value == NULL ) |
5041 | 0 | { |
5042 | 0 | libcerror_error_set( |
5043 | 0 | error, |
5044 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5045 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5046 | 0 | "%s: invalid value.", |
5047 | 0 | function ); |
5048 | |
|
5049 | 0 | return( -1 ); |
5050 | 0 | } |
5051 | 0 | internal_value = (libfvalue_internal_value_t *) value; |
5052 | |
|
5053 | 0 | if( internal_value->type_description == NULL ) |
5054 | 0 | { |
5055 | 0 | libcerror_error_set( |
5056 | 0 | error, |
5057 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5058 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5059 | 0 | "%s: invalid value - missing type description.", |
5060 | 0 | function ); |
5061 | |
|
5062 | 0 | return( -1 ); |
5063 | 0 | } |
5064 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
5065 | | if( internal_value->get_utf16_string_size == NULL ) |
5066 | | #else |
5067 | 0 | if( internal_value->get_utf8_string_size == NULL ) |
5068 | 0 | #endif |
5069 | 0 | { |
5070 | 0 | libcerror_error_set( |
5071 | 0 | error, |
5072 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5073 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5074 | 0 | "%s: invalid value - missing get string size function.", |
5075 | 0 | function ); |
5076 | |
|
5077 | 0 | return( -1 ); |
5078 | 0 | } |
5079 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
5080 | | if( internal_value->copy_to_utf16_string_with_index == NULL ) |
5081 | | #else |
5082 | 0 | if( internal_value->copy_to_utf8_string_with_index == NULL ) |
5083 | 0 | #endif |
5084 | 0 | { |
5085 | 0 | libcerror_error_set( |
5086 | 0 | error, |
5087 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5088 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5089 | 0 | "%s: invalid value - missing copy to string function.", |
5090 | 0 | function ); |
5091 | |
|
5092 | 0 | return( -1 ); |
5093 | 0 | } |
5094 | 0 | if( ( flags & ~( LIBFVALUE_PRINT_FLAG_WITH_TYPE_DESCRIPTION ) ) != 0 ) |
5095 | 0 | { |
5096 | 0 | libcerror_error_set( |
5097 | 0 | error, |
5098 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5099 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
5100 | 0 | "%s: unsupported flags: 0x%02" PRIx8 ".", |
5101 | 0 | function, |
5102 | 0 | flags ); |
5103 | |
|
5104 | 0 | return( -1 ); |
5105 | 0 | } |
5106 | 0 | if( ( flags & LIBFVALUE_PRINT_FLAG_WITH_TYPE_DESCRIPTION ) != 0 ) |
5107 | 0 | { |
5108 | 0 | libcnotify_printf( |
5109 | 0 | "%s\t: ", |
5110 | 0 | internal_value->type_description ); |
5111 | 0 | } |
5112 | 0 | result = libfvalue_value_has_data( |
5113 | 0 | value, |
5114 | 0 | error ); |
5115 | |
|
5116 | 0 | if( result == -1 ) |
5117 | 0 | { |
5118 | 0 | libcerror_error_set( |
5119 | 0 | error, |
5120 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5121 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5122 | 0 | "%s: unable to determine if value has data.", |
5123 | 0 | function ); |
5124 | |
|
5125 | 0 | goto on_error; |
5126 | 0 | } |
5127 | 0 | else if( result != 0 ) |
5128 | 0 | { |
5129 | 0 | if( libfvalue_value_get_value_instance_by_index( |
5130 | 0 | value, |
5131 | 0 | value_entry_index, |
5132 | 0 | &value_instance, |
5133 | 0 | error ) != 1 ) |
5134 | 0 | { |
5135 | 0 | libcerror_error_set( |
5136 | 0 | error, |
5137 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5138 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5139 | 0 | "%s: unable to retrieve value instance: %d.", |
5140 | 0 | function, |
5141 | 0 | value_entry_index ); |
5142 | |
|
5143 | 0 | goto on_error; |
5144 | 0 | } |
5145 | 0 | if( value_instance != NULL ) |
5146 | 0 | { |
5147 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
5148 | | result = internal_value->get_utf16_string_size( |
5149 | | value_instance, |
5150 | | &value_string_size, |
5151 | | internal_value->format_flags, |
5152 | | error ); |
5153 | | #else |
5154 | 0 | result = internal_value->get_utf8_string_size( |
5155 | 0 | value_instance, |
5156 | 0 | &value_string_size, |
5157 | 0 | internal_value->format_flags, |
5158 | 0 | error ); |
5159 | 0 | #endif |
5160 | 0 | if( result != 1 ) |
5161 | 0 | { |
5162 | 0 | libcerror_error_set( |
5163 | 0 | error, |
5164 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5165 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5166 | 0 | "%s: unable to determine size value string of instance.", |
5167 | 0 | function ); |
5168 | |
|
5169 | 0 | goto on_error; |
5170 | 0 | } |
5171 | 0 | if( value_string_size > 0 ) |
5172 | 0 | { |
5173 | 0 | value_string = system_string_allocate( |
5174 | 0 | value_string_size ); |
5175 | |
|
5176 | 0 | if( value_string == NULL ) |
5177 | 0 | { |
5178 | 0 | libcerror_error_set( |
5179 | 0 | error, |
5180 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
5181 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
5182 | 0 | "%s: unable to value string.", |
5183 | 0 | function ); |
5184 | |
|
5185 | 0 | goto on_error; |
5186 | 0 | } |
5187 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
5188 | | result = internal_value->copy_to_utf16_string_with_index( |
5189 | | value_instance, |
5190 | | (uint16_t *) value_string, |
5191 | | value_string_size, |
5192 | | &value_string_index, |
5193 | | internal_value->format_flags, |
5194 | | error ); |
5195 | | #else |
5196 | 0 | result = internal_value->copy_to_utf8_string_with_index( |
5197 | 0 | value_instance, |
5198 | 0 | (uint8_t *) value_string, |
5199 | 0 | value_string_size, |
5200 | 0 | &value_string_index, |
5201 | 0 | internal_value->format_flags, |
5202 | 0 | error ); |
5203 | 0 | #endif |
5204 | 0 | if( result != 1 ) |
5205 | 0 | { |
5206 | 0 | libcerror_error_set( |
5207 | 0 | error, |
5208 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5209 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
5210 | 0 | "%s: unable to copy instance to value string.", |
5211 | 0 | function ); |
5212 | |
|
5213 | 0 | goto on_error; |
5214 | 0 | } |
5215 | 0 | libcnotify_printf( |
5216 | 0 | "%" PRIs_SYSTEM "", |
5217 | 0 | value_string ); |
5218 | |
|
5219 | 0 | memory_free( |
5220 | 0 | value_string ); |
5221 | |
|
5222 | 0 | value_string = NULL; |
5223 | 0 | } |
5224 | 0 | } |
5225 | 0 | } |
5226 | 0 | if( ( flags & LIBFVALUE_PRINT_FLAG_WITH_TYPE_DESCRIPTION ) != 0 ) |
5227 | 0 | { |
5228 | 0 | libcnotify_printf( |
5229 | 0 | "\n\n" ); |
5230 | 0 | } |
5231 | 0 | return( 1 ); |
5232 | | |
5233 | 0 | on_error: |
5234 | 0 | if( value_string != NULL ) |
5235 | 0 | { |
5236 | 0 | memory_free( |
5237 | 0 | value_string ); |
5238 | 0 | } |
5239 | 0 | return( -1 ); |
5240 | 0 | } |
5241 | | |