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