Coverage Report

Created: 2024-02-25 07:20

/src/libpff/libpff/libpff_file.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * File functions
3
 *
4
 * Copyright (C) 2008-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 <narrow_string.h>
25
#include <types.h>
26
#include <wide_string.h>
27
28
#include "libpff_codepage.h"
29
#include "libpff_debug.h"
30
#include "libpff_definitions.h"
31
#include "libpff_descriptors_index.h"
32
#include "libpff_file.h"
33
#include "libpff_file_header.h"
34
#include "libpff_folder.h"
35
#include "libpff_io_handle.h"
36
#include "libpff_item.h"
37
#include "libpff_item_descriptor.h"
38
#include "libpff_item_tree.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_name_to_id_map.h"
46
#include "libpff_offsets_index.h"
47
#include "libpff_recover.h"
48
#include "libpff_types.h"
49
50
/* Creates a file
51
 * Make sure the value file is referencing, is set to NULL
52
 * Returns 1 if successful or -1 on error
53
 */
54
int libpff_file_initialize(
55
     libpff_file_t **file,
56
     libcerror_error_t **error )
57
9.60k
{
58
9.60k
  libpff_internal_file_t *internal_file = NULL;
59
9.60k
  static char *function                 = "libpff_file_initialize";
60
61
9.60k
  if( file == NULL )
62
0
  {
63
0
    libcerror_error_set(
64
0
     error,
65
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
66
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
67
0
     "%s: invalid file.",
68
0
     function );
69
70
0
    return( -1 );
71
0
  }
72
9.60k
  if( *file != NULL )
73
0
  {
74
0
    libcerror_error_set(
75
0
     error,
76
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
77
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
78
0
     "%s: invalid file value already set.",
79
0
     function );
80
81
0
    return( -1 );
82
0
  }
83
9.60k
  internal_file = memory_allocate_structure(
84
9.60k
                   libpff_internal_file_t );
85
86
9.60k
  if( internal_file == NULL )
87
0
  {
88
0
    libcerror_error_set(
89
0
     error,
90
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
91
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
92
0
     "%s: unable to create file.",
93
0
     function );
94
95
0
    goto on_error;
96
0
  }
97
9.60k
  if( memory_set(
98
9.60k
       internal_file,
99
9.60k
       0,
100
9.60k
       sizeof( libpff_internal_file_t ) ) == NULL )
101
0
  {
102
0
    libcerror_error_set(
103
0
     error,
104
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
105
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
106
0
     "%s: unable to clear file.",
107
0
     function );
108
109
0
    goto on_error;
110
0
  }
111
9.60k
  if( libpff_io_handle_initialize(
112
9.60k
       &( internal_file->io_handle ),
113
9.60k
       error ) != 1 )
114
0
  {
115
0
    libcerror_error_set(
116
0
     error,
117
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
118
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
119
0
     "%s: unable to create IO handle.",
120
0
     function );
121
122
0
    goto on_error;
123
0
  }
124
9.60k
  *file = (libpff_file_t *) internal_file;
125
126
9.60k
  return( 1 );
127
128
0
on_error:
129
0
  if( internal_file != NULL )
130
0
  {
131
0
    memory_free(
132
0
     internal_file );
133
0
  }
134
0
  return( -1 );
135
9.60k
}
136
137
/* Frees a file
138
 * Returns 1 if successful or -1 on error
139
 */
140
int libpff_file_free(
141
     libpff_file_t **file,
142
     libcerror_error_t **error )
143
9.60k
{
144
9.60k
  libpff_internal_file_t *internal_file = NULL;
145
9.60k
  static char *function                 = "libpff_file_free";
146
9.60k
  int result                            = 1;
147
148
9.60k
  if( file == NULL )
149
0
  {
150
0
    libcerror_error_set(
151
0
     error,
152
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
153
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
154
0
     "%s: invalid file.",
155
0
     function );
156
157
0
    return( -1 );
158
0
  }
159
9.60k
  if( *file != NULL )
160
9.60k
  {
161
9.60k
    internal_file = (libpff_internal_file_t *) *file;
162
163
9.60k
    if( internal_file->file_io_handle != NULL )
164
0
    {
165
0
      if( libpff_file_close(
166
0
           *file,
167
0
           error ) != 0 )
168
0
      {
169
0
        libcerror_error_set(
170
0
         error,
171
0
         LIBCERROR_ERROR_DOMAIN_IO,
172
0
         LIBCERROR_IO_ERROR_CLOSE_FAILED,
173
0
         "%s: unable to close file.",
174
0
         function );
175
176
0
        result = -1;
177
0
      }
178
0
    }
179
9.60k
    *file = NULL;
180
181
9.60k
    if( libpff_io_handle_free(
182
9.60k
         &( internal_file->io_handle ),
183
9.60k
         error ) != 1 )
184
0
    {
185
0
      libcerror_error_set(
186
0
       error,
187
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
188
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
189
0
       "%s: unable to free IO handle.",
190
0
       function );
191
192
0
      result = -1;
193
0
    }
194
9.60k
    memory_free(
195
9.60k
     internal_file );
196
9.60k
  }
197
9.60k
  return( result );
198
9.60k
}
199
200
/* Signals the file to abort its current activity
201
 * Returns 1 if successful or -1 on error
202
 */
203
int libpff_file_signal_abort(
204
     libpff_file_t *file,
205
     libcerror_error_t **error )
206
0
{
207
0
  libpff_internal_file_t *internal_file = NULL;
208
0
  static char *function                 = "libpff_file_signal_abort";
209
210
0
  if( file == NULL )
211
0
  {
212
0
    libcerror_error_set(
213
0
     error,
214
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
215
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
216
0
     "%s: invalid file.",
217
0
     function );
218
219
0
    return( -1 );
220
0
  }
221
0
  internal_file = (libpff_internal_file_t *) file;
222
223
0
  if( internal_file->io_handle == NULL )
224
0
  {
225
0
    libcerror_error_set(
226
0
     error,
227
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
228
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
229
0
     "%s: invalid file - missing IO handle.",
230
0
     function );
231
232
0
    return( -1 );
233
0
  }
234
0
  internal_file->io_handle->abort = 1;
235
236
0
  return( 1 );
237
0
}
238
239
/* Opens a file
240
 * Returns 1 if successful or -1 on error
241
 */
242
int libpff_file_open(
243
     libpff_file_t *file,
244
     const char *filename,
245
     int access_flags,
246
     libcerror_error_t **error )
247
0
{
248
0
  libbfio_handle_t *file_io_handle      = NULL;
249
0
  libpff_internal_file_t *internal_file = NULL;
250
0
  static char *function                 = "libpff_file_open";
251
0
  size_t filename_length                = 0;
252
253
0
  if( file == NULL )
254
0
  {
255
0
    libcerror_error_set(
256
0
     error,
257
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
258
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
259
0
     "%s: invalid file.",
260
0
     function );
261
262
0
    return( -1 );
263
0
  }
264
0
  internal_file = (libpff_internal_file_t *) file;
265
266
0
  if( filename == NULL )
267
0
  {
268
0
    libcerror_error_set(
269
0
     error,
270
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
271
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
272
0
     "%s: invalid filename.",
273
0
     function );
274
275
0
    return( -1 );
276
0
  }
277
0
  if( libbfio_file_initialize(
278
0
       &file_io_handle,
279
0
       error ) != 1 )
280
0
  {
281
0
    libcerror_error_set(
282
0
     error,
283
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
284
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
285
0
     "%s: unable to create file IO handle.",
286
0
     function );
287
288
0
    goto on_error;
289
0
  }
290
#if defined( HAVE_DEBUG_OUTPUT )
291
  if( libbfio_handle_set_track_offsets_read(
292
       file_io_handle,
293
       1,
294
       error ) != 1 )
295
  {
296
                libcerror_error_set(
297
                 error,
298
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
299
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
300
                 "%s: unable to set track offsets read in file IO handle.",
301
                 function );
302
303
    goto on_error;
304
  }
305
#endif
306
0
  filename_length = narrow_string_length(
307
0
                     filename );
308
309
0
  if( libbfio_file_set_name(
310
0
       file_io_handle,
311
0
       filename,
312
0
       filename_length + 1,
313
0
       error ) != 1 )
314
0
  {
315
0
                libcerror_error_set(
316
0
                 error,
317
0
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
318
0
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
319
0
                 "%s: unable to set filename in file IO handle.",
320
0
                 function );
321
322
0
    goto on_error;
323
0
  }
324
0
  if( libpff_file_open_file_io_handle(
325
0
       file,
326
0
       file_io_handle,
327
0
       access_flags,
328
0
       error ) != 1 )
329
0
  {
330
0
    libcerror_error_set(
331
0
     error,
332
0
     LIBCERROR_ERROR_DOMAIN_IO,
333
0
     LIBCERROR_IO_ERROR_OPEN_FAILED,
334
0
     "%s: unable to open file: %s.",
335
0
     function,
336
0
     filename );
337
338
0
    goto on_error;
339
0
  }
340
0
  internal_file->file_io_handle_created_in_library = 1;
341
342
0
  return( 1 );
343
344
0
on_error:
345
0
  if( file_io_handle != NULL )
346
0
  {
347
0
    libbfio_handle_free(
348
0
     &file_io_handle,
349
0
     NULL );
350
0
  }
351
0
  return( -1 );
352
0
}
353
354
#if defined( HAVE_WIDE_CHARACTER_TYPE )
355
356
/* Opens a file
357
 * Returns 1 if successful or -1 on error
358
 */
359
int libpff_file_open_wide(
360
     libpff_file_t *file,
361
     const wchar_t *filename,
362
     int access_flags,
363
     libcerror_error_t **error )
364
{
365
  libbfio_handle_t *file_io_handle      = NULL;
366
  libpff_internal_file_t *internal_file = NULL;
367
  static char *function                 = "libpff_file_open_wide";
368
  size_t filename_length                = 0;
369
370
  if( file == NULL )
371
  {
372
    libcerror_error_set(
373
     error,
374
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
375
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
376
     "%s: invalid file.",
377
     function );
378
379
    return( -1 );
380
  }
381
  internal_file = (libpff_internal_file_t *) file;
382
383
  if( filename == NULL )
384
  {
385
    libcerror_error_set(
386
     error,
387
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
388
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
389
     "%s: invalid filename.",
390
     function );
391
392
    return( -1 );
393
  }
394
  if( libbfio_file_initialize(
395
       &file_io_handle,
396
       error ) != 1 )
397
  {
398
    libcerror_error_set(
399
     error,
400
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
401
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
402
     "%s: unable to create file IO handle.",
403
     function );
404
405
    goto on_error;
406
  }
407
#if defined( HAVE_DEBUG_OUTPUT )
408
  if( libbfio_handle_set_track_offsets_read(
409
       file_io_handle,
410
       1,
411
       error ) != 1 )
412
  {
413
                libcerror_error_set(
414
                 error,
415
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
416
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
417
                 "%s: unable to set track offsets read in file IO handle.",
418
                 function );
419
420
    goto on_error;
421
  }
422
#endif
423
  filename_length = wide_string_length(
424
                     filename );
425
426
  if( libbfio_file_set_name_wide(
427
       file_io_handle,
428
       filename,
429
       filename_length + 1,
430
       error ) != 1 )
431
  {
432
                libcerror_error_set(
433
                 error,
434
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
435
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
436
                 "%s: unable to set filename in file IO handle.",
437
                 function );
438
439
    goto on_error;
440
  }
441
  if( libpff_file_open_file_io_handle(
442
       file,
443
       file_io_handle,
444
       access_flags,
445
       error ) != 1 )
446
  {
447
    libcerror_error_set(
448
     error,
449
     LIBCERROR_ERROR_DOMAIN_IO,
450
     LIBCERROR_IO_ERROR_OPEN_FAILED,
451
     "%s: unable to open file: %ls.",
452
     function,
453
     filename );
454
455
    goto on_error;
456
  }
457
  internal_file->file_io_handle_created_in_library = 1;
458
459
  return( 1 );
460
461
on_error:
462
  if( file_io_handle != NULL )
463
  {
464
    libbfio_handle_free(
465
     &file_io_handle,
466
     NULL );
467
  }
468
  return( -1 );
469
}
470
471
#endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */
472
473
/* Opens a file using a Basic File IO (bfio) handle
474
 * Returns 1 if successful or -1 on error
475
 */
