Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmsiecf/libmsiecf/libmsiecf_file.c
Line
Count
Source
1
/*
2
 * File functions
3
 *
4
 * Copyright (C) 2009-2026, 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 "libmsiecf_allocation_table.h"
29
#include "libmsiecf_cache_directory_table.h"
30
#include "libmsiecf_codepage.h"
31
#include "libmsiecf_debug.h"
32
#include "libmsiecf_definitions.h"
33
#include "libmsiecf_file_header.h"
34
#include "libmsiecf_io_handle.h"
35
#include "libmsiecf_item.h"
36
#include "libmsiecf_item_descriptor.h"
37
#include "libmsiecf_file.h"
38
#include "libmsiecf_libbfio.h"
39
#include "libmsiecf_libcdata.h"
40
#include "libmsiecf_libcerror.h"
41
#include "libmsiecf_libcnotify.h"
42
#include "libmsiecf_libcthreads.h"
43
44
#include "msiecf_file_header.h"
45
46
/* Creates a file
47
 * Make sure the value file is referencing, is set to NULL
48
 * Returns 1 if successful or -1 on error
49
 */
50
int libmsiecf_file_initialize(
51
     libmsiecf_file_t **file,
52
     libcerror_error_t **error )
53
4.31k
{
54
4.31k
  libmsiecf_internal_file_t *internal_file = NULL;
55
4.31k
  static char *function                    = "libmsiecf_file_initialize";
56
57
4.31k
  if( file == NULL )
58
0
  {
59
0
    libcerror_error_set(
60
0
     error,
61
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
62
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
63
0
     "%s: invalid file.",
64
0
     function );
65
66
0
    return( -1 );
67
0
  }
68
4.31k
  if( *file != NULL )
69
0
  {
70
0
    libcerror_error_set(
71
0
     error,
72
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
73
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
74
0
     "%s: invalid file value already set.",
75
0
     function );
76
77
0
    return( -1 );
78
0
  }
79
4.31k
  internal_file = memory_allocate_structure(
80
4.31k
                   libmsiecf_internal_file_t );
81
82
4.31k
  if( internal_file == 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.",
89
0
     function );
90
91
0
    goto on_error;
92
0
  }
93
4.31k
  if( memory_set(
94
4.31k
       internal_file,
95
4.31k
       0,
96
4.31k
       sizeof( libmsiecf_internal_file_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.",
103
0
     function );
104
105
0
    memory_free(
106
0
     internal_file );
107
108
0
    return( -1 );
109
0
  }
110
4.31k
  if( libmsiecf_io_handle_initialize(
111
4.31k
       &( internal_file->io_handle ),
112
4.31k
       error ) != 1 )
113
0
  {
114
0
    libcerror_error_set(
115
0
     error,
116
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
117
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
118
0
     "%s: unable to create IO handle.",
119
0
     function );
120
121
0
    goto on_error;
122
0
  }
123
4.31k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
124
4.31k
  if( libcthreads_read_write_lock_initialize(
125
4.31k
       &( internal_file->read_write_lock ),
126
4.31k
       error ) != 1 )
127
0
  {
128
0
    libcerror_error_set(
129
0
     error,
130
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
131
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
132
0
     "%s: unable to initialize read/write lock.",
133
0
     function );
134
135
0
    goto on_error;
136
0
  }
137
4.31k
#endif
138
4.31k
  *file = (libmsiecf_file_t *) internal_file;
139
140
4.31k
  return( 1 );
141
142
0
on_error:
143
0
  if( internal_file != NULL )
144
0
  {
145
0
    if( internal_file->io_handle != NULL )
146
0
    {
147
0
      libmsiecf_io_handle_free(
148
0
       &( internal_file->io_handle ),
149
0
       NULL );
150
0
    }
151
0
    memory_free(
152
0
     internal_file );
153
0
  }
154
0
  return( -1 );
155
4.31k
}
156
157
/* Frees a file
158
 * Returns 1 if successful or -1 on error
159
 */
160
int libmsiecf_file_free(
161
     libmsiecf_file_t **file,
162
     libcerror_error_t **error )
163
4.31k
{
164
4.31k
  libmsiecf_internal_file_t *internal_file = NULL;
165
4.31k
  static char *function                    = "libmsiecf_file_free";
166
4.31k
  int result                               = 1;
167
168
4.31k
  if( file == NULL )
169
0
  {
170
0
    libcerror_error_set(
171
0
     error,
172
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
173
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
174
0
     "%s: invalid file.",
175
0
     function );
176
177
0
    return( -1 );
178
0
  }
179
4.31k
  if( *file != NULL )
180
4.31k
  {
181
4.31k
    internal_file = (libmsiecf_internal_file_t *) *file;
182
183
4.31k
    if( internal_file->file_io_handle != NULL )
184
0
    {
185
0
      if( libmsiecf_file_close(
186
0
           *file,
187
0
           error ) != 0 )
188
0
      {
189
0
        libcerror_error_set(
190
0
         error,
191
0
         LIBCERROR_ERROR_DOMAIN_IO,
192
0
         LIBCERROR_IO_ERROR_CLOSE_FAILED,
193
0
         "%s: unable to close file.",
194
0
         function );
195
196
0
        result = -1;
197
0
      }
198
0
    }
199
4.31k
    *file = NULL;
200
201
4.31k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
202
4.31k
    if( libcthreads_read_write_lock_free(
203
4.31k
         &( internal_file->read_write_lock ),
204
4.31k
         error ) != 1 )
205
0
    {
206
0
      libcerror_error_set(
207
0
       error,
208
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
209
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
210
0
       "%s: unable to free read/write lock.",
211
0
       function );
212
213
0
      result = -1;
214
0
    }
215
4.31k
#endif
216
4.31k
    if( libmsiecf_io_handle_free(
217
4.31k
         &( internal_file->io_handle ),
218
4.31k
         error ) != 1 )
219
0
    {
220
0
      libcerror_error_set(
221
0
       error,
222
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
223
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
224
0
       "%s: unable to free IO handle.",
225
0
       function );
226
227
0
      result = -1;
228
0
    }
229
4.31k
    memory_free(
230
4.31k
     internal_file );
231
4.31k
  }
232
4.31k
  return( result );
233
4.31k
}
234
235
/* Signals the libmsiecf file to abort its current activity
236
 * Returns 1 if successful or -1 on error
237
 */
238
int libmsiecf_file_signal_abort(
239
     libmsiecf_file_t *file,
240
     libcerror_error_t **error )
241
4.74k
{
242
4.74k
  libmsiecf_internal_file_t *internal_file = NULL;
243
4.74k
  static char *function                    = "libmsiecf_file_signal_abort";
244
245
4.74k
  if( file == NULL )
246
2.00k
  {
247
2.00k
    libcerror_error_set(
248
2.00k
     error,
249
2.00k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
250
2.00k
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
251
2.00k
     "%s: invalid file.",
252
2.00k
     function );
253
254
2.00k
    return( -1 );
255
2.00k
  }
256
2.73k
  internal_file = (libmsiecf_internal_file_t *) file;
257
258
2.73k
  if( internal_file->io_handle == NULL )
259
0
  {
260
0
    libcerror_error_set(
261
0
     error,
262
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
263
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
264
0
     "%s: invalid file - missing IO handle.",
265
0
     function );
266
267
0
    return( -1 );
268
0
  }
269
2.73k
  internal_file->io_handle->abort = 1;
270
271
2.73k
  return( 1 );
272
2.73k
}
273
274
/* Opens a file
275
 * Returns 1 if successful or -1 on error
276
 */
277
int libmsiecf_file_open(
278
     libmsiecf_file_t *file,
279
     const char *filename,
280
     int access_flags,
281
     libcerror_error_t **error )
282
0
{
283
0
  libbfio_handle_t *file_io_handle         = NULL;
284
0
  libmsiecf_internal_file_t *internal_file = NULL;
285
0
  static char *function                    = "libmsiecf_file_open";
286
0
  size_t filename_length                   = 0;
287
288
0
  if( file == NULL )
289
0
  {
290
0
    libcerror_error_set(
291
0
     error,
292
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
293
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
294
0
     "%s: invalid file.",
295
0
     function );
296
297
0
    return( -1 );
298
0
  }
299
0
  internal_file = (libmsiecf_internal_file_t *) file;
300
301
0
  if( filename == NULL )
302
0
  {
303
0
    libcerror_error_set(
304
0
     error,
305
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
306
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
307
0
     "%s: invalid filename.",
308
0
     function );
309
310
0
    return( -1 );
311
0
  }
312
0
  if( ( ( access_flags & LIBMSIECF_ACCESS_FLAG_READ ) == 0 )
313
0
   && ( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) == 0 ) )
314
0
  {
315
0
    libcerror_error_set(
316
0
     error,
317
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
318
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
319
0
     "%s: unsupported access flags.",
320
0
     function );
321
322
0
    return( -1 );
323
0
  }
324
0
  if( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) != 0 )
325
0
  {
326
0
    libcerror_error_set(
327
0
     error,
328
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
329
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
330
0
     "%s: write access currently not supported.",
331
0
     function );
332
333
0
    return( -1 );
334
0
  }
335
0
  if( libbfio_file_initialize(
336
0
       &file_io_handle,
337
0
       error ) != 1 )
338
0
  {
339
0
    libcerror_error_set(
340
0
     error,
341
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
342
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
343
0
     "%s: unable to create file IO handle.",
344
0
     function );
345
346
0
    goto on_error;
347
0
  }
348
#if defined( HAVE_DEBUG_OUTPUT )
349
  if( libbfio_handle_set_track_offsets_read(
350
       file_io_handle,
351
       1,
352
       error ) != 1 )
