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