476
int libpff_file_open_file_io_handle(
477
     libpff_file_t *file,
478
     libbfio_handle_t *file_io_handle,
479
     int access_flags,
480
     libcerror_error_t **error )
481
9.60k
{
482
9.60k
  libpff_internal_file_t *internal_file = NULL;
483
9.60k
  static char *function                 = "libpff_file_open_file_io_handle";
484
9.60k
  int bfio_access_flags                 = 0;
485
9.60k
  int file_io_handle_is_open            = 0;
486
487
9.60k
  if( file == NULL )
488
0
  {
489
0
    libcerror_error_set(
490
0
     error,
491
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
492
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
493
0
     "%s: invalid file.",
494
0
     function );
495
496
0
    return( -1 );
497
0
  }
498
9.60k
  internal_file = (libpff_internal_file_t *) file;
499
500
9.60k
  if( internal_file->file_io_handle != NULL )
501
0
  {
502
0
    libcerror_error_set(
503
0
     error,
504
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
505
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
506
0
     "%s: invalid file - file IO handle already set.",
507
0
     function );
508
509
0
    return( -1 );
510
0
  }
511
9.60k
  if( file_io_handle == NULL )
512
0
  {
513
0
    libcerror_error_set(
514
0
     error,
515
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
516
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
517
0
     "%s: invalid file IO handle.",
518
0
     function );
519
520
0
    return( -1 );
521
0
  }
522
9.60k
  if( ( ( access_flags & LIBPFF_ACCESS_FLAG_READ ) == 0 )
523
9.60k
   && ( ( access_flags & LIBPFF_ACCESS_FLAG_WRITE ) == 0 ) )
524
0
  {
525
0
    libcerror_error_set(
526
0
     error,
527
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
528
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
529
0
     "%s: unsupported access flags.",
530
0
     function );
531
532
0
    return( -1 );
533
0
  }
534
9.60k
  if( ( access_flags & LIBPFF_ACCESS_FLAG_WRITE ) != 0 )
535
0
  {
536
0
    libcerror_error_set(
537
0
     error,
538
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
539
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
540
0
     "%s: write access currently not supported.",
541
0
     function );
542
543
0
    return( -1 );
544
0
  }
545
9.60k
  if( ( access_flags & LIBPFF_ACCESS_FLAG_READ ) != 0 )
546
9.60k
  {
547
9.60k
    bfio_access_flags = LIBBFIO_ACCESS_FLAG_READ;
548
9.60k
  }
549
9.60k
  file_io_handle_is_open = libbfio_handle_is_open(
550
9.60k
                            file_io_handle,
551
9.60k
                            error );
552
553
9.60k
  if( file_io_handle_is_open == -1 )
554
0
  {
555
0
    libcerror_error_set(
556
0
     error,
557
0
     LIBCERROR_ERROR_DOMAIN_IO,
558
0
     LIBCERROR_IO_ERROR_OPEN_FAILED,
559
0
     "%s: unable to determine if file IO handle is open.",
560
0
     function );
561
562
0
    goto on_error;
563
0
  }
564
9.60k
  else if( file_io_handle_is_open == 0 )
565
9.60k
  {
566
9.60k
    if( libbfio_handle_open(
567
9.60k
         file_io_handle,
568
9.60k
         bfio_access_flags,
569
9.60k
         error ) != 1 )
570
0
    {
571
0
      libcerror_error_set(
572
0
       error,
573
0
       LIBCERROR_ERROR_DOMAIN_IO,
574
0
       LIBCERROR_IO_ERROR_OPEN_FAILED,
575
0
       "%s: unable to open file IO handle.",
576
0
       function );
577
578
0
      goto on_error;
579
0
    }
580
9.60k
    internal_file->file_io_handle_opened_in_library = 1;
581
9.60k
  }
582
9.60k
  if( libpff_internal_file_open_read(
583
9.60k
       internal_file,
584
9.60k
       file_io_handle,
585
9.60k
       error ) != 1 )
586
7.34k
  {
587
7.34k
    libcerror_error_set(
588
7.34k
     error,
589
7.34k
     LIBCERROR_ERROR_DOMAIN_IO,
590
7.34k
     LIBCERROR_IO_ERROR_READ_FAILED,
591
7.34k
     "%s: unable to read from file handle.",
592
7.34k
     function );
593
594
7.34k
    goto on_error;
595
7.34k
  }
596
2.26k
  internal_file->file_io_handle = file_io_handle;
597
598
2.26k
  return( 1 );
599
600
7.34k
on_error:
601
7.34k
  if( ( file_io_handle_is_open == 0 )
602
7.34k
   && ( internal_file->file_io_handle_opened_in_library != 0 ) )
603
7.34k
  {
604
7.34k
    libbfio_handle_close(
605
7.34k
     file_io_handle,
606
7.34k
     error );
607
608
7.34k
    internal_file->file_io_handle_opened_in_library = 0;
609
7.34k
  }
610
7.34k
  internal_file->file_io_handle = NULL;
611
612
7.34k
  return( -1 );
613
9.60k
}
614
615
/* Closes a file
616
 * Returns 0 if successful or -1 on error
617
 */
618
int libpff_file_close(
619
     libpff_file_t *file,
620
     libcerror_error_t **error )
621
2.26k
{
622
2.26k
  libpff_internal_file_t *internal_file = NULL;
623
2.26k
  static char *function                 = "libpff_file_close";
624
2.26k
  int result                            = 0;
625
626
2.26k
  if( file == NULL )
627
0
  {
628
0
    libcerror_error_set(
629
0
     error,
630
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
631
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
632
0
     "%s: invalid file.",
633
0
     function );
634
635
0
    return( -1 );
636
0
  }
637
2.26k
  internal_file = (libpff_internal_file_t *) file;
638
639
2.26k
  if( internal_file->file_io_handle == NULL )
640
0
  {
641
0
    libcerror_error_set(
642
0
     error,
643
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
644
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
645
0
     "%s: invalid file - missing file IO handle.",
646
0
     function );
647
648
0
    return( -1 );
649
0
  }
650
#if defined( HAVE_DEBUG_OUTPUT )
651
  if( libcnotify_verbose != 0 )
652
  {
653
    if( internal_file->file_io_handle_created_in_library != 0 )
654
    {
655
      if( libpff_debug_print_read_offsets(
656
           internal_file->file_io_handle,
657
           error ) != 1 )
658
      {
659
        libcerror_error_set(
660
         error,
661
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
662
         LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
663
         "%s: unable to print the read offsets.",
664
         function );
665
666
        result = -1;
667
      }
668
    }
669
  }
670
#endif
671
2.26k
  if( internal_file->file_io_handle_opened_in_library != 0 )
672
2.26k
  {
673
2.26k
    if( libbfio_handle_close(
674
2.26k
         internal_file->file_io_handle,
675
2.26k
         error ) != 0 )
676
0
    {
677
0
      libcerror_error_set(
678
0
       error,
679
0
       LIBCERROR_ERROR_DOMAIN_IO,
680
0
       LIBCERROR_IO_ERROR_CLOSE_FAILED,
681
0
       "%s: unable to close file IO handle.",
682
0
       function );
683
684
0
      result = -1;
685
0
    }
686
2.26k
    internal_file->file_io_handle_opened_in_library = 0;
687
2.26k
  }
688
2.26k
  if( internal_file->file_io_handle_created_in_library != 0 )
689
0
  {
690
0
    if( libbfio_handle_free(
691
0
         &( internal_file->file_io_handle ),
692
0
         error ) != 1 )
693
0
    {
694
0
      libcerror_error_set(
695
0
       error,
696
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
697
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
698
0
       "%s: unable to free file IO handle.",
699
0
       function );
700
701
0
      result = -1;
702
0
    }
703
0
    internal_file->file_io_handle_created_in_library = 0;
704
0
  }
705
2.26k
  internal_file->file_io_handle = NULL;
706
707
2.26k
  if( libpff_io_handle_clear(
708
2.26k
       internal_file->io_handle,
709
2.26k
       error ) != 1 )
710
0
  {
711
0
    libcerror_error_set(
712
0
     error,
713
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
714
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
715
0
     "%s: unable to clear IO handle.",
716
0
     function );
717
718
0
    result = -1;
719
0
  }
720
2.26k
  if( libpff_file_header_free(
721
2.26k
       &( internal_file->file_header ),
722
2.26k
       error ) != 1 )
723
0
  {
724
0
    libcerror_error_set(
725
0
     error,
726
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
727
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
728
0
     "%s: unable to free file header.",
729
0
     function );
730
731
0
    result = -1;
732
0
  }
733
2.26k
  if( libpff_descriptors_index_free(
734
2.26k
       &( internal_file->descriptors_index ),
735
2.26k
       error ) != 1 )
736
0
  {
737
0
    libcerror_error_set(
738
0
     error,
739
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
740
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
741
0
     "%s: unable to free descriptors index.",
742
0
     function );
743
744
0
    result = -1;
745
0
  }
746
2.26k
  if( libpff_offsets_index_free(
747
2.26k
       &( internal_file->offsets_index ),
748
2.26k
       error ) != 1 )
749
0
  {
750
0
    libcerror_error_set(
751
0
     error,
752
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
753
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
754
0
     "%s: unable to free offsets index.",
755
0
     function );
756
757
0
    result = -1;
758
0
  }
759
2.26k
  if( libpff_item_tree_free(
760
2.26k
       &( internal_file->item_tree ),
761
2.26k
       error ) != 1 )
762
0
  {
763
0
    libcerror_error_set(
764
0
     error,
765
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
766
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
767
0
     "%s: unable to free item tree.",
768
0
     function );
769
770
0
    result = -1;
771
0
  }
772
2.26k
  internal_file->root_folder_item_tree_node = NULL;
773
774
2.26k
  if( libcdata_list_free(
775
2.26k
       &( internal_file->orphan_item_list ),
776
2.26k
       (int (*)(intptr_t **, libcerror_error_t **)) &libpff_item_tree_node_free_recovered,
777
2.26k
       error ) != 1 )
778
0
  {
779
0
    libcerror_error_set(
780
0
     error,
781
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
782
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
783
0
     "%s: unable to free orphan item list.",
784
0
     function );
785
786
0
    result = -1;
787
0
  }
788
2.26k
  if( libcdata_list_free(
789
2.26k
       &( internal_file->name_to_id_map_list ),
790
2.26k
       (int (*)(intptr_t **, libcerror_error_t **)) &libpff_name_to_id_map_entry_free,
791
2.26k
       error ) != 1 )
792
0
  {
793
0
    libcerror_error_set(
794
0
     error,
795
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
796
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
797
0
     "%s: unable to free name to id map list.",
798
0
     function );
799
800
0
    result = -1;
801
0
  }
802
2.26k
  if( internal_file->recovered_item_list != NULL )
803
0
  {
804
0
    if( libcdata_list_free(
805
0
         &( internal_file->recovered_item_list ),
806
0
         (int (*)(intptr_t **, libcerror_error_t **)) &libpff_item_tree_node_free_recovered,
807
0
         error ) != 1 )
808
0
    {
809
0
      libcerror_error_set(
810
0
       error,
811
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
812
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
813
0
       "%s: unable to free recovered item list.",
814
0
       function );
815
816
0
      result = -1;
817
0
    }
818
0
  }
819
2.26k
  if( internal_file->unallocated_data_block_list != NULL )
820
0
  {
821
0
    if( libcdata_range_list_free(
822
0
         &( internal_file->unallocated_data_block_list ),
823
0
         NULL,
824
0
         error ) != 1 )
825
0
    {
826
0
      libcerror_error_set(
827
0
       error,
828
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
829
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
830
0
       "%s: unable to free unallocated data block list.",
831
0
       function );
832
833
0
      result = -1;
834
0
    }
835
0
  }
836
2.26k
  if( internal_file->unallocated_page_block_list != NULL )
837
0
  {
838
0
    if( libcdata_range_list_free(
839
0
         &( internal_file->unallocated_page_block_list ),
840
0
         NULL,
841
0
         error ) != 1 )
842
0
    {
843
0
      libcerror_error_set(
844
0
       error,
845
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
846
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
847
0
       "%s: unable to free unallocated page block list.",
848
0
       function );
849
850
0
      result = -1;
851
0
    }
852
0
  }
853
2.26k
  return( result );
854
2.26k
}
855
856
/* Opens a file for reading
857
 * Returns 1 if successful or -1 on error
858
 */