353
  {
354
                libcerror_error_set(
355
                 error,
356
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
357
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
358
                 "%s: unable to set track offsets read in file IO handle.",
359
                 function );
360
361
    goto on_error;
362
  }
363
#endif
364
0
  filename_length = narrow_string_length(
365
0
                     filename );
366
367
0
  if( libbfio_file_set_name(
368
0
       file_io_handle,
369
0
       filename,
370
0
       filename_length + 1,
371
0
       error ) != 1 )
372
0
  {
373
0
                libcerror_error_set(
374
0
                 error,
375
0
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
376
0
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
377
0
                 "%s: unable to set filename in file IO handle.",
378
0
                 function );
379
380
0
    goto on_error;
381
0
  }
382
0
  if( libmsiecf_file_open_file_io_handle(
383
0
       file,
384
0
       file_io_handle,
385
0
       access_flags,
386
0
       error ) != 1 )
387
0
  {
388
0
    libcerror_error_set(
389
0
     error,
390
0
     LIBCERROR_ERROR_DOMAIN_IO,
391
0
     LIBCERROR_IO_ERROR_OPEN_FAILED,
392
0
     "%s: unable to open file: %s.",
393
0
     function,
394
0
     filename );
395
396
0
    goto on_error;
397
0
  }
398
0
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
399
0
  if( libcthreads_read_write_lock_grab_for_write(
400
0
       internal_file->read_write_lock,
401
0
       error ) != 1 )
402
0
  {
403
0
    libcerror_error_set(
404
0
     error,
405
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
406
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
407
0
     "%s: unable to grab read/write lock for writing.",
408
0
     function );
409
410
0
    goto on_error;
411
0
  }
412
0
#endif
413
0
  internal_file->file_io_handle_created_in_library = 1;
414
415
0
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
416
0
  if( libcthreads_read_write_lock_release_for_write(
417
0
       internal_file->read_write_lock,
418
0
       error ) != 1 )
419
0
  {
420
0
    libcerror_error_set(
421
0
     error,
422
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
423
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
424
0
     "%s: unable to release read/write lock for writing.",
425
0
     function );
426
427
0
    internal_file->file_io_handle_created_in_library = 0;
428
429
0
    goto on_error;
430
0
  }
431
0
#endif
432
0
  return( 1 );
433
434
0
on_error:
435
0
  if( file_io_handle != NULL )
436
0
  {
437
0
    libbfio_handle_free(
438
0
     &file_io_handle,
439
0
     NULL );
440
0
  }
441
0
  return( -1 );
442
0
}
443
444
#if defined( HAVE_WIDE_CHARACTER_TYPE )
445
446
/* Opens a file
447
 * Returns 1 if successful or -1 on error
448
 */
449
int libmsiecf_file_open_wide(
450
     libmsiecf_file_t *file,
451
     const wchar_t *filename,
452
     int access_flags,
453
     libcerror_error_t **error )
454
{
455
  libbfio_handle_t *file_io_handle         = NULL;
456
  libmsiecf_internal_file_t *internal_file = NULL;
457
  static char *function                    = "libmsiecf_file_open_wide";
458
  size_t filename_length                   = 0;
459
460
  if( file == NULL )
461
  {
462
    libcerror_error_set(
463
     error,
464
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
465
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
466
     "%s: invalid file.",
467
     function );
468
469
    return( -1 );
470
  }
471
  internal_file = (libmsiecf_internal_file_t *) file;
472
473
  if( filename == NULL )
474
  {
475
    libcerror_error_set(
476
     error,
477
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
478
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
479
     "%s: invalid filename.",
480
     function );
481
482
    return( -1 );
483
  }
484
  if( ( ( access_flags & LIBMSIECF_ACCESS_FLAG_READ ) == 0 )
485
   && ( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) == 0 ) )
486
  {
487
    libcerror_error_set(
488
     error,
489
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
490
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
491
     "%s: unsupported access flags.",
492
     function );
493
494
    return( -1 );
495
  }
496
  if( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) != 0 )
497
  {
498
    libcerror_error_set(
499
     error,
500
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
501
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
502
     "%s: write access currently not supported.",
503
     function );
504
505
    return( -1 );
506
  }
507
  if( libbfio_file_initialize(
508
       &file_io_handle,
509
       error ) != 1 )
510
  {
511
    libcerror_error_set(
512
     error,
513
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
514
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
515
     "%s: unable to create file IO handle.",
516
     function );
517
518
    goto on_error;
519
  }
520
#if defined( HAVE_DEBUG_OUTPUT )
521
  if( libbfio_handle_set_track_offsets_read(
522
       file_io_handle,
523
       1,
524
       error ) != 1 )
525
  {
526
                libcerror_error_set(
527
                 error,
528
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
529
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
530
                 "%s: unable to set track offsets read in file IO handle.",
531
                 function );
532
533
    goto on_error;
534
  }
535
#endif
536
  filename_length = wide_string_length(
537
                     filename );
538
539
  if( libbfio_file_set_name_wide(
540
       file_io_handle,
541
       filename,
542
       filename_length + 1,
543
       error ) != 1 )
544
  {
545
                libcerror_error_set(
546
                 error,
547
                 LIBCERROR_ERROR_DOMAIN_RUNTIME,
548
                 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
549
                 "%s: unable to set filename in file IO handle.",
550
                 function );
551
552
    goto on_error;
553
  }
554
  if( libmsiecf_file_open_file_io_handle(
555
       file,
556
       file_io_handle,
557
       access_flags,
558
       error ) != 1 )
559
  {
560
    libcerror_error_set(
561
     error,
562
     LIBCERROR_ERROR_DOMAIN_IO,
563
     LIBCERROR_IO_ERROR_OPEN_FAILED,
564
     "%s: unable to open file: %ls.",
565
     function,
566
     filename );
567
568
    goto on_error;
569
  }
570
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
571
  if( libcthreads_read_write_lock_grab_for_write(
572
       internal_file->read_write_lock,
573
       error ) != 1 )
574
  {
575
    libcerror_error_set(
576
     error,
577
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
578
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
579
     "%s: unable to grab read/write lock for writing.",
580
     function );
581
582
    goto on_error;
583
  }
584
#endif
585
  internal_file->file_io_handle_created_in_library = 1;
586
587
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
588
  if( libcthreads_read_write_lock_release_for_write(
589
       internal_file->read_write_lock,
590
       error ) != 1 )
591
  {
592
    libcerror_error_set(
593
     error,
594
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
595
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
596
     "%s: unable to release read/write lock for writing.",
597
     function );
598
599
    internal_file->file_io_handle_created_in_library = 0;
600
601
    goto on_error;
602
  }
603
#endif
604
  return( 1 );
605
606
on_error:
607
  if( file_io_handle != NULL )
608
  {
609
    libbfio_handle_free(
610
     &file_io_handle,
611
     NULL );
612
  }
613
  return( -1 );
614
}
615
616
#endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */
617
618
/* Opens a file using a Basic File IO (bfio) handle
619
 * Returns 1 if successful or -1 on error
620
 */
621
int libmsiecf_file_open_file_io_handle(
622
     libmsiecf_file_t *file,
623
     libbfio_handle_t *file_io_handle,
624
     int access_flags,
625
     libcerror_error_t **error )
626
13.0k
{
627
13.0k
  libmsiecf_internal_file_t *internal_file = NULL;
628
13.0k
  static char *function                    = "libmsiecf_file_open_file_io_handle";
629
13.0k
  uint8_t file_io_handle_opened_in_library = 0;
630
13.0k
  int bfio_access_flags                    = 0;
631
13.0k
  int file_io_handle_is_open               = 0;
632
633
13.0k
  if( file == NULL )
634
2.00k
  {
635
2.00k
    libcerror_error_set(
636
2.00k
     error,
637
2.00k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
638
2.00k
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
639
2.00k
     "%s: invalid file.",
640
2.00k
     function );
641
642
2.00k
    return( -1 );
643
2.00k
  }
644
11.0k
  internal_file = (libmsiecf_internal_file_t *) file;
645
646
11.0k
  if( internal_file->file_io_handle != NULL )
647
722
  {
648
722
    libcerror_error_set(
649
722
     error,
650
722
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
651
722
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
652
722
     "%s: invalid file - file IO handle already set.",
653
722
     function );
654
655
722
    return( -1 );
656
722
  }
657
10.3k
  if( file_io_handle == NULL )
658
2.00k
  {
659
2.00k
    libcerror_error_set(
660
2.00k
     error,
661
2.00k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
662
2.00k
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
663
2.00k
     "%s: invalid file IO handle.",
664
2.00k
     function );
665
666
2.00k
    return( -1 );
667
2.00k
  }
668
8.33k
  if( ( ( access_flags & LIBMSIECF_ACCESS_FLAG_READ ) == 0 )
669
2.00k
   && ( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) == 0 ) )
670
2.00k
  {
671
2.00k
    libcerror_error_set(
672
2.00k
     error,
673
2.00k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
674
2.00k
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
675
2.00k
     "%s: unsupported access flags.",
676
2.00k
     function );
677
678
2.00k
    return( -1 );
679
2.00k
  }
680
6.32k
  if( ( access_flags & LIBMSIECF_ACCESS_FLAG_WRITE ) != 0 )
681
2.00k
  {
682
2.00k
    libcerror_error_set(
683
2.00k
     error,
684
2.00k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
685
2.00k
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
686
2.00k
     "%s: write access currently not supported.",
687
2.00k
     function );
688
689
2.00k
    return( -1 );
690
2.00k
  }
691
4.31k
  if( ( access_flags & LIBMSIECF_ACCESS_FLAG_READ ) != 0 )
