/src/libfwsi/libfwsi/libfwsi_file_entry_extension_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * File entry extension values functions |
3 | | * |
4 | | * Copyright (C) 2010-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libfwsi_debug.h" |
28 | | #include "libfwsi_definitions.h" |
29 | | #include "libfwsi_file_entry_extension_values.h" |
30 | | #include "libfwsi_libcerror.h" |
31 | | #include "libfwsi_libcnotify.h" |
32 | | #include "libfwsi_libfdatetime.h" |
33 | | #include "libfwsi_libuna.h" |
34 | | |
35 | | /* Creates file entry extension values |
36 | | * Make sure the value file_entry_extension_values is referencing, is set to NULL |
37 | | * Returns 1 if successful or -1 on error |
38 | | */ |
39 | | int libfwsi_file_entry_extension_values_initialize( |
40 | | libfwsi_file_entry_extension_values_t **file_entry_extension_values, |
41 | | libcerror_error_t **error ) |
42 | 0 | { |
43 | 0 | static char *function = "libfwsi_file_entry_extension_values_initialize"; |
44 | |
|
45 | 0 | if( file_entry_extension_values == NULL ) |
46 | 0 | { |
47 | 0 | libcerror_error_set( |
48 | 0 | error, |
49 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
50 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
51 | 0 | "%s: invalid file entry extension values.", |
52 | 0 | function ); |
53 | |
|
54 | 0 | return( -1 ); |
55 | 0 | } |
56 | 0 | if( *file_entry_extension_values != NULL ) |
57 | 0 | { |
58 | 0 | libcerror_error_set( |
59 | 0 | error, |
60 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
61 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
62 | 0 | "%s: invalid file entry extension values value already set.", |
63 | 0 | function ); |
64 | |
|
65 | 0 | return( -1 ); |
66 | 0 | } |
67 | 0 | *file_entry_extension_values = memory_allocate_structure( |
68 | 0 | libfwsi_file_entry_extension_values_t ); |
69 | |
|
70 | 0 | if( *file_entry_extension_values == NULL ) |
71 | 0 | { |
72 | 0 | libcerror_error_set( |
73 | 0 | error, |
74 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
75 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
76 | 0 | "%s: unable to create file entry extension values.", |
77 | 0 | function ); |
78 | |
|
79 | 0 | goto on_error; |
80 | 0 | } |
81 | 0 | if( memory_set( |
82 | 0 | *file_entry_extension_values, |
83 | 0 | 0, |
84 | 0 | sizeof( libfwsi_file_entry_extension_values_t ) ) == NULL ) |
85 | 0 | { |
86 | 0 | libcerror_error_set( |
87 | 0 | error, |
88 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
89 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
90 | 0 | "%s: unable to clear file entry extension values.", |
91 | 0 | function ); |
92 | |
|
93 | 0 | goto on_error; |
94 | 0 | } |
95 | 0 | return( 1 ); |
96 | | |
97 | 0 | on_error: |
98 | 0 | if( *file_entry_extension_values != NULL ) |
99 | 0 | { |
100 | 0 | memory_free( |
101 | 0 | *file_entry_extension_values ); |
102 | |
|
103 | 0 | *file_entry_extension_values = NULL; |
104 | 0 | } |
105 | 0 | return( -1 ); |
106 | 0 | } |
107 | | |
108 | | /* Frees file entry extension values |
109 | | * Returns 1 if successful or -1 on error |
110 | | */ |
111 | | int libfwsi_file_entry_extension_values_free( |
112 | | libfwsi_file_entry_extension_values_t **file_entry_extension_values, |
113 | | libcerror_error_t **error ) |
114 | 0 | { |
115 | 0 | static char *function = "libfwsi_file_entry_extension_values_free"; |
116 | |
|
117 | 0 | if( file_entry_extension_values == NULL ) |
118 | 0 | { |
119 | 0 | libcerror_error_set( |
120 | 0 | error, |
121 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
122 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
123 | 0 | "%s: invalid file entry extension values.", |
124 | 0 | function ); |
125 | |
|
126 | 0 | return( -1 ); |
127 | 0 | } |
128 | 0 | if( *file_entry_extension_values != NULL ) |
129 | 0 | { |
130 | 0 | if( ( *file_entry_extension_values )->long_name != NULL ) |
131 | 0 | { |
132 | 0 | memory_free( |
133 | 0 | ( *file_entry_extension_values )->long_name ); |
134 | 0 | } |
135 | 0 | if( ( *file_entry_extension_values )->localized_name != NULL ) |
136 | 0 | { |
137 | 0 | memory_free( |
138 | 0 | ( *file_entry_extension_values )->localized_name ); |
139 | 0 | } |
140 | 0 | memory_free( |
141 | 0 | *file_entry_extension_values ); |
142 | |
|
143 | 0 | *file_entry_extension_values = NULL; |
144 | 0 | } |
145 | 0 | return( 1 ); |
146 | 0 | } |
147 | | |
148 | | /* Reads the file entry extension values |
149 | | * Returns 1 if successful, 0 if not supported or -1 on error |
150 | | */ |
151 | | int libfwsi_file_entry_extension_values_read_data( |
152 | | libfwsi_file_entry_extension_values_t *file_entry_extension_values, |
153 | | const uint8_t *data, |
154 | | size_t data_size, |
155 | | int ascii_codepage, |
156 | | libcerror_error_t **error ) |
157 | 0 | { |
158 | 0 | static char *function = "libfwsi_file_entry_extension_values_read_data"; |
159 | 0 | size_t data_offset = 0; |
160 | 0 | size_t string_size = 0; |
161 | 0 | uint32_t signature = 0; |
162 | 0 | uint16_t long_string_size = 0; |
163 | 0 | uint16_t version = 0; |
164 | |
|
165 | | #if defined( HAVE_DEBUG_OUTPUT ) |
166 | | uint16_t value_16bit = 0; |
167 | | #endif |
168 | |
|
169 | 0 | if( file_entry_extension_values == NULL ) |
170 | 0 | { |
171 | 0 | libcerror_error_set( |
172 | 0 | error, |
173 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
174 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
175 | 0 | "%s: invalid file entry extension values.", |
176 | 0 | function ); |
177 | |
|
178 | 0 | return( -1 ); |
179 | 0 | } |
180 | 0 | if( data == NULL ) |
181 | 0 | { |
182 | 0 | libcerror_error_set( |
183 | 0 | error, |
184 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
185 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
186 | 0 | "%s: invalid data.", |
187 | 0 | function ); |
188 | |
|
189 | 0 | return( -1 ); |
190 | 0 | } |
191 | 0 | if( data_size > (size_t) SSIZE_MAX ) |
192 | 0 | { |
193 | 0 | libcerror_error_set( |
194 | 0 | error, |
195 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
196 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
197 | 0 | "%s: data size exceeds maximum.", |
198 | 0 | function ); |
199 | |
|
200 | 0 | return( -1 ); |
201 | 0 | } |
202 | | /* Do not try to parse unsupported data sizes |
203 | | */ |
204 | 0 | if( data_size < 20 ) |
205 | 0 | { |
206 | 0 | return( 0 ); |
207 | 0 | } |
208 | | /* Do not try to parse unsupported extension block signatures |
209 | | */ |
210 | 0 | byte_stream_copy_to_uint32_little_endian( |
211 | 0 | &( data[ 4 ] ), |
212 | 0 | signature ); |
213 | |
|
214 | 0 | if( signature != 0xbeef0004 ) |
215 | 0 | { |
216 | 0 | return( 0 ); |
217 | 0 | } |
218 | | /* Do not try to parse unsupported version values |
219 | | */ |
220 | 0 | byte_stream_copy_to_uint32_little_endian( |
221 | 0 | &( data[ 2 ] ), |
222 | 0 | version ); |
223 | |
|
224 | 0 | if( ( version != 3 ) |
225 | 0 | && ( version != 7 ) |
226 | 0 | && ( version != 8 ) |
227 | 0 | && ( version != 9 ) ) |
228 | 0 | { |
229 | 0 | return( 0 ); |
230 | 0 | } |
231 | 0 | file_entry_extension_values->ascii_codepage = ascii_codepage; |
232 | |
|
233 | 0 | byte_stream_copy_to_uint32_little_endian( |
234 | 0 | &( data[ 8 ] ), |
235 | 0 | file_entry_extension_values->creation_time ); |
236 | |
|
237 | 0 | byte_stream_copy_to_uint32_little_endian( |
238 | 0 | &( data[ 12 ] ), |
239 | 0 | file_entry_extension_values->access_time ); |
240 | |
|
241 | | #if defined( HAVE_DEBUG_OUTPUT ) |
242 | | if( libcnotify_verbose != 0 ) |
243 | | { |
244 | | if( libfwsi_debug_print_fat_date_time_value( |
245 | | function, |
246 | | "creation time\t\t", |
247 | | &( data[ 8 ] ), |
248 | | 4, |
249 | | LIBFDATETIME_ENDIAN_LITTLE, |
250 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
251 | | error ) != 1 ) |
252 | | { |
253 | | libcerror_error_set( |
254 | | error, |
255 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
256 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
257 | | "%s: unable to print FAT date time value.", |
258 | | function ); |
259 | | |
260 | | goto on_error; |
261 | | } |
262 | | if( libfwsi_debug_print_fat_date_time_value( |
263 | | function, |
264 | | "access time\t\t", |
265 | | &( data[ 12 ] ), |
266 | | 4, |
267 | | LIBFDATETIME_ENDIAN_LITTLE, |
268 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
269 | | error ) != 1 ) |
270 | | { |
271 | | libcerror_error_set( |
272 | | error, |
273 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
274 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
275 | | "%s: unable to print FAT date time value.", |
276 | | function ); |
277 | | |
278 | | goto on_error; |
279 | | } |
280 | | byte_stream_copy_to_uint16_little_endian( |
281 | | &( data[ 16 ] ), |
282 | | value_16bit ); |
283 | | libcnotify_printf( |
284 | | "%s: unknown1\t\t\t: 0x%04" PRIx16 "\n", |
285 | | function, |
286 | | value_16bit ); |
287 | | } |
288 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
289 | |
|
290 | 0 | data_offset = 18; |
291 | |
|
292 | 0 | if( version >= 7 ) |
293 | 0 | { |
294 | | /* Do not try to parse unsupported data sizes |
295 | | */ |
296 | 0 | if( data_offset >= ( data_size - 18 ) ) |
297 | 0 | { |
298 | 0 | return( 0 ); |
299 | 0 | } |
300 | | #if defined( HAVE_DEBUG_OUTPUT ) |
301 | | if( libcnotify_verbose != 0 ) |
302 | | { |
303 | | byte_stream_copy_to_uint16_little_endian( |
304 | | &( data[ data_offset ] ), |
305 | | value_16bit ); |
306 | | |
307 | | libcnotify_printf( |
308 | | "%s: unknown2\t\t\t: 0x%04" PRIx16 "\n", |
309 | | function, |
310 | | value_16bit ); |
311 | | } |
312 | | #endif |
313 | 0 | data_offset += 2; |
314 | |
|
315 | 0 | byte_stream_copy_to_uint64_little_endian( |
316 | 0 | &( data[ data_offset ] ), |
317 | 0 | file_entry_extension_values->file_reference ); |
318 | |
|
319 | | #if defined( HAVE_DEBUG_OUTPUT ) |
320 | | if( libcnotify_verbose != 0 ) |
321 | | { |
322 | | if( file_entry_extension_values->file_reference == 0 ) |
323 | | { |
324 | | libcnotify_printf( |
325 | | "%s: file reference\t\t: %" PRIu64 "\n", |
326 | | function, |
327 | | file_entry_extension_values->file_reference ); |
328 | | } |
329 | | else |
330 | | { |
331 | | libcnotify_printf( |
332 | | "%s: file reference\t\t: MFT entry: %" PRIu64 ", sequence: %" PRIu64 "\n", |
333 | | function, |
334 | | file_entry_extension_values->file_reference & 0xffffffffffffUL, |
335 | | file_entry_extension_values->file_reference >> 48 ); |
336 | | } |
337 | | } |
338 | | #endif |
339 | 0 | data_offset += 8; |
340 | |
|
341 | | #if defined( HAVE_DEBUG_OUTPUT ) |
342 | | if( libcnotify_verbose != 0 ) |
343 | | { |
344 | | libcnotify_printf( |
345 | | "%s: unknown4:\n", |
346 | | function ); |
347 | | libcnotify_print_data( |
348 | | &( data[ data_offset ] ), |
349 | | 8, |
350 | | 0 ); |
351 | | } |
352 | | #endif |
353 | 0 | data_offset += 8; |
354 | 0 | } |
355 | | /* Do not try to parse unsupported data sizes |
356 | | */ |
357 | 0 | if( data_offset >= ( data_size - 2 ) ) |
358 | 0 | { |
359 | 0 | return( 0 ); |
360 | 0 | } |
361 | 0 | byte_stream_copy_to_uint16_little_endian( |
362 | 0 | &( data[ data_offset ] ), |
363 | 0 | long_string_size ); |
364 | |
|
365 | | #if defined( HAVE_DEBUG_OUTPUT ) |
366 | | if( libcnotify_verbose != 0 ) |
367 | | { |
368 | | libcnotify_printf( |
369 | | "%s: long name size\t\t: %" PRIu16 "\n", |
370 | | function, |
371 | | long_string_size ); |
372 | | } |
373 | | #endif |
374 | 0 | data_offset += 2; |
375 | |
|
376 | 0 | if( version >= 9 ) |
377 | 0 | { |
378 | | /* Do not try to parse unsupported data sizes |
379 | | */ |
380 | 0 | if( data_offset >= ( data_size - 4 ) ) |
381 | 0 | { |
382 | 0 | return( 0 ); |
383 | 0 | } |
384 | | #if defined( HAVE_DEBUG_OUTPUT ) |
385 | | if( libcnotify_verbose != 0 ) |
386 | | { |
387 | | libcnotify_printf( |
388 | | "%s: unknown5:\n", |
389 | | function ); |
390 | | libcnotify_print_data( |
391 | | &( data[ data_offset ] ), |
392 | | 4, |
393 | | 0 ); |
394 | | } |
395 | | #endif |
396 | 0 | data_offset += 4; |
397 | 0 | } |
398 | 0 | if( version >= 8 ) |
399 | 0 | { |
400 | | /* Do not try to parse unsupported data sizes |
401 | | */ |
402 | 0 | if( data_offset >= ( data_size - 4 ) ) |
403 | 0 | { |
404 | 0 | return( 0 ); |
405 | 0 | } |
406 | | #if defined( HAVE_DEBUG_OUTPUT ) |
407 | | if( libcnotify_verbose != 0 ) |
408 | | { |
409 | | libcnotify_printf( |
410 | | "%s: unknown6:\n", |
411 | | function ); |
412 | | libcnotify_print_data( |
413 | | &( data[ data_offset ] ), |
414 | | 4, |
415 | | 0 ); |
416 | | } |
417 | | #endif |
418 | 0 | data_offset += 4; |
419 | 0 | } |
420 | | /* Do not try to parse unsupported data sizes |
421 | | */ |
422 | 0 | if( data_offset >= data_size ) |
423 | 0 | { |
424 | 0 | return( 0 ); |
425 | 0 | } |
426 | | /* Determine the long name size |
427 | | */ |
428 | 0 | for( string_size = data_offset; |
429 | 0 | ( string_size + 1 ) < data_size - 2; |
430 | 0 | string_size += 2 ) |
431 | 0 | { |
432 | 0 | if( ( data[ string_size ] == 0 ) |
433 | 0 | && ( data[ string_size + 1 ] == 0 ) ) |
434 | 0 | { |
435 | 0 | string_size += 2; |
436 | |
|
437 | 0 | break; |
438 | 0 | } |
439 | 0 | } |
440 | 0 | string_size -= data_offset; |
441 | |
|
442 | 0 | if( ( string_size == 0 ) |
443 | 0 | || ( string_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
444 | 0 | { |
445 | 0 | libcerror_error_set( |
446 | 0 | error, |
447 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
448 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
449 | 0 | "%s: invalid long name string size value out of bounds.", |
450 | 0 | function ); |
451 | |
|
452 | 0 | goto on_error; |
453 | 0 | } |
454 | 0 | file_entry_extension_values->long_name = (uint8_t *) memory_allocate( |
455 | 0 | sizeof( uint8_t ) * string_size ); |
456 | |
|
457 | 0 | if( file_entry_extension_values->long_name == NULL ) |
458 | 0 | { |
459 | 0 | libcerror_error_set( |
460 | 0 | error, |
461 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
462 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
463 | 0 | "%s: unable to create long name.", |
464 | 0 | function ); |
465 | |
|
466 | 0 | goto on_error; |
467 | 0 | } |
468 | 0 | if( memory_copy( |
469 | 0 | file_entry_extension_values->long_name, |
470 | 0 | &( data[ data_offset ] ), |
471 | 0 | string_size ) == NULL ) |
472 | 0 | { |
473 | 0 | libcerror_error_set( |
474 | 0 | error, |
475 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
476 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
477 | 0 | "%s: unable to copy long name.", |
478 | 0 | function ); |
479 | |
|
480 | 0 | goto on_error; |
481 | 0 | } |
482 | 0 | file_entry_extension_values->long_name_size = string_size; |
483 | |
|
484 | | #if defined( HAVE_DEBUG_OUTPUT ) |
485 | | if( libcnotify_verbose != 0 ) |
486 | | { |
487 | | if( libfwsi_debug_print_utf16_string_value( |
488 | | function, |
489 | | "long name\t\t", |
490 | | file_entry_extension_values->long_name, |
491 | | file_entry_extension_values->long_name_size, |
492 | | LIBUNA_ENDIAN_LITTLE, |
493 | | error ) != 1 ) |
494 | | { |
495 | | libcerror_error_set( |
496 | | error, |
497 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
498 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
499 | | "%s: unable to print UTF-16 string value.", |
500 | | function ); |
501 | | |
502 | | goto on_error; |
503 | | } |
504 | | } |
505 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
506 | |
|
507 | 0 | data_offset += string_size; |
508 | |
|
509 | 0 | if( long_string_size > 0 ) |
510 | 0 | { |
511 | | /* Do not try to parse unsupported data sizes |
512 | | */ |
513 | 0 | if( data_offset >= data_size ) |
514 | 0 | { |
515 | 0 | return( 0 ); |
516 | 0 | } |
517 | 0 | if( version >= 7 ) |
518 | 0 | { |
519 | | /* Determine the localized name size |
520 | | */ |
521 | 0 | for( string_size = data_offset; |
522 | 0 | ( string_size + 1 ) < data_size - 2; |
523 | 0 | string_size += 2 ) |
524 | 0 | { |
525 | 0 | if( ( data[ string_size ] == 0 ) |
526 | 0 | && ( data[ string_size + 1 ] == 0 ) ) |
527 | 0 | { |
528 | 0 | string_size += 2; |
529 | |
|
530 | 0 | break; |
531 | 0 | } |
532 | 0 | } |
533 | 0 | string_size -= data_offset; |
534 | |
|
535 | 0 | if( ( string_size == 0 ) |
536 | 0 | || ( string_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
537 | 0 | { |
538 | 0 | libcerror_error_set( |
539 | 0 | error, |
540 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
541 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
542 | 0 | "%s: invalid localized name string size value out of bounds.", |
543 | 0 | function ); |
544 | |
|
545 | 0 | goto on_error; |
546 | 0 | } |
547 | 0 | file_entry_extension_values->localized_name = (uint8_t *) memory_allocate( |
548 | 0 | sizeof( uint8_t ) * string_size ); |
549 | |
|
550 | 0 | if( file_entry_extension_values->localized_name == NULL ) |
551 | 0 | { |
552 | 0 | libcerror_error_set( |
553 | 0 | error, |
554 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
555 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
556 | 0 | "%s: unable to create localized name.", |
557 | 0 | function ); |
558 | |
|
559 | 0 | goto on_error; |
560 | 0 | } |
561 | 0 | if( memory_copy( |
562 | 0 | file_entry_extension_values->localized_name, |
563 | 0 | &( data[ data_offset ] ), |
564 | 0 | string_size ) == NULL ) |
565 | 0 | { |
566 | 0 | libcerror_error_set( |
567 | 0 | error, |
568 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
569 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
570 | 0 | "%s: unable to copy localized name.", |
571 | 0 | function ); |
572 | |
|
573 | 0 | goto on_error; |
574 | 0 | } |
575 | 0 | file_entry_extension_values->localized_name_size = string_size; |
576 | |
|
577 | | #if defined( HAVE_DEBUG_OUTPUT ) |
578 | | if( libcnotify_verbose != 0 ) |
579 | | { |
580 | | if( libfwsi_debug_print_utf16_string_value( |
581 | | function, |
582 | | "localized name\t\t", |
583 | | file_entry_extension_values->localized_name, |
584 | | file_entry_extension_values->localized_name_size, |
585 | | LIBUNA_ENDIAN_LITTLE, |
586 | | error ) != 1 ) |
587 | | { |
588 | | libcerror_error_set( |
589 | | error, |
590 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
591 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
592 | | "%s: unable to print UTF-16 string value.", |
593 | | function ); |
594 | | |
595 | | goto on_error; |
596 | | } |
597 | | } |
598 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
599 | 0 | } |
600 | 0 | else if( version >= 3 ) |
601 | 0 | { |
602 | | /* Determine the localized name size |
603 | | */ |
604 | 0 | for( string_size = data_offset; |
605 | 0 | string_size < data_size - 2; |
606 | 0 | string_size += 1 ) |
607 | 0 | { |
608 | 0 | if( data[ string_size ] == 0 ) |
609 | 0 | { |
610 | 0 | string_size += 1; |
611 | |
|
612 | 0 | break; |
613 | 0 | } |
614 | 0 | } |
615 | 0 | string_size -= data_offset; |
616 | |
|
617 | 0 | if( ( string_size == 0 ) |
618 | 0 | || ( string_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
619 | 0 | { |
620 | 0 | libcerror_error_set( |
621 | 0 | error, |
622 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
623 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
624 | 0 | "%s: invalid localized name string size value out of bounds.", |
625 | 0 | function ); |
626 | |
|
627 | 0 | goto on_error; |
628 | 0 | } |
629 | 0 | file_entry_extension_values->localized_name = (uint8_t *) memory_allocate( |
630 | 0 | sizeof( uint8_t ) * string_size ); |
631 | |
|
632 | 0 | if( file_entry_extension_values->localized_name == NULL ) |
633 | 0 | { |
634 | 0 | libcerror_error_set( |
635 | 0 | error, |
636 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
637 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
638 | 0 | "%s: unable to create localized name.", |
639 | 0 | function ); |
640 | |
|
641 | 0 | goto on_error; |
642 | 0 | } |
643 | 0 | if( memory_copy( |
644 | 0 | file_entry_extension_values->localized_name, |
645 | 0 | &( data[ data_offset ] ), |
646 | 0 | string_size ) == NULL ) |
647 | 0 | { |
648 | 0 | libcerror_error_set( |
649 | 0 | error, |
650 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
651 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
652 | 0 | "%s: unable to copy localized name.", |
653 | 0 | function ); |
654 | |
|
655 | 0 | goto on_error; |
656 | 0 | } |
657 | 0 | file_entry_extension_values->localized_name_size = string_size; |
658 | |
|
659 | | #if defined( HAVE_DEBUG_OUTPUT ) |
660 | | if( libcnotify_verbose != 0 ) |
661 | | { |
662 | | if( libfwsi_debug_print_string_value( |
663 | | function, |
664 | | "localized name\t\t", |
665 | | file_entry_extension_values->localized_name, |
666 | | file_entry_extension_values->localized_name_size, |
667 | | ascii_codepage, |
668 | | error ) != 1 ) |
669 | | { |
670 | | libcerror_error_set( |
671 | | error, |
672 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
673 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
674 | | "%s: unable to print string value.", |
675 | | function ); |
676 | | |
677 | | goto on_error; |
678 | | } |
679 | | } |
680 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
681 | 0 | } |
682 | 0 | data_offset += string_size; |
683 | 0 | } |
684 | 0 | return( 1 ); |
685 | | |
686 | 0 | on_error: |
687 | 0 | if( file_entry_extension_values->localized_name != NULL ) |
688 | 0 | { |
689 | 0 | memory_free( |
690 | 0 | file_entry_extension_values->localized_name ); |
691 | |
|
692 | 0 | file_entry_extension_values->localized_name = NULL; |
693 | 0 | } |
694 | 0 | file_entry_extension_values->localized_name_size = 0; |
695 | |
|
696 | 0 | if( file_entry_extension_values->long_name != NULL ) |
697 | 0 | { |
698 | 0 | memory_free( |
699 | 0 | file_entry_extension_values->long_name ); |
700 | |
|
701 | 0 | file_entry_extension_values->long_name = NULL; |
702 | 0 | } |
703 | 0 | file_entry_extension_values->long_name_size = 0; |
704 | |
|
705 | 0 | return( -1 ); |
706 | 0 | } |
707 | | |