859
int libpff_internal_file_open_read(
860
     libpff_internal_file_t *internal_file,
861
     libbfio_handle_t *file_io_handle,
862
     libcerror_error_t **error )
863
9.60k
{
864
9.60k
  static char *function = "libpff_internal_file_open_read";
865
9.60k
  int result            = 0;
866
867
#if defined( HAVE_DEBUG_OUTPUT )
868
  size_t page_size      = 0;
869
#endif
870
871
9.60k
  if( internal_file == NULL )
872
0
  {
873
0
    libcerror_error_set(
874
0
     error,
875
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
876
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
877
0
     "%s: invalid file.",
878
0
     function );
879
880
0
    return( -1 );
881
0
  }
882
9.60k
  if( internal_file->file_header != NULL )
883
0
  {
884
0
    libcerror_error_set(
885
0
     error,
886
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
887
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
888
0
     "%s: invalid file - file header value already set.",
889
0
     function );
890
891
0
    return( -1 );
892
0
  }
893
9.60k
  if( internal_file->descriptors_index != NULL )
894
0
  {
895
0
    libcerror_error_set(
896
0
     error,
897
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
898
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
899
0
     "%s: invalid file - descriptors index value already set.",
900
0
     function );
901
902
0
    return( -1 );
903
0
  }
904
9.60k
  if( internal_file->offsets_index != NULL )
905
0
  {
906
0
    libcerror_error_set(
907
0
     error,
908
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
909
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
910
0
     "%s: invalid file - offsets index value already set.",
911
0
     function );
912
913
0
    return( -1 );
914
0
  }
915
9.60k
  if( internal_file->item_tree != NULL )
916
0
  {
917
0
    libcerror_error_set(
918
0
     error,
919
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
920
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
921
0
     "%s: invalid file - item tree value already set.",
922
0
     function );
923
924
0
    return( -1 );
925
0
  }
926
9.60k
  if( internal_file->root_folder_item_tree_node != NULL )
927
0
  {
928
0
    libcerror_error_set(
929
0
     error,
930
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
931
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
932
0
     "%s: invalid file - root folder item tree root node value already set.",
933
0
     function );
934
935
0
    return( -1 );
936
0
  }
937
9.60k
  if( internal_file->orphan_item_list != NULL )
938
0
  {
939
0
    libcerror_error_set(
940
0
     error,
941
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
942
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
943
0
     "%s: invalid file - orphan item list value already set.",
944
0
     function );
945
946
0
    return( -1 );
947
0
  }
948
9.60k
  if( internal_file->name_to_id_map_list != NULL )
949
0
  {
950
0
    libcerror_error_set(
951
0
     error,
952
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
953
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
954
0
     "%s: invalid file - name to id map list value already set.",
955
0
     function );
956
957
0
    return( -1 );
958
0
  }
959
#if defined( HAVE_DEBUG_OUTPUT )
960
  if( libcnotify_verbose != 0 )
961
  {
962
    libcnotify_printf(
963
     "Reading file header:\n" );
964
  }
965
#endif
966
9.60k
  if( libpff_file_header_initialize(
967
9.60k
       &( internal_file->file_header ),
968
9.60k
       error ) != 1 )
969
0
  {
970
0
    libcerror_error_set(
971
0
     error,
972
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
973
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
974
0
     "%s: unable to create file header.",
975
0
     function );
976
977
0
    goto on_error;
978
0
  }
979
9.60k
  if( libpff_file_header_read_file_io_handle(
980
9.60k
       internal_file->file_header,
981
9.60k
       file_io_handle,
982
9.60k
       error ) != 1 )
983
1.00k
  {
984
1.00k
    libcerror_error_set(
985
1.00k
     error,
986
1.00k
     LIBCERROR_ERROR_DOMAIN_IO,
987
1.00k
     LIBCERROR_IO_ERROR_READ_FAILED,
988
1.00k
     "%s: unable to read file header data.",
989
1.00k
     function );
990
991
1.00k
    goto on_error;
992
1.00k
  }
993
8.60k
  internal_file->io_handle->encryption_type = internal_file->file_header->encryption_type;
994
8.60k
  internal_file->io_handle->file_size       = internal_file->file_header->file_size;
995
8.60k
  internal_file->io_handle->file_type       = internal_file->file_header->file_type;
996
997
8.60k
  if( ( internal_file->io_handle->encryption_type != LIBPFF_ENCRYPTION_TYPE_NONE )
998
8.60k
   && ( internal_file->io_handle->encryption_type != LIBPFF_ENCRYPTION_TYPE_COMPRESSIBLE )
999
8.60k
   && ( internal_file->io_handle->encryption_type != LIBPFF_ENCRYPTION_TYPE_HIGH ) )
1000
25
  {
1001
25
    libcerror_error_set(
1002
25
     error,
1003
25
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1004
25
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1005
25
     "%s: unsupported encryption type: 0x%02x",
1006
25
     function,
1007
25
     internal_file->io_handle->encryption_type );
1008
1009
25
    goto on_error;
1010
25
  }
1011
#if defined( HAVE_DEBUG_OUTPUT )
1012
  if( libcnotify_verbose != 0 )
1013
  {
1014
    libcnotify_printf(
1015
     "%s: file type\t\t\t\t: %" PRIu8 "\n",
1016
     function,
1017
     internal_file->io_handle->file_type );
1018
1019
    if( internal_file->io_handle->file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE )
1020
    {
1021
      page_size = 4096;
1022
    }
1023
    else
1024
    {
1025
      page_size = 512;
1026
    }
1027
    libcnotify_printf(
1028
     "%s: page size\t\t\t\t: %" PRIzd "\n",
1029
     function,
1030
     page_size );
1031
1032
    libcnotify_printf(
1033
     "\n" );
1034
  }
1035
#endif
1036
#if defined( HAVE_DEBUG_OUTPUT )
1037
  if( libcnotify_verbose != 0 )
1038
  {
1039
    libcnotify_printf(
1040
     "Creating item tree:\n" );
1041
  }
1042
#endif
1043
8.57k
  if( libpff_descriptors_index_initialize(
1044
8.57k
       &( internal_file->descriptors_index ),
1045
8.57k
       internal_file->file_header->descriptors_index_root_node_offset,
1046
8.57k
       internal_file->file_header->descriptors_index_root_node_back_pointer,
1047
8.57k
       error ) != 1 )
1048
0
  {
1049
0
    libcerror_error_set(
1050
0
     error,
1051
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1052
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1053
0
     "%s: unable to create descriptors index.",
1054
0
     function );
1055
1056
0
    goto on_error;
1057
0
  }
1058
8.57k
  if( libpff_offsets_index_initialize(
1059
8.57k
       &( internal_file->offsets_index ),
1060
8.57k
       internal_file->file_header->offsets_index_root_node_offset,
1061
8.57k
       internal_file->file_header->offsets_index_root_node_back_pointer,
1062
8.57k
       error ) != 1 )
1063
0
  {
1064
0
    libcerror_error_set(
1065
0
     error,
1066
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1067
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1068
0
     "%s: unable to create offsets index.",
1069
0
     function );
1070
1071
0
    goto on_error;
1072
0
  }
1073
8.57k
  if( libcdata_list_initialize(
1074
8.57k
       &( internal_file->orphan_item_list ),
1075
8.57k
       error ) != 1 )
1076
0
  {
1077
0
    libcerror_error_set(
1078
0
     error,
1079
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1080
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1081
0
     "%s: unable to create orphan item list.",
1082
0
     function );
1083
1084
0
    goto on_error;
1085
0
  }
1086
8.57k
  if( libpff_item_tree_initialize(
1087
8.57k
       &( internal_file->item_tree ),
1088
8.57k
       error ) != 1 )
1089
0
  {
1090
0
    libcerror_error_set(
1091
0
     error,
1092
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1093
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1094
0
     "%s: unable to create item tree.",
1095
0
     function );
1096
1097
0
    goto on_error;
1098
0
  }
1099
8.57k
  if( libpff_item_tree_create(
1100
8.57k
             internal_file->item_tree,
1101
8.57k
             internal_file->io_handle,
1102
8.57k
       file_io_handle,
1103
8.57k
       internal_file->descriptors_index,
1104
8.57k
       internal_file->orphan_item_list,
1105
8.57k
       &( internal_file->root_folder_item_tree_node ),
1106
8.57k
       error ) != 1 )
1107
1.12k
  {
1108
1.12k
    libcerror_error_set(
1109
1.12k
     error,
1110
1.12k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1111
1.12k
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1112
1.12k
     "%s: unable to create item tree.",
1113
1.12k
     function );
1114
1115
1.12k
    goto on_error;
1116
1.12k
  }
1117
#if defined( HAVE_DEBUG_OUTPUT )
1118
  if( libcnotify_verbose != 0 )
1119
  {
1120
    libcnotify_printf(
1121
     "Name to ID map:\n" );
1122
  }
1123
#endif
1124
7.44k
  if( libcdata_list_initialize(
1125
7.44k
       &( internal_file->name_to_id_map_list ),
1126
7.44k
       error ) != 1 )
1127
0
  {
1128
0
    libcerror_error_set(
1129
0
     error,
1130
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1131
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1132
0
     "%s: unable to create name to id map list.",
1133
0
     function );
1134
1135
0
    goto on_error;
1136
0
  }
1137
7.44k
  result = libpff_name_to_id_map_read(
1138
7.44k
      internal_file->name_to_id_map_list,
1139
7.44k
      internal_file->io_handle,
1140
7.44k
      file_io_handle,
1141
7.44k
      internal_file->descriptors_index,
1142
7.44k
      internal_file->offsets_index,
1143
7.44k
      error );
1144
1145
7.44k
  if( result == -1 )
1146
5.18k
  {
1147
5.18k
    libcerror_error_set(
1148
5.18k
     error,
1149
5.18k
     LIBCERROR_ERROR_DOMAIN_IO,
1150
5.18k
     LIBCERROR_IO_ERROR_READ_FAILED,
1151
5.18k
     "%s: unable to read name to id map.",
1152
5.18k
     function );
1153
1154
5.18k
    goto on_error;
1155
5.18k
  }
1156
/* TODO flag missing name to id map if 0 */
1157
2.26k
  return( 1 );
1158
1159
7.34k
on_error:
1160
7.34k
  if( internal_file->name_to_id_map_list != NULL )
1161
5.18k
  {
1162
5.18k
    libcdata_list_free(
1163
5.18k
     &( internal_file->name_to_id_map_list ),
1164
5.18k
     (int (*)(intptr_t **, libcerror_error_t **)) &libpff_name_to_id_map_entry_free,
1165
5.18k
     NULL );
1166
5.18k
  }
1167
7.34k
  internal_file->root_folder_item_tree_node = NULL;
1168
1169
7.34k
  if( internal_file->orphan_item_list != NULL )
1170
6.31k
  {
1171
6.31k
    libcdata_list_free(
1172
6.31k
     &( internal_file->orphan_item_list ),
1173
6.31k
     (int (*)(intptr_t **, libcerror_error_t **)) &libpff_item_tree_node_free_recovered,
1174
6.31k
     NULL );
1175
6.31k
  }
1176
7.34k
  if( internal_file->item_tree != NULL )
1177
6.31k
  {
1178
6.31k
    libpff_item_tree_free(
1179
6.31k
     &( internal_file->item_tree ),
1180
6.31k
     NULL );
1181
6.31k
  }
1182
7.34k
  if( internal_file->offsets_index != NULL )
1183
6.31k
  {
1184
6.31k
    libpff_offsets_index_free(
1185
6.31k
     &( internal_file->offsets_index ),
1186
6.31k
     NULL );
1187
6.31k
  }
1188
7.34k
  if( internal_file->descriptors_index != NULL )
1189
6.31k
  {
1190
6.31k
    libpff_descriptors_index_free(
1191
6.31k
     &( internal_file->descriptors_index ),
1192
6.31k
     NULL );
1193
6.31k
  }
1194
7.34k
  if( internal_file->file_header != NULL )
1195
7.34k
  {
1196
7.34k
    libpff_file_header_free(
1197
7.34k
     &( internal_file->file_header ),
1198
7.34k
     NULL );
1199
7.34k
  }
1200
7.34k
  return( -1 );
1201
7.44k
}
1202
1203
/* Reads the allocation tables
1204
 * Returns 1 if successful or -1 on error
1205
 */