692
4.31k
  {
693
4.31k
    bfio_access_flags = LIBBFIO_ACCESS_FLAG_READ;
694
4.31k
  }
695
4.31k
  file_io_handle_is_open = libbfio_handle_is_open(
696
4.31k
                            file_io_handle,
697
4.31k
                            error );
698
699
4.31k
  if( file_io_handle_is_open == -1 )
700
0
  {
701
0
    libcerror_error_set(
702
0
     error,
703
0
     LIBCERROR_ERROR_DOMAIN_IO,
704
0
     LIBCERROR_IO_ERROR_OPEN_FAILED,
705
0
     "%s: unable to open file.",
706
0
     function );
707
708
0
    goto on_error;
709
0
  }
710
4.31k
  else if( file_io_handle_is_open == 0 )
711
4.31k
  {
712
4.31k
    if( libbfio_handle_open(
713
4.31k
         file_io_handle,
714
4.31k
         bfio_access_flags,
715
4.31k
         error ) != 1 )
716
0
    {
717
0
      libcerror_error_set(
718
0
       error,
719
0
       LIBCERROR_ERROR_DOMAIN_IO,
720
0
       LIBCERROR_IO_ERROR_OPEN_FAILED,
721
0
       "%s: unable to open file IO handle.",
722
0
       function );
723
724
0
      goto on_error;
725
0
    }
726
4.31k
    file_io_handle_opened_in_library = 1;
727
4.31k
  }
728
4.31k
  if( libmsiecf_internal_file_open_read(
729
4.31k
       internal_file,
730
4.31k
       file_io_handle,
731
4.31k
       error ) != 1 )
732
2.46k
  {
733
2.46k
    libcerror_error_set(
734
2.46k
     error,
735
2.46k
     LIBCERROR_ERROR_DOMAIN_IO,
736
2.46k
     LIBCERROR_IO_ERROR_READ_FAILED,
737
2.46k
     "%s: unable to read from file handle.",
738
2.46k
     function );
739
740
2.46k
    goto on_error;
741
2.46k
  }
742
1.84k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
743
1.84k
  if( libcthreads_read_write_lock_grab_for_write(
744
1.84k
       internal_file->read_write_lock,
745
1.84k
       error ) != 1 )
746
0
  {
747
0
    libcerror_error_set(
748
0
     error,
749
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
750
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
751
0
     "%s: unable to grab read/write lock for writing.",
752
0
     function );
753
754
0
    goto on_error;
755
0
  }
756
1.84k
#endif
757
1.84k
  internal_file->file_io_handle                   = file_io_handle;
758
1.84k
  internal_file->file_io_handle_opened_in_library = file_io_handle_opened_in_library;
759
760
1.84k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
761
1.84k
  if( libcthreads_read_write_lock_release_for_write(
762
1.84k
       internal_file->read_write_lock,
763
1.84k
       error ) != 1 )
764
0
  {
765
0
    libcerror_error_set(
766
0
     error,
767
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
768
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
769
0
     "%s: unable to release read/write lock for writing.",
770
0
     function );
771
772
0
    internal_file->file_io_handle                   = NULL;
773
0
    internal_file->file_io_handle_opened_in_library = 0;
774
775
0
    goto on_error;
776
0
  }
777
1.84k
#endif
778
1.84k
  return( 1 );
779
780
2.46k
on_error:
781
2.46k
  if( file_io_handle_opened_in_library != 0 )
782
2.46k
  {
783
2.46k
    libbfio_handle_close(
784
2.46k
     file_io_handle,
785
2.46k
     error );
786
2.46k
  }
787
2.46k
  return( -1 );
788
1.84k
}
789
790
/* Closes a file
791
 * Returns 0 if successful or -1 on error
792
 */
793
int libmsiecf_file_close(
794
     libmsiecf_file_t *file,
795
     libcerror_error_t **error )
