/src/libpff/libpff/libpff_multi_value.c
Line | Count | Source |
1 | | /* |
2 | | * Multi value functions |
3 | | * |
4 | | * Copyright (C) 2008-2026, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libpff_definitions.h" |
27 | | #include "libpff_libcerror.h" |
28 | | #include "libpff_libfmapi.h" |
29 | | #include "libpff_mapi.h" |
30 | | #include "libpff_multi_value.h" |
31 | | #include "libpff_value_type.h" |
32 | | #include "libpff_types.h" |
33 | | |
34 | | /* Creates a multi value |
35 | | * Make sure the value multi_value is referencing, is set to NULL |
36 | | * Returns 1 if successful or -1 on error |
37 | | */ |
38 | | int libpff_multi_value_initialize( |
39 | | libpff_multi_value_t **multi_value, |
40 | | libcerror_error_t **error ) |
41 | 835 | { |
42 | 835 | libpff_internal_multi_value_t *internal_multi_value = NULL; |
43 | 835 | static char *function = "libpff_multi_value_initialize"; |
44 | | |
45 | 835 | if( multi_value == NULL ) |
46 | 0 | { |
47 | 0 | libcerror_error_set( |
48 | 0 | error, |
49 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
50 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
51 | 0 | "%s: invalid multi value.", |
52 | 0 | function ); |
53 | |
|
54 | 0 | return( -1 ); |
55 | 0 | } |
56 | 835 | if( *multi_value != NULL ) |
57 | 0 | { |
58 | 0 | libcerror_error_set( |
59 | 0 | error, |
60 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
61 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
62 | 0 | "%s: invalid multi value value already set.", |
63 | 0 | function ); |
64 | |
|
65 | 0 | return( -1 ); |
66 | 0 | } |
67 | 835 | internal_multi_value = memory_allocate_structure( |
68 | 835 | libpff_internal_multi_value_t ); |
69 | | |
70 | 835 | if( internal_multi_value == NULL ) |
71 | 0 | { |
72 | 0 | libcerror_error_set( |
73 | 0 | error, |
74 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
75 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
76 | 0 | "%s: unable to create multi value.", |
77 | 0 | function ); |
78 | |
|
79 | 0 | goto on_error; |
80 | 0 | } |
81 | 835 | if( memory_set( |
82 | 835 | internal_multi_value, |
83 | 835 | 0, |
84 | 835 | sizeof( libpff_internal_multi_value_t ) ) == NULL ) |
85 | 0 | { |
86 | 0 | libcerror_error_set( |
87 | 0 | error, |
88 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
89 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
90 | 0 | "%s: unable to clear multi value.", |
91 | 0 | function ); |
92 | |
|
93 | 0 | goto on_error; |
94 | 0 | } |
95 | 835 | *multi_value = (libpff_multi_value_t *) internal_multi_value; |
96 | | |
97 | 835 | return( 1 ); |
98 | | |
99 | 0 | on_error: |
100 | 0 | if( internal_multi_value != NULL ) |
101 | 0 | { |
102 | 0 | memory_free( |
103 | 0 | internal_multi_value ); |
104 | 0 | } |
105 | 0 | return( -1 ); |
106 | 835 | } |
107 | | |
108 | | /* Frees a multi value |
109 | | * Returns 1 if successful or -1 on error |
110 | | */ |
111 | | int libpff_multi_value_free( |
112 | | libpff_multi_value_t **multi_value, |
113 | | libcerror_error_t **error ) |
114 | 835 | { |
115 | 835 | static char *function = "libpff_multi_value_free"; |
116 | | |
117 | 835 | if( multi_value == NULL ) |
118 | 0 | { |
119 | 0 | libcerror_error_set( |
120 | 0 | error, |
121 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
122 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
123 | 0 | "%s: invalid multi value.", |
124 | 0 | function ); |
125 | |
|
126 | 0 | return( -1 ); |
127 | 0 | } |
128 | 835 | if( *multi_value != NULL ) |
129 | 835 | { |
130 | 835 | if( ( (libpff_internal_multi_value_t *) *multi_value )->value_data != NULL ) |
131 | 835 | { |
132 | 835 | memory_free( |
133 | 835 | ( (libpff_internal_multi_value_t *) *multi_value )->value_data ); |
134 | 835 | } |
135 | 835 | if( ( (libpff_internal_multi_value_t *) *multi_value )->value_offset != NULL ) |
136 | 546 | { |
137 | 546 | memory_free( |
138 | 546 | ( (libpff_internal_multi_value_t *) *multi_value )->value_offset ); |
139 | 546 | } |
140 | 835 | if( ( (libpff_internal_multi_value_t *) *multi_value )->value_size != NULL ) |
141 | 546 | { |
142 | 546 | memory_free( |
143 | 546 | ( (libpff_internal_multi_value_t *) *multi_value )->value_size ); |
144 | 546 | } |
145 | 835 | memory_free( |
146 | 835 | *multi_value ); |
147 | | |
148 | 835 | *multi_value = NULL; |
149 | 835 | } |
150 | 835 | return( 1 ); |
151 | 835 | } |
152 | | |
153 | | /* Retrieves the number of values of the multi value |
154 | | * Returns 1 if successful or -1 on error |
155 | | */ |
156 | | int libpff_multi_value_get_number_of_values( |
157 | | libpff_multi_value_t *multi_value, |
158 | | int *number_of_values, |
159 | | libcerror_error_t **error ) |
160 | 357 | { |
161 | 357 | libpff_internal_multi_value_t *internal_multi_value = NULL; |
162 | 357 | static char *function = "libpff_multi_value_get_number_of_entries"; |
163 | | |
164 | 357 | if( multi_value == NULL ) |
165 | 0 | { |
166 | 0 | libcerror_error_set( |
167 | 0 | error, |
168 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
169 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
170 | 0 | "%s: invalid multi value.", |
171 | 0 | function ); |
172 | |
|
173 | 0 | return( -1 ); |
174 | 0 | } |
175 | 357 | internal_multi_value = (libpff_internal_multi_value_t *) multi_value; |
176 | | |
177 | 357 | if( number_of_values == NULL ) |
178 | 0 | { |
179 | 0 | libcerror_error_set( |
180 | 0 | error, |
181 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
182 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
183 | 0 | "%s: invalid number of values.", |
184 | 0 | function ); |
185 | |
|
186 | 0 | return( -1 ); |
187 | 0 | } |
188 | 357 | if( internal_multi_value->number_of_values > (uint32_t) INT_MAX ) |
189 | 0 | { |
190 | 0 | libcerror_error_set( |
191 | 0 | error, |
192 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
193 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
194 | 0 | "%s: invalid number of values value exceeds maximum.", |
195 | 0 | function ); |
196 | |
|
197 | 0 | return( -1 ); |
198 | 0 | } |
199 | 357 | *number_of_values = (int) internal_multi_value->number_of_values; |
200 | | |
201 | 357 | return( 1 ); |
202 | 357 | } |
203 | | |
204 | | /* Retrieves a specific value of the multi value |
205 | | * Returns 1 if successful or -1 on error |
206 | | */ |
207 | | int libpff_multi_value_get_value( |
208 | | libpff_multi_value_t *multi_value, |
209 | | int value_index, |
210 | | uint32_t *value_type, |
211 | | uint8_t **value_data, |
212 | | size_t *value_data_size, |
213 | | libcerror_error_t **error ) |
214 | 2.13k | { |
215 | 2.13k | libpff_internal_multi_value_t *internal_multi_value = NULL; |
216 | 2.13k | static char *function = "libpff_multi_value_get_value"; |
217 | 2.13k | uint32_t value_offset = 0; |
218 | | |
219 | 2.13k | if( multi_value == NULL ) |
220 | 0 | { |
221 | 0 | libcerror_error_set( |
222 | 0 | error, |
223 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
224 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
225 | 0 | "%s: invalid multi value.", |
226 | 0 | function ); |
227 | |
|
228 | 0 | return( -1 ); |
229 | 0 | } |
230 | 2.13k | internal_multi_value = (libpff_internal_multi_value_t *) multi_value; |
231 | | |
232 | 2.13k | if( value_type == NULL ) |
233 | 0 | { |
234 | 0 | libcerror_error_set( |
235 | 0 | error, |
236 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
237 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
238 | 0 | "%s: invalid value type.", |
239 | 0 | function ); |
240 | |
|
241 | 0 | return( -1 ); |
242 | 0 | } |
243 | 2.13k | if( ( value_index < 0 ) |
244 | 2.13k | || ( value_index >= (int) internal_multi_value->number_of_values ) ) |
245 | 0 | { |
246 | 0 | libcerror_error_set( |
247 | 0 | error, |
248 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
249 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
250 | 0 | "%s: invalid value index.", |
251 | 0 | function ); |
252 | |
|
253 | 0 | return( -1 ); |
254 | 0 | } |
255 | 2.13k | value_offset = internal_multi_value->value_offset[ value_index ]; |
256 | | |
257 | | /* Returns the value type without the multi value flag |
258 | | */ |
259 | 2.13k | *value_type = internal_multi_value->value_type & 0xefff; |
260 | 2.13k | *value_data_size = internal_multi_value->value_size[ value_index ]; |
261 | | |
262 | 2.13k | if( internal_multi_value->value_size[ value_index ] == 0 ) |
263 | 132 | { |
264 | 132 | *value_data = NULL; |
265 | | |
266 | 132 | return( 1 ); |
267 | 132 | } |
268 | 2.00k | if( internal_multi_value->value_data == NULL ) |
269 | 0 | { |
270 | 0 | libcerror_error_set( |
271 | 0 | error, |
272 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
273 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
274 | 0 | "%s: missing value data.", |
275 | 0 | function ); |
276 | |
|
277 | 0 | return( -1 ); |
278 | 0 | } |
279 | 2.00k | if( ( ( size_t ) value_offset > internal_multi_value->value_data_size ) |
280 | 2.00k | || ( ( size_t ) internal_multi_value->value_size[ value_index ] > ( internal_multi_value->value_data_size - ( size_t ) value_offset ) ) ) |
281 | 0 | { |
282 | 0 | libcerror_error_set( |
283 | 0 | error, |
284 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
285 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
286 | 0 | "%s: invalid value: offset: %" PRIu32 " and size: %" PRIzd " out of bounds of value data size: %" PRIzd ".", |
287 | 0 | function, |
288 | 0 | value_offset, |
289 | 0 | internal_multi_value->value_size[ value_index ], |
290 | 0 | internal_multi_value->value_data_size ); |
291 | |
|
292 | 0 | return( -1 ); |
293 | 0 | } |
294 | 2.00k | *value_data = &( internal_multi_value->value_data[ value_offset ] ); |
295 | | |
296 | 2.00k | return( 1 ); |
297 | 2.00k | } |
298 | | |
299 | | /* Retrieves the 32-bit value of a specific value of the multi value |
300 | | * Returns 1 if successful or -1 on error |
301 | | */ |
302 | | int libpff_multi_value_get_value_32bit( |
303 | | libpff_multi_value_t *multi_value, |
304 | | int value_index, |
305 | | uint32_t *value, |
306 | | libcerror_error_t **error ) |
307 | 0 | { |
308 | 0 | uint8_t *value_data = NULL; |
309 | 0 | static char *function = "libpff_multi_value_get_value_32bit"; |
310 | 0 | size_t value_data_size = 0; |
311 | 0 | uint32_t value_type = LIBPFF_VALUE_TYPE_INTEGER_32BIT_SIGNED; |
312 | 0 | int result = 0; |
313 | |
|
314 | 0 | result = libpff_multi_value_get_value( |
315 | 0 | multi_value, |
316 | 0 | value_index, |
317 | 0 | &value_type, |
318 | 0 | &value_data, |
319 | 0 | &value_data_size, |
320 | 0 | error ); |
321 | |
|
322 | 0 | if( result == -1 ) |
323 | 0 | { |
324 | 0 | libcerror_error_set( |
325 | 0 | error, |
326 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
327 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
328 | 0 | "%s: unable to retrieve value.", |
329 | 0 | function ); |
330 | 0 | } |
331 | 0 | else if( result == 1 ) |
332 | 0 | { |
333 | 0 | if( libpff_value_type_copy_to_32bit( |
334 | 0 | value_data, |
335 | 0 | value_data_size, |
336 | 0 | value, |
337 | 0 | error ) != 1 ) |
338 | 0 | { |
339 | 0 | libcerror_error_set( |
340 | 0 | error, |
341 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
342 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
343 | 0 | "%s: unable to set 32-bit value.", |
344 | 0 | function ); |
345 | |
|
346 | 0 | return( -1 ); |
347 | 0 | } |
348 | 0 | } |
349 | 0 | return( result ); |
350 | 0 | } |
351 | | |
352 | | /* Retrieves the 64-bit value of a specific value of the multi value |
353 | | * Returns 1 if successful or -1 on error |
354 | | */ |
355 | | int libpff_multi_value_get_value_64bit( |
356 | | libpff_multi_value_t *multi_value, |
357 | | int value_index, |
358 | | uint64_t *value, |
359 | | libcerror_error_t **error ) |
360 | 0 | { |
361 | 0 | uint8_t *value_data = NULL; |
362 | 0 | static char *function = "libpff_multi_value_get_value_64bit"; |
363 | 0 | size_t value_data_size = 0; |
364 | 0 | uint32_t value_type = LIBPFF_VALUE_TYPE_INTEGER_64BIT_SIGNED; |
365 | 0 | int result = 0; |
366 | |
|
367 | 0 | result = libpff_multi_value_get_value( |
368 | 0 | multi_value, |
369 | 0 | value_index, |
370 | 0 | &value_type, |
371 | 0 | &value_data, |
372 | 0 | &value_data_size, |
373 | 0 | error ); |
374 | |
|
375 | 0 | if( result == -1 ) |
376 | 0 | { |
377 | 0 | libcerror_error_set( |
378 | 0 | error, |
379 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
380 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
381 | 0 | "%s: unable to retrieve value.", |
382 | 0 | function ); |
383 | 0 | } |
384 | 0 | else if( result == 1 ) |
385 | 0 | { |
386 | 0 | if( libpff_value_type_copy_to_64bit( |
387 | 0 | value_data, |
388 | 0 | value_data_size, |
389 | 0 | value, |
390 | 0 | error ) != 1 ) |
391 | 0 | { |
392 | 0 | libcerror_error_set( |
393 | 0 | error, |
394 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
395 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
396 | 0 | "%s: unable to set 64-bit value.", |
397 | 0 | function ); |
398 | |
|
399 | 0 | return( -1 ); |
400 | 0 | } |
401 | 0 | } |
402 | 0 | return( result ); |
403 | 0 | } |
404 | | |
405 | | /* Retrieves the 64-bit filetime value of a specific value of the multi value |
406 | | * Returns 1 if successful or -1 on error |
407 | | */ |
408 | | int libpff_multi_value_get_value_filetime( |
409 | | libpff_multi_value_t *multi_value, |
410 | | int value_index, |
411 | | uint64_t *filetime, |
412 | | libcerror_error_t **error ) |
413 | 0 | { |
414 | 0 | uint8_t *value_data = NULL; |
415 | 0 | static char *function = "libpff_multi_value_get_value_filetime"; |
416 | 0 | size_t value_data_size = 0; |
417 | 0 | uint32_t value_type = LIBPFF_VALUE_TYPE_FILETIME; |
418 | 0 | int result = 0; |
419 | |
|
420 | 0 | result = libpff_multi_value_get_value( |
421 | 0 | multi_value, |
422 | 0 | value_index, |
423 | 0 | &value_type, |
424 | 0 | &value_data, |
425 | 0 | &value_data_size, |
426 | 0 | error ); |
427 | |
|
428 | 0 | if( result == -1 ) |
429 | 0 | { |
430 | 0 | libcerror_error_set( |
431 | 0 | error, |
432 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
433 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
434 | 0 | "%s: unable to retrieve value.", |
435 | 0 | function ); |
436 | 0 | } |
437 | 0 | else if( result == 1 ) |
438 | 0 | { |
439 | 0 | if( libpff_value_type_copy_to_64bit( |
440 | 0 | value_data, |
441 | 0 | value_data_size, |
442 | 0 | filetime, |
443 | 0 | error ) != 1 ) |
444 | 0 | { |
445 | 0 | libcerror_error_set( |
446 | 0 | error, |
447 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
448 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
449 | 0 | "%s: unable to set filetime value.", |
450 | 0 | function ); |
451 | |
|
452 | 0 | return( -1 ); |
453 | 0 | } |
454 | 0 | } |
455 | 0 | return( result ); |
456 | 0 | } |
457 | | |
458 | | /* Retrieves the UTF-8 string size of a specific value of the multi value |
459 | | * The returned size includes the end of string character |
460 | | * Returns 1 if successful or -1 on error |
461 | | */ |
462 | | int libpff_multi_value_get_value_utf8_string_size( |
463 | | libpff_multi_value_t *multi_value, |
464 | | int value_index, |
465 | | size_t *utf8_string_size, |
466 | | libcerror_error_t **error ) |
467 | 0 | { |
468 | 0 | uint8_t *value_data = NULL; |
469 | 0 | static char *function = "libpff_multi_value_get_value_utf8_string_size"; |
470 | 0 | size_t value_data_size = 0; |
471 | 0 | uint32_t value_type = 0; |
472 | 0 | uint8_t is_ascii_string = 0; |
473 | 0 | int result = 0; |
474 | |
|
475 | 0 | result = libpff_multi_value_get_value( |
476 | 0 | multi_value, |
477 | 0 | value_index, |
478 | 0 | &value_type, |
479 | 0 | &value_data, |
480 | 0 | &value_data_size, |
481 | 0 | error ); |
482 | |
|
483 | 0 | if( result == -1 ) |
484 | 0 | { |
485 | 0 | libcerror_error_set( |
486 | 0 | error, |
487 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
488 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
489 | 0 | "%s: unable to retrieve value.", |
490 | 0 | function ); |
491 | 0 | } |
492 | 0 | else if( result == 1 ) |
493 | 0 | { |
494 | 0 | if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII ) |
495 | 0 | && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) ) |
496 | 0 | { |
497 | 0 | libcerror_error_set( |
498 | 0 | error, |
499 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
500 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
501 | 0 | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
502 | 0 | function, |
503 | 0 | value_type ); |
504 | |
|
505 | 0 | return( -1 ); |
506 | 0 | } |
507 | 0 | if( value_type == LIBPFF_VALUE_TYPE_STRING_ASCII ) |
508 | 0 | { |
509 | 0 | is_ascii_string = 1; |
510 | 0 | } |
511 | 0 | if( libpff_value_type_get_utf8_string_size( |
512 | 0 | value_data, |
513 | 0 | value_data_size, |
514 | 0 | is_ascii_string, |
515 | 0 | ( (libpff_internal_multi_value_t *) multi_value )->ascii_codepage, |
516 | 0 | utf8_string_size, |
517 | 0 | error ) != 1 ) |
518 | 0 | { |
519 | 0 | libcerror_error_set( |
520 | 0 | error, |
521 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
522 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
523 | 0 | "%s: unable to set UTF-8 string size.", |
524 | 0 | function ); |
525 | |
|
526 | 0 | return( -1 ); |
527 | 0 | } |
528 | 0 | } |
529 | 0 | return( result ); |
530 | 0 | } |
531 | | |
532 | | /* Retrieves the UTF-8 string value of a specific value of the multi value |
533 | | * The size should include the end of string character |
534 | | * Returns 1 if successful or -1 on error |
535 | | */ |
536 | | int libpff_multi_value_get_value_utf8_string( |
537 | | libpff_multi_value_t *multi_value, |
538 | | int value_index, |
539 | | uint8_t *utf8_string, |
540 | | size_t utf8_string_size, |
541 | | libcerror_error_t **error ) |
542 | 0 | { |
543 | 0 | uint8_t *value_data = NULL; |
544 | 0 | static char *function = "libpff_multi_value_get_value_utf8_string"; |
545 | 0 | size_t value_data_size = 0; |
546 | 0 | uint32_t value_type = 0; |
547 | 0 | uint8_t is_ascii_string = 0; |
548 | 0 | int result = 0; |
549 | |
|
550 | 0 | result = libpff_multi_value_get_value( |
551 | 0 | multi_value, |
552 | 0 | value_index, |
553 | 0 | &value_type, |
554 | 0 | &value_data, |
555 | 0 | &value_data_size, |
556 | 0 | error ); |
557 | |
|
558 | 0 | if( result == -1 ) |
559 | 0 | { |
560 | 0 | libcerror_error_set( |
561 | 0 | error, |
562 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
563 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
564 | 0 | "%s: unable to retrieve value.", |
565 | 0 | function ); |
566 | 0 | } |
567 | 0 | else if( result == 1 ) |
568 | 0 | { |
569 | 0 | if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII ) |
570 | 0 | && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) ) |
571 | 0 | { |
572 | 0 | libcerror_error_set( |
573 | 0 | error, |
574 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
575 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
576 | 0 | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
577 | 0 | function, |
578 | 0 | value_type ); |
579 | |
|
580 | 0 | return( -1 ); |
581 | 0 | } |
582 | 0 | if( value_type == LIBPFF_VALUE_TYPE_STRING_ASCII ) |
583 | 0 | { |
584 | 0 | is_ascii_string = 1; |
585 | 0 | } |
586 | 0 | if( libpff_value_type_copy_to_utf8_string( |
587 | 0 | value_data, |
588 | 0 | value_data_size, |
589 | 0 | is_ascii_string, |
590 | 0 | ( (libpff_internal_multi_value_t *) multi_value )->ascii_codepage, |
591 | 0 | utf8_string, |
592 | 0 | utf8_string_size, |
593 | 0 | error ) != 1 ) |
594 | 0 | { |
595 | 0 | libcerror_error_set( |
596 | 0 | error, |
597 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
598 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
599 | 0 | "%s: unable to set UTF-8 string.", |
600 | 0 | function ); |
601 | |
|
602 | 0 | return( -1 ); |
603 | 0 | } |
604 | 0 | } |
605 | 0 | return( result ); |
606 | 0 | } |
607 | | |
608 | | /* Retrieves the UTF-16 string size of a specific value of the multi value |
609 | | * The returned size includes the end of string character |
610 | | * Returns 1 if successful or -1 on error |
611 | | */ |
612 | | int libpff_multi_value_get_value_utf16_string_size( |
613 | | libpff_multi_value_t *multi_value, |
614 | | int value_index, |
615 | | size_t *utf16_string_size, |
616 | | libcerror_error_t **error ) |
617 | 0 | { |
618 | 0 | uint8_t *value_data = NULL; |
619 | 0 | static char *function = "libpff_multi_value_get_value_utf16_string_size"; |
620 | 0 | size_t value_data_size = 0; |
621 | 0 | uint32_t value_type = 0; |
622 | 0 | uint8_t is_ascii_string = 0; |
623 | 0 | int result = 0; |
624 | |
|
625 | 0 | result = libpff_multi_value_get_value( |
626 | 0 | multi_value, |
627 | 0 | value_index, |
628 | 0 | &value_type, |
629 | 0 | &value_data, |
630 | 0 | &value_data_size, |
631 | 0 | error ); |
632 | |
|
633 | 0 | if( result == -1 ) |
634 | 0 | { |
635 | 0 | libcerror_error_set( |
636 | 0 | error, |
637 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
638 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
639 | 0 | "%s: unable to retrieve value.", |
640 | 0 | function ); |
641 | 0 | } |
642 | 0 | else if( result == 1 ) |
643 | 0 | { |
644 | 0 | if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII ) |
645 | 0 | && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) ) |
646 | 0 | { |
647 | 0 | libcerror_error_set( |
648 | 0 | error, |
649 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
650 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
651 | 0 | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
652 | 0 | function, |
653 | 0 | value_type ); |
654 | |
|
655 | 0 | return( -1 ); |
656 | 0 | } |
657 | 0 | if( value_type == LIBPFF_VALUE_TYPE_STRING_ASCII ) |
658 | 0 | { |
659 | 0 | is_ascii_string = 1; |
660 | 0 | } |
661 | 0 | if( libpff_value_type_get_utf16_string_size( |
662 | 0 | value_data, |
663 | 0 | value_data_size, |
664 | 0 | is_ascii_string, |
665 | 0 | ( (libpff_internal_multi_value_t *) multi_value )->ascii_codepage, |
666 | 0 | utf16_string_size, |
667 | 0 | error ) != 1 ) |
668 | 0 | { |
669 | 0 | libcerror_error_set( |
670 | 0 | error, |
671 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
672 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
673 | 0 | "%s: unable to set UTF-16 string size.", |
674 | 0 | function ); |
675 | |
|
676 | 0 | return( -1 ); |
677 | 0 | } |
678 | 0 | } |
679 | 0 | return( result ); |
680 | 0 | } |
681 | | |
682 | | /* Retrieves the UTF-16 string value of a specific value of the multi value |
683 | | * The size should include the end of string character |
684 | | * Returns 1 if successful or -1 on error |
685 | | */ |
686 | | int libpff_multi_value_get_value_utf16_string( |
687 | | libpff_multi_value_t *multi_value, |
688 | | int value_index, |
689 | | uint16_t *utf16_string, |
690 | | size_t utf16_string_size, |
691 | | libcerror_error_t **error ) |
692 | 0 | { |
693 | 0 | uint8_t *value_data = NULL; |
694 | 0 | static char *function = "libpff_multi_value_get_value_utf16_string"; |
695 | 0 | size_t value_data_size = 0; |
696 | 0 | uint32_t value_type = 0; |
697 | 0 | uint8_t is_ascii_string = 0; |
698 | 0 | int result = 0; |
699 | |
|
700 | 0 | result = libpff_multi_value_get_value( |
701 | 0 | multi_value, |
702 | 0 | value_index, |
703 | 0 | &value_type, |
704 | 0 | &value_data, |
705 | 0 | &value_data_size, |
706 | 0 | error ); |
707 | |
|
708 | 0 | if( result == -1 ) |
709 | 0 | { |
710 | 0 | libcerror_error_set( |
711 | 0 | error, |
712 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
713 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
714 | 0 | "%s: unable to retrieve value.", |
715 | 0 | function ); |
716 | 0 | } |
717 | 0 | else if( result == 1 ) |
718 | 0 | { |
719 | 0 | if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII ) |
720 | 0 | && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) ) |
721 | 0 | { |
722 | 0 | libcerror_error_set( |
723 | 0 | error, |
724 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
725 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
726 | 0 | "%s: unsupported string value type: 0x%04" PRIx32 ".", |
727 | 0 | function, |
728 | 0 | value_type ); |
729 | |
|
730 | 0 | return( -1 ); |
731 | 0 | } |
732 | 0 | if( value_type == LIBPFF_VALUE_TYPE_STRING_ASCII ) |
733 | 0 | { |
734 | 0 | is_ascii_string = 1; |
735 | 0 | } |
736 | 0 | if( libpff_value_type_copy_to_utf16_string( |
737 | 0 | value_data, |
738 | 0 | value_data_size, |
739 | 0 | is_ascii_string, |
740 | 0 | ( (libpff_internal_multi_value_t *) multi_value )->ascii_codepage, |
741 | 0 | utf16_string, |
742 | 0 | utf16_string_size, |
743 | 0 | error ) != 1 ) |
744 | 0 | { |
745 | 0 | libcerror_error_set( |
746 | 0 | error, |
747 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
748 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
749 | 0 | "%s: unable to set UTF-16 string.", |
750 | 0 | function ); |
751 | |
|
752 | 0 | return( -1 ); |
753 | 0 | } |
754 | 0 | } |
755 | 0 | return( result ); |
756 | 0 | } |
757 | | |
758 | | /* Retrieves the size of a binary data value of a specific value of the multi value |
759 | | * Returns 1 if successful or -1 on error |
760 | | */ |
761 | | int libpff_multi_value_get_value_binary_data_size( |
762 | | libpff_multi_value_t *multi_value, |
763 | | int value_index, |
764 | | size_t *size, |
765 | | libcerror_error_t **error ) |
766 | 0 | { |
767 | 0 | uint8_t *value_data = NULL; |
768 | 0 | static char *function = "libpff_multi_value_get_value_binary_data_size"; |
769 | 0 | size_t value_data_size = 0; |
770 | 0 | uint32_t value_type = LIBPFF_VALUE_TYPE_BINARY_DATA; |
771 | 0 | int result = 0; |
772 | |
|
773 | 0 | result = libpff_multi_value_get_value( |
774 | 0 | multi_value, |
775 | 0 | value_index, |
776 | 0 | &value_type, |
777 | 0 | &value_data, |
778 | 0 | &value_data_size, |
779 | 0 | error ); |
780 | |
|
781 | 0 | if( result == -1 ) |
782 | 0 | { |
783 | 0 | libcerror_error_set( |
784 | 0 | error, |
785 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
786 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
787 | 0 | "%s: unable to retrieve value.", |
788 | 0 | function ); |
789 | 0 | } |
790 | 0 | else if( result == 1 ) |
791 | 0 | { |
792 | 0 | if( libpff_value_type_get_binary_data_size( |
793 | 0 | value_data, |
794 | 0 | value_data_size, |
795 | 0 | size, |
796 | 0 | error ) != 1 ) |
797 | 0 | { |
798 | 0 | libcerror_error_set( |
799 | 0 | error, |
800 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
801 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
802 | 0 | "%s: unable to set binary data size.", |
803 | 0 | function ); |
804 | |
|
805 | 0 | return( -1 ); |
806 | 0 | } |
807 | 0 | } |
808 | 0 | return( result ); |
809 | 0 | } |
810 | | |
811 | | /* Retrieves the binary data value of a specific value of the multi value |
812 | | * Returns 1 if successful or -1 on error |
813 | | */ |
814 | | int libpff_multi_value_get_value_binary_data( |
815 | | libpff_multi_value_t *multi_value, |
816 | | int value_index, |
817 | | uint8_t *binary_data, |
818 | | size_t size, |
819 | | libcerror_error_t **error ) |
820 | 0 | { |
821 | 0 | uint8_t *value_data = NULL; |
822 | 0 | static char *function = "libpff_multi_value_get_value_binary_data"; |
823 | 0 | size_t value_data_size = 0; |
824 | 0 | uint32_t value_type = LIBPFF_VALUE_TYPE_BINARY_DATA; |
825 | 0 | int result = 0; |
826 | |
|
827 | 0 | result = libpff_multi_value_get_value( |
828 | 0 | multi_value, |
829 | 0 | value_index, |
830 | 0 | &value_type, |
831 | 0 | &value_data, |
832 | 0 | &value_data_size, |
833 | 0 | error ); |
834 | |
|
835 | 0 | if( result == -1 ) |
836 | 0 | { |
837 | 0 | libcerror_error_set( |
838 | 0 | error, |
839 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
840 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
841 | 0 | "%s: unable to retrieve value.", |
842 | 0 | function ); |
843 | 0 | } |
844 | 0 | else if( result == 1 ) |
845 | 0 | { |
846 | 0 | if( libpff_value_type_copy_to_binary_data( |
847 | 0 | value_data, |
848 | 0 | value_data_size, |
849 | 0 | binary_data, |
850 | 0 | size, |
851 | 0 | error ) != 1 ) |
852 | 0 | { |
853 | 0 | libcerror_error_set( |
854 | 0 | error, |
855 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
856 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
857 | 0 | "%s: unable to set binary data.", |
858 | 0 | function ); |
859 | |
|
860 | 0 | return( -1 ); |
861 | 0 | } |
862 | 0 | } |
863 | 0 | return( result ); |
864 | 0 | } |
865 | | |
866 | | /* Retrieves the GUID value of a specific value of the multi value |
867 | | * Returns 1 if successful or -1 on error |
868 | | */ |
869 | | int libpff_multi_value_get_value_guid( |
870 | | libpff_multi_value_t *multi_value, |
871 | | int value_index, |
872 | | uint8_t *guid, |
873 | | size_t size, |
874 | | libcerror_error_t **error ) |
875 | 0 | { |
876 | 0 | uint8_t *value_data = NULL; |
877 | 0 | static char *function = "libpff_multi_value_get_value_guid"; |
878 | 0 | size_t value_data_size = 0; |
879 | 0 | uint32_t value_type = LIBPFF_VALUE_TYPE_GUID; |
880 | 0 | int result = 0; |
881 | |
|
882 | 0 | result = libpff_multi_value_get_value( |
883 | 0 | multi_value, |
884 | 0 | value_index, |
885 | 0 | &value_type, |
886 | 0 | &value_data, |
887 | 0 | &value_data_size, |
888 | 0 | error ); |
889 | |
|
890 | 0 | if( result == -1 ) |
891 | 0 | { |
892 | 0 | libcerror_error_set( |
893 | 0 | error, |
894 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
895 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
896 | 0 | "%s: unable to retrieve value.", |
897 | 0 | function ); |
898 | 0 | } |
899 | 0 | else if( result == 1 ) |
900 | 0 | { |
901 | 0 | if( libpff_value_type_copy_to_binary_data( |
902 | 0 | value_data, |
903 | 0 | value_data_size, |
904 | 0 | guid, |
905 | 0 | size, |
906 | 0 | error ) != 1 ) |
907 | 0 | { |
908 | 0 | libcerror_error_set( |
909 | 0 | error, |
910 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
911 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
912 | 0 | "%s: unable to set GUID.", |
913 | 0 | function ); |
914 | |
|
915 | 0 | return( -1 ); |
916 | 0 | } |
917 | 0 | } |
918 | 0 | return( result ); |
919 | 0 | } |
920 | | |