1206
int libpff_internal_file_read_allocation_tables(
1207
     libpff_internal_file_t *internal_file,
1208
     libcerror_error_t **error )
1209
0
{
1210
0
  static char *function = "libpff_internal_file_read_allocation_tables";
1211
1212
0
  if( internal_file == NULL )
1213
0
  {
1214
0
    libcerror_error_set(
1215
0
     error,
1216
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1217
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1218
0
     "%s: invalid file.",
1219
0
     function );
1220
1221
0
    return( -1 );
1222
0
  }
1223
0
  if( internal_file->io_handle == NULL )
1224
0
  {
1225
0
    libcerror_error_set(
1226
0
     error,
1227
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1228
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1229
0
     "%s: invalid file - missing IO handle.",
1230
0
     function );
1231
1232
0
    return( -1 );
1233
0
  }
1234
0
  if( ( internal_file->io_handle->file_type != LIBPFF_FILE_TYPE_32BIT )
1235
0
   && ( internal_file->io_handle->file_type != LIBPFF_FILE_TYPE_64BIT )
1236
0
   && ( internal_file->io_handle->file_type != LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) )
1237
0
  {
1238
0
    libcerror_error_set(
1239
0
     error,
1240
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1241
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1242
0
     "%s: unsupported file type.",
1243
0
     function );
1244
1245
0
    return( -1 );
1246
0
  }
1247
0
  if( internal_file->read_allocation_tables != 0 )
1248
0
  {
1249
0
    libcerror_error_set(
1250
0
     error,
1251
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1252
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1253
0
     "%s: invalid file - allocation tables already set.",
1254
0
     function );
1255
1256
0
    return( -1 );
1257
0
  }
1258
0
  if( internal_file->unallocated_data_block_list != NULL )
1259
0
  {
1260
0
    libcerror_error_set(
1261
0
     error,
1262
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1263
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1264
0
     "%s: invalid file - allocaled data block list already set.",
1265
0
     function );
1266
1267
0
    return( -1 );
1268
0
  }
1269
0
  if( internal_file->unallocated_page_block_list != NULL )
1270
0
  {
1271
0
    libcerror_error_set(
1272
0
     error,
1273
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1274
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1275
0
     "%s: invalid file - allocaled page block list already set.",
1276
0
     function );
1277
1278
0
    return( -1 );
1279
0
  }
1280
#if defined( HAVE_DEBUG_OUTPUT )
1281
  if( libcnotify_verbose != 0 )
1282
  {
1283
    libcnotify_printf(
1284
     "Reading the unallocated data blocks:\n" );
1285
  }
1286
#endif
1287
0
  if( libcdata_range_list_initialize(
1288
0
       &( internal_file->unallocated_data_block_list ),
1289
0
       error ) != 1 )
1290
0
  {
1291
0
    libcerror_error_set(
1292
0
     error,
1293
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1294
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1295
0
     "%s: unable to create unallocated data block list.",
1296
0
     function );
1297
1298
0
    goto on_error;
1299
0
  }
1300
0
  if( libpff_io_handle_read_unallocated_data_blocks(
1301
0
       internal_file->io_handle,
1302
0
       internal_file->file_io_handle,
1303
0
       internal_file->unallocated_data_block_list,
1304
0
       error ) != 1 )
1305
0
  {
1306
0
    libcerror_error_set(
1307
0
     error,
1308
0
     LIBCERROR_ERROR_DOMAIN_IO,
1309
0
     LIBCERROR_IO_ERROR_READ_FAILED,
1310
0
     "%s: unable to read unallocated data blocks.",
1311
0
     function );
1312
1313
0
    goto on_error;
1314
0
  }
1315
0
  if( ( internal_file->io_handle->file_type == LIBPFF_FILE_TYPE_32BIT )
1316
0
   || ( internal_file->io_handle->file_type == LIBPFF_FILE_TYPE_64BIT ) )
1317
0
  {
1318
#if defined( HAVE_DEBUG_OUTPUT )
1319
    if( libcnotify_verbose != 0 )
1320
    {
1321
      libcnotify_printf(
1322
       "Reading the unallocated page blocks:\n" );
1323
    }
1324
#endif
1325
0
    if( libcdata_range_list_initialize(
1326
0
         &( internal_file->unallocated_page_block_list ),
1327
0
         error ) != 1 )
1328
0
    {
1329
0
      libcerror_error_set(
1330
0
       error,
1331
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1332
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1333
0
       "%s: unable to create unallocated page block list.",
1334
0
       function );
1335
1336
0
      goto on_error;
1337
0
    }
1338
0
    if( libpff_io_handle_read_unallocated_page_blocks(
1339
0
         internal_file->io_handle,
1340
0
         internal_file->file_io_handle,
1341
0
         internal_file->unallocated_page_block_list,
1342
0
         error ) != 1 )
1343
0
    {
1344
0
      libcerror_error_set(
1345
0
       error,
1346
0
       LIBCERROR_ERROR_DOMAIN_IO,
1347
0
       LIBCERROR_IO_ERROR_READ_FAILED,
1348
0
       "%s: unable to read unallocated page blocks.",
1349
0
       function );
1350
1351
0
      goto on_error;
1352
0
    }
1353
0
  }
1354
0
  internal_file->read_allocation_tables = 1;
1355
1356
0
  return( 1 );
1357
1358
0
on_error:
1359
0
  if( internal_file->unallocated_page_block_list != NULL )
1360
0
  {
1361
0
    libcdata_range_list_free(
1362
0
     &( internal_file->unallocated_page_block_list ),
1363
0
     NULL,
1364
0
     NULL );
1365
0
  }
1366
0
  if( internal_file->unallocated_data_block_list != NULL )
1367
0
  {
1368
0
    libcdata_range_list_free(
1369
0
     &( internal_file->unallocated_data_block_list ),
1370
0
     NULL,
1371
0
     NULL );
1372
0
  }
1373
0
  return( -1 );
1374
0
}
1375
1376
/* Determine if the file corrupted
1377
 * Returns 1 if corrupted, 0 if not or -1 on error
1378
 */
1379
int libpff_file_is_corrupted(
1380
     libpff_file_t *file,
1381
     libcerror_error_t **error )
1382
0
{
1383
0
  libpff_internal_file_t *internal_file = NULL;
1384
0
  static char *function                 = "libpff_file_is_corrupted";
1385
1386
0
  if( file == NULL )
1387
0
  {
1388
0
    libcerror_error_set(
1389
0
     error,
1390
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1391
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1392
0
     "%s: invalid file.",
1393
0
     function );
1394
1395
0
    return( -1 );
1396
0
  }
1397
0
  internal_file = (libpff_internal_file_t *) file;
1398
1399
0
  if( internal_file->io_handle == NULL )
1400
0
  {
1401
0
    libcerror_error_set(
1402
0
     error,
1403
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1404
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1405
0
     "%s: invalid file - missing IO handle.",
1406
0
     function );
1407
1408
0
    return( -1 );
1409
0
  }
1410
0
  if( ( internal_file->io_handle->flags & LIBPFF_IO_HANDLE_FLAG_IS_CORRUPTED ) != 0 )
1411
0
  {
1412
0
    return( 1 );
1413
0
  }
1414
0
  return( 0 );
1415
0
}
1416
1417
/* Recovers deleted items
1418
 * By default only the unallocated space is checked for recoverable items
1419
 * Returns 1 if successful or -1 on error
1420
 */
1421
int libpff_file_recover_items(
1422
     libpff_file_t *file,
1423
     uint8_t recovery_flags,
1424
     libcerror_error_t **error )