796
5.86k
{
797
5.86k
  libmsiecf_internal_file_t *internal_file = NULL;
798
5.86k
  static char *function                    = "libmsiecf_file_close";
799
5.86k
  int result                               = 0;
800
801
5.86k
  if( file == NULL )
802
2.00k
  {
803
2.00k
    libcerror_error_set(
804
2.00k
     error,
805
2.00k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
806
2.00k
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
807
2.00k
     "%s: invalid file.",
808
2.00k
     function );
809
810
2.00k
    return( -1 );
811
2.00k
  }
812
3.85k
  internal_file = (libmsiecf_internal_file_t *) file;
813
814
3.85k
  if( internal_file->file_io_handle == NULL )
815
2.00k
  {
816
2.00k
    libcerror_error_set(
817
2.00k
     error,
818
2.00k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
819
2.00k
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
820
2.00k
     "%s: invalid file - missing file IO handle.",
821
2.00k
     function );
822
823
2.00k
    return( -1 );
824
2.00k
  }
825
1.84k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
826
1.84k
  if( libcthreads_read_write_lock_grab_for_write(
827
1.84k
       internal_file->read_write_lock,
828
1.84k
       error ) != 1 )
829
0
  {
830
0
    libcerror_error_set(
831
0
     error,
832
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
833
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
834
0
     "%s: unable to grab read/write lock for writing.",
835
0
     function );
836
837
0
    return( -1 );
838
0
  }
839
1.84k
#endif
840
#if defined( HAVE_DEBUG_OUTPUT )
841
  if( libcnotify_verbose != 0 )
842
  {
843
    if( internal_file->file_io_handle_created_in_library != 0 )
844
    {
845
      if( libmsiecf_debug_print_read_offsets(
846
           internal_file->file_io_handle,
847
           error ) != 1 )
848
      {
849
        libcerror_error_set(
850
         error,
851
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
852
         LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
853
         "%s: unable to print the read offsets.",
854
         function );
855
      }
856
    }
857
  }
858
#endif
859
1.84k
  if( internal_file->file_io_handle_opened_in_library != 0 )
860
1.84k
  {
861
1.84k
    if( libbfio_handle_close(
862
1.84k
         internal_file->file_io_handle,
863
1.84k
         error ) != 0 )
864
0
    {
865
0
      libcerror_error_set(
866
0
       error,
867
0
       LIBCERROR_ERROR_DOMAIN_IO,
868
0
       LIBCERROR_IO_ERROR_CLOSE_FAILED,
869
0
       "%s: unable to close file IO handle.",
870
0
       function );
871
872
0
      result = -1;
873
0
    }
874
1.84k
    internal_file->file_io_handle_opened_in_library = 0;
875
1.84k
  }
876
1.84k
  if( internal_file->file_io_handle_created_in_library != 0 )
877
0
  {
878
0
    if( libbfio_handle_free(
879
0
         &( internal_file->file_io_handle ),
880
0
         error ) != 1 )
881
0
    {
882
0
      libcerror_error_set(
883
0
       error,
884
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
885
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
886
0
       "%s: unable to free file IO handle.",
887
0
       function );
888
889
0
      result = -1;
890
0
    }
891
0
    internal_file->file_io_handle_created_in_library = 0;
892
0
  }
893
1.84k
  internal_file->file_io_handle = NULL;
894
895
1.84k
  if( libmsiecf_io_handle_clear(
896
1.84k
       internal_file->io_handle,
897
1.84k
       error ) != 1 )
898
0
  {
899
0
    libcerror_error_set(
900
0
     error,
901
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
902
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
903
0
     "%s: unable to clear IO handle.",
904
0
     function );
905
906
0
    result = -1;
907
0
  }
908
1.84k
  if( internal_file->file_header != NULL )
909
1.84k
  {
910
1.84k
    if( libmsiecf_file_header_free(
911
1.84k
         &( internal_file->file_header ),
912
1.84k
         error ) != 1 )
913
0
    {
914
0
      libcerror_error_set(
915
0
       error,
916
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
917
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
918
0
       "%s: unable to free file header.",
919
0
       function );
920
921
0
      result = -1;
922
0
    }
923
1.84k
  }
924
1.84k
  if( internal_file->cache_directory_table != NULL )
925
1.84k
  {
926
1.84k
    if( libmsiecf_cache_directory_table_free(
927
1.84k
         &( internal_file->cache_directory_table ),
928
1.84k
         error ) != 1 )
929
0
    {
930
0
      libcerror_error_set(
931
0
       error,
932
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
933
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
934
0
       "%s: unable to free cache directory table.",
935
0
       function );
936
937
0
      result = -1;
938
0
    }
939
1.84k
  }
940
1.84k
  if( internal_file->item_array != NULL )
941
1.84k
  {
942
1.84k
    if( libcdata_array_free(
943
1.84k
         &( internal_file->item_array ),
944
1.84k
         (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
945
1.84k
         error ) != 1 )
946
0
    {
947
0
      libcerror_error_set(
948
0
       error,
949
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
950
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
951
0
       "%s: unable to free item array.",
952
0
       function );
953
954
0
      result = -1;
955
0
    }
956
1.84k
  }
957
1.84k
  if( internal_file->recovered_item_array != NULL )
958
1.84k
  {
959
1.84k
    if( libcdata_array_free(
960
1.84k
         &( internal_file->recovered_item_array ),
961
1.84k
         (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
962
1.84k
         error ) != 1 )
963
0
    {
964
0
      libcerror_error_set(
965
0
       error,
966
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
967
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
968
0
       "%s: unable to free recovered item array.",
969
0
       function );
970
971
0
      result = -1;
972
0
    }
973
1.84k
  }
974
1.84k
  if( internal_file->unallocated_block_list != NULL )
975
1.84k
  {
976
1.84k
    if( libcdata_range_list_free(
977
1.84k
         &( internal_file->unallocated_block_list ),
978
1.84k
         NULL,
979
1.84k
         error ) != 1 )
980
0
    {
981
0
      libcerror_error_set(
982
0
       error,
983
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
984
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
985
0
       "%s: unable to free unallocated block list.",
986
0
       function );
987
988
0
      result = -1;
989
0
    }
990
1.84k
  }
991
1.84k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
992
1.84k
  if( libcthreads_read_write_lock_release_for_write(
993
1.84k
       internal_file->read_write_lock,
994
1.84k
       error ) != 1 )
995
0
  {
996
0
    libcerror_error_set(
997
0
     error,
998
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
999
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1000
0
     "%s: unable to release read/write lock for writing.",
1001
0
     function );
1002
1003
0
    return( -1 );
1004
0
  }
1005
1.84k
#endif
1006
1.84k
  return( result );
1007
1.84k
}
1008
1009
/* Opens a file for reading
1010
 * Returns 1 if successful or -1 on error
1011
 */
1012
int libmsiecf_internal_file_open_read(
1013
     libmsiecf_internal_file_t *internal_file,
1014
     libbfio_handle_t *file_io_handle,
1015
     libcerror_error_t **error )
1016
4.31k
{
1017
4.31k
  static char *function = "libmsiecf_internal_file_open_read";
1018
1019
4.31k
  if( internal_file == NULL )
1020
0
  {
1021
0
    libcerror_error_set(
1022
0
     error,
1023
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1024
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1025
0
     "%s: invalid file.",
1026
0
     function );
1027
1028
0
    return( -1 );
1029
0
  }
1030
4.31k
  if( internal_file->io_handle == NULL )
1031
0
  {
1032
0
    libcerror_error_set(
1033
0
     error,
1034
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1035
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1036
0
     "%s: invalid file - missing IO handle.",
1037
0
     function );
1038
1039
0
    return( -1 );
1040
0
  }
1041
4.31k
  if( internal_file->file_header != NULL )
1042
0
  {
1043
0
    libcerror_error_set(
1044
0
     error,
1045
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1046
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1047
0
     "%s: invalid file - file header already set.",
1048
0
     function );
1049
1050
0
    return( -1 );
1051
0
  }
1052
4.31k
  if( internal_file->cache_directory_table != NULL )
1053
0
  {
1054
0
    libcerror_error_set(
1055
0
     error,
1056
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1057
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1058
0
     "%s: invalid file - cache directory table value already set.",
1059
0
     function );
1060
1061
0
    return( -1 );
1062
0
  }
1063
4.31k
  if( internal_file->item_array != NULL )
1064
0
  {
1065
0
    libcerror_error_set(
1066
0
     error,
1067
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1068
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1069
0
     "%s: invalid file - item array already set.",
1070
0
     function );
1071
1072
0
    return( -1 );
1073
0
  }
1074
4.31k
  if( internal_file->recovered_item_array != NULL )
1075
0
  {
1076
0
    libcerror_error_set(
1077
0
     error,
1078
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1079
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1080
0
     "%s: invalid file - recovered item array already set.",
1081
0
     function );
1082
1083
0
    return( -1 );
1084
0
  }
1085
4.31k
  if( internal_file->unallocated_block_list != NULL )
1086
0
  {
1087
0
    libcerror_error_set(
1088
0
     error,
1089
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1090
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1091
0
     "%s: invalid file - unallocated block list already set.",
1092
0
     function );
1093
1094
0
    return( -1 );
1095
0
  }
1096
#if defined( HAVE_DEBUG_OUTPUT )
1097
  if( libcnotify_verbose != 0 )
1098
  {
1099
    libcnotify_printf(
1100
     "Reading file header:\n" );
1101
  }
1102
#endif
1103
4.31k
  if( libmsiecf_file_header_initialize(
1104
4.31k
       &( internal_file->file_header ),
1105
4.31k
       error ) != 1 )
1106
0
  {
1107
0
    libcerror_error_set(
1108
0
     error,
1109
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1110
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1111
0
     "%s: unable to create file handle.",
1112
0
     function );
1113
1114
0
    goto on_error;
1115
0
  }
1116
4.31k
  if( libmsiecf_file_header_read_file_io_handle(
1117
4.31k
       internal_file->file_header,
1118
4.31k
       file_io_handle,
1119
4.31k
       0,
1120
4.31k
       error ) != 1 )
1121
435
  {
1122
435
    libcerror_error_set(
1123
435
     error,
1124
435
     LIBCERROR_ERROR_DOMAIN_IO,
1125
435
     LIBCERROR_IO_ERROR_READ_FAILED,
1126
435
     "%s: unable to read file header.",
1127
435
     function );
1128
1129
435
    goto on_error;
1130
435
  }
1131
3.87k
  internal_file->io_handle->major_version = internal_file->file_header->major_version;
1132
3.87k
  internal_file->io_handle->minor_version = internal_file->file_header->minor_version;
1133
3.87k
  internal_file->io_handle->file_size     = internal_file->file_header->file_size;
1134
1135
#if defined( HAVE_DEBUG_OUTPUT )
1136
  if( libcnotify_verbose != 0 )
1137
  {
1138
    libcnotify_printf(
1139
     "Reading cache directory table:\n" );
1140
  }
1141
#endif
1142
3.87k
  if( libmsiecf_cache_directory_table_initialize(
1143
3.87k
       &( internal_file->cache_directory_table ),
1144
3.87k
       error ) != 1 )
1145
0
  {
1146
0
    libcerror_error_set(
1147
0
     error,
1148
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1149
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1150
0
     "%s: unable to create cache directory table.",
1151
0
     function );
1152
1153
0
    goto on_error;
1154
0
  }
1155
3.87k
  if( libmsiecf_cache_directory_table_read_file_io_handle(
1156
3.87k
       internal_file->cache_directory_table,
1157
3.87k
       file_io_handle,
1158
3.87k
       sizeof( msiecf_file_header_t ),
1159
3.87k
       error ) != 1 )
1160
107
  {
1161
107
    libcerror_error_set(
1162
107
     error,
1163
107
     LIBCERROR_ERROR_DOMAIN_IO,
1164
107
     LIBCERROR_IO_ERROR_READ_FAILED,
1165
107
     "%s: unable to read cache directory table.",
1166
107
     function );
1167
1168
107
    goto on_error;
1169
107
  }
1170
#if defined( HAVE_DEBUG_OUTPUT )
1171
  if( libcnotify_verbose != 0 )
1172
  {
1173
    libcnotify_printf(
1174
     "Reading allocation table:\n" );
1175
  }
1176
#endif
1177
3.77k
  if( libcdata_range_list_initialize(
1178
3.77k
       &( internal_file->unallocated_block_list ),
1179
3.77k
       error ) != 1 )
1180
0
  {
1181
0
    libcerror_error_set(
1182
0
     error,
1183
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1184
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1185
0
     "%s: unable to create unallocated data block list.",
1186
0
     function );
1187
1188
0
    goto on_error;
1189
0
  }
1190
3.77k
  if( libmsiecf_allocation_table_read_file_io_handle(
1191
3.77k
       internal_file->unallocated_block_list,
1192
3.77k
       file_io_handle,
1193
3.77k
       0x250,
1194
3.77k
       internal_file->file_header->file_size,
1195
3.77k
       0x4000,
1196
3.77k
       internal_file->io_handle->block_size,
1197
3.77k
       internal_file->file_header->number_of_blocks,
1198
3.77k
       internal_file->file_header->number_of_allocated_blocks,
1199
3.77k
       error ) != 1 )
1200
272
  {
1201
272
    libcerror_error_set(
1202
272
     error,
1203
272
     LIBCERROR_ERROR_DOMAIN_IO,
1204
272
     LIBCERROR_IO_ERROR_READ_FAILED,
1205
272
     "%s: unable to read allocation table.",
1206
272
     function );
1207
1208
272
    goto on_error;
1209
272
  }
1210
#if defined( HAVE_DEBUG_OUTPUT )
1211
  if( libcnotify_verbose != 0 )
1212
  {
1213
    libcnotify_printf(
1214
     "Reading hash table:\n" );
1215
  }
1216
#endif
1217
3.49k
  if( libcdata_array_initialize(
1218
3.49k
       &( internal_file->item_array ),
1219
3.49k
       0,
1220
3.49k
       error ) != 1 )
1221
0
  {
1222
0
    libcerror_error_set(
1223
0
     error,
1224
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1225
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1226
0
     "%s: unable to create item array.",
1227
0
     function );
1228
1229
0
    goto on_error;
1230
0
  }
1231
3.49k
  if( libmsiecf_io_handle_read_hash_table(
1232
3.49k
       internal_file->item_array,
1233
3.49k
       internal_file->io_handle,
1234
3.49k
       file_io_handle,
1235
3.49k
       internal_file->file_header->hash_table_offset,
1236
3.49k
       error ) != 1 )
1237
404
  {
1238
404
    libcerror_error_set(
1239
404
     error,
1240
404
     LIBCERROR_ERROR_DOMAIN_IO,
1241
404
     LIBCERROR_IO_ERROR_READ_FAILED,
1242
404
     "%s: unable to read hash table.",
1243
404
     function );
1244
1245
404
    goto on_error;
1246
404
  }
1247
#if defined( HAVE_DEBUG_OUTPUT )
1248
  if( libcnotify_verbose != 0 )
1249
  {
1250
    libcnotify_printf(
1251
     "Scanning for records:\n" );
1252
  }
1253
#endif
1254
3.09k
  if( libcdata_array_initialize(
1255
3.09k
       &( internal_file->recovered_item_array ),
1256
3.09k
       0,
1257
3.09k
       error ) != 1 )
1258
0
  {
1259
0
    libcerror_error_set(
1260
0
     error,
1261
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1262
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1263
0
     "%s: unable to create recovered item array.",
1264
0
     function );
1265
1266
0
    goto on_error;
1267
0
  }
1268
3.09k
  if( libmsiecf_io_handle_read_record_scan(
1269
3.09k
       internal_file->item_array,
1270
3.09k
       internal_file->recovered_item_array,
1271
3.09k
       internal_file->io_handle,
1272
3.09k
       file_io_handle,
1273
3.09k
       internal_file->file_header->hash_table_offset,
1274
3.09k
       internal_file->unallocated_block_list,
1275
3.09k
       error ) != 1 )
1276
1.24k
  {
1277
1.24k
    libcerror_error_set(
1278
1.24k
     error,
1279
1.24k
     LIBCERROR_ERROR_DOMAIN_IO,
1280
1.24k
     LIBCERROR_IO_ERROR_READ_FAILED,
1281
1.24k
     "%s: unable to perform record scan.",
1282
1.24k
     function );
1283
1284
1.24k
    goto on_error;
1285
1.24k
  }
1286
1.84k
  return( 1 );
1287
1288
2.46k
on_error:
1289
2.46k
  if( internal_file->recovered_item_array != NULL )
1290
1.24k
  {
1291
1.24k
    libcdata_array_free(
1292
1.24k
     &( internal_file->recovered_item_array ),
1293
1.24k
     (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
1294
1.24k
     NULL );
1295
1.24k
  }
1296
2.46k
  if( internal_file->item_array != NULL )
1297
1.65k
  {
1298
1.65k
    libcdata_array_free(
1299
1.65k
     &( internal_file->item_array ),
1300
1.65k
     (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free,
1301
1.65k
     NULL );
1302
1.65k
  }
1303
2.46k
  if( internal_file->unallocated_block_list != NULL )
1304
1.92k
  {
1305
1.92k
    libcdata_range_list_free(
1306
1.92k
     &( internal_file->unallocated_block_list ),
1307
1.92k
     NULL,
1308
1.92k
     NULL );
1309
1.92k
  }
1310
2.46k
  if( internal_file->cache_directory_table != NULL )
1311
2.03k
  {
1312
2.03k
    libmsiecf_cache_directory_table_free(
1313
2.03k
     &( internal_file->cache_directory_table ),
1314
2.03k
     NULL );
1315
2.03k
  }
1316
2.46k
  if( internal_file->file_header != NULL )
1317
2.46k
  {
1318
2.46k
    libmsiecf_file_header_free(
1319
2.46k
     &( internal_file->file_header ),
1320
2.46k
     NULL );
1321
2.46k
  }
1322
2.46k
  return( -1 );
1323
3.09k
}
1324
1325
/* Retrieves the file size
1326
 * Returns 1 if successful or -1 on error
1327
 */
1328
int libmsiecf_file_get_size(
1329
     libmsiecf_file_t *file,
1330
     size64_t *size,
1331
     libcerror_error_t **error )
1332
5.46k
{
1333
5.46k
  libmsiecf_internal_file_t *internal_file = NULL;
1334
5.46k
  static char *function                    = "libmsiecf_file_get_size";
1335
1336
5.46k
  if( file == NULL )
1337
0
  {
1338
0
    libcerror_error_set(
1339
0
     error,
1340
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1341
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1342
0
     "%s: invalid file.",
1343
0
     function );
1344
1345
0
    return( -1 );
1346
0
  }
1347
5.46k
  internal_file = (libmsiecf_internal_file_t *) file;
1348
1349
5.46k
  if( internal_file->file_header == NULL )
1350
4.01k
  {
1351
4.01k
    libcerror_error_set(
1352
4.01k
     error,
1353
4.01k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1354
4.01k
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1355
4.01k
     "%s: invalid file - missing file header.",
1356
4.01k
     function );
1357
1358
4.01k
    return( -1 );
1359
4.01k
  }
1360
1.44k
  if( size == NULL )
1361
722
  {
1362
722
    libcerror_error_set(
1363
722
     error,
1364
722
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1365
722
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1366
722
     "%s: invalid size.",
1367
722
     function );
1368
1369
722
    return( -1 );
1370
722
  }
1371
722
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1372
722
  if( libcthreads_read_write_lock_grab_for_read(
1373
722
       internal_file->read_write_lock,
1374
722
       error ) != 1 )
1375
0
  {
1376
0
    libcerror_error_set(
1377
0
     error,
1378
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1379
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1380
0
     "%s: unable to grab read/write lock for reading.",
1381
0
     function );
1382
1383
0
    return( -1 );
1384
0
  }
1385
722
#endif
1386
722
  *size = internal_file->file_header->file_size;
1387
1388
722
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1389
722
  if( libcthreads_read_write_lock_release_for_read(
1390
722
       internal_file->read_write_lock,
1391
722
       error ) != 1 )
1392
0
  {
1393
0
    libcerror_error_set(
1394
0
     error,
1395
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1396
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1397
0
     "%s: unable to release read/write lock for reading.",
1398
0
     function );
1399
1400
0
    return( -1 );
1401
0
  }
1402
722
#endif
1403
722
  return( 1 );
1404
722
}
1405
1406
/* Retrieves the file ASCII codepage
1407
 * Returns 1 if successful or -1 on error
1408
 */
1409
int libmsiecf_file_get_ascii_codepage(
1410
     libmsiecf_file_t *file,
1411
     int *ascii_codepage,
1412
     libcerror_error_t **error )
1413
5.29k
{
1414
5.29k
  libmsiecf_internal_file_t *internal_file = NULL;
1415
5.29k
  static char *function                    = "libmsiecf_file_get_ascii_codepage";
1416
1417
5.29k
  if( file == NULL )
1418
0
  {
1419
0
    libcerror_error_set(
1420
0
     error,
1421
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1422
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1423
0
     "%s: invalid file.",
1424
0
     function );
1425
1426
0
    return( -1 );
1427
0
  }
1428
5.29k
  internal_file = (libmsiecf_internal_file_t *) file;
1429
1430
5.29k
  if( internal_file->io_handle == NULL )
1431
0
  {
1432
0
    libcerror_error_set(
1433
0
     error,
1434
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1435
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1436
0
     "%s: invalid file - missing IO handle.",
1437
0
     function );
1438
1439
0
    return( -1 );
1440
0
  }
1441
5.29k
  if( ascii_codepage == NULL )
1442
3.85k
  {
1443
3.85k
    libcerror_error_set(
1444
3.85k
     error,
1445
3.85k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1446
3.85k
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1447
3.85k
     "%s: invalid ASCII codepage.",
1448
3.85k
     function );
1449
1450
3.85k
    return( -1 );
1451
3.85k
  }
1452
1.44k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1453
1.44k
  if( libcthreads_read_write_lock_grab_for_read(
1454
1.44k
       internal_file->read_write_lock,
1455
1.44k
       error ) != 1 )
1456
0
  {
1457
0
    libcerror_error_set(
1458
0
     error,
1459
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1460
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1461
0
     "%s: unable to grab read/write lock for reading.",
1462
0
     function );
1463
1464
0
    return( -1 );
1465
0
  }
1466
1.44k
#endif
1467
1.44k
  *ascii_codepage = internal_file->io_handle->ascii_codepage;
1468
1469
1.44k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1470
1.44k
  if( libcthreads_read_write_lock_release_for_read(
1471
1.44k
       internal_file->read_write_lock,
1472
1.44k
       error ) != 1 )
1473
0
  {
1474
0
    libcerror_error_set(
1475
0
     error,
1476
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1477
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1478
0
     "%s: unable to release read/write lock for reading.",
1479
0
     function );
1480
1481
0
    return( -1 );
1482
0
  }
1483
1.44k
#endif
1484
1.44k
  return( 1 );
1485
1.44k
}
1486
1487
/* Sets the file ASCII codepage
1488
 * Returns 1 if successful or -1 on error
1489
 */
1490
int libmsiecf_file_set_ascii_codepage(
1491
     libmsiecf_file_t *file,
1492
     int ascii_codepage,
1493
     libcerror_error_t **error )
1494
3.69k
{
1495
3.69k
  libmsiecf_internal_file_t *internal_file = NULL;
1496
3.69k
  static char *function                    = "libmsiecf_file_set_ascii_codepage";
1497
1498
3.69k
  if( file == NULL )
1499
0
  {
1500
0
    libcerror_error_set(
1501
0
     error,
1502
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1503
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1504
0
     "%s: invalid file.",
1505
0
     function );
1506
1507
0
    return( -1 );
1508
0
  }
1509
3.69k
  internal_file = (libmsiecf_internal_file_t *) file;
1510
1511
3.69k
  if( internal_file->io_handle == NULL )
1512
0
  {
1513
0
    libcerror_error_set(
1514
0
     error,
1515
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1516
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1517
0
     "%s: invalid file - missing IO handle.",
1518
0
     function );
1519
1520
0
    return( -1 );
1521
0
  }
1522
3.69k
  if( ( ascii_codepage != LIBMSIECF_CODEPAGE_ASCII )
1523
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_874 )
1524
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_932 )
1525
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_936 )
1526
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_949 )
1527
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_950 )
1528
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1250 )
1529
3.69k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1251 )
1530
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1252 )
1531
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1253 )
1532
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1254 )
1533
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1255 )
1534
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1256 )
1535
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1257 )
1536
1.84k
   && ( ascii_codepage != LIBMSIECF_CODEPAGE_WINDOWS_1258 ) )
