/src/libvhdi/libvhdi/libvhdi_parent_locator_entry.c
Line | Count | Source |
1 | | /* |
2 | | * Parent locator entry functions |
3 | | * |
4 | | * Copyright (C) 2012-2025, 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 <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libvhdi_debug.h" |
28 | | #include "libvhdi_libcerror.h" |
29 | | #include "libvhdi_libcnotify.h" |
30 | | #include "libvhdi_libfguid.h" |
31 | | #include "libvhdi_libuna.h" |
32 | | #include "libvhdi_parent_locator_entry.h" |
33 | | |
34 | | #include "vhdi_parent_locator.h" |
35 | | |
36 | | /* Creates parent locator entry |
37 | | * Make sure the value parent_locator_entry is referencing, is set to NULL |
38 | | * Returns 1 if successful or -1 on error |
39 | | */ |
40 | | int libvhdi_parent_locator_entry_initialize( |
41 | | libvhdi_parent_locator_entry_t **parent_locator_entry, |
42 | | libcerror_error_t **error ) |
43 | 544 | { |
44 | 544 | static char *function = "libvhdi_parent_locator_entry_initialize"; |
45 | | |
46 | 544 | if( parent_locator_entry == NULL ) |
47 | 0 | { |
48 | 0 | libcerror_error_set( |
49 | 0 | error, |
50 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
51 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
52 | 0 | "%s: invalid parent locator entry.", |
53 | 0 | function ); |
54 | |
|
55 | 0 | return( -1 ); |
56 | 0 | } |
57 | 544 | if( *parent_locator_entry != NULL ) |
58 | 0 | { |
59 | 0 | libcerror_error_set( |
60 | 0 | error, |
61 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
62 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
63 | 0 | "%s: invalid parent locator entry value already set.", |
64 | 0 | function ); |
65 | |
|
66 | 0 | return( -1 ); |
67 | 0 | } |
68 | 544 | *parent_locator_entry = memory_allocate_structure( |
69 | 544 | libvhdi_parent_locator_entry_t ); |
70 | | |
71 | 544 | if( *parent_locator_entry == NULL ) |
72 | 0 | { |
73 | 0 | libcerror_error_set( |
74 | 0 | error, |
75 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
76 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
77 | 0 | "%s: unable to create parent locator entry.", |
78 | 0 | function ); |
79 | |
|
80 | 0 | goto on_error; |
81 | 0 | } |
82 | 544 | if( memory_set( |
83 | 544 | *parent_locator_entry, |
84 | 544 | 0, |
85 | 544 | sizeof( libvhdi_parent_locator_entry_t ) ) == NULL ) |
86 | 0 | { |
87 | 0 | libcerror_error_set( |
88 | 0 | error, |
89 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
90 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
91 | 0 | "%s: unable to clear parent locator entry.", |
92 | 0 | function ); |
93 | |
|
94 | 0 | goto on_error; |
95 | 0 | } |
96 | 544 | return( 1 ); |
97 | | |
98 | 0 | on_error: |
99 | 0 | if( *parent_locator_entry != NULL ) |
100 | 0 | { |
101 | 0 | memory_free( |
102 | 0 | *parent_locator_entry ); |
103 | |
|
104 | 0 | *parent_locator_entry = NULL; |
105 | 0 | } |
106 | 0 | return( -1 ); |
107 | 544 | } |
108 | | |
109 | | /* Frees parent locator entry |
110 | | * Returns 1 if successful or -1 on error |
111 | | */ |
112 | | int libvhdi_parent_locator_entry_free( |
113 | | libvhdi_parent_locator_entry_t **parent_locator_entry, |
114 | | libcerror_error_t **error ) |
115 | 544 | { |
116 | 544 | static char *function = "libvhdi_parent_locator_entry_free"; |
117 | | |
118 | 544 | if( parent_locator_entry == NULL ) |
119 | 0 | { |
120 | 0 | libcerror_error_set( |
121 | 0 | error, |
122 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
123 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
124 | 0 | "%s: invalid parent locator entry.", |
125 | 0 | function ); |
126 | |
|
127 | 0 | return( -1 ); |
128 | 0 | } |
129 | 544 | if( *parent_locator_entry != NULL ) |
130 | 544 | { |
131 | 544 | if( ( *parent_locator_entry )->key_data != NULL ) |
132 | 452 | { |
133 | 452 | memory_free( |
134 | 452 | ( *parent_locator_entry )->key_data ); |
135 | 452 | } |
136 | 544 | if( ( *parent_locator_entry )->value_data != NULL ) |
137 | 452 | { |
138 | 452 | memory_free( |
139 | 452 | ( *parent_locator_entry )->value_data ); |
140 | 452 | } |
141 | 544 | memory_free( |
142 | 544 | *parent_locator_entry ); |
143 | | |
144 | 544 | *parent_locator_entry = NULL; |
145 | 544 | } |
146 | 544 | return( 1 ); |
147 | 544 | } |
148 | | |
149 | | /* Reads the parent locator entry data |
150 | | * Returns 1 if successful or -1 on error |
151 | | */ |
152 | | int libvhdi_parent_locator_entry_read_data( |
153 | | libvhdi_parent_locator_entry_t *parent_locator_entry, |
154 | | const uint8_t *data, |
155 | | size_t data_size, |
156 | | libcerror_error_t **error ) |
157 | 544 | { |
158 | 544 | static char *function = "libvhdi_parent_locator_entry_read_data"; |
159 | | |
160 | 544 | if( parent_locator_entry == NULL ) |
161 | 0 | { |
162 | 0 | libcerror_error_set( |
163 | 0 | error, |
164 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
165 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
166 | 0 | "%s: invalid parent locator entry.", |
167 | 0 | function ); |
168 | |
|
169 | 0 | return( -1 ); |
170 | 0 | } |
171 | 544 | if( data == NULL ) |
172 | 0 | { |
173 | 0 | libcerror_error_set( |
174 | 0 | error, |
175 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
176 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
177 | 0 | "%s: invalid data.", |
178 | 0 | function ); |
179 | |
|
180 | 0 | return( -1 ); |
181 | 0 | } |
182 | 544 | if( ( data_size < sizeof( vhdi_parent_locator_entry_t ) ) |
183 | 544 | || ( data_size > (size_t) SSIZE_MAX ) ) |
184 | 0 | { |
185 | 0 | libcerror_error_set( |
186 | 0 | error, |
187 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
188 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
189 | 0 | "%s: invalid data size value out of bounds.", |
190 | 0 | function ); |
191 | |
|
192 | 0 | return( -1 ); |
193 | 0 | } |
194 | | #if defined( HAVE_DEBUG_OUTPUT ) |
195 | | if( libcnotify_verbose != 0 ) |
196 | | { |
197 | | libcnotify_printf( |
198 | | "%s: parent locator entry data:\n", |
199 | | function ); |
200 | | libcnotify_print_data( |
201 | | data, |
202 | | sizeof( vhdi_parent_locator_entry_t ), |
203 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
204 | | } |
205 | | #endif |
206 | 544 | byte_stream_copy_to_uint32_little_endian( |
207 | 544 | ( (vhdi_parent_locator_entry_t *) data )->key_data_offset, |
208 | 544 | parent_locator_entry->key_data_offset ); |
209 | | |
210 | 544 | byte_stream_copy_to_uint32_little_endian( |
211 | 544 | ( (vhdi_parent_locator_entry_t *) data )->value_data_offset, |
212 | 544 | parent_locator_entry->value_data_offset ); |
213 | | |
214 | 544 | byte_stream_copy_to_uint16_little_endian( |
215 | 544 | ( (vhdi_parent_locator_entry_t *) data )->key_data_size, |
216 | 544 | parent_locator_entry->key_data_size ); |
217 | | |
218 | 544 | byte_stream_copy_to_uint16_little_endian( |
219 | 544 | ( (vhdi_parent_locator_entry_t *) data )->value_data_size, |
220 | 544 | parent_locator_entry->value_data_size ); |
221 | | |
222 | | #if defined( HAVE_DEBUG_OUTPUT ) |
223 | | if( libcnotify_verbose != 0 ) |
224 | | { |
225 | | libcnotify_printf( |
226 | | "%s: key data offset\t\t\t: 0x%08" PRIx32 "\n", |
227 | | function, |
228 | | parent_locator_entry->key_data_offset ); |
229 | | |
230 | | libcnotify_printf( |
231 | | "%s: value data offset\t\t: 0x%08" PRIx32 "\n", |
232 | | function, |
233 | | parent_locator_entry->value_data_offset ); |
234 | | |
235 | | libcnotify_printf( |
236 | | "%s: key data size\t\t\t: %" PRIu16 "\n", |
237 | | function, |
238 | | parent_locator_entry->key_data_size ); |
239 | | |
240 | | libcnotify_printf( |
241 | | "%s: value data size\t\t\t: %" PRIu16 "\n", |
242 | | function, |
243 | | parent_locator_entry->value_data_size ); |
244 | | |
245 | | libcnotify_printf( |
246 | | "\n" ); |
247 | | } |
248 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
249 | | |
250 | 544 | return( 1 ); |
251 | 544 | } |
252 | | |
253 | | /* Reads the parent locator entry key and value data |
254 | | * Returns 1 if successful or -1 on error |
255 | | */ |
256 | | int libvhdi_parent_locator_entry_read_key_value_data( |
257 | | libvhdi_parent_locator_entry_t *parent_locator_entry, |
258 | | const uint8_t *data, |
259 | | size_t data_size, |
260 | | libcerror_error_t **error ) |
261 | 544 | { |
262 | 544 | static char *function = "libvhdi_parent_locator_entry_read_key_value_data"; |
263 | | |
264 | 544 | if( parent_locator_entry == NULL ) |
265 | 0 | { |
266 | 0 | libcerror_error_set( |
267 | 0 | error, |
268 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
269 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
270 | 0 | "%s: invalid parent locator entry.", |
271 | 0 | function ); |
272 | |
|
273 | 0 | return( -1 ); |
274 | 0 | } |
275 | 544 | if( parent_locator_entry->key_data != NULL ) |
276 | 0 | { |
277 | 0 | libcerror_error_set( |
278 | 0 | error, |
279 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
280 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
281 | 0 | "%s: invalid parent locator entry - key data already set.", |
282 | 0 | function ); |
283 | |
|
284 | 0 | return( -1 ); |
285 | 0 | } |
286 | 544 | if( parent_locator_entry->value_data != NULL ) |
287 | 0 | { |
288 | 0 | libcerror_error_set( |
289 | 0 | error, |
290 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
291 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
292 | 0 | "%s: invalid parent locator entry - value data already set.", |
293 | 0 | function ); |
294 | |
|
295 | 0 | return( -1 ); |
296 | 0 | } |
297 | 544 | if( data == NULL ) |
298 | 0 | { |
299 | 0 | libcerror_error_set( |
300 | 0 | error, |
301 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
302 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
303 | 0 | "%s: invalid data.", |
304 | 0 | function ); |
305 | |
|
306 | 0 | return( -1 ); |
307 | 0 | } |
308 | 544 | if( data_size > (size_t) SSIZE_MAX ) |
309 | 0 | { |
310 | 0 | libcerror_error_set( |
311 | 0 | error, |
312 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
313 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
314 | 0 | "%s: invalid data size value out of bounds.", |
315 | 0 | function ); |
316 | |
|
317 | 0 | return( -1 ); |
318 | 0 | } |
319 | 544 | if( ( parent_locator_entry->key_data_offset < sizeof( vhdi_parent_locator_header_t ) ) |
320 | 540 | || ( parent_locator_entry->key_data_offset > data_size ) ) |
321 | 39 | { |
322 | 39 | libcerror_error_set( |
323 | 39 | error, |
324 | 39 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
325 | 39 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
326 | 39 | "%s: invalid parent locator entry - key data offset value out of bounds.", |
327 | 39 | function ); |
328 | | |
329 | 39 | return( -1 ); |
330 | 39 | } |
331 | 505 | if( ( parent_locator_entry->key_data_size == 0 ) |
332 | 503 | || ( (size_t) parent_locator_entry->key_data_size > ( data_size - parent_locator_entry->key_data_offset ) ) ) |
333 | 8 | { |
334 | 8 | libcerror_error_set( |
335 | 8 | error, |
336 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
337 | 8 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
338 | 8 | "%s: invalid parent locator entry - key data size value out of bounds.", |
339 | 8 | function ); |
340 | | |
341 | 8 | return( -1 ); |
342 | 8 | } |
343 | 497 | if( ( parent_locator_entry->value_data_offset < sizeof( vhdi_parent_locator_header_t ) ) |
344 | 492 | || ( parent_locator_entry->value_data_offset > data_size ) ) |
345 | 37 | { |
346 | 37 | libcerror_error_set( |
347 | 37 | error, |
348 | 37 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
349 | 37 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
350 | 37 | "%s: invalid parent locator entry - value data offset value out of bounds.", |
351 | 37 | function ); |
352 | | |
353 | 37 | return( -1 ); |
354 | 37 | } |
355 | 460 | if( ( parent_locator_entry->value_data_size == 0 ) |
356 | 458 | || ( (size_t) parent_locator_entry->value_data_size > ( data_size - parent_locator_entry->value_data_offset ) ) ) |
357 | 8 | { |
358 | 8 | libcerror_error_set( |
359 | 8 | error, |
360 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
361 | 8 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
362 | 8 | "%s: invalid parent locator entry - value data size value out of bounds.", |
363 | 8 | function ); |
364 | | |
365 | 8 | return( -1 ); |
366 | 8 | } |
367 | | #if defined( HAVE_DEBUG_OUTPUT ) |
368 | | if( libcnotify_verbose != 0 ) |
369 | | { |
370 | | libcnotify_printf( |
371 | | "%s: key data:\n", |
372 | | function ); |
373 | | libcnotify_print_data( |
374 | | &( data[ parent_locator_entry->key_data_offset ] ), |
375 | | (size_t) parent_locator_entry->key_data_size, |
376 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
377 | | |
378 | | if( libvhdi_debug_print_utf16_string_value( |
379 | | function, |
380 | | "key\t\t\t", |
381 | | &( data[ parent_locator_entry->key_data_offset ] ), |
382 | | (size_t) parent_locator_entry->key_data_size, |
383 | | LIBUNA_ENDIAN_LITTLE, |
384 | | error ) != 1 ) |
385 | | { |
386 | | libcerror_error_set( |
387 | | error, |
388 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
389 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
390 | | "%s: unable to print UTF-16 string value.", |
391 | | function ); |
392 | | |
393 | | goto on_error; |
394 | | } |
395 | | libcnotify_printf( |
396 | | "\n" ); |
397 | | } |
398 | | #endif |
399 | 452 | parent_locator_entry->key_data = (uint8_t *) memory_allocate( |
400 | 452 | sizeof( uint8_t ) * parent_locator_entry->key_data_size ); |
401 | | |
402 | 452 | if( parent_locator_entry->key_data == NULL ) |
403 | 0 | { |
404 | 0 | libcerror_error_set( |
405 | 0 | error, |
406 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
407 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
408 | 0 | "%s: unable to create key data.", |
409 | 0 | function ); |
410 | |
|
411 | 0 | goto on_error; |
412 | 0 | } |
413 | 452 | if( memory_copy( |
414 | 452 | parent_locator_entry->key_data, |
415 | 452 | &( data[ parent_locator_entry->key_data_offset ] ), |
416 | 452 | (size_t) parent_locator_entry->key_data_size ) == NULL ) |
417 | 0 | { |
418 | 0 | libcerror_error_set( |
419 | 0 | error, |
420 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
421 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
422 | 0 | "%s: unable to copy key data.", |
423 | 0 | function ); |
424 | |
|
425 | 0 | goto on_error; |
426 | 0 | } |
427 | | #if defined( HAVE_DEBUG_OUTPUT ) |
428 | | if( libcnotify_verbose != 0 ) |
429 | | { |
430 | | libcnotify_printf( |
431 | | "%s: value data:\n", |
432 | | function ); |
433 | | libcnotify_print_data( |
434 | | &( data[ parent_locator_entry->value_data_offset ] ), |
435 | | (size_t) parent_locator_entry->value_data_size, |
436 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
437 | | |
438 | | if( libvhdi_debug_print_utf16_string_value( |
439 | | function, |
440 | | "value\t\t\t", |
441 | | &( data[ parent_locator_entry->value_data_offset ] ), |
442 | | (size_t) parent_locator_entry->value_data_size, |
443 | | LIBUNA_ENDIAN_LITTLE, |
444 | | error ) != 1 ) |
445 | | { |
446 | | libcerror_error_set( |
447 | | error, |
448 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
449 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
450 | | "%s: unable to print UTF-16 string value.", |
451 | | function ); |
452 | | |
453 | | goto on_error; |
454 | | } |
455 | | libcnotify_printf( |
456 | | "\n" ); |
457 | | } |
458 | | #endif |
459 | 452 | parent_locator_entry->value_data = (uint8_t *) memory_allocate( |
460 | 452 | sizeof( uint8_t ) * parent_locator_entry->value_data_size ); |
461 | | |
462 | 452 | if( parent_locator_entry->value_data == NULL ) |
463 | 0 | { |
464 | 0 | libcerror_error_set( |
465 | 0 | error, |
466 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
467 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
468 | 0 | "%s: unable to create value data.", |
469 | 0 | function ); |
470 | |
|
471 | 0 | goto on_error; |
472 | 0 | } |
473 | 452 | if( memory_copy( |
474 | 452 | parent_locator_entry->value_data, |
475 | 452 | &( data[ parent_locator_entry->value_data_offset ] ), |
476 | 452 | (size_t) parent_locator_entry->value_data_size ) == NULL ) |
477 | 0 | { |
478 | 0 | libcerror_error_set( |
479 | 0 | error, |
480 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
481 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
482 | 0 | "%s: unable to copy value data.", |
483 | 0 | function ); |
484 | |
|
485 | 0 | goto on_error; |
486 | 0 | } |
487 | 452 | return( 1 ); |
488 | | |
489 | 0 | on_error: |
490 | 0 | if( parent_locator_entry->key_data != NULL ) |
491 | 0 | { |
492 | 0 | memory_free( |
493 | 0 | parent_locator_entry->key_data ); |
494 | |
|
495 | 0 | parent_locator_entry->key_data = NULL; |
496 | 0 | } |
497 | 0 | if( parent_locator_entry->value_data != NULL ) |
498 | 0 | { |
499 | 0 | memory_free( |
500 | 0 | parent_locator_entry->value_data ); |
501 | |
|
502 | 0 | parent_locator_entry->value_data = NULL; |
503 | 0 | } |
504 | 0 | return( -1 ); |
505 | 452 | } |
506 | | |
507 | | /* Compares an UTF-8 string with the parent locator entry key |
508 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
509 | | */ |
510 | | int libvhdi_parent_locator_compare_key_with_utf8_string( |
511 | | libvhdi_parent_locator_entry_t *parent_locator_entry, |
512 | | const uint8_t *utf8_string, |
513 | | size_t utf8_string_length, |
514 | | libcerror_error_t **error ) |
515 | 1.40k | { |
516 | 1.40k | static char *function = "libvhdi_parent_locator_compare_key_with_utf8_string"; |
517 | 1.40k | int result = 0; |
518 | | |
519 | 1.40k | if( parent_locator_entry == NULL ) |
520 | 0 | { |
521 | 0 | libcerror_error_set( |
522 | 0 | error, |
523 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
524 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
525 | 0 | "%s: invalid parent locator entry.", |
526 | 0 | function ); |
527 | |
|
528 | 0 | return( -1 ); |
529 | 0 | } |
530 | 1.40k | result = libuna_utf8_string_compare_with_utf16_stream( |
531 | 1.40k | utf8_string, |
532 | 1.40k | utf8_string_length, |
533 | 1.40k | parent_locator_entry->key_data, |
534 | 1.40k | parent_locator_entry->key_data_size, |
535 | 1.40k | LIBUNA_ENDIAN_LITTLE, |
536 | 1.40k | error ); |
537 | | |
538 | 1.40k | if( result == -1 ) |
539 | 41 | { |
540 | 41 | libcerror_error_set( |
541 | 41 | error, |
542 | 41 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
543 | 41 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
544 | 41 | "%s: unable to compare UTF-8 string with key.", |
545 | 41 | function ); |
546 | | |
547 | 41 | return( -1 ); |
548 | 41 | } |
549 | 1.36k | return( result ); |
550 | 1.40k | } |
551 | | |
552 | | /* Retrieves the parent locator entry value as a big-endian GUID |
553 | | * Returns 1 if successful or -1 on error |
554 | | */ |
555 | | int libvhdi_parent_locator_get_value_as_guid( |
556 | | libvhdi_parent_locator_entry_t *parent_locator_entry, |
557 | | uint8_t *guid_data, |
558 | | size_t guid_data_size, |
559 | | libcerror_error_t **error ) |
560 | 0 | { |
561 | 0 | uint8_t guid_string[ 48 ]; |
562 | |
|
563 | 0 | libfguid_identifier_t *identifier = NULL; |
564 | 0 | static char *function = "libvhdi_parent_locator_get_value_as_guid"; |
565 | |
|
566 | 0 | if( parent_locator_entry == NULL ) |
567 | 0 | { |
568 | 0 | libcerror_error_set( |
569 | 0 | error, |
570 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
571 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
572 | 0 | "%s: missing parent locator entry.", |
573 | 0 | function ); |
574 | |
|
575 | 0 | goto on_error; |
576 | 0 | } |
577 | 0 | if( libuna_utf8_string_copy_from_utf16_stream( |
578 | 0 | guid_string, |
579 | 0 | 48, |
580 | 0 | parent_locator_entry->value_data, |
581 | 0 | parent_locator_entry->value_data_size, |
582 | 0 | LIBUNA_ENDIAN_LITTLE, |
583 | 0 | error ) != 1 ) |
584 | 0 | { |
585 | 0 | libcerror_error_set( |
586 | 0 | error, |
587 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
588 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
589 | 0 | "%s: unable to copy value data to UTF-8 string.", |
590 | 0 | function ); |
591 | |
|
592 | 0 | goto on_error; |
593 | 0 | } |
594 | 0 | if( libfguid_identifier_initialize( |
595 | 0 | &identifier, |
596 | 0 | error ) != 1 ) |
597 | 0 | { |
598 | 0 | libcerror_error_set( |
599 | 0 | error, |
600 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
601 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
602 | 0 | "%s: unable to create identifier.", |
603 | 0 | function ); |
604 | |
|
605 | 0 | goto on_error; |
606 | 0 | } |
607 | | /* TODO add libfguid_identifier_copy_from_utf16_stream ? */ |
608 | 0 | if( libfguid_identifier_copy_from_utf8_string( |
609 | 0 | identifier, |
610 | 0 | guid_string, |
611 | 0 | 38, |
612 | 0 | LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, |
613 | 0 | error ) != 1 ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
619 | 0 | "%s: unable to copy UTF-8 string to identifier.", |
620 | 0 | function ); |
621 | |
|
622 | 0 | goto on_error; |
623 | 0 | } |
624 | 0 | if( libfguid_identifier_copy_to_byte_stream( |
625 | 0 | identifier, |
626 | 0 | guid_data, |
627 | 0 | guid_data_size, |
628 | 0 | LIBFGUID_ENDIAN_BIG, |
629 | 0 | error ) != 1 ) |
630 | 0 | { |
631 | 0 | libcerror_error_set( |
632 | 0 | error, |
633 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
634 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
635 | 0 | "%s: unable to copy identifier to GUID data.", |
636 | 0 | function ); |
637 | |
|
638 | 0 | goto on_error; |
639 | 0 | } |
640 | 0 | if( libfguid_identifier_free( |
641 | 0 | &identifier, |
642 | 0 | error ) != 1 ) |
643 | 0 | { |
644 | 0 | libcerror_error_set( |
645 | 0 | error, |
646 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
647 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
648 | 0 | "%s: unable to free identifier.", |
649 | 0 | function ); |
650 | |
|
651 | 0 | goto on_error; |
652 | 0 | } |
653 | 0 | return( 1 ); |
654 | | |
655 | 0 | on_error: |
656 | 0 | if( identifier != NULL ) |
657 | 0 | { |
658 | 0 | libfguid_identifier_free( |
659 | 0 | &identifier, |
660 | | NULL ); |
661 | 0 | } |
662 | 0 | return( 1 ); |
663 | 0 | } |
664 | | |