1425
0
{
1426
0
  libpff_internal_file_t *internal_file = NULL;
1427
0
  static char *function                 = "libpff_file_recover_items";
1428
0
  int result                            = 0;
1429
1430
0
  if( file == NULL )
1431
0
  {
1432
0
    libcerror_error_set(
1433
0
     error,
1434
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1435
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1436
0
     "%s: invalid file.",
1437
0
     function );
1438
1439
0
    return( -1 );
1440
0
  }
1441
0
  internal_file = (libpff_internal_file_t *) file;
1442
1443
0
  if( internal_file->io_handle == NULL )
1444
0
  {
1445
0
    libcerror_error_set(
1446
0
     error,
1447
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1448
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1449
0
     "%s: invalid file - missing IO handle.",
1450
0
     function );
1451
1452
0
    return( -1 );
1453
0
  }
1454
0
  if( internal_file->recovered_item_list != NULL )
1455
0
  {
1456
0
    libcerror_error_set(
1457
0
     error,
1458
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1459
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1460
0
     "%s: invalid file - recovered item list already set.",
1461
0
     function );
1462
1463
0
    return( -1 );
1464
0
  }
1465
0
  if( internal_file->read_allocation_tables == 0 )
1466
0
  {
1467
0
    if( libpff_internal_file_read_allocation_tables(
1468
0
         internal_file,
1469
0
         error ) != 1 )
1470
0
    {
1471
0
      libcerror_error_set(
1472
0
       error,
1473
0
       LIBCERROR_ERROR_DOMAIN_IO,
1474
0
       LIBCERROR_IO_ERROR_READ_FAILED,
1475
0
       "%s: unable to read allocation tables.",
1476
0
       function );
1477
1478
#if defined( HAVE_DEBUG_OUTPUT )
1479
      if( ( error != NULL )
1480
       && ( *error != NULL ) )
1481
      {
1482
        libcnotify_print_error_backtrace(
1483
         *error );
1484
      }
1485
#endif
1486
0
      libcerror_error_free(
1487
0
       error );
1488
1489
/* TODO set recovery_flags |= LIBPFF_RECOVERY_FLAG_IGNORE_ALLOCATION_DATA ? */
1490
0
    }
1491
0
  }
1492
0
  if( libcdata_list_initialize(
1493
0
       &( internal_file->recovered_item_list ),
1494
0
       error ) != 1 )
1495
0
  {
1496
0
    libcerror_error_set(
1497
0
     error,
1498
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1499
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1500
0
     "%s: unable to create recovered item list.",
1501
0
     function );
1502
1503
0
    return( -1 );
1504
0
  }
1505
0
  result = libpff_recover_items(
1506
0
            internal_file->io_handle,
1507
0
            internal_file->file_io_handle,
1508
0
            internal_file->descriptors_index,
1509
0
            internal_file->offsets_index,
1510
0
            internal_file->unallocated_data_block_list,
1511
0
            internal_file->unallocated_page_block_list,
1512
0
            internal_file->recovered_item_list,
1513
0
            recovery_flags,
1514
0
            error );
1515
1516
0
  if( result != 1 )
1517
0
  {
1518
0
    libcerror_error_set(
1519
0
     error,
1520
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1521
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1522
0
     "%s: unable to recover items.",
1523
0
     function );
1524
1525
0
    return( -1 );
1526
0
  }
1527
0
        if( internal_file->io_handle->abort != 0 )
1528
0
        {
1529
0
                internal_file->io_handle->abort = 0;
1530
0
        }
1531
0
  return( result );
1532
0
}
1533
1534
/* Retrieves the file size
1535
 * Returns 1 if successful, 0 if not available or -1 on error
1536
 */
1537
int libpff_file_get_size(
1538
     libpff_file_t *file,
1539
     size64_t *size,
1540
     libcerror_error_t **error )
1541
0
{
1542
0
  libpff_internal_file_t *internal_file = NULL;
1543
0
  static char *function                 = "libpff_file_get_size";
1544
1545
0
  if( file == 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 file.",
1552
0
     function );
1553
1554
0
    return( -1 );
1555
0
  }
1556
0
  internal_file = (libpff_internal_file_t *) file;
1557
1558
0
  if( internal_file->io_handle == NULL )
1559
0
  {
1560
0
    libcerror_error_set(
1561
0
     error,
1562
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1563
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1564
0
     "%s: invalid file - missing IO handle.",
1565
0
     function );
1566
1567
0
    return( -1 );
1568
0
  }
1569
0
  if( size == NULL )
1570
0
  {
1571
0
    libcerror_error_set(
1572
0
     error,
1573
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1574
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1575
0
     "%s: invalid size.",
1576
0
     function );
1577
1578
0
    return( -1 );
1579
0
  }
1580
0
  if( internal_file->file_io_handle == NULL )
1581
0
  {
1582
0
    return( 0 );
1583
0
  }
1584
0
  *size = internal_file->io_handle->file_size;
1585
1586
0
  return( 1 );
1587
0
}
1588
1589
/* Retrieves the content type
1590
 * Returns 1 if successful, 0 if not available or -1 on error
1591
 */
1592
int libpff_file_get_content_type(
1593
     libpff_file_t *file,
1594
     uint8_t *content_type,
1595
     libcerror_error_t **error )
1596
0
{
1597
0
  libpff_internal_file_t *internal_file = NULL;
1598
0
  static char *function                 = "libpff_file_get_content_type";
1599
1600
0
  if( file == NULL )
1601
0
  {
1602
0
    libcerror_error_set(
1603
0
     error,
1604
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1605
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1606
0
     "%s: invalid file.",
1607
0
     function );
1608
1609
0
    return( -1 );
1610
0
  }
1611
0
  internal_file = (libpff_internal_file_t *) file;
1612
1613
0
  if( internal_file->file_header == NULL )
1614
0
  {
1615
0
    libcerror_error_set(
1616
0
     error,
1617
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1618
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1619
0
     "%s: invalid file - missing file header.",
1620
0
     function );
1621
1622
0
    return( -1 );
1623
0
  }
1624
0
  if( content_type == 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 content type.",
1631
0
     function );
1632
1633
0
    return( -1 );
1634
0
  }
1635
0
  if( internal_file->file_io_handle == NULL )
1636
0
  {
1637
0
    return( 0 );
1638
0
  }
1639
0
  *content_type = (uint8_t) internal_file->file_header->file_content_type;
1640
1641
0
  return( 1 );
1642
0
}
1643
1644
/* Retrieves the file type
1645
 * Returns 1 if successful, 0 if not available or -1 on error
1646
 */
1647
int libpff_file_get_type(
1648
     libpff_file_t *file,
1649
     uint8_t *type,
1650
     libcerror_error_t **error )
1651
0
{
1652
0
  libpff_internal_file_t *internal_file = NULL;
1653
0
  static char *function                 = "libpff_file_get_type";
1654
1655
0
  if( file == NULL )
1656
0
  {
1657
0
    libcerror_error_set(
1658
0
     error,
1659
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1660
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1661
0
     "%s: invalid file.",
1662
0
     function );
1663
1664
0
    return( -1 );
1665
0
  }
1666
0
  internal_file = (libpff_internal_file_t *) file;
1667
1668
0
  if( internal_file->io_handle == NULL )
1669
0
  {
1670
0
    libcerror_error_set(
1671
0
     error,
1672
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1673
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1674
0
     "%s: invalid file - missing IO handle.",
1675
0
     function );
1676
1677
0
    return( -1 );
1678
0
  }
1679
0
  if( type == NULL )
1680
0
  {
1681
0
    libcerror_error_set(
1682
0
     error,
1683
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1684
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1685
0
     "%s: invalid type.",
1686
0
     function );
1687
1688
0
    return( -1 );
1689
0
  }
1690
0
  if( internal_file->file_io_handle == NULL )
1691
0
  {
1692
0
    return( 0 );
1693
0
  }
1694
0
  *type = internal_file->io_handle->file_type;
1695
1696
0
  return( 1 );
1697
0
}
1698
1699
/* Retrieves the encryption type
1700
 * Returns 1 if successful, 0 if not available or -1 on error
1701
 */
1702
int libpff_file_get_encryption_type(
1703
     libpff_file_t *file,
1704
     uint8_t *encryption_type,
1705
     libcerror_error_t **error )
1706
0
{
1707
0
  libpff_internal_file_t *internal_file = NULL;
1708
0
  static char *function                 = "libpff_file_get_encryption_type";
1709
1710
0
  if( file == NULL )
1711
0
  {
1712
0
    libcerror_error_set(
1713
0
     error,
1714
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1715
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1716
0
     "%s: invalid file.",
1717
0
     function );
1718
1719
0
    return( -1 );
1720
0
  }
1721
0
  internal_file = (libpff_internal_file_t *) file;
1722
1723
0
  if( internal_file->io_handle == NULL )
1724
0
  {
1725
0
    libcerror_error_set(
1726
0
     error,
1727
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1728
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1729
0
     "%s: invalid file - missing IO handle.",
1730
0
     function );
1731
1732
0
    return( -1 );
1733
0
  }
1734
0
  if( encryption_type == NULL )
1735
0
  {
1736
0
    libcerror_error_set(
1737
0
     error,
1738
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1739
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1740
0
     "%s: invalid encryption type.",
1741
0
     function );
1742
1743
0
    return( -1 );
1744
0
  }
1745
0
  if( internal_file->file_io_handle == NULL )
1746
0
  {
1747
0
    return( 0 );
1748
0
  }
1749
0
  *encryption_type = internal_file->io_handle->encryption_type;
1750
1751
0
  return( 1 );
1752
0
}
1753
1754
/* Retrieves the ASCII codepage
1755
 * Returns 1 if successful or -1 on error
1756
 */
1757
int libpff_file_get_ascii_codepage(
1758
     libpff_file_t *file,
1759
     int *ascii_codepage,
1760
     libcerror_error_t **error )
1761
0
{
1762
0
  libpff_internal_file_t *internal_file = NULL;
1763
0
  static char *function                 = "libpff_file_get_ascii_codepage";
1764
1765
0
  if( file == NULL )
1766
0
  {
1767
0
    libcerror_error_set(
1768
0
     error,
1769
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1770
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1771
0
     "%s: invalid file.",
1772
0
     function );
1773
1774
0
    return( -1 );
1775
0
  }
1776
0
  internal_file = (libpff_internal_file_t *) file;
1777
1778
0
  if( internal_file->io_handle == NULL )
1779
0
  {
1780
0
    libcerror_error_set(
1781
0
     error,
1782
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1783
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1784
0
     "%s: invalid file - missing IO handle.",
1785
0
     function );
1786
1787
0
    return( -1 );
1788
0
  }
1789
0
  if( ascii_codepage == NULL )
1790
0
  {
1791
0
    libcerror_error_set(
1792
0
     error,
1793
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1794
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1795
0
     "%s: invalid ASCII codepage.",
1796
0
     function );
1797
1798
0
    return( -1 );
1799
0
  }
1800
0
  *ascii_codepage = internal_file->io_handle->ascii_codepage;
1801
1802
0
  return( 1 );
1803
0
}
1804
1805
/* Sets the ASCII codepage
1806
 * Returns 1 if successful or -1 on error
1807
 */