1537
1.84k
  {
1538
1.84k
    libcerror_error_set(
1539
1.84k
     error,
1540
1.84k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1541
1.84k
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1542
1.84k
     "%s: unsupported ASCII codepage.",
1543
1.84k
     function );
1544
1545
1.84k
    return( -1 );
1546
1.84k
  }
1547
1.84k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1548
1.84k
  if( libcthreads_read_write_lock_grab_for_write(
1549
1.84k
       internal_file->read_write_lock,
1550
1.84k
       error ) != 1 )
1551
0
  {
1552
0
    libcerror_error_set(
1553
0
     error,
1554
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1555
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1556
0
     "%s: unable to grab read/write lock for writing.",
1557
0
     function );
1558
1559
0
    return( -1 );
1560
0
  }
1561
1.84k
#endif
1562
1.84k
  internal_file->io_handle->ascii_codepage = ascii_codepage;
1563
1564
1.84k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1565
1.84k
  if( libcthreads_read_write_lock_release_for_write(
1566
1.84k
       internal_file->read_write_lock,
1567
1.84k
       error ) != 1 )
1568
0
  {
1569
0
    libcerror_error_set(
1570
0
     error,
1571
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1572
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1573
0
     "%s: unable to release read/write lock for writing.",
1574
0
     function );
1575
1576
0
    return( -1 );
1577
0
  }
