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