1808
int libpff_file_set_ascii_codepage(
1809
     libpff_file_t *file,
1810
     int ascii_codepage,
1811
     libcerror_error_t **error )
1812
0
{
1813
0
  libpff_internal_file_t *internal_file = NULL;
1814
0
  static char *function                 = "libpff_file_set_ascii_codepage";
1815
1816
0
  if( file == NULL )
1817
0
  {
1818
0
    libcerror_error_set(
1819
0
     error,
1820
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1821
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1822
0
     "%s: invalid file.",
1823
0
     function );
1824
1825
0
    return( -1 );
1826
0
  }
1827
0
  internal_file = (libpff_internal_file_t *) file;
1828
1829
0
  if( internal_file->io_handle == NULL )
1830
0
  {
1831
0
    libcerror_error_set(
1832
0
     error,
1833
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1834
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1835
0
     "%s: invalid file - missing IO handle.",
1836
0
     function );
1837
1838
0
    return( -1 );
1839
0
  }
1840
0
  if( ( ascii_codepage != LIBPFF_CODEPAGE_ASCII )
1841
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_874 )
1842
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_932 )
1843
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_936 )
1844
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_949 )
1845
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_950 )
1846
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1250 )
1847
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1251 )
1848
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1252 )
1849
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1253 )
1850
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1254 )
1851
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1255 )
1852
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1256 )
1853
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1257 )
1854
0
   && ( ascii_codepage != LIBPFF_CODEPAGE_WINDOWS_1258 ) )
1855
0
  {
1856
0
    libcerror_error_set(
1857
0
     error,
1858
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1859
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1860
0
     "%s: unsupported ASCII codepage.",
1861
0
     function );
1862
1863
0
    return( -1 );
1864
0
  }
1865
0
  internal_file->io_handle->ascii_codepage = ascii_codepage;
1866
1867
0
  return( 1 );
1868
0
}
1869
1870
/* Retrieves the number of unallocated blocks
1871
 * Returns 1 if successful or -1 on error
1872
 */
1873
int libpff_file_get_number_of_unallocated_blocks(
1874
     libpff_file_t *file,
1875
     int unallocated_block_type,
1876
     int *number_of_unallocated_blocks,
1877
     libcerror_error_t **error )
1878
0
{
1879
0
  libcdata_range_list_t *unallocated_block_list = NULL;
1880
0
  libpff_internal_file_t *internal_file         = NULL;
1881
0
  static char *function                         = "libpff_file_get_number_of_unallocated_blocks";
1882
1883
0
  if( file == NULL )
1884
0
  {
1885
0
    libcerror_error_set(
1886
0
     error,
1887
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1888
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1889
0
     "%s: invalid file.",
1890
0
     function );
1891
1892
0
    return( -1 );
1893
0
  }
1894
0
  if( ( unallocated_block_type != LIBPFF_UNALLOCATED_BLOCK_TYPE_DATA )
1895
0
   && ( unallocated_block_type != LIBPFF_UNALLOCATED_BLOCK_TYPE_PAGE ) )
1896
0
  {
1897
0
    libcerror_error_set(
1898
0
     error,
1899
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1900
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1901
0
     "%s: unsupported unallocated block type.",
1902
0
     function );
1903
1904
0
    return( -1 );
1905
0
  }
1906
0
  internal_file = (libpff_internal_file_t *) file;
1907
1908
0
  if( internal_file->read_allocation_tables == 0 )
1909
0
  {
1910
0
    if( libpff_internal_file_read_allocation_tables(
1911
0
         internal_file,
1912
0
         error ) != 1 )
1913
0
    {
1914
0
      libcerror_error_set(
1915
0
       error,
1916
0
       LIBCERROR_ERROR_DOMAIN_IO,
1917
0
       LIBCERROR_IO_ERROR_READ_FAILED,
1918
0
       "%s: unable to read allocation tables.",
1919
0
       function );
1920
1921
0
      return( -1 );
1922
0
    }
1923
0
  }
1924
0
  if( unallocated_block_type == LIBPFF_UNALLOCATED_BLOCK_TYPE_DATA )
1925
0
  {
1926
0
    unallocated_block_list = internal_file->unallocated_data_block_list;
1927
0
  }
1928
0
  else if( unallocated_block_type == LIBPFF_UNALLOCATED_BLOCK_TYPE_PAGE )
1929
0
  {
1930
0
    unallocated_block_list = internal_file->unallocated_page_block_list;
1931
0
  }
1932
0
  if( unallocated_block_list == NULL )
1933
0
  {
1934
0
    if( number_of_unallocated_blocks == NULL )
1935
0
    {
1936
0
      libcerror_error_set(
1937
0
       error,
1938
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1939
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1940
0
       "%s: invalid number of unallocated blocks.",
1941
0
       function );
1942
1943
0
      return( -1 );
1944
0
    }
1945
0
    *number_of_unallocated_blocks = 0;
1946
0
  }
1947
0
  else
1948
0
  {
1949
0
    if( libcdata_range_list_get_number_of_elements(
1950
0
         unallocated_block_list,
1951
0
         number_of_unallocated_blocks,
1952
0
         error ) != 1 )
1953
0
    {
1954
0
      libcerror_error_set(
1955
0
       error,
1956
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1957
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1958
0
       "%s: unable to retrieve number of unallocated blocks.",
1959
0
       function );
1960
1961
0
      return( -1 );
1962
0
    }
1963
0
  }
1964
0
  return( 1 );
1965
0
}
1966
1967
/* Retrieves a specific unallocated block
1968
 * Returns 1 if successful or -1 on error
1969
 */
1970
int libpff_file_get_unallocated_block(
1971
     libpff_file_t *file,
1972
     int unallocated_block_type,
1973
     int unallocated_block_index,
1974
     off64_t *offset,
1975
     size64_t *size,
1976
     libcerror_error_t **error )
1977
0
{
1978
0
  libcdata_range_list_t *unallocated_block_list = NULL;
1979
0
  libpff_internal_file_t *internal_file         = NULL;
1980
0
  intptr_t *value                               = NULL;
1981
0
  static char *function                         = "libpff_file_get_unallocated_block";
1982
1983
0
  if( file == NULL )
1984
0
  {
1985
0
    libcerror_error_set(
1986
0
     error,
1987
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1988
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1989
0
     "%s: invalid file.",
1990
0
     function );
1991
1992
0
    return( -1 );
1993
0
  }
1994
0
  if( ( unallocated_block_type != LIBPFF_UNALLOCATED_BLOCK_TYPE_DATA )
1995
0
   && ( unallocated_block_type != LIBPFF_UNALLOCATED_BLOCK_TYPE_PAGE ) )
1996
0
  {
1997
0
    libcerror_error_set(
1998
0
     error,
1999
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2000
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
2001
0
     "%s: unsupported unallocated block type.",
2002
0
     function );
2003
2004
0
    return( -1 );
2005
0
  }
2006
0
  internal_file = (libpff_internal_file_t *) file;
2007
2008
0
  if( unallocated_block_type == LIBPFF_UNALLOCATED_BLOCK_TYPE_DATA )
2009
0
  {
2010
0
    unallocated_block_list = internal_file->unallocated_data_block_list;
2011
0
  }
2012
0
  else if( unallocated_block_type == LIBPFF_UNALLOCATED_BLOCK_TYPE_PAGE )
2013
0
  {
2014
0
    unallocated_block_list = internal_file->unallocated_page_block_list;
2015
0
  }
2016
0
  if( unallocated_block_list == NULL )
2017
0
  {
2018
0
    libcerror_error_set(
2019
0
     error,
2020
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2021
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2022
0
     "%s: invalid file - missing unallocated block list.",
2023
0
     function );
2024
2025
0
    return( -1 );
2026
0
  }
2027
0
  if( internal_file->read_allocation_tables == 0 )
2028
0
  {
2029
0
    if( libpff_internal_file_read_allocation_tables(
2030
0
         internal_file,
2031
0
         error ) != 1 )
2032
0
    {
2033
0
      libcerror_error_set(
2034
0
       error,
2035
0
       LIBCERROR_ERROR_DOMAIN_IO,
2036
0
       LIBCERROR_IO_ERROR_READ_FAILED,
2037
0
       "%s: unable to read allocation tables.",
2038
0
       function );
2039
2040
0
      return( -1 );
2041
0
    }
2042
0
  }
2043
0
  if( libcdata_range_list_get_range_by_index(
2044
0
       unallocated_block_list,
2045
0
       unallocated_block_index,
2046
0
       (uint64_t *) offset,
2047
0
       (uint64_t *) size,
2048
0
       &value,
2049
0
       error ) != 1 )
2050
0
  {
2051
0
    libcerror_error_set(
2052
0
     error,
2053
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2054
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2055
0
     "%s: unable to retrieve range list element: %d.",
2056
0
     function,
2057
0
     unallocated_block_index );
2058
2059
0
    return( -1 );
2060
0
  }
2061
0
  return( 1 );
2062
0
}
2063
2064
/* Retrieves the root item
2065
 * Returns 1 if successful or -1 on error
2066
 */
2067
int libpff_file_get_root_item(
2068
     libpff_file_t *file,
2069
     libpff_item_t **root_item,
2070
     libcerror_error_t **error )
2071
0
{
2072
0
  libpff_internal_file_t *internal_file = NULL;
2073
0
  static char *function                 = "libpff_file_get_root_item";
2074
2075
0
  if( file == NULL )
2076
0
  {
2077
0
    libcerror_error_set(
2078
0
     error,
2079
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2080
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2081
0
     "%s: invalid file.",
2082
0
     function );
2083
2084
0
    return( -1 );
2085
0
  }
2086
0
  internal_file = (libpff_internal_file_t *) file;
2087
2088
0
  if( internal_file->file_io_handle == NULL )
2089
0
  {
2090
0
    libcerror_error_set(
2091
0
     error,
2092
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2093
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2094
0
     "%s: invalid file - missing file IO handle.",
2095
0
     function );
2096
2097
0
    return( -1 );
2098
0
  }
2099
0
  if( internal_file->item_tree == NULL )
2100
0
  {
2101
0
    libcerror_error_set(
2102
0
     error,
2103
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2104
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2105
0
     "%s: invalid file - missing item tree.",
2106
0
     function );
2107
2108
0
    return( -1 );
2109
0
  }
2110
0
  if( root_item == NULL )
2111
0
  {
2112
0
    libcerror_error_set(
2113
0
     error,
2114
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2115
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2116
0
     "%s: invalid root item.",
2117
0
     function );
2118
2119
0
    return( -1 );
2120
0
  }
2121
0
  if( *root_item != NULL )
2122
0
  {
2123
0
    libcerror_error_set(
2124
0
     error,
2125
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2126
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2127
0
     "%s: root item already set.",
2128
0
     function );
2129
2130
0
    return( -1 );
2131
0
  }
2132
0
  if( libpff_item_initialize(
2133
0
       root_item,
2134
0
       internal_file->io_handle,
2135
0
       internal_file->file_io_handle,
2136
0
       internal_file->name_to_id_map_list,
2137
0
       internal_file->descriptors_index,
2138
0
       internal_file->offsets_index,
2139
0
       internal_file->item_tree,
2140
0
       internal_file->item_tree->root_node,
2141
0
       LIBPFF_ITEM_FLAGS_DEFAULT,
2142
0
       error ) != 1 )
2143
0
  {
2144
0
    libcerror_error_set(
2145
0
     error,
2146
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2147
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2148
0
     "%s: unable to create root item.",
2149
0
     function );
2150
2151
0
    return( -1 );
2152
0
  }
2153
0
  return( 1 );
2154
0
}
2155
2156
/* Retrieves the message store
2157
 * Returns 1 if successful, 0 if not available or -1 on error
2158
 */