1578
1.84k
#endif
1579
1.84k
  return( 1 );
1580
1.84k
}
1581
1582
/* Retrieves the format version
1583
 * Returns 1 if successful or -1 on error
1584
 */
1585
int libmsiecf_file_get_format_version(
1586
     libmsiecf_file_t *file,
1587
     uint8_t *major_version,
1588
     uint8_t *minor_version,
1589
     libcerror_error_t **error )
1590
3.45k
{
1591
3.45k
  libmsiecf_internal_file_t *internal_file = NULL;
1592
3.45k
  static char *function                    = "libmsiecf_file_get_format_version";
1593
1594
3.45k
  if( file == NULL )
1595
0
  {
1596
0
    libcerror_error_set(
1597
0
     error,
1598
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1599
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1600
0
     "%s: invalid file.",
1601
0
     function );
1602
1603
0
    return( -1 );
1604
0
  }
1605
3.45k
  internal_file = (libmsiecf_internal_file_t *) file;
1606
1607
3.45k
  if( internal_file->file_header == NULL )
1608
2.00k
  {
1609
2.00k
    libcerror_error_set(
1610
2.00k
     error,
1611
2.00k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1612
2.00k
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1613
2.00k
     "%s: invalid file - missing file header.",
1614
2.00k
     function );
1615
1616
2.00k
    return( -1 );
1617
2.00k
  }
1618
1.44k
  if( major_version == NULL )
1619
722
  {
1620
722
    libcerror_error_set(
1621
722
     error,
1622
722
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1623
722
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1624
722
     "%s: invalid major version.",
1625
722
     function );
1626
1627
722
    return( -1 );
1628
722
  }
1629
722
  if( minor_version == NULL )
1630
0
  {
1631
0
    libcerror_error_set(
1632
0
     error,
1633
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1634
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1635
0
     "%s: invalid minor version.",
1636
0
     function );
1637
1638
0
    return( -1 );
1639
0
  }
1640
722
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1641
722
  if( libcthreads_read_write_lock_grab_for_read(
1642
722
       internal_file->read_write_lock,
1643
722
       error ) != 1 )
1644
0
  {
1645
0
    libcerror_error_set(
1646
0
     error,
1647
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1648
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1649
0
     "%s: unable to grab read/write lock for reading.",
1650
0
     function );
1651
1652
0
    return( -1 );
1653
0
  }
1654
722
#endif
1655
722
  *major_version = internal_file->file_header->major_version;
1656
722
  *minor_version = internal_file->file_header->minor_version;
1657
1658
722
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1659
722
  if( libcthreads_read_write_lock_release_for_read(
1660
722
       internal_file->read_write_lock,
1661
722
       error ) != 1 )
1662
0
  {
1663
0
    libcerror_error_set(
1664
0
     error,
1665
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1666
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1667
0
     "%s: unable to release read/write lock for reading.",
1668
0
     function );
1669
1670
0
    return( -1 );
1671
0
  }
1672
722
#endif
1673
722
  return( 1 );
1674
722
}
1675
1676
/* Retrieves the number of unallocated blocks
1677
 * Returns 1 if successful or -1 on error
1678
 */
1679
int libmsiecf_file_get_number_of_unallocated_blocks(
1680
     libmsiecf_file_t *file,
1681
     int *number_of_unallocated_blocks,
1682
     libcerror_error_t **error )
1683
3.45k
{
1684
3.45k
  libmsiecf_internal_file_t *internal_file = NULL;
1685
3.45k
  static char *function                    = "libmsiecf_file_get_number_of_unallocated_blocks";
1686
3.45k
  int result                               = 1;
1687
1688
3.45k
  if( file == NULL )
1689
0
  {
1690
0
    libcerror_error_set(
1691
0
     error,
1692
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1693
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1694
0
     "%s: invalid file.",
1695
0
     function );
1696
1697
0
    return( -1 );
1698
0
  }
1699
3.45k
  internal_file = (libmsiecf_internal_file_t *) file;
1700
1701
3.45k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1702
3.45k
  if( libcthreads_read_write_lock_grab_for_read(
1703
3.45k
       internal_file->read_write_lock,
1704
3.45k
       error ) != 1 )
1705
0
  {
1706
0
    libcerror_error_set(
1707
0
     error,
1708
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1709
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1710
0
     "%s: unable to grab read/write lock for reading.",
1711
0
     function );
1712
1713
0
    return( -1 );
1714
0
  }
1715
3.45k
#endif
1716
3.45k
  result = libcdata_range_list_get_number_of_elements(
1717
3.45k
            internal_file->unallocated_block_list,
1718
3.45k
            number_of_unallocated_blocks,
1719
3.45k
            error );
1720
1721
3.45k
  if( result != 1 )
1722
2.73k
  {
1723
2.73k
    libcerror_error_set(
1724
2.73k
     error,
1725
2.73k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1726
2.73k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1727
2.73k
     "%s: unable to retrieve number of elements.",
1728
2.73k
     function );
1729
1730
2.73k
    result = -1;
1731
2.73k
  }
1732
3.45k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1733
3.45k
  if( libcthreads_read_write_lock_release_for_read(
1734
3.45k
       internal_file->read_write_lock,
1735
3.45k
       error ) != 1 )
1736
0
  {
1737
0
    libcerror_error_set(
1738
0
     error,
1739
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1740
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1741
0
     "%s: unable to release read/write lock for reading.",
1742
0
     function );
1743
1744
0
    return( -1 );
1745
0
  }
1746
3.45k
#endif
1747
3.45k
  return( result );
1748
3.45k
}
1749
1750
/* Retrieves a specific unallocated block
1751
 * Returns 1 if successful or -1 on error
1752
 */
1753
int libmsiecf_file_get_unallocated_block(
1754
     libmsiecf_file_t *file,
1755
     int unallocated_block_index,
1756
     off64_t *offset,
1757
     size64_t *size,
1758
     libcerror_error_t **error )
1759
27.5k
{
1760
27.5k
  libmsiecf_internal_file_t *internal_file = NULL;
1761
27.5k
  intptr_t *value                          = NULL;
1762
27.5k
  static char *function                    = "libmsiecf_file_get_unallocated_block";
1763
27.5k
  int result                               = 1;
1764
1765
27.5k
  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
27.5k
  internal_file = (libmsiecf_internal_file_t *) file;
1777
1778
27.5k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1779
27.5k
  if( libcthreads_read_write_lock_grab_for_read(
1780
27.5k
       internal_file->read_write_lock,
1781
27.5k
       error ) != 1 )
1782
0
  {
1783
0
    libcerror_error_set(
1784
0
     error,
1785
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1786
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1787
0
     "%s: unable to grab read/write lock for reading.",
1788
0
     function );
1789
1790
0
    return( -1 );
1791
0
  }
1792
27.5k
#endif
1793
27.5k
  result = libcdata_range_list_get_range_by_index(
1794
27.5k
            internal_file->unallocated_block_list,
1795
27.5k
            unallocated_block_index,
1796
27.5k
            (uint64_t *) offset,
1797
27.5k
            (uint64_t *) size,
1798
27.5k
            &value,
1799
27.5k
            error );
1800
1801
27.5k
  if( result != 1 )
1802
3.37k
  {
1803
3.37k
    libcerror_error_set(
1804
3.37k
     error,
1805
3.37k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1806
3.37k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1807
3.37k
     "%s: unable to retrieve unallocated block range: %d.",
1808
3.37k
     function,
1809
3.37k
     unallocated_block_index );
1810
1811
3.37k
    result = -1;
1812
3.37k
  }
1813
27.5k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1814
27.5k
  if( libcthreads_read_write_lock_release_for_read(
1815
27.5k
       internal_file->read_write_lock,
1816
27.5k
       error ) != 1 )
1817
0
  {
1818
0
    libcerror_error_set(
1819
0
     error,
1820
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1821
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1822
0
     "%s: unable to release read/write lock for reading.",
1823
0
     function );
1824
1825
0
    return( -1 );
1826
0
  }
1827
27.5k
#endif
1828
27.5k
  return( result );
1829
27.5k
}
1830
1831
/* Retrieves the number of cache directories
1832
 * Returns 1 if successful or -1 on error
1833
 */
1834
int libmsiecf_file_get_number_of_cache_directories(
1835
     libmsiecf_file_t *file,
1836
     int *number_of_cache_directories,
1837
     libcerror_error_t **error )