2159
int libpff_file_get_message_store(
2160
     libpff_file_t *file,
2161
     libpff_item_t **message_store,
2162
     libcerror_error_t **error )
2163
0
{
2164
0
  libcdata_tree_node_t *message_store_item_tree_node = NULL;
2165
0
  libpff_internal_file_t *internal_file              = NULL;
2166
0
  static char *function                              = "libpff_file_get_message_store";
2167
0
  int result                                         = 0;
2168
2169
0
  if( file == NULL )
2170
0
  {
2171
0
    libcerror_error_set(
2172
0
     error,
2173
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2174
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2175
0
     "%s: invalid file.",
2176
0
     function );
2177
2178
0
    return( -1 );
2179
0
  }
2180
0
  internal_file = (libpff_internal_file_t *) file;
2181
2182
0
  if( internal_file->file_io_handle == NULL )
2183
0
  {
2184
0
    libcerror_error_set(
2185
0
     error,
2186
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2187
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2188
0
     "%s: invalid file - missing file IO handle.",
2189
0
     function );
2190
2191
0
    return( -1 );
2192
0
  }
2193
0
  if( message_store == NULL )
2194
0
  {
2195
0
    libcerror_error_set(
2196
0
     error,
2197
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2198
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2199
0
     "%s: invalid message store.",
2200
0
     function );
2201
2202
0
    return( -1 );
2203
0
  }
2204
0
  if( *message_store != NULL )
2205
0
  {
2206
0
    libcerror_error_set(
2207
0
     error,
2208
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2209
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2210
0
     "%s: message store already set.",
2211
0
     function );
2212
2213
0
    return( -1 );
2214
0
  }
2215
0
  result = libpff_item_tree_get_node_by_identifier(
2216
0
            internal_file->item_tree,
2217
0
            LIBPFF_DESCRIPTOR_IDENTIFIER_MESSAGE_STORE,
2218
0
                  &message_store_item_tree_node,
2219
0
            error );
2220
2221
0
  if( result == -1 )
2222
0
  {
2223
0
    libcerror_error_set(
2224
0
     error,
2225
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2226
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2227
0
     "%s: unable to retrieve message store item tree node: %" PRIu32 ".",
2228
0
     function,
2229
0
     LIBPFF_DESCRIPTOR_IDENTIFIER_MESSAGE_STORE );
2230
2231
0
    return( -1 );
2232
0
  }
2233
0
  else if( result != 0 )
2234
0
  {
2235
0
    if( libpff_item_initialize(
2236
0
         message_store,
2237
0
         internal_file->io_handle,
2238
0
         internal_file->file_io_handle,
2239
0
         internal_file->name_to_id_map_list,
2240
0
         internal_file->descriptors_index,
2241
0
         internal_file->offsets_index,
2242
0
         internal_file->item_tree,
2243
0
         message_store_item_tree_node,
2244
0
         LIBPFF_ITEM_FLAGS_DEFAULT,
2245
0
         error ) != 1 )
2246
0
    {
2247
0
      libcerror_error_set(
2248
0
       error,
2249
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2250
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2251
0
       "%s: unable to create message store.",
2252
0
       function );
2253
2254
0
      return( -1 );
2255
0
    }
2256
0
  }
2257
0
  return( result );
2258
0
}
2259
2260
/* Retrieves the name to id map
2261
 * Returns 1 if successful, 0 if not available or -1 on error
2262
 */
2263
int libpff_file_get_name_to_id_map(
2264
     libpff_file_t *file,
2265
     libpff_item_t **name_to_id_map,
2266
     libcerror_error_t **error )
2267
0
{
2268
0
  libcdata_tree_node_t *name_to_id_map_item_tree_node = NULL;
2269
0
  libpff_internal_file_t *internal_file               = NULL;
2270
0
  static char *function                               = "libpff_file_get_name_to_id_map";
2271
0
  int result                                          = 0;
2272
2273
0
  if( file == NULL )
2274
0
  {
2275
0
    libcerror_error_set(
2276
0
     error,
2277
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2278
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2279
0
     "%s: invalid file.",
2280
0
     function );
2281
2282
0
    return( -1 );
2283
0
  }
2284
0
  internal_file = (libpff_internal_file_t *) file;
2285
2286
0
  if( internal_file->file_io_handle == NULL )
2287
0
  {
2288
0
    libcerror_error_set(
2289
0
     error,
2290
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2291
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2292
0
     "%s: invalid file - missing file IO handle.",
2293
0
     function );
2294
2295
0
    return( -1 );
2296
0
  }
2297
0
  if( name_to_id_map == NULL )
2298
0
  {
2299
0
    libcerror_error_set(
2300
0
     error,
2301
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2302
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2303
0
     "%s: invalid name to id map.",
2304
0
     function );
2305
2306
0
    return( -1 );
2307
0
  }
2308
0
  if( *name_to_id_map != NULL )
2309
0
  {
2310
0
    libcerror_error_set(
2311
0
     error,
2312
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2313
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2314
0
     "%s: name to id map already set.",
2315
0
     function );
2316
2317
0
    return( -1 );
2318
0
  }
2319
0
  result = libpff_item_tree_get_node_by_identifier(
2320
0
            internal_file->item_tree,
2321
0
            LIBPFF_DESCRIPTOR_IDENTIFIER_NAME_TO_ID_MAP,
2322
0
                  &name_to_id_map_item_tree_node,
2323
0
            error );
2324
2325
0
  if( result == -1 )
2326
0
  {
2327
0
    libcerror_error_set(
2328
0
     error,
2329
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2330
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2331
0
     "%s: unable to retrieve name to ip map item tree node: %" PRIu32 ".",
2332
0
     function,
2333
0
     LIBPFF_DESCRIPTOR_IDENTIFIER_NAME_TO_ID_MAP );
2334
2335
0
    return( -1 );
2336
0
  }
2337
0
  else if( result != 0 )
2338
0
  {
2339
0
    if( libpff_item_initialize(
2340
0
         name_to_id_map,
2341
0
         internal_file->io_handle,
2342
0
         internal_file->file_io_handle,
2343
0
         internal_file->name_to_id_map_list,
2344
0
         internal_file->descriptors_index,
2345
0
         internal_file->offsets_index,
2346
0
         internal_file->item_tree,
2347
0
         name_to_id_map_item_tree_node,
2348
0
         LIBPFF_ITEM_FLAGS_DEFAULT,
2349
0
         error ) != 1 )
2350
0
    {
2351
0
      libcerror_error_set(
2352
0
       error,
2353
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2354
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2355
0
       "%s: unable to create name to id map.",
2356
0
       function );
2357
2358
0
      return( -1 );
2359
0
    }
2360
0
  }
2361
0
  return( result );
2362
0
}
2363
2364
/* Retrieves the root folder
2365
 * Returns 1 if successful, 0 if not available or -1 on error
2366
 */
2367
int libpff_file_get_root_folder(
2368
     libpff_file_t *file,
2369
     libpff_item_t **root_folder,
2370
     libcerror_error_t **error )
2371
1.99k
{
2372
1.99k
  libpff_internal_file_t *internal_file = NULL;
2373
1.99k
  static char *function                 = "libpff_file_get_root_folder";
2374
2375
1.99k
  if( file == NULL )
2376
0
  {
2377
0
    libcerror_error_set(
2378
0
     error,
2379
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2380
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2381
0
     "%s: invalid file.",
2382
0
     function );
2383
2384
0
    return( -1 );
2385
0
  }
2386
1.99k
  internal_file = (libpff_internal_file_t *) file;
2387
2388
1.99k
  if( internal_file->file_io_handle == NULL )
2389
0
  {
2390
0
    libcerror_error_set(
2391
0
     error,
2392
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2393
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2394
0
     "%s: invalid file - missing file IO handle.",
2395
0
     function );
2396
2397
0
    return( -1 );
2398
0
  }
2399
1.99k
  if( root_folder == NULL )
2400
0
  {
2401
0
    libcerror_error_set(
2402
0
     error,
2403
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2404
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2405
0
     "%s: invalid root folder.",
2406
0
     function );
2407
2408
0
    return( -1 );
2409
0
  }
2410
1.99k
  if( *root_folder != NULL )
2411
0
  {
2412
0
    libcerror_error_set(
2413
0
     error,
2414
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2415
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2416
0
     "%s: root folder already set.",
2417
0
     function );
2418
2419
0
    return( -1 );
2420
0
  }
2421
1.99k
  if( internal_file->root_folder_item_tree_node == NULL )
2422
376
  {
2423
376
    return( 0 );
2424
376
  }
2425
1.62k
  if( libpff_item_initialize(
2426
1.62k
       root_folder,
2427
1.62k
       internal_file->io_handle,
2428
1.62k
       internal_file->file_io_handle,
2429
1.62k
       internal_file->name_to_id_map_list,
2430
1.62k
       internal_file->descriptors_index,
2431
1.62k
       internal_file->offsets_index,
2432
1.62k
       internal_file->item_tree,
2433
1.62k
       internal_file->root_folder_item_tree_node,
2434
1.62k
       LIBPFF_ITEM_FLAGS_DEFAULT,
2435
1.62k
       error ) != 1 )
2436
0
  {
2437
0
    libcerror_error_set(
2438
0
     error,
2439
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2440
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2441
0
     "%s: unable to create root folder.",
2442
0
     function );
2443
2444
0
    return( -1 );
2445
0
  }
2446
1.62k
  return( 1 );
2447
1.62k
}
2448
2449
/* Retrieves an item for a specific identifier
2450
 * Returns 1 if successful, 0 if not available or -1 on error
2451
 */
2452
int libpff_file_get_item_by_identifier(
2453
     libpff_file_t *file,
2454
     uint32_t item_identifier,
2455
     libpff_item_t **item,
2456
     libcerror_error_t **error )
2457
0
{
2458
0
  libcdata_tree_node_t *item_tree_node  = NULL;
2459
0
  libpff_internal_file_t *internal_file = NULL;
2460
0
  static char *function                 = "libpff_file_get_item_by_identifier";
2461
0
  int result                            = 0;
2462
2463
0
  if( file == NULL )
2464
0
  {
2465
0
    libcerror_error_set(
2466
0
     error,
2467
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2468
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2469
0
     "%s: invalid file.",
2470
0
     function );
2471
2472
0
    return( -1 );
2473
0
  }
2474
0
  internal_file = (libpff_internal_file_t *) file;
2475
2476
0
  if( internal_file->file_io_handle == NULL )
2477
0
  {
2478
0
    libcerror_error_set(
2479
0
     error,
2480
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2481
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2482
0
     "%s: invalid file - missing file IO handle.",
2483
0
     function );
2484
2485
0
    return( -1 );
2486
0
  }
2487
0
  if( item == NULL )
2488
0
  {
2489
0
    libcerror_error_set(
2490
0
     error,
2491
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2492
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2493
0
     "%s: invalid item.",
2494
0
     function );
2495
2496
0
    return( -1 );
2497
0
  }
2498
0
  if( *item != NULL )
2499
0
  {
2500
0
    libcerror_error_set(
2501
0
     error,
2502
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2503
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2504
0
     "%s: item already set.",
2505
0
     function );
2506
2507
0
    return( -1 );
2508
0
  }
2509
0
  result = libpff_item_tree_get_node_by_identifier(
2510
0
            internal_file->item_tree,
2511
0
                  item_identifier,
2512
0
                  &item_tree_node,
2513
0
            error );
2514
2515
0
  if( result == -1 )
2516
0
  {
2517
0
    libcerror_error_set(
2518
0
     error,
2519
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2520
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2521
0
     "%s: unable to retrieve item tree node: %" PRIu32 ".",
2522
0
     function,
2523
0
     item_identifier );
2524
2525
0
    return( -1 );
2526
0
  }
2527
0
  else if( result == 0 )
2528
0
  {
2529
0
    return( 0 );
2530
0
  }
2531
0
  if( item_tree_node == NULL )
2532
0
  {
2533
0
    libcerror_error_set(
2534
0
     error,
2535
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2536
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2537
0
     "%s: invalid item tree node.",
2538
0
     function );
2539
2540
0
    return( -1 );
2541
0
  }
2542
0
  if( libpff_item_initialize(
2543
0
       item,
2544
0
       internal_file->io_handle,
2545
0
       internal_file->file_io_handle,
2546
0
       internal_file->name_to_id_map_list,
2547
0
       internal_file->descriptors_index,
2548
0
       internal_file->offsets_index,
2549
0
       internal_file->item_tree,
2550
0
       item_tree_node,
2551
0
       LIBPFF_ITEM_FLAGS_DEFAULT,
2552
0
       error ) != 1 )
2553
0
  {
2554
0
    libcerror_error_set(
2555
0
     error,
2556
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2557
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2558
0
     "%s: unable to initialize item.",
2559
0
     function );
2560
2561
0
    return( -1 );
2562
0
  }
2563
0
  return( 1 );
2564
0
}
2565
2566
/* Retrieves the number of orphan items
2567
 * Returns 1 if successful or -1 on error
2568
 */
2569
int libpff_file_get_number_of_orphan_items(
2570
     libpff_file_t *file,
2571
     int *number_of_orphan_items,
2572
     libcerror_error_t **error )
2573
0
{
2574
0
  libpff_internal_file_t *internal_file = NULL;
2575
0
  static char *function                 = "libpff_file_get_number_of_orphan_items";
2576
2577
0
  if( file == NULL )
2578
0
  {
2579
0
    libcerror_error_set(
2580
0
     error,
2581
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2582
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2583
0
     "%s: invalid file.",
2584
0
     function );
2585
2586
0
    return( -1 );
2587
0
  }
2588
0
  internal_file = (libpff_internal_file_t *) file;
2589
2590
0
  if( internal_file->file_io_handle == NULL )
2591
0
  {
2592
0
    libcerror_error_set(
2593
0
     error,
2594
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2595
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2596
0
     "%s: invalid file - missing file IO handle.",
2597
0
     function );
2598
2599
0
    return( -1 );
2600
0
  }
2601
0
  if( libcdata_list_get_number_of_elements(
2602
0
       internal_file->orphan_item_list,
2603
0
       number_of_orphan_items,
2604
0
       error ) != 1 )
2605
0
  {
2606
0
    libcerror_error_set(
2607
0
     error,
2608
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2609
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2610
0
     "%s: unable to retrieve number of orphan items.",
2611
0
     function );
2612
2613
0
    return( -1 );
2614
0
  }
2615
0
  return( 1 );
2616
0
}
2617
2618
/* Retrieves a specific orphan item
2619
 * Returns 1 if successful or -1 on error
2620
 */
2621
int libpff_file_get_orphan_item_by_index(
2622
     libpff_file_t *file,
2623
     int orphan_item_index,
2624
     libpff_item_t **orphan_item,
2625
     libcerror_error_t **error )
2626
0
{
2627
0
  libcdata_tree_node_t *orphan_item_tree_node = NULL;
2628
0
  libpff_internal_file_t *internal_file       = NULL;
2629
0
  static char *function                       = "libpff_file_get_orphan_item_by_index";
2630
2631
0
  if( file == NULL )
2632
0
  {
2633
0
    libcerror_error_set(
2634
0
     error,
2635
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2636
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2637
0
     "%s: invalid file.",
2638
0
     function );
2639
2640
0
    return( -1 );
2641
0
  }
2642
0
  internal_file = (libpff_internal_file_t *) file;
2643
2644
0
  if( internal_file->file_io_handle == NULL )
2645
0
  {
2646
0
    libcerror_error_set(
2647
0
     error,
2648
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2649
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2650
0
     "%s: invalid file - missing file IO handle.",
2651
0
     function );
2652
2653
0
    return( -1 );
2654
0
  }
2655
0
  if( orphan_item == NULL )
2656
0
  {
2657
0
    libcerror_error_set(
2658
0
     error,
2659
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2660
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2661
0
     "%s: invalid orphan item.",
2662
0
     function );
2663
2664
0
    return( -1 );
2665
0
  }
2666
0
  if( libcdata_list_get_value_by_index(
2667
0
       internal_file->orphan_item_list,
2668
0
       orphan_item_index,
2669
0
       (intptr_t **) &orphan_item_tree_node,
2670
0
       error ) != 1 )
2671
0
  {
2672
0
    libcerror_error_set(
2673
0
     error,
2674
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2675
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2676
0
     "%s: unable to retrieve orphan item tree node: %d.",
2677
0
     function,
2678
0
     orphan_item_index );
2679
2680
0
    return( -1 );
2681
0
  }
2682
0
  if( libpff_item_initialize(
2683
0
       orphan_item,
2684
0
       internal_file->io_handle,
2685
0
       internal_file->file_io_handle,
2686
0
       internal_file->name_to_id_map_list,
2687
0
       internal_file->descriptors_index,
2688
0
       internal_file->offsets_index,
2689
0
       internal_file->item_tree,
2690
0
       orphan_item_tree_node,
2691
0
       LIBPFF_ITEM_FLAGS_DEFAULT,
2692
0
       error ) != 1 )
2693
0
  {
2694
0
    libcerror_error_set(
2695
0
     error,
2696
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2697
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2698
0
     "%s: unable to create orphan item.",
2699
0
     function );
2700
2701
0
    return( -1 );
2702
0
  }
2703
0
  return( 1 );
2704
0
}
2705
2706
/* Retrieves the number of recovered items
2707
 * Returns 1 if successful or -1 on error
2708
 */
2709
int libpff_file_get_number_of_recovered_items(
2710
     libpff_file_t *file,
2711
     int *number_of_recovered_items,
2712
     libcerror_error_t **error )
2713
0
{
2714
0
  libpff_internal_file_t *internal_file = NULL;
2715
0
  static char *function                 = "libpff_file_get_number_of_recovered_items";
2716
2717
0
  if( file == NULL )
2718
0
  {
2719
0
    libcerror_error_set(
2720
0
     error,
2721
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2722
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2723
0
     "%s: invalid file.",
2724
0
     function );
2725
2726
0
    return( -1 );
2727
0
  }
2728
0
  internal_file = (libpff_internal_file_t *) file;
2729
2730
0
  if( internal_file->file_io_handle == NULL )
2731
0
  {
2732
0
    libcerror_error_set(
2733
0
     error,
2734
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2735
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2736
0
     "%s: invalid file - missing file IO handle.",
2737
0
     function );
2738
2739
0
    return( -1 );
2740
0
  }
2741
0
  if( libcdata_list_get_number_of_elements(
2742
0
       internal_file->recovered_item_list,
2743
0
       number_of_recovered_items,
2744
0
       error ) != 1 )
2745
0
  {
2746
0
    libcerror_error_set(
2747
0
     error,
2748
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2749
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2750
0
     "%s: unable to retrieve number of recovered items.",
2751
0
     function );
2752
2753
0
    return( -1 );
2754
0
  }
2755
0
  return( 1 );
2756
0
}
2757
2758
/* Retrieves a specific recovered item
2759
 * Returns 1 if successful or -1 on error
2760
 */
2761
int libpff_file_get_recovered_item_by_index(
2762
     libpff_file_t *file,
2763
     int recovered_item_index,
2764
     libpff_item_t **recovered_item,
2765
     libcerror_error_t **error )
2766
0
{
2767
0
  libcdata_tree_node_t *recovered_item_tree_node = NULL;
2768
0
  libpff_internal_file_t *internal_file          = NULL;
2769
0
  static char *function                          = "libpff_file_get_recovered_item_by_index";
2770
2771
0
  if( file == NULL )
2772
0
  {
2773
0
    libcerror_error_set(
2774
0
     error,
2775
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2776
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2777
0
     "%s: invalid file.",
2778
0
     function );
2779
2780
0
    return( -1 );
2781
0
  }
2782
0
  internal_file = (libpff_internal_file_t *) file;
2783
2784
0
  if( internal_file->file_io_handle == NULL )
2785
0
  {
2786
0
    libcerror_error_set(
2787
0
     error,
2788
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2789
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2790
0
     "%s: invalid file - missing file IO handle.",
2791
0
     function );
2792
2793
0
    return( -1 );
2794
0
  }
2795
0
  if( recovered_item == NULL )
2796
0
  {
2797
0
    libcerror_error_set(
2798
0
     error,
2799
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2800
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2801
0
     "%s: invalid recovered item.",
2802
0
     function );
2803
2804
0
    return( -1 );
2805
0
  }
2806
0
  if( libcdata_list_get_value_by_index(
2807
0
       internal_file->recovered_item_list,
2808
0
       recovered_item_index,
2809
0
       (intptr_t **) &recovered_item_tree_node,
2810
0
       error ) != 1 )
2811
0
  {
2812
0
    libcerror_error_set(
2813
0
     error,
2814
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2815
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2816
0
     "%s: unable to retrieve recovered item tree node: %d.",
2817
0
     function,
2818
0
     recovered_item_index );
2819
2820
0
    return( -1 );
2821
0
  }
2822
0
  if( libpff_item_initialize(
2823
0
       recovered_item,
2824
0
       internal_file->io_handle,
2825
0
       internal_file->file_io_handle,
2826
0
       internal_file->name_to_id_map_list,
2827
0
       internal_file->descriptors_index,
2828
0
       internal_file->offsets_index,
2829
0
       internal_file->item_tree,
2830
0
       recovered_item_tree_node,
2831
0
       LIBPFF_ITEM_FLAGS_DEFAULT,
2832
0
       error ) != 1 )
2833
0
  {
2834
0
    libcerror_error_set(
2835
0
     error,
2836
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2837
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2838
0
     "%s: unable to create recovered item.",
2839
0
     function );
2840
2841
0
    return( -1 );
2842
0
  }
2843
0
  return( 1 );
2844
0
}
2845