1838
3.45k
{
1839
3.45k
  libmsiecf_internal_file_t *internal_file = NULL;
1840
3.45k
  static char *function                    = "libmsiecf_file_get_number_of_cache_directories";
1841
3.45k
  int result                               = 1;
1842
1843
3.45k
  if( file == NULL )
1844
0
  {
1845
0
    libcerror_error_set(
1846
0
     error,
1847
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1848
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1849
0
     "%s: invalid file.",
1850
0
     function );
1851
1852
0
    return( -1 );
1853
0
  }
1854
3.45k
  internal_file = (libmsiecf_internal_file_t *) file;
1855
1856
3.45k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1857
3.45k
  if( libcthreads_read_write_lock_grab_for_read(
1858
3.45k
       internal_file->read_write_lock,
1859
3.45k
       error ) != 1 )
1860
0
  {
1861
0
    libcerror_error_set(
1862
0
     error,
1863
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1864
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1865
0
     "%s: unable to grab read/write lock for reading.",
1866
0
     function );
1867
1868
0
    return( -1 );
1869
0
  }
1870
3.45k
#endif
1871
3.45k
  result = libmsiecf_cache_directory_table_get_number_of_cache_directories(
1872
3.45k
            internal_file->cache_directory_table,
1873
3.45k
            number_of_cache_directories,
1874
3.45k
            error );
1875
1876
3.45k
  if( result != 1 )
1877
2.73k
  {
1878
2.73k
    libcerror_error_set(
1879
2.73k
     error,
1880
2.73k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1881
2.73k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1882
2.73k
     "%s: unable to retrieve number of elements from directory array.",
1883
2.73k
     function );
1884
1885
2.73k
    result = -1;
1886
2.73k
  }
1887
3.45k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1888
3.45k
  if( libcthreads_read_write_lock_release_for_read(
1889
3.45k
       internal_file->read_write_lock,
1890
3.45k
       error ) != 1 )
1891
0
  {
1892
0
    libcerror_error_set(
1893
0
     error,
1894
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1895
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1896
0
     "%s: unable to release read/write lock for reading.",
1897
0
     function );
1898
1899
0
    return( -1 );
1900
0
  }
1901
3.45k
#endif
1902
3.45k
  return( result );
1903
3.45k
}
1904
1905
/* Retrieves the extended ASCII encoded name of a certain cache directory
1906
 * The size should include the end of string character
1907
 * The cache directory name consists of 8 characters + end of string character
1908
 * Returns 1 if successful or -1 on error
1909
 */
1910
int libmsiecf_file_get_cache_directory_name(
1911
     libmsiecf_file_t *file,
1912
     int cache_directory_index,
1913
     char *string,
1914
     size_t string_size,
1915
     libcerror_error_t **error )
1916
3.99k
{
1917
3.99k
  libmsiecf_internal_file_t *internal_file = NULL;
1918
3.99k
  static char *function                    = "libmsiecf_file_get_cache_directory_name";
1919
3.99k
  int result                               = 1;
1920
1921
3.99k
  if( file == NULL )
1922
0
  {
1923
0
    libcerror_error_set(
1924
0
     error,
1925
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1926
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1927
0
     "%s: invalid file.",
1928
0
     function );
1929
1930
0
    return( -1 );
1931
0
  }
1932
3.99k
  internal_file = (libmsiecf_internal_file_t *) file;
1933
1934
3.99k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1935
3.99k
  if( libcthreads_read_write_lock_grab_for_read(
1936
3.99k
       internal_file->read_write_lock,
1937
3.99k
       error ) != 1 )
1938
0
  {
1939
0
    libcerror_error_set(
1940
0
     error,
1941
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1942
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1943
0
     "%s: unable to grab read/write lock for reading.",
1944
0
     function );
1945
1946
0
    return( -1 );
1947
0
  }
1948
3.99k
#endif
1949
3.99k
  result = libmsiecf_cache_directory_table_get_directory_name_by_index(
1950
3.99k
            internal_file->cache_directory_table,
1951
3.99k
            cache_directory_index,
1952
3.99k
            string,
1953
3.99k
            string_size,
1954
3.99k
            error );
1955
1956
3.99k
  if( result != 1 )
1957
3.03k
  {
1958
3.03k
    libcerror_error_set(
1959
3.03k
     error,
1960
3.03k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1961
3.03k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1962
3.03k
     "%s: unable to retrieve cache directory: %d name.",
1963
3.03k
     function,
1964
3.03k
     cache_directory_index );
1965
1966
3.03k
    result = -1;
1967
3.03k
  }
1968
3.99k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
1969
3.99k
  if( libcthreads_read_write_lock_release_for_read(
1970
3.99k
       internal_file->read_write_lock,
1971
3.99k
       error ) != 1 )
1972
0
  {
1973
0
    libcerror_error_set(
1974
0
     error,
1975
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1976
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1977
0
     "%s: unable to release read/write lock for reading.",
1978
0
     function );
1979
1980
0
    return( -1 );
1981
0
  }
1982
3.99k
#endif
1983
3.99k
  return( result );
1984
3.99k
}
1985
1986
/* Retrieves the number of items
1987
 * Returns 1 if successful or -1 on error
1988
 */
1989
int libmsiecf_file_get_number_of_items(
1990
     libmsiecf_file_t *file,
1991
     int *number_of_items,
1992
     libcerror_error_t **error )
1993
4.57k
{
1994
4.57k
  libmsiecf_internal_file_t *internal_file = NULL;
1995
4.57k
  static char *function                    = "libmsiecf_file_get_number_of_items";
1996
4.57k
  int result                               = 1;
1997
1998
4.57k
  if( file == NULL )
1999
0
  {
2000
0
    libcerror_error_set(
2001
0
     error,
2002
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2003
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2004
0
     "%s: invalid file.",
2005
0
     function );
2006
2007
0
    return( -1 );
2008
0
  }
2009
4.57k
  internal_file = (libmsiecf_internal_file_t *) file;
2010
2011
4.57k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2012
4.57k
  if( libcthreads_read_write_lock_grab_for_read(
2013
4.57k
       internal_file->read_write_lock,
2014
4.57k
       error ) != 1 )
2015
0
  {
2016
0
    libcerror_error_set(
2017
0
     error,
2018
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2019
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2020
0
     "%s: unable to grab read/write lock for reading.",
2021
0
     function );
2022
2023
0
    return( -1 );
2024
0
  }
2025
4.57k
#endif
2026
4.57k
  result = libcdata_array_get_number_of_entries(
2027
4.57k
            internal_file->item_array,
2028
4.57k
            number_of_items,
2029
4.57k
            error );
2030
2031
4.57k
  if( result != 1 )
2032
2.73k
  {
2033
2.73k
    libcerror_error_set(
2034
2.73k
     error,
2035
2.73k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2036
2.73k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2037
2.73k
     "%s: unable to retrieve number of elements from item array.",
2038
2.73k
     function );
2039
2040
2.73k
    result = -1;
2041
2.73k
  }
2042
4.57k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2043
4.57k
  if( libcthreads_read_write_lock_release_for_read(
2044
4.57k
       internal_file->read_write_lock,
2045
4.57k
       error ) != 1 )
2046
0
  {
2047
0
    libcerror_error_set(
2048
0
     error,
2049
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2050
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2051
0
     "%s: unable to release read/write lock for reading.",
2052
0
     function );
2053
2054
0
    return( -1 );
2055
0
  }
2056
4.57k
#endif
2057
4.57k
  return( result );
2058
4.57k
}
2059
2060
/* Retrieves the item for the specific index
2061
 * Returns 1 if successful or -1 on error
2062
 */
2063
int libmsiecf_file_get_item_by_index(
2064
     libmsiecf_file_t *file,
2065
     int item_index,
2066
     libmsiecf_item_t **item,
2067
     libcerror_error_t **error )
2068
19.4k
{
2069
19.4k
  libmsiecf_internal_file_t *internal_file     = NULL;
2070
19.4k
  libmsiecf_item_descriptor_t *item_descriptor = NULL;
2071
19.4k
  static char *function                        = "libmsiecf_file_get_item_by_index";
2072
19.4k
  int result                               = 1;
2073
2074
19.4k
  if( file == NULL )
2075
0
  {
2076
0
    libcerror_error_set(
2077
0
     error,
2078
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2079
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2080
0
     "%s: invalid file.",
2081
0
     function );
2082
2083
0
    return( -1 );
2084
0
  }
2085
19.4k
  internal_file = (libmsiecf_internal_file_t *) file;
2086
2087
19.4k
  if( internal_file->item_array == NULL )
2088
2.00k
  {
2089
2.00k
    libcerror_error_set(
2090
2.00k
     error,
2091
2.00k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2092
2.00k
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2093
2.00k
     "%s: invalid file - missing item array.",
2094
2.00k
     function );
2095
2096
2.00k
    return( -1 );
2097
2.00k
  }
2098
17.4k
  if( item == NULL )
2099
722
  {
2100
722
    libcerror_error_set(
2101
722
     error,
2102
722
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2103
722
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2104
722
     "%s: invalid item.",
2105
722
     function );
2106
2107
722
    return( -1 );
2108
722
  }
2109
16.7k
  if( *item != NULL )
2110
5.10k
  {
2111
5.10k
    libcerror_error_set(
2112
5.10k
     error,
2113
5.10k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2114
5.10k
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2115
5.10k
     "%s: item already set.",
2116
5.10k
     function );
2117
2118
5.10k
    return( -1 );
2119
5.10k
  }
2120
11.6k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2121
11.6k
  if( libcthreads_read_write_lock_grab_for_read(
2122
11.6k
       internal_file->read_write_lock,
2123
11.6k
       error ) != 1 )
2124
0
  {
2125
0
    libcerror_error_set(
2126
0
     error,
2127
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2128
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2129
0
     "%s: unable to grab read/write lock for reading.",
2130
0
     function );
2131
2132
0
    return( -1 );
2133
0
  }
2134
11.6k
#endif
2135
11.6k
  if( libcdata_array_get_entry_by_index(
2136
11.6k
       internal_file->item_array,
2137
11.6k
       item_index,
2138
11.6k
       (intptr_t **) &item_descriptor,
2139
11.6k
       error ) != 1 )
2140
1.12k
  {
2141
1.12k
    libcerror_error_set(
2142
1.12k
     error,
2143
1.12k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2144
1.12k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2145
1.12k
     "%s: unable to retrieve item descriptor.",
2146
1.12k
     function );
2147
2148
1.12k
    result = -1;
2149
1.12k
  }
2150
10.5k
  else if( libmsiecf_item_initialize(
2151
10.5k
            item,
2152
10.5k
            item_descriptor,
2153
10.5k
            error ) != 1 )
2154
0
  {
2155
0
    libcerror_error_set(
2156
0
     error,
2157
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2158
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2159
0
     "%s: unable to create item.",
2160
0
     function );
2161
2162
0
    result = -1;
2163
0
  }
2164
/* TODO make more error tollerant for corrupt items */
2165
10.5k
  else if( libmsiecf_internal_item_read_values(
2166
10.5k
            (libmsiecf_internal_item_t *) *item,
2167
10.5k
            internal_file->io_handle,
2168
10.5k
            internal_file->file_io_handle,
2169
10.5k
            error ) != 1 )
2170
5.39k
  {
2171
5.39k
    libcerror_error_set(
2172
5.39k
     error,
2173
5.39k
     LIBCERROR_ERROR_DOMAIN_IO,
2174
5.39k
     LIBCERROR_IO_ERROR_READ_FAILED,
2175
5.39k
     "%s: unable to read item values.",
2176
5.39k
     function );
2177
2178
5.39k
    libmsiecf_item_free(
2179
5.39k
     item,
2180
5.39k
     NULL );
2181
2182
5.39k
    result = -1;
2183
5.39k
  }
2184
11.6k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2185
11.6k
  if( libcthreads_read_write_lock_release_for_read(
2186
11.6k
       internal_file->read_write_lock,
2187
11.6k
       error ) != 1 )
2188
0
  {
2189
0
    libcerror_error_set(
2190
0
     error,
2191
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2192
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2193
0
     "%s: unable to release read/write lock for reading.",
2194
0
     function );
2195
2196
0
    return( -1 );
2197
0
  }
2198
11.6k
#endif
2199
11.6k
  return( result );
2200
11.6k
}
2201
2202
/* Retrieves the number of recovered items
2203
 * Returns 1 if successful or -1 on error
2204
 */
2205
int libmsiecf_file_get_number_of_recovered_items(
2206
     libmsiecf_file_t *file,
2207
     int *number_of_recovered_items,
2208
     libcerror_error_t **error )
2209
4.57k
{
2210
4.57k
  libmsiecf_internal_file_t *internal_file = NULL;
2211
4.57k
  static char *function                    = "libmsiecf_file_get_number_of_recovered_items";
2212
4.57k
  int result                               = 1;
2213
2214
4.57k
  if( file == NULL )
2215
0
  {
2216
0
    libcerror_error_set(
2217
0
     error,
2218
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2219
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2220
0
     "%s: invalid file.",
2221
0
     function );
2222
2223
0
    return( -1 );
2224
0
  }
2225
4.57k
  internal_file = (libmsiecf_internal_file_t *) file;
2226
2227
4.57k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2228
4.57k
  if( libcthreads_read_write_lock_grab_for_read(
2229
4.57k
       internal_file->read_write_lock,
2230
4.57k
       error ) != 1 )
2231
0
  {
2232
0
    libcerror_error_set(
2233
0
     error,
2234
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2235
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2236
0
     "%s: unable to grab read/write lock for reading.",
2237
0
     function );
2238
2239
0
    return( -1 );
2240
0
  }
2241
4.57k
#endif
2242
4.57k
  result = libcdata_array_get_number_of_entries(
2243
4.57k
            internal_file->recovered_item_array,
2244
4.57k
            number_of_recovered_items,
2245
4.57k
            error );
2246
2247
4.57k
  if( result != 1 )
2248
2.73k
  {
2249
2.73k
    libcerror_error_set(
2250
2.73k
     error,
2251
2.73k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2252
2.73k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2253
2.73k
     "%s: unable to retrieve number of elements from recovered item array.",
2254
2.73k
     function );
2255
2256
2.73k
    result = -1;
2257
2.73k
  }
2258
4.57k
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2259
4.57k
  if( libcthreads_read_write_lock_release_for_read(
2260
4.57k
       internal_file->read_write_lock,
2261
4.57k
       error ) != 1 )
2262
0
  {
2263
0
    libcerror_error_set(
2264
0
     error,
2265
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2266
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2267
0
     "%s: unable to release read/write lock for reading.",
2268
0
     function );
2269
2270
0
    return( -1 );
2271
0
  }
2272
4.57k
#endif
2273
4.57k
  return( result );
2274
4.57k
}
2275
2276
/* Retrieves the recovered item for the specific index
2277
 * Returns 1 if successful or -1 on error
2278
 */
2279
int libmsiecf_file_get_recovered_item_by_index(
2280
     libmsiecf_file_t *file,
2281
     int recovered_item_index,
2282
     libmsiecf_item_t **recovered_item,
2283
     libcerror_error_t **error )
2284
2.82k
{
2285
2.82k
  libmsiecf_internal_file_t *internal_file     = NULL;
2286
2.82k
  libmsiecf_item_descriptor_t *item_descriptor = NULL;
2287
2.82k
  static char *function                        = "libmsiecf_file_get_recovered_item_by_index";
2288
2.82k
  int result                               = 1;
2289
2290
2.82k
  if( file == NULL )
2291
0
  {
2292
0
    libcerror_error_set(
2293
0
     error,
2294
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2295
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2296
0
     "%s: invalid file.",
2297
0
     function );
2298
2299
0
    return( -1 );
2300
0
  }
2301
2.82k
  internal_file = (libmsiecf_internal_file_t *) file;
2302
2303
2.82k
  if( internal_file->recovered_item_array == NULL )
2304
2.00k
  {
2305
2.00k
    libcerror_error_set(
2306
2.00k
     error,
2307
2.00k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2308
2.00k
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2309
2.00k
     "%s: invalid file - missing recovered item array.",
2310
2.00k
     function );
2311
2312
2.00k
    return( -1 );
2313
2.00k
  }
2314
811
  if( recovered_item == NULL )
2315
722
  {
2316
722
    libcerror_error_set(
2317
722
     error,
2318
722
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2319
722
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2320
722
     "%s: invalid recovered item.",
2321
722
     function );
2322
2323
722
    return( -1 );
2324
722
  }
2325
89
  if( *recovered_item != NULL )
2326
41
  {
2327
41
    libcerror_error_set(
2328
41
     error,
2329
41
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2330
41
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2331
41
     "%s: recovered item already set.",
2332
41
     function );
2333
2334
41
    return( -1 );
2335
41
  }
2336
48
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2337
48
  if( libcthreads_read_write_lock_grab_for_read(
2338
48
       internal_file->read_write_lock,
2339
48
       error ) != 1 )
2340
0
  {
2341
0
    libcerror_error_set(
2342
0
     error,
2343
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2344
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2345
0
     "%s: unable to grab read/write lock for reading.",
2346
0
     function );
2347
2348
0
    return( -1 );
2349
0
  }
2350
48
#endif
2351
48
  if( libcdata_array_get_entry_by_index(
2352
48
       internal_file->recovered_item_array,
2353
48
       recovered_item_index,
2354
48
       (intptr_t **) &item_descriptor,
2355
48
       error ) != 1 )
2356
0
  {
2357
0
    libcerror_error_set(
2358
0
     error,
2359
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2360
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2361
0
     "%s: unable to retrieve recovered item descriptor.",
2362
0
     function );
2363
2364
0
    result = -1;
2365
0
  }
2366
48
  else if( libmsiecf_item_initialize(
2367
48
            recovered_item,
2368
48
            item_descriptor,
2369
48
            error ) != 1 )
2370
0
  {
2371
0
    libcerror_error_set(
2372
0
     error,
2373
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2374
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2375
0
     "%s: unable to create recovered item.",
2376
0
     function );
2377
2378
0
    result = -1;
2379
0
  }
2380
/* TODO make more error tollerant for corrupt items */
2381
48
  else if( libmsiecf_internal_item_read_values(
2382
48
            (libmsiecf_internal_item_t *) *recovered_item,
2383
48
            internal_file->io_handle,
2384
48
            internal_file->file_io_handle,
2385
48
            error ) != 1 )
2386
7
  {
2387
7
    libcerror_error_set(
2388
7
     error,
2389
7
     LIBCERROR_ERROR_DOMAIN_IO,
2390
7
     LIBCERROR_IO_ERROR_READ_FAILED,
2391
7
     "%s: unable to read recovered item values.",
2392
7
     function );
2393
2394
7
    libmsiecf_item_free(
2395
7
     recovered_item,
2396
7
     NULL );
2397
2398
7
    result = -1;
2399
7
  }
2400
48
#if defined( HAVE_LIBMSIECF_MULTI_THREAD_SUPPORT )
2401
48
  if( libcthreads_read_write_lock_release_for_read(
2402
48
       internal_file->read_write_lock,
2403
48
       error ) != 1 )
2404
0
  {
2405
0
    libcerror_error_set(
2406
0
     error,
2407
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2408
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2409
0
     "%s: unable to release read/write lock for reading.",
2410
0
     function );
2411
2412
0
    return( -1 );
2413
0
  }
2414
48
#endif
2415
48
  return( result );
2416
48
}
2417