Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libpff/libpff/libpff_item.c
Line
Count
Source
1
/*
2
 * Item functions
3
 *
4
 * Copyright (C) 2008-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 <byte_stream.h>
24
#include <memory.h>
25
#include <narrow_string.h>
26
#include <types.h>
27
28
#include "libpff_debug.h"
29
#include "libpff_definitions.h"
30
#include "libpff_descriptor_data_stream.h"
31
#include "libpff_descriptors_index.h"
32
#include "libpff_item_descriptor.h"
33
#include "libpff_item.h"
34
#include "libpff_item_tree.h"
35
#include "libpff_item_values.h"
36
#include "libpff_libbfio.h"
37
#include "libpff_libcdata.h"
38
#include "libpff_libcerror.h"
39
#include "libpff_libcnotify.h"
40
#include "libpff_libfcache.h"
41
#include "libpff_libfdata.h"
42
#include "libpff_libfmapi.h"
43
#include "libpff_mapi.h"
44
#include "libpff_offsets_index.h"
45
#include "libpff_record_entry.h"
46
#include "libpff_table.h"
47
#include "libpff_types.h"
48
#include "libpff_value_type.h"
49
50
/* Creates an item
51
 * Make sure the value item is referencing, is set to NULL
52
 * Returns 1 if successful or -1 on error
53
 */
54
int libpff_item_initialize(
55
     libpff_item_t **item,
56
     libpff_io_handle_t *io_handle,
57
     libbfio_handle_t *file_io_handle,
58
     libcdata_list_t *name_to_id_map_list,
59
     libpff_descriptors_index_t *descriptors_index,
60
     libpff_offsets_index_t *offsets_index,
61
     libpff_item_tree_t *item_tree,
62
     libcdata_tree_node_t *item_tree_node,
63
     uint8_t flags,
64
     libcerror_error_t **error )
65
39.2k
{
66
39.2k
  libpff_internal_item_t *internal_item     = NULL;
67
39.2k
  libpff_item_descriptor_t *item_descriptor = NULL;
68
39.2k
  static char *function                     = "libpff_item_initialize";
69
70
39.2k
  if( item == NULL )
71
0
  {
72
0
    libcerror_error_set(
73
0
     error,
74
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
75
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
76
0
     "%s: invalid item.",
77
0
     function );
78
79
0
    return( -1 );
80
0
  }
81
39.2k
  if( *item != NULL )
82
0
  {
83
0
    libcerror_error_set(
84
0
     error,
85
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
86
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
87
0
     "%s: invalid item value already set.",
88
0
     function );
89
90
0
    return( -1 );
91
0
  }
92
39.2k
  if( io_handle == NULL )
93
0
  {
94
0
    libcerror_error_set(
95
0
     error,
96
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
97
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
98
0
     "%s: invalid IO handle.",
99
0
     function );
100
101
0
    return( -1 );
102
0
  }
103
39.2k
  if( ( flags & ~( LIBPFF_ITEM_FLAG_MANAGED_ITEM_TREE_NODE ) ) != 0 )
104
0
  {
105
0
    libcerror_error_set(
106
0
     error,
107
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
108
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
109
0
     "%s: unsupported flags: 0x%02" PRIx8 ".",
110
0
     function,
111
0
     flags );
112
113
0
    return( -1 );
114
0
  }
115
39.2k
  if( libcdata_tree_node_get_value(
116
39.2k
       item_tree_node,
117
39.2k
       (intptr_t **) &item_descriptor,
118
39.2k
       error ) != 1 )
119
0
  {
120
0
    libcerror_error_set(
121
0
     error,
122
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
123
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
124
0
     "%s: unable to retrieve item descriptor from item tree node.",
125
0
     function );
126
127
0
    return( -1 );
128
0
  }
129
39.2k
  if( item_descriptor == NULL )
130
0
  {
131
0
    libcerror_error_set(
132
0
     error,
133
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
134
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
135
0
     "%s: invalid item descriptor.",
136
0
     function );
137
138
0
    return( -1 );
139
0
  }
140
39.2k
  internal_item = memory_allocate_structure(
141
39.2k
                   libpff_internal_item_t );
142
143
39.2k
  if( internal_item == NULL )
144
0
  {
145
0
    libcerror_error_set(
146
0
     error,
147
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
148
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
149
0
     "%s: unable to create item.",
150
0
     function );
151
152
0
    goto on_error;
153
0
  }
154
39.2k
  if( memory_set(
155
39.2k
       internal_item,
156
39.2k
       0,
157
39.2k
       sizeof( libpff_internal_item_t ) ) == NULL )
158
0
  {
159
0
    libcerror_error_set(
160
0
     error,
161
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
162
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
163
0
     "%s: unable to clear item.",
164
0
     function );
165
166
0
    memory_free(
167
0
     internal_item );
168
169
0
    return( -1 );
170
0
  }
171
39.2k
  if( libpff_item_values_initialize(
172
39.2k
       &( internal_item->item_values ),
173
39.2k
       item_descriptor->descriptor_identifier,
174
39.2k
       item_descriptor->data_identifier,
175
39.2k
       item_descriptor->local_descriptors_identifier,
176
39.2k
       item_descriptor->recovered,
177
39.2k
       error ) != 1 )
178
0
  {
179
0
    libcerror_error_set(
180
0
     error,
181
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
182
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
183
0
     "%s: unable to create item values.",
184
0
     function );
185
186
0
    goto on_error;
187
0
  }
188
39.2k
  if( ( flags & LIBPFF_ITEM_FLAG_MANAGED_ITEM_TREE_NODE ) == 0 )
189
39.1k
  {
190
39.1k
    internal_item->item_tree_node = item_tree_node;
191
39.1k
  }
192
104
  else
193
104
  {
194
104
    if( libcdata_tree_node_clone(
195
104
         &( internal_item->item_tree_node ),
196
104
         item_tree_node,
197
104
         (int (*)(intptr_t **, libcerror_error_t **)) &libpff_item_descriptor_free,
198
104
         (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libpff_item_descriptor_clone,
199
104
         error ) != 1 )
200
0
    {
201
0
      libcerror_error_set(
202
0
       error,
203
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
204
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
205
0
       "%s: unable to copy item tree node.",
206
0
       function );
207
208
0
      goto on_error;
209
0
    }
210
104
  }
211
39.2k
  internal_item->type                = LIBPFF_ITEM_TYPE_UNDEFINED;
212
39.2k
  internal_item->io_handle           = io_handle;
213
39.2k
  internal_item->file_io_handle      = file_io_handle;
214
39.2k
  internal_item->name_to_id_map_list = name_to_id_map_list;
215
39.2k
  internal_item->descriptors_index   = descriptors_index;
216
39.2k
  internal_item->offsets_index       = offsets_index;
217
39.2k
  internal_item->item_tree           = item_tree;
218
39.2k
  internal_item->item_descriptor     = item_descriptor;
219
39.2k
  internal_item->ascii_codepage      = io_handle->ascii_codepage;
220
39.2k
  internal_item->flags               = flags;
221
222
39.2k
  *item = (libpff_item_t *) internal_item;
223
224
39.2k
  return( 1 );
225
226
0
on_error:
227
0
  if( internal_item != NULL )
228
0
  {
229
0
    if( internal_item->item_values != NULL )
230
0
    {
231
0
      libpff_item_values_free(
232
0
       &( internal_item->item_values ),
233
0
       NULL );
234
0
    }
235
0
    memory_free(
236
0
     internal_item );
237
0
  }
238
0
  return( -1 );
239
39.2k
}
240
241
/* Frees an item
242
 * Returns 1 if successful or -1 on error
243
 */
244
int libpff_item_free(
245
     libpff_item_t **item,
246
     libcerror_error_t **error )
247
39.2k
{
248
39.2k
  libpff_internal_item_t *internal_item = NULL;
249
39.2k
  static char *function                 = "libpff_item_free";
250
39.2k
  int result                            = 1;
251
39.2k
  int sub_item_iterator                 = 0;
252
253
39.2k
  if( item == 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 item.",
260
0
     function );
261
262
0
    return( -1 );
263
0
  }
264
39.2k
  if( *item != NULL )
265
39.2k
  {
266
39.2k
    internal_item = (libpff_internal_item_t *) *item;
267
39.2k
    *item         = NULL;
268
269
    /* The io_handle, file_io_handle, name_to_id_map_list, descriptors_index, offsets_index and item_tree reference is freed elsewhere
270
     */
271
    /* If not managed the item_tree_node reference is freed elsewhere
272
     */
273
39.2k
    if( ( internal_item->flags & LIBPFF_ITEM_FLAG_MANAGED_ITEM_TREE_NODE ) != 0 )
274
104
    {
275
104
      if( internal_item->item_tree_node != NULL )
276
104
      {
277
104
        if( libcdata_tree_node_free(
278
104
             &( internal_item->item_tree_node ),
279
104
             (int (*)(intptr_t **, libcerror_error_t **)) &libpff_item_descriptor_free,
280
104
             error ) != 1 )
281
0
        {
282
0
          libcerror_error_set(
283
0
           error,
284
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
285
0
           LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
286
0
           "%s: unable to free item tree node.",
287
0
           function );
288
289
0
          return( -1 );
290
0
        }
291
104
      }
292
104
    }
293
39.2k
    if( internal_item->item_values != NULL )
294
39.2k
    {
295
39.2k
      if( libpff_item_values_free(
296
39.2k
           &( internal_item->item_values ),
297
39.2k
           error ) != 1 )
298
0
      {
299
0
        libcerror_error_set(
300
0
         error,
301
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
302
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
303
0
         "%s: unable to free item values.",
304
0
         function );
305
306
0
        result = -1;
307
0
      }
308
39.2k
    }
309
39.2k
    for( sub_item_iterator = 0;
310
196k
         sub_item_iterator < LIBPFF_ITEM_NUMBER_OF_SUB_ITEMS;
311
157k
         sub_item_iterator++ )
312
157k
    {
313
157k
      if( internal_item->sub_item_tree_node[ sub_item_iterator ] != NULL )
314
420
      {
315
420
        if( libcdata_tree_node_free(
316
420
             &( internal_item->sub_item_tree_node[ sub_item_iterator ] ),
317
420
             (int (*)(intptr_t **, libcerror_error_t **)) &libpff_item_descriptor_free,
318
420
             error ) != 1 )
319
0
        {
320
0
          libcerror_error_set(
321
0
           error,
322
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
323
0
           LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
324
0
           "%s: unable to free sub item tree node: %d.",
325
0
           function,
326
0
           sub_item_iterator );
327
328
0
          result = -1;
329
0
        }
330
420
      }
331
157k
    }
332
39.2k
    for( sub_item_iterator = 0;
333
196k
         sub_item_iterator < LIBPFF_ITEM_NUMBER_OF_SUB_ITEMS;
334
157k
         sub_item_iterator++ )
335
157k
    {
336
157k
      if( internal_item->sub_item_values[ sub_item_iterator ] != NULL )
337
8.82k
      {
338
8.82k
        if( libpff_item_values_free(
339
8.82k
             &( internal_item->sub_item_values[ sub_item_iterator ] ),
340
8.82k
             error ) != 1 )
341
0
        {
342
0
          libcerror_error_set(
343
0
           error,
344
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
345
0
           LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
346
0
           "%s: unable to free sub item values: %d.",
347
0
           function,
348
0
           sub_item_iterator );
349
350
0
          result = -1;
351
0
        }
352
8.82k
      }
353
157k
    }
354
39.2k
    if( internal_item->embedded_object_data_stream != NULL )
355
0
    {
356
0
      if( libfdata_stream_free(
357
0
           &( internal_item->embedded_object_data_stream ),
358
0
           error ) != 1 )
359
0
      {
360
0
        libcerror_error_set(
361
0
         error,
362
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
363
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
364
0
         "%s: unable to free embedded object data stream.",
365
0
         function );
366
367
0
        result = -1;
368
0
      }
369
0
    }
370
39.2k
    memory_free(
371
39.2k
     internal_item );
372
39.2k
  }
373
39.2k
  return( result );
374
39.2k
}
375
376
/* Determines the item type
377
 * Returns 1 if successful or -1 on error
378
 */
379
int libpff_internal_item_determine_type(
380
     libpff_internal_item_t *internal_item,
381
     libcerror_error_t **error )
382
30.0k
{
383
30.0k
  libpff_record_entry_t *record_entry = NULL;
384
30.0k
  char *item_type_string              = NULL;
385
30.0k
  static char *function               = "libpff_internal_item_determine_type";
386
30.0k
  size_t item_type_string_size        = 0;
387
30.0k
  uint32_t value_type                 = 0;
388
30.0k
  int result                          = 0;
389
390
30.0k
  if( internal_item == NULL )
391
0
  {
392
0
    libcerror_error_set(
393
0
     error,
394
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
395
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
396
0
     "%s: invalid item.",
397
0
     function );
398
399
0
    return( -1 );
400
0
  }
401
30.0k
  if( internal_item->type != LIBPFF_ITEM_TYPE_UNDEFINED )
402
0
  {
403
0
    return( 1 );
404
0
  }
405
30.0k
  result = libpff_item_values_get_record_entry_by_type(
406
30.0k
            internal_item->item_values,
407
30.0k
            internal_item->name_to_id_map_list,
408
30.0k
            internal_item->io_handle,
409
30.0k
            internal_item->file_io_handle,
410
30.0k
            internal_item->offsets_index,
411
30.0k
            0,
412
30.0k
            LIBPFF_ENTRY_TYPE_MESSAGE_CLASS,
413
30.0k
            0,
414
30.0k
            &record_entry,
415
30.0k
            LIBPFF_ENTRY_VALUE_FLAG_MATCH_ANY_VALUE_TYPE,
416
30.0k
            error );
417
418
30.0k
  if( result == -1 )
419
18.9k
  {
420
18.9k
    libcerror_error_set(
421
18.9k
     error,
422
18.9k
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
423
18.9k
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
424
18.9k
     "%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
425
18.9k
     function,
426
18.9k
     LIBPFF_ENTRY_TYPE_MESSAGE_CLASS );
427
428
18.9k
    goto on_error;
429
18.9k
  }
430
11.1k
  else if( result == 0 )
431
10.0k
  {
432
    /* The item does not contain a message class and therefore is a folder
433
     */
434
10.0k
    internal_item->type = LIBPFF_ITEM_TYPE_FOLDER;
435
10.0k
  }
436
1.13k
  else
437
1.13k
  {
438
1.13k
    if( libpff_record_entry_get_value_type(
439
1.13k
         record_entry,
440
1.13k
         &value_type,
441
1.13k
         error ) != 1 )
442
0
    {
443
0
      libcerror_error_set(
444
0
       error,
445
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
446
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
447
0
       "%s: unable to retrieve value type.",
448
0
       function );
449
450
0
      goto on_error;
451
0
    }
452
1.13k
    if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII )
453
1.10k
     && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) )
454
7
    {
455
7
      libcerror_error_set(
456
7
       error,
457
7
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
458
7
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
459
7
       "%s: unsupported value type: 0x%04" PRIx32 ".",
460
7
       function,
461
7
       value_type );
462
463
7
      goto on_error;
464
7
    }
465
1.12k
    if( libpff_record_entry_get_data_as_utf8_string_size_with_codepage(
466
1.12k
         record_entry,
467
1.12k
         internal_item->ascii_codepage,
468
1.12k
         &item_type_string_size,
469
1.12k
         error ) != 1 )
470
34
    {
471
34
      libcerror_error_set(
472
34
       error,
473
34
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
474
34
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
475
34
       "%s: unable to retrieve UTF-8 string size.",
476
34
       function );
477
478
34
      goto on_error;
479
34
    }
480
1.09k
    if( item_type_string_size > 0 )
481
873
    {
482
873
      item_type_string = narrow_string_allocate(
483
873
                          item_type_string_size );
484
485
873
      if( item_type_string == NULL )
486
0
      {
487
0
        libcerror_error_set(
488
0
         error,
489
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
490
0
         LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
491
0
         "%s: unable to create item type string.",
492
0
         function );
493
494
0
        goto on_error;
495
0
      }
496
873
      if( libpff_record_entry_get_data_as_utf8_string_with_codepage(
497
873
           record_entry,
498
873
           internal_item->ascii_codepage,
499
873
           (uint8_t *) item_type_string,
500
873
           item_type_string_size,
501
873
           error ) != 1 )
502
0
      {
503
0
        libcerror_error_set(
504
0
         error,
505
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
506
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
507
0
         "%s: unable to retrieve UTF-8 string of record entry.",
508
0
         function );
509
510
0
        goto on_error;
511
0
      }
512
873
      if( item_type_string_size == 4 )
513
10
      {
514
10
        if( narrow_string_compare_no_case(
515
10
             item_type_string,
516
10
             "IPM",
517
10
             3 ) == 0 )
518
3
        {
519
3
          internal_item->type = LIBPFF_ITEM_TYPE_COMMON;
520
3
        }
521
10
      }
522
863
      else if( item_type_string_size == 8 )
523
25
      {
524
25
        if( narrow_string_compare_no_case(
525
25
             item_type_string,
526
25
             "IPM.FAX",
527
25
             7 ) == 0 )
528
0
        {
529
0
          internal_item->type = LIBPFF_ITEM_TYPE_FAX;
530
0
        }
531
25
      }
532
838
      else if( item_type_string_size == 9 )
533
214
      {
534
214
        if( narrow_string_compare_no_case(
535
214
             item_type_string,
536
214
             "IPM.Note",
537
214
             8 ) == 0 )
538
135
        {
539
135
          internal_item->type = LIBPFF_ITEM_TYPE_EMAIL;
540
135
        }
541
79
        else if( narrow_string_compare_no_case(
542
79
            item_type_string,
543
79
            "IPM.Post",
544
79
            8 ) == 0 )
545
0
        {
546
0
          internal_item->type = LIBPFF_ITEM_TYPE_POSTING_NOTE;
547
0
        }
548
79
        else if( narrow_string_compare_no_case(
549
79
            item_type_string,
550
79
            "IPM.Task",
551
79
            8 ) == 0 )
552
0
        {
553
0
          internal_item->type = LIBPFF_ITEM_TYPE_TASK;
554
0
        }
555
214
      }
556
624
      else if( item_type_string_size == 12 )
557
47
      {
558
47
        if( narrow_string_compare_no_case(
559
47
             item_type_string,
560
47
             "IPM.Contact",
561
47
             11 ) == 0 )
562
0
        {
563
0
          internal_item->type = LIBPFF_ITEM_TYPE_CONTACT;
564
0
        }
565
47
      }
566
577
      else if( item_type_string_size == 13 )
567
48
      {
568
48
        if( narrow_string_compare_no_case(
569
48
             item_type_string,
570
48
             "IPM.Activity",
571
48
             12 ) == 0 )
572
0
        {
573
0
          internal_item->type = LIBPFF_ITEM_TYPE_ACTIVITY;
574
0
        }
575
48
        else if( narrow_string_compare_no_case(
576
48
            item_type_string,
577
48
            "IPM.DistList",
578
48
            12 ) == 0 )
579
0
        {
580
0
          internal_item->type = LIBPFF_ITEM_TYPE_DISTRIBUTION_LIST;
581
0
        }
582
48
        else if( narrow_string_compare_no_case(
583
48
            item_type_string,
584
48
            "IPM.Note.Fax",
585
48
            12 ) == 0 )
586
0
        {
587
0
          internal_item->type = LIBPFF_ITEM_TYPE_FAX;
588
0
        }
589
48
        else if( narrow_string_compare_no_case(
590
48
            item_type_string,
591
48
            "IPM.Post.RSS",
592
48
            12 ) == 0 )
593
0
        {
594
0
          internal_item->type = LIBPFF_ITEM_TYPE_RSS_FEED;
595
0
        }
596
48
      }
597
529
      else if( item_type_string_size == 15 )
598
70
      {
599
70
        if( narrow_string_compare_no_case(
600
70
             item_type_string,
601
70
             "IPM.StickyNote",
602
70
             15 ) == 0 )
603
0
        {
604
0
          internal_item->type = LIBPFF_ITEM_TYPE_NOTE;
605
0
        }
606
70
      }
607
459
      else if( item_type_string_size == 16 )
608
41
      {
609
41
        if( narrow_string_compare_no_case(
610
41
             item_type_string,
611
41
             "IPM.Appointment",
612
41
             15 ) == 0 )
613
0
        {
614
0
          internal_item->type = LIBPFF_ITEM_TYPE_APPOINTMENT;
615
0
        }
616
41
      }
617
418
      else if( item_type_string_size == 19 )
618
30
      {
619
30
        if( narrow_string_compare_no_case(
620
30
             item_type_string,
621
30
             "IPM.Note.Voicemail",
622
30
             18 ) == 0 )
623
0
        {
624
0
          internal_item->type = LIBPFF_ITEM_TYPE_VOICEMAIL;
625
0
        }
626
30
      }
627
388
      else if( item_type_string_size == 20 )
628
18
      {
629
18
        if( narrow_string_compare_no_case(
630
18
             item_type_string,
631
18
             "IPM.Note.Mobile.SMS",
632
18
             19 ) == 0 )
633
0
        {
634
0
          internal_item->type = LIBPFF_ITEM_TYPE_SMS;
635
0
        }
636
18
        else if( narrow_string_compare_no_case(
637
18
            item_type_string,
638
18
            "IPM.Note.Mobile.MMS",
639
18
            19 ) == 0 )
640
0
        {
641
0
          internal_item->type = LIBPFF_ITEM_TYPE_MMS;
642
0
        }
643
18
      }
644
370
      else if( item_type_string_size == 21 )
645
18
      {
646
18
        if( narrow_string_compare_no_case(
647
18
             item_type_string,
648
18
             "IPM.Conflict.Message",
649
18
             20 ) == 0 )
650
0
        {
651
0
          internal_item->type = LIBPFF_ITEM_TYPE_CONFLICT_MESSAGE;
652
0
        }
653
18
      }
654
352
      else if( item_type_string_size == 53 )
655
1
      {
656
1
        if( narrow_string_compare_no_case(
657
1
             item_type_string,
658
1
             "IPM.OLE.CLASS.{00061055-0000-0000-C000-000000000046}",
659
1
             52 ) == 0 )
660
0
        {
661
0
          internal_item->type = LIBPFF_ITEM_TYPE_APPOINTMENT;
662
0
        }
663
1
      }
664
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
665
735
      {
666
735
        if( item_type_string_size >= 12 )
667
443
        {
668
443
          if( narrow_string_compare_no_case(
669
443
               item_type_string,
670
443
               "IPM.Sharing",
671
443
               11 ) == 0 )
672
0
          {
673
0
            internal_item->type = LIBPFF_ITEM_TYPE_SHARING;
674
0
          }
675
443
        }
676
735
      }
677
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
678
735
      {
679
735
        if( item_type_string_size >= 13 )
680
396
        {
681
396
          if( narrow_string_compare_no_case(
682
396
               item_type_string,
683
396
               "IPM.Document",
684
396
               12 ) == 0 )
685
0
          {
686
0
            internal_item->type = LIBPFF_ITEM_TYPE_DOCUMENT;
687
0
          }
688
396
        }
689
735
      }
690
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
691
735
      {
692
735
        if( item_type_string_size >= 15 )
693
340
        {
694
340
          if( narrow_string_compare_no_case(
695
340
               item_type_string,
696
340
               "IPM.Note.SMIME",
697
340
               14 ) == 0 )
698
0
          {
699
0
            internal_item->type = LIBPFF_ITEM_TYPE_EMAIL_SMIME;
700
0
          }
701
340
        }
702
735
      }
703
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
704
735
      {
705
735
        if( item_type_string_size >= 16 )
706
270
        {
707
270
          if( narrow_string_compare_no_case(
708
270
               item_type_string,
709
270
               "IPM.TaskRequest",
710
270
               15 ) == 0 )
711
0
          {
712
0
            internal_item->type = LIBPFF_ITEM_TYPE_TASK_REQUEST;
713
0
          }
714
270
          else if( narrow_string_compare_no_case(
715
270
              item_type_string,
716
270
              "REPORT.IPM.Note",
717
270
              15 ) == 0 )
718
0
          {
719
0
            internal_item->type = LIBPFF_ITEM_TYPE_EMAIL;
720
0
          }
721
270
        }
722
735
      }
723
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
724
735
      {
725
735
        if( item_type_string_size >= 18 )
726
139
        {
727
139
          if( narrow_string_compare_no_case(
728
139
               item_type_string,
729
139
               "IPM.Configuration",
730
139
               17 ) == 0 )
731
0
          {
732
0
            internal_item->type = LIBPFF_ITEM_TYPE_CONFIGURATION;
733
0
          }
734
139
        }
735
735
      }
736
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
737
735
      {
738
735
        if( item_type_string_size >= 21 )
739
77
        {
740
77
          if( narrow_string_compare_no_case(
741
77
               item_type_string,
742
77
               "IPM.Schedule.Meeting",
743
77
               20 ) == 0 )
744
0
          {
745
0
            internal_item->type = LIBPFF_ITEM_TYPE_MEETING;
746
0
          }
747
77
        }
748
735
      }
749
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
750
735
      {
751
735
        if( item_type_string_size >= 28 )
752
30
        {
753
30
          if( narrow_string_compare_no_case(
754
30
               item_type_string,
755
30
               "REPORT.IPM.Schedule.Meeting",
756
30
               27 ) == 0 )
757
0
          {
758
0
            internal_item->type = LIBPFF_ITEM_TYPE_MEETING;
759
0
          }
760
30
        }
761
735
      }
762
873
      if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
763
735
      {
764
        /* Consider any remaining IPM.Note as an e-mail
765
         * should catch IPM.Note.StorageQuotaWarning
766
         */
767
735
        if( item_type_string_size >= 10 )
768
592
        {
769
592
          if( narrow_string_compare_no_case(
770
592
               item_type_string,
771
592
               "IPM.Note.",
772
592
               9 ) == 0 )
773
0
          {
774
0
            internal_item->type = LIBPFF_ITEM_TYPE_EMAIL;
775
0
          }
776
592
        }
777
735
      }
778
#if defined( HAVE_DEBUG_OUTPUT )
779
      if( ( libcnotify_verbose != 0 )
780
       && ( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED ) )
781
      {
782
        libcnotify_printf(
783
         "%s: unsupported item type: %s\n",
784
         function,
785
         item_type_string );
786
      }
787
#endif
788
873
      memory_free(
789
873
       item_type_string );
790
873
    }
791
1.09k
  }
792
11.1k
  return( 1 );
793
794
18.9k
on_error:
795
18.9k
  if( item_type_string != NULL )
796
0
  {
797
0
    memory_free(
798
0
     item_type_string );
799
0
  }
800
18.9k
  return( -1 );
801
30.0k
}
802
803
/* Retrieves the identifier
804
 * Returns 1 if successful or -1 on error
805
 */
806
int libpff_item_get_identifier(
807
     libpff_item_t *item,
808
     uint32_t *identifier,
809
     libcerror_error_t **error )
810
371
{
811
371
  libpff_internal_item_t *internal_item = NULL;
812
371
  static char *function                 = "libpff_item_get_identifier";
813
814
371
  if( item == NULL )
815
0
  {
816
0
    libcerror_error_set(
817
0
     error,
818
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
819
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
820
0
     "%s: invalid item.",
821
0
     function );
822
823
0
    return( -1 );
824
0
  }
825
371
  internal_item = (libpff_internal_item_t *) item;
826
827
371
  if( libpff_item_descriptor_get_descriptor_identifier(
828
371
       internal_item->item_descriptor,
829
371
       identifier,
830
371
       error ) != 1 )
831
0
  {
832
0
    libcerror_error_set(
833
0
     error,
834
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
835
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
836
0
     "%s: unable to retrieve descriptor identifier.",
837
0
     function );
838
839
0
    return( -1 );
840
0
  }
841
371
  return( 1 );
842
371
}
843
844
/* Retrieves the number of record sets
845
 * Returns 1 if successful or -1 on error
846
 */
847
int libpff_item_get_number_of_record_sets(
848
     libpff_item_t *item,
849
     int *number_of_record_sets,
850
     libcerror_error_t **error )
851
12.3k
{
852
12.3k
  libpff_internal_item_t *internal_item = NULL;
853
12.3k
  static char *function                 = "libpff_item_get_number_of_record_sets";
854
855
12.3k
  if( item == NULL )
856
0
  {
857
0
    libcerror_error_set(
858
0
     error,
859
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
860
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
861
0
     "%s: invalid item.",
862
0
     function );
863
864
0
    return( -1 );
865
0
  }
866
12.3k
  internal_item = (libpff_internal_item_t *) item;
867
868
12.3k
  if( internal_item->item_values == NULL )
869
0
  {
870
0
    libcerror_error_set(
871
0
     error,
872
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
873
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
874
0
     "%s: invalid item - missing item values.",
875
0
     function );
876
877
0
    return( -1 );
878
0
  }
879
12.3k
  if( internal_item->item_values->table == NULL )
880
12.3k
  {
881
12.3k
    if( libpff_item_values_read(
882
12.3k
         internal_item->item_values,
883
12.3k
         internal_item->name_to_id_map_list,
884
12.3k
         internal_item->io_handle,
885
12.3k
         internal_item->file_io_handle,
886
12.3k
         internal_item->offsets_index,
887
12.3k
         LIBPFF_DEBUG_ITEM_TYPE_DEFAULT,
888
12.3k
         error ) != 1 )
889
10.8k
    {
890
10.8k
      libcerror_error_set(
891
10.8k
       error,
892
10.8k
       LIBCERROR_ERROR_DOMAIN_IO,
893
10.8k
       LIBCERROR_IO_ERROR_READ_FAILED,
894
10.8k
       "%s: unable to read item values.",
895
10.8k
       function );
896
897
10.8k
      return( -1 );
898
10.8k
    }
899
1.50k
    if( internal_item->item_values->table == NULL )
900
0
    {
901
0
      libcerror_error_set(
902
0
       error,
903
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
904
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
905
0
       "%s: invalid item - invalid item values - missing table.",
906
0
       function );
907
908
0
      return( -1 );
909
0
    }
910
1.50k
  }
911
1.50k
  if( libpff_table_get_number_of_record_sets(
912
1.50k
       internal_item->item_values->table,
913
1.50k
       number_of_record_sets,
914
1.50k
       error ) != 1 )
915
0
  {
916
0
    libcerror_error_set(
917
0
     error,
918
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
919
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
920
0
     "%s: unable to retrieve number of record sets.",
921
0
     function );
922
923
0
    return( -1 );
924
0
  }
925
1.50k
  return( 1 );
926
1.50k
}
927
928
/* Retrieves a specific record set
929
 * Returns 1 if successful or -1 on error
930
 */
931
int libpff_item_get_record_set_by_index(
932
     libpff_item_t *item,
933
     int record_set_index,
934
     libpff_record_set_t **record_set,
935
     libcerror_error_t **error )
936
2.12k
{
937
2.12k
  libpff_internal_item_t *internal_item = NULL;
938
2.12k
  static char *function                 = "libpff_item_get_record_set_by_index";
939
940
2.12k
  if( item == NULL )
941
0
  {
942
0
    libcerror_error_set(
943
0
     error,
944
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
945
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
946
0
     "%s: invalid item.",
947
0
     function );
948
949
0
    return( -1 );
950
0
  }
951
2.12k
  internal_item = (libpff_internal_item_t *) item;
952
953
2.12k
  if( internal_item->item_values == NULL )
954
0
  {
955
0
    libcerror_error_set(
956
0
     error,
957
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
958
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
959
0
     "%s: invalid item - missing item values.",
960
0
     function );
961
962
0
    return( -1 );
963
0
  }
964
2.12k
  if( record_set == NULL )
965
0
  {
966
0
    libcerror_error_set(
967
0
     error,
968
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
969
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
970
0
     "%s: invalid record set.",
971
0
     function );
972
973
0
    return( -1 );
974
0
  }
975
2.12k
  if( *record_set != NULL )
976
0
  {
977
0
    libcerror_error_set(
978
0
     error,
979
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
980
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
981
0
     "%s: record set already set.",
982
0
     function );
983
984
0
    return( -1 );
985
0
  }
986
2.12k
  if( internal_item->item_values->table == NULL )
987
0
  {
988
0
    if( libpff_item_values_read(
989
0
         internal_item->item_values,
990
0
         internal_item->name_to_id_map_list,
991
0
         internal_item->io_handle,
992
0
         internal_item->file_io_handle,
993
0
         internal_item->offsets_index,
994
0
         LIBPFF_DEBUG_ITEM_TYPE_DEFAULT,
995
0
         error ) != 1 )
996
0
    {
997
0
      libcerror_error_set(
998
0
       error,
999
0
       LIBCERROR_ERROR_DOMAIN_IO,
1000
0
       LIBCERROR_IO_ERROR_READ_FAILED,
1001
0
       "%s: unable to read item values.",
1002
0
       function );
1003
1004
0
      return( -1 );
1005
0
    }
1006
0
    if( internal_item->item_values->table == NULL )
1007
0
    {
1008
0
      libcerror_error_set(
1009
0
       error,
1010
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1011
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1012
0
       "%s: invalid item - invalid item values - missing table.",
1013
0
       function );
1014
1015
0
      return( -1 );
1016
0
    }
1017
0
  }
1018
2.12k
  if( libpff_table_get_record_set_by_index(
1019
2.12k
       internal_item->item_values->table,
1020
2.12k
       record_set_index,
1021
2.12k
       record_set,
1022
2.12k
       error ) != 1 )
1023
0
  {
1024
0
    libcerror_error_set(
1025
0
     error,
1026
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1027
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1028
0
     "%s: unable to retrieve record set: %d.",
1029
0
     function,
1030
0
     record_set_index );
1031
1032
0
    return( -1 );
1033
0
  }
1034
2.12k
  return( 1 );
1035
2.12k
}
1036
1037
/* Retrieves the number of entries (of a set)
1038
 * All sets in an item contain the same number of entries
1039
 * Returns 1 if successful or -1 on error
1040
 */
1041
int libpff_item_get_number_of_entries(
1042
     libpff_item_t *item,
1043
     uint32_t *number_of_entries,
1044
     libcerror_error_t **error )
1045
5
{
1046
5
  libpff_internal_item_t *internal_item = NULL;
1047
5
  static char *function                 = "libpff_item_get_number_of_entries";
1048
5
  int table_number_of_entries           = 0;
1049
1050
5
  if( item == NULL )
1051
0
  {
1052
0
    libcerror_error_set(
1053
0
     error,
1054
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1055
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1056
0
     "%s: invalid item.",
1057
0
     function );
1058
1059
0
    return( -1 );
1060
0
  }
1061
5
  internal_item = (libpff_internal_item_t *) item;
1062
1063
5
  if( internal_item->item_values == NULL )
1064
0
  {
1065
0
    libcerror_error_set(
1066
0
     error,
1067
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1068
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1069
0
     "%s: invalid item - missing item values.",
1070
0
     function );
1071
1072
0
    return( -1 );
1073
0
  }
1074
5
  if( number_of_entries == NULL )
1075
0
  {
1076
0
    libcerror_error_set(
1077
0
     error,
1078
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1079
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1080
0
     "%s: invalid number of entries.",
1081
0
     function );
1082
1083
0
    return( -1 );
1084
0
  }
1085
5
  if( internal_item->item_values->table == NULL )
1086
0
  {
1087
0
    if( libpff_item_values_read(
1088
0
         internal_item->item_values,
1089
0
         internal_item->name_to_id_map_list,
1090
0
         internal_item->io_handle,
1091
0
         internal_item->file_io_handle,
1092
0
         internal_item->offsets_index,
1093
0
         LIBPFF_DEBUG_ITEM_TYPE_DEFAULT,
1094
0
         error ) != 1 )
1095
0
    {
1096
0
      libcerror_error_set(
1097
0
       error,
1098
0
       LIBCERROR_ERROR_DOMAIN_IO,
1099
0
       LIBCERROR_IO_ERROR_READ_FAILED,
1100
0
       "%s: unable to read item values.",
1101
0
       function );
1102
1103
0
      return( -1 );
1104
0
    }
1105
0
    if( internal_item->item_values->table == NULL )
1106
0
    {
1107
0
      libcerror_error_set(
1108
0
       error,
1109
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1110
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1111
0
       "%s: invalid item - invalid item values - missing table.",
1112
0
       function );
1113
1114
0
      return( -1 );
1115
0
    }
1116
0
  }
1117
5
  if( libpff_table_get_number_of_entries(
1118
5
       internal_item->item_values->table,
1119
5
       &table_number_of_entries,
1120
5
       error ) != 1 )
1121
0
  {
1122
0
    libcerror_error_set(
1123
0
     error,
1124
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1125
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1126
0
     "%s: unable to retrieve number of entries.",
1127
0
     function );
1128
1129
0
    return( -1 );
1130
0
  }
1131
5
  *number_of_entries = (uint32_t) table_number_of_entries;
1132
1133
5
  return( 1 );
1134
5
}
1135
1136
/* Retrieves a 32-bit integer value
1137
 * Returns 1 if successful, 0 if not available or -1 on error
1138
 */
1139
int libpff_internal_item_get_entry_value_32bit_integer(
1140
     libpff_internal_item_t *internal_item,
1141
     uint32_t entry_type,
1142
     uint32_t *value_32bit,
1143
     libcerror_error_t **error )
1144
618
{
1145
618
  libpff_record_entry_t *record_entry = NULL;
1146
618
  static char *function               = "libpff_internal_item_get_entry_value_32bit_integer";
1147
618
  int result                          = 0;
1148
1149
618
  if( internal_item == NULL )
1150
0
  {
1151
0
    libcerror_error_set(
1152
0
     error,
1153
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1154
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1155
0
     "%s: invalid item.",
1156
0
     function );
1157
1158
0
    return( -1 );
1159
0
  }
1160
618
  result = libpff_item_values_get_record_entry_by_type(
1161
618
            internal_item->item_values,
1162
618
            internal_item->name_to_id_map_list,
1163
618
            internal_item->io_handle,
1164
618
            internal_item->file_io_handle,
1165
618
            internal_item->offsets_index,
1166
618
            0,
1167
618
            entry_type,
1168
618
            LIBPFF_VALUE_TYPE_INTEGER_32BIT_SIGNED,
1169
618
            &record_entry,
1170
618
            0,
1171
618
            error );
1172
1173
618
  if( result == -1 )
1174
0
  {
1175
0
    libcerror_error_set(
1176
0
     error,
1177
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1178
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1179
0
     "%s: unable to retrieve record entry: 0x%04" PRIx32 " 0x%04" PRIx32 ".",
1180
0
     function,
1181
0
     entry_type,
1182
0
     LIBPFF_VALUE_TYPE_INTEGER_32BIT_SIGNED );
1183
1184
0
    goto on_error;
1185
0
  }
1186
618
  else if( result != 0 )
1187
295
  {
1188
295
    if( libpff_record_entry_get_data_as_32bit_integer(
1189
295
         record_entry,
1190
295
         value_32bit,
1191
295
         error ) != 1 )
1192
0
    {
1193
0
      libcerror_error_set(
1194
0
       error,
1195
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1196
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1197
0
       "%s: unable to retrieve 32-bit integer value.",
1198
0
       function );
1199
1200
0
      goto on_error;
1201
0
    }
1202
295
    if( libpff_record_entry_free(
1203
295
         &record_entry,
1204
295
         error ) != 1 )
1205
0
    {
1206
0
      libcerror_error_set(
1207
0
       error,
1208
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1209
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1210
0
       "%s: unable to free record entry.",
1211
0
       function );
1212
1213
0
      goto on_error;
1214
0
    }
1215
295
  }
1216
618
  return( result );
1217
1218
0
on_error:
1219
0
  if( record_entry != NULL )
1220
0
  {
1221
0
    libpff_record_entry_free(
1222
0
     &record_entry,
1223
0
     NULL );
1224
0
  }
1225
0
  return( -1 );
1226
618
}
1227
1228
/* Retrieves a 64-bit FILETIME entry value
1229
 * Returns 1 if successful, 0 if not available or -1 on error
1230
 */
1231
int libpff_internal_item_get_entry_value_filetime(
1232
     libpff_internal_item_t *internal_item,
1233
     uint32_t entry_type,
1234
     uint64_t *filetime,
1235
     libcerror_error_t **error )
1236
0
{
1237
0
  libpff_record_entry_t *record_entry = NULL;
1238
0
  static char *function               = "libpff_internal_item_get_entry_value_filetime";
1239
0
  int result                          = 0;
1240
1241
0
  if( internal_item == NULL )
1242
0
  {
1243
0
    libcerror_error_set(
1244
0
     error,
1245
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1246
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1247
0
     "%s: invalid item.",
1248
0
     function );
1249
1250
0
    return( -1 );
1251
0
  }
1252
0
  result = libpff_item_values_get_record_entry_by_type(
1253
0
            internal_item->item_values,
1254
0
            internal_item->name_to_id_map_list,
1255
0
            internal_item->io_handle,
1256
0
            internal_item->file_io_handle,
1257
0
            internal_item->offsets_index,
1258
0
            0,
1259
0
            entry_type,
1260
0
            LIBPFF_VALUE_TYPE_FILETIME,
1261
0
            &record_entry,
1262
0
            0,
1263
0
            error );
1264
1265
0
  if( result == -1 )
1266
0
  {
1267
0
    libcerror_error_set(
1268
0
     error,
1269
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1270
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1271
0
     "%s: unable to retrieve record entry: 0x%04" PRIx32 " 0x%04" PRIx32 ".",
1272
0
     function,
1273
0
     entry_type,
1274
0
     LIBPFF_VALUE_TYPE_FILETIME );
1275
1276
0
    goto on_error;
1277
0
  }
1278
0
  else if( result != 0 )
1279
0
  {
1280
0
    if( libpff_record_entry_get_data_as_filetime(
1281
0
         record_entry,
1282
0
         filetime,
1283
0
         error ) != 1 )
1284
0
    {
1285
0
      libcerror_error_set(
1286
0
       error,
1287
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1288
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1289
0
       "%s: unable to retrieve filetime value.",
1290
0
       function );
1291
1292
0
      goto on_error;
1293
0
    }
1294
0
    if( libpff_record_entry_free(
1295
0
         &record_entry,
1296
0
         error ) != 1 )
1297
0
    {
1298
0
      libcerror_error_set(
1299
0
       error,
1300
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1301
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1302
0
       "%s: unable to free record entry.",
1303
0
       function );
1304
1305
0
      goto on_error;
1306
0
    }
1307
0
  }
1308
0
  return( result );
1309
1310
0
on_error:
1311
0
  if( record_entry != NULL )
1312
0
  {
1313
0
    libpff_record_entry_free(
1314
0
     &record_entry,
1315
0
     NULL );
1316
0
  }
1317
0
  return( -1 );
1318
0
}
1319
1320
/* Retrieves the UTF-8 string size of a specific entry
1321
 * The size includes the end of string character
1322
 * Returns 1 if successful, 0 if not available or -1 on error
1323
 */
1324
int libpff_internal_item_get_entry_value_utf8_string_size(
1325
     libpff_internal_item_t *internal_item,
1326
     uint32_t entry_type,
1327
     int ascii_codepage,
1328
     size_t *utf8_string_size,
1329
     libcerror_error_t **error )
1330
136
{
1331
136
  libpff_record_entry_t *record_entry = NULL;
1332
136
  static char *function               = "libpff_internal_item_get_entry_value_utf8_string_size";
1333
136
  uint32_t value_type                 = 0;
1334
136
  int result                          = 0;
1335
1336
136
  if( internal_item == 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 item.",
1343
0
     function );
1344
1345
0
    return( -1 );
1346
0
  }
1347
136
  result = libpff_item_values_get_record_entry_by_type(
1348
136
            internal_item->item_values,
1349
136
            internal_item->name_to_id_map_list,
1350
136
            internal_item->io_handle,
1351
136
            internal_item->file_io_handle,
1352
136
            internal_item->offsets_index,
1353
136
            0,
1354
136
            entry_type,
1355
136
            0,
1356
136
            &record_entry,
1357
136
            LIBPFF_ENTRY_VALUE_FLAG_MATCH_ANY_VALUE_TYPE,
1358
136
            error );
1359
1360
136
  if( result == -1 )
1361
35
  {
1362
35
    libcerror_error_set(
1363
35
     error,
1364
35
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1365
35
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1366
35
     "%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
1367
35
     function,
1368
35
     entry_type );
1369
1370
35
    goto on_error;
1371
35
  }
1372
101
  else if( result != 0 )
1373
87
  {
1374
87
    if( libpff_record_entry_get_value_type(
1375
87
         record_entry,
1376
87
         &value_type,
1377
87
         error ) != 1 )
1378
0
    {
1379
0
      libcerror_error_set(
1380
0
       error,
1381
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1382
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1383
0
       "%s: unable to retrieve value type.",
1384
0
       function );
1385
1386
0
      goto on_error;
1387
0
    }
1388
87
    if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII )
1389
87
     && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) )
1390
5
    {
1391
5
      libcerror_error_set(
1392
5
       error,
1393
5
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1394
5
       LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1395
5
       "%s: unsupported value type: 0x%04" PRIx32 ".",
1396
5
       function,
1397
5
       value_type );
1398
1399
5
      goto on_error;
1400
5
    }
1401
82
    if( libpff_record_entry_get_data_as_utf8_string_size_with_codepage(
1402
82
         record_entry,
1403
82
         ascii_codepage,
1404
82
         utf8_string_size,
1405
82
         error ) != 1 )
1406
15
    {
1407
15
      libcerror_error_set(
1408
15
       error,
1409
15
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1410
15
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1411
15
       "%s: unable to retrieve UTF-8 string size.",
1412
15
       function );
1413
1414
15
      goto on_error;
1415
15
    }
1416
67
    if( libpff_record_entry_free(
1417
67
         &record_entry,
1418
67
         error ) != 1 )
1419
0
    {
1420
0
      libcerror_error_set(
1421
0
       error,
1422
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1423
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1424
0
       "%s: unable to free record entry.",
1425
0
       function );
1426
1427
0
      goto on_error;
1428
0
    }
1429
67
  }
1430
81
  return( result );
1431
1432
55
on_error:
1433
55
  if( record_entry != NULL )
1434
20
  {
1435
20
    libpff_record_entry_free(
1436
20
     &record_entry,
1437
20
     NULL );
1438
20
  }
1439
55
  return( -1 );
1440
136
}
1441
1442
/* Retrieves the UTF-8 string value of a specific entry
1443
 * The function uses a codepage if necessary, it uses the codepage set for the library
1444
 * Returns 1 if successful, 0 if not available or -1 on error
1445
 */
1446
int libpff_internal_item_get_entry_value_utf8_string(
1447
     libpff_internal_item_t *internal_item,
1448
     uint32_t entry_type,
1449
     int ascii_codepage,
1450
     uint8_t *utf8_string,
1451
     size_t utf8_string_size,
1452
     libcerror_error_t **error )
1453
67
{
1454
67
  libpff_record_entry_t *record_entry = NULL;
1455
67
  static char *function               = "libpff_internal_item_get_entry_value_utf8_string";
1456
67
  uint32_t value_type                 = 0;
1457
67
  int result                          = 0;
1458
1459
67
  if( internal_item == NULL )
1460
0
  {
1461
0
    libcerror_error_set(
1462
0
     error,
1463
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1464
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1465
0
     "%s: invalid item.",
1466
0
     function );
1467
1468
0
    return( -1 );
1469
0
  }
1470
67
  result = libpff_item_values_get_record_entry_by_type(
1471
67
            internal_item->item_values,
1472
67
            internal_item->name_to_id_map_list,
1473
67
            internal_item->io_handle,
1474
67
            internal_item->file_io_handle,
1475
67
            internal_item->offsets_index,
1476
67
            0,
1477
67
            entry_type,
1478
67
            0,
1479
67
            &record_entry,
1480
67
            LIBPFF_ENTRY_VALUE_FLAG_MATCH_ANY_VALUE_TYPE,
1481
67
            error );
1482
1483
67
  if( result == -1 )
1484
0
  {
1485
0
    libcerror_error_set(
1486
0
     error,
1487
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1488
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1489
0
     "%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
1490
0
     function,
1491
0
     entry_type );
1492
1493
0
    goto on_error;
1494
0
  }
1495
67
  else if( result != 0 )
1496
67
  {
1497
67
    if( libpff_record_entry_get_value_type(
1498
67
         record_entry,
1499
67
         &value_type,
1500
67
         error ) != 1 )
1501
0
    {
1502
0
      libcerror_error_set(
1503
0
       error,
1504
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1505
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1506
0
       "%s: unable to retrieve value type.",
1507
0
       function );
1508
1509
0
      goto on_error;
1510
0
    }
1511
67
    if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII )
1512
67
     && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) )
1513
0
    {
1514
0
      libcerror_error_set(
1515
0
       error,
1516
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1517
0
       LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1518
0
       "%s: unsupported value type: 0x%04" PRIx32 ".",
1519
0
       function,
1520
0
       value_type );
1521
1522
0
      goto on_error;
1523
0
    }
1524
67
    if( libpff_record_entry_get_data_as_utf8_string_with_codepage(
1525
67
         record_entry,
1526
67
         ascii_codepage,
1527
67
         utf8_string,
1528
67
         utf8_string_size,
1529
67
         error ) != 1 )
1530
0
    {
1531
0
      libcerror_error_set(
1532
0
       error,
1533
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1534
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1535
0
       "%s: unable to copy record entry to UTF-8 string.",
1536
0
       function );
1537
1538
0
      goto on_error;
1539
0
    }
1540
67
    if( libpff_record_entry_free(
1541
67
         &record_entry,
1542
67
         error ) != 1 )
1543
0
    {
1544
0
      libcerror_error_set(
1545
0
       error,
1546
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1547
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1548
0
       "%s: unable to free record entry.",
1549
0
       function );
1550
1551
0
      goto on_error;
1552
0
    }
1553
67
  }
1554
67
  return( result );
1555
1556
0
on_error:
1557
0
  if( record_entry != NULL )
1558
0
  {
1559
0
    libpff_record_entry_free(
1560
0
     &record_entry,
1561
0
     NULL );
1562
0
  }
1563
0
  return( -1 );
1564
67
}
1565
1566
/* Retrieves the UTF-16 string size of a specific entry
1567
 * The size includes the end of string character
1568
 * Returns 1 if successful, 0 if not available or -1 on error
1569
 */
1570
int libpff_internal_item_get_entry_value_utf16_string_size(
1571
     libpff_internal_item_t *internal_item,
1572
     uint32_t entry_type,
1573
     int ascii_codepage,
1574
     size_t *utf16_string_size,
1575
     libcerror_error_t **error )
1576
67
{
1577
67
  libpff_record_entry_t *record_entry = NULL;
1578
67
  static char *function               = "libpff_internal_item_get_entry_value_utf16_string_size";
1579
67
  uint32_t value_type                 = 0;
1580
67
  int result                          = 0;
1581
1582
67
  if( internal_item == NULL )
1583
0
  {
1584
0
    libcerror_error_set(
1585
0
     error,
1586
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1587
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1588
0
     "%s: invalid item.",
1589
0
     function );
1590
1591
0
    return( -1 );
1592
0
  }
1593
67
  result = libpff_item_values_get_record_entry_by_type(
1594
67
            internal_item->item_values,
1595
67
            internal_item->name_to_id_map_list,
1596
67
            internal_item->io_handle,
1597
67
            internal_item->file_io_handle,
1598
67
            internal_item->offsets_index,
1599
67
            0,
1600
67
            entry_type,
1601
67
            0,
1602
67
            &record_entry,
1603
67
            LIBPFF_ENTRY_VALUE_FLAG_MATCH_ANY_VALUE_TYPE,
1604
67
            error );
1605
1606
67
  if( result == -1 )
1607
0
  {
1608
0
    libcerror_error_set(
1609
0
     error,
1610
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1611
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1612
0
     "%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
1613
0
     function,
1614
0
     entry_type );
1615
1616
0
    goto on_error;
1617
0
  }
1618
67
  else if( result != 0 )
1619
67
  {
1620
67
    if( libpff_record_entry_get_value_type(
1621
67
         record_entry,
1622
67
         &value_type,
1623
67
         error ) != 1 )
1624
0
    {
1625
0
      libcerror_error_set(
1626
0
       error,
1627
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1628
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1629
0
       "%s: unable to retrieve value type.",
1630
0
       function );
1631
1632
0
      goto on_error;
1633
0
    }
1634
67
    if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII )
1635
67
     && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) )
1636
0
    {
1637
0
      libcerror_error_set(
1638
0
       error,
1639
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1640
0
       LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1641
0
       "%s: unsupported value type: 0x%04" PRIx32 ".",
1642
0
       function,
1643
0
       value_type );
1644
1645
0
      goto on_error;
1646
0
    }
1647
67
    if( libpff_record_entry_get_data_as_utf16_string_size_with_codepage(
1648
67
         record_entry,
1649
67
         ascii_codepage,
1650
67
         utf16_string_size,
1651
67
         error ) != 1 )
1652
0
    {
1653
0
      libcerror_error_set(
1654
0
       error,
1655
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1656
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1657
0
       "%s: unable to retrieve UTF-16 string size.",
1658
0
       function );
1659
1660
0
      goto on_error;
1661
0
    }
1662
67
    if( libpff_record_entry_free(
1663
67
         &record_entry,
1664
67
         error ) != 1 )
1665
0
    {
1666
0
      libcerror_error_set(
1667
0
       error,
1668
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1669
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1670
0
       "%s: unable to free record entry.",
1671
0
       function );
1672
1673
0
      goto on_error;
1674
0
    }
1675
67
  }
1676
67
  return( result );
1677
1678
0
on_error:
1679
0
  if( record_entry != NULL )
1680
0
  {
1681
0
    libpff_record_entry_free(
1682
0
     &record_entry,
1683
0
     NULL );
1684
0
  }
1685
0
  return( -1 );
1686
67
}
1687
1688
/* Retrieves the UTF-16 string value of a specific entry
1689
 * The function uses a codepage if necessary, it uses the codepage set for the library
1690
 * Returns 1 if successful, 0 if not available or -1 on error
1691
 */
1692
int libpff_internal_item_get_entry_value_utf16_string(
1693
     libpff_internal_item_t *internal_item,
1694
     uint32_t entry_type,
1695
     int ascii_codepage,
1696
     uint16_t *utf16_string,
1697
     size_t utf16_string_size,
1698
     libcerror_error_t **error )
1699
67
{
1700
67
  libpff_record_entry_t *record_entry = NULL;
1701
67
  static char *function               = "libpff_internal_item_get_entry_value_utf16_string";
1702
67
  uint32_t value_type                 = 0;
1703
67
  int result                          = 0;
1704
1705
67
  if( internal_item == NULL )
1706
0
  {
1707
0
    libcerror_error_set(
1708
0
     error,
1709
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1710
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1711
0
     "%s: invalid item.",
1712
0
     function );
1713
1714
0
    return( -1 );
1715
0
  }
1716
67
  result = libpff_item_values_get_record_entry_by_type(
1717
67
            internal_item->item_values,
1718
67
            internal_item->name_to_id_map_list,
1719
67
            internal_item->io_handle,
1720
67
            internal_item->file_io_handle,
1721
67
            internal_item->offsets_index,
1722
67
            0,
1723
67
            entry_type,
1724
67
            0,
1725
67
            &record_entry,
1726
67
            LIBPFF_ENTRY_VALUE_FLAG_MATCH_ANY_VALUE_TYPE,
1727
67
            error );
1728
1729
67
  if( result == -1 )
1730
0
  {
1731
0
    libcerror_error_set(
1732
0
     error,
1733
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1734
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1735
0
     "%s: unable to retrieve record entry: 0x%04" PRIx32 ".",
1736
0
     function,
1737
0
     entry_type );
1738
1739
0
    goto on_error;
1740
0
  }
1741
67
  else if( result != 0 )
1742
67
  {
1743
67
    if( libpff_record_entry_get_value_type(
1744
67
         record_entry,
1745
67
         &value_type,
1746
67
         error ) != 1 )
1747
0
    {
1748
0
      libcerror_error_set(
1749
0
       error,
1750
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1751
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1752
0
       "%s: unable to retrieve value type.",
1753
0
       function );
1754
1755
0
      goto on_error;
1756
0
    }
1757
67
    if( ( value_type != LIBPFF_VALUE_TYPE_STRING_ASCII )
1758
67
     && ( value_type != LIBPFF_VALUE_TYPE_STRING_UNICODE ) )
1759
0
    {
1760
0
      libcerror_error_set(
1761
0
       error,
1762
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1763
0
       LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
1764
0
       "%s: unsupported value type: 0x%04" PRIx32 ".",
1765
0
       function,
1766
0
       value_type );
1767
1768
0
      goto on_error;
1769
0
    }
1770
67
    if( libpff_record_entry_get_data_as_utf16_string_with_codepage(
1771
67
         record_entry,
1772
67
         ascii_codepage,
1773
67
         utf16_string,
1774
67
         utf16_string_size,
1775
67
         error ) != 1 )
1776
0
    {
1777
0
      libcerror_error_set(
1778
0
       error,
1779
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1780
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1781
0
       "%s: unable to copy record entry to UTF-16 string.",
1782
0
       function );
1783
1784
0
      goto on_error;
1785
0
    }
1786
67
    if( libpff_record_entry_free(
1787
67
         &record_entry,
1788
67
         error ) != 1 )
1789
0
    {
1790
0
      libcerror_error_set(
1791
0
       error,
1792
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1793
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1794
0
       "%s: unable to free record entry.",
1795
0
       function );
1796
1797
0
      goto on_error;
1798
0
    }
1799
67
  }
1800
67
  return( result );
1801
1802
0
on_error:
1803
0
  if( record_entry != NULL )
1804
0
  {
1805
0
    libpff_record_entry_free(
1806
0
     &record_entry,
1807
0
     NULL );
1808
0
  }
1809
0
  return( -1 );
1810
67
}
1811
1812
/* Retrieves the embedded object data
1813
 * Returns 1 if successful or -1 on error
1814
 */
1815
int libpff_internal_item_get_embedded_object_data(
1816
     libpff_internal_item_t *internal_item,
1817
     libpff_record_entry_t *record_entry,
1818
     libcerror_error_t **error )
1819
0
{
1820
0
  libfcache_cache_t *embedded_object_data_cache           = NULL;
1821
0
  libfdata_list_t *embedded_object_data_list              = NULL;
1822
0
  libpff_local_descriptor_value_t *local_descriptor_value = NULL;
1823
0
  static char *function                                   = "libpff_internal_item_get_embedded_object_data";
1824
0
  uint32_t embedded_object_data_identifier                = 0;
1825
1826
0
  if( internal_item == NULL )
1827
0
  {
1828
0
    libcerror_error_set(
1829
0
     error,
1830
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1831
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1832
0
     "%s: invalid item.",
1833
0
     function );
1834
1835
0
    return( -1 );
1836
0
  }
1837
0
  if( internal_item->item_values == NULL )
1838
0
  {
1839
0
    libcerror_error_set(
1840
0
     error,
1841
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1842
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1843
0
     "%s: invalid item - missing item values.",
1844
0
     function );
1845
1846
0
    return( -1 );
1847
0
  }
1848
0
  if( internal_item->item_values->table == NULL )
1849
0
  {
1850
0
    libcerror_error_set(
1851
0
     error,
1852
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1853
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1854
0
     "%s: invalid item - invalid item values - missing table.",
1855
0
     function );
1856
1857
0
    return( -1 );
1858
0
  }
1859
0
  if( internal_item->embedded_object_data_stream != NULL )
1860
0
  {
1861
0
    libcerror_error_set(
1862
0
     error,
1863
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1864
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
1865
0
     "%s: invalid item - embedded object data stream already set.",
1866
0
     function );
1867
1868
0
    return( -1 );
1869
0
  }
1870
0
  if( libpff_record_entry_copy_object_identifier(
1871
0
       record_entry,
1872
0
       &embedded_object_data_identifier,
1873
0
       error ) != 1 )
1874
0
  {
1875
0
    libcerror_error_set(
1876
0
     error,
1877
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1878
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
1879
0
     "%s: unable to copy record entry object identifier.",
1880
0
     function );
1881
1882
0
    goto on_error;
1883
0
  }
1884
  /* The descriptor identifier is located in the local descriptors tree
1885
   */
1886
0
  if( libpff_table_get_local_descriptors_value_by_identifier(
1887
0
       internal_item->item_values->table,
1888
0
       internal_item->file_io_handle,
1889
0
       (uint64_t) embedded_object_data_identifier,
1890
0
       &local_descriptor_value,
1891
0
       error ) != 1 )
1892
0
  {
1893
0
    libcerror_error_set(
1894
0
     error,
1895
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1896
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1897
0
     "%s: unable to retrieve local descriptor identifier: %" PRIu32 ".",
1898
0
     function,
1899
0
     embedded_object_data_identifier );
1900
1901
0
    goto on_error;
1902
0
  }
1903
0
  if( local_descriptor_value == NULL )
1904
0
  {
1905
0
    libcerror_error_set(
1906
0
     error,
1907
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1908
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1909
0
     "%s: invalid local descriptor values.",
1910
0
     function );
1911
1912
0
    goto on_error;
1913
0
  }
1914
#if defined( HAVE_DEBUG_OUTPUT )
1915
  if( libcnotify_verbose != 0 )
1916
  {
1917
    libcnotify_printf(
1918
     "%s: identifier: %" PRIu64 " (%s), data: %" PRIu64 ", local descriptors: %" PRIu64 "\n",
1919
     function,
1920
     local_descriptor_value->identifier,
1921
     libpff_debug_get_node_identifier_type(
1922
      (uint8_t) ( local_descriptor_value->identifier & 0x0000001fUL ) ),
1923
     local_descriptor_value->data_identifier,
1924
     local_descriptor_value->local_descriptors_identifier );
1925
  }
1926
#endif
1927
0
  if( local_descriptor_value->data_identifier == 0 )
1928
0
  {
1929
0
    libcerror_error_set(
1930
0
     error,
1931
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1932
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1933
0
     "%s: invalid local descriptor values - missing data identifier.",
1934
0
     function );
1935
1936
0
    goto on_error;
1937
0
  }
1938
/* TODO handle multiple recovered offset index values */
1939
0
  if( libpff_table_read_descriptor_data_list(
1940
0
       internal_item->item_values->table,
1941
0
       internal_item->io_handle,
1942
0
       internal_item->file_io_handle,
1943
0
       internal_item->offsets_index,
1944
0
       embedded_object_data_identifier,
1945
0
       local_descriptor_value->data_identifier,
1946
0
       internal_item->item_values->recovered,
1947
0
       0,
1948
0
       &embedded_object_data_list,
1949
0
       &embedded_object_data_cache,
1950
0
       error ) != 1 )
1951
0
  {
1952
0
    libcerror_error_set(
1953
0
     error,
1954
0
     LIBCERROR_ERROR_DOMAIN_IO,
1955
0
     LIBCERROR_IO_ERROR_READ_FAILED,
1956
0
     "%s: unable to read descriptor: %" PRIu32 " data: %" PRIu64 " list.",
1957
0
     function,
1958
0
     embedded_object_data_identifier,
1959
0
     local_descriptor_value->data_identifier );
1960
1961
0
    goto on_error;
1962
0
  }
1963
0
  if( libpff_descriptor_data_stream_initialize(
1964
0
       &( internal_item->embedded_object_data_stream ),
1965
0
       embedded_object_data_list,
1966
0
       embedded_object_data_cache,
1967
0
       LIBPFF_DESCRIPTOR_DATA_STREAM_DATA_HANDLE_FLAG_MANAGED,
1968
0
       error ) != 1 )
1969
0
  {
1970
0
    libcerror_error_set(
1971
0
     error,
1972
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1973
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1974
0
     "%s: unable to create descriptor data stream.",
1975
0
     function );
1976
1977
0
    goto on_error;
1978
0
  }
1979
0
  if( libpff_local_descriptor_value_free(
1980
0
       &local_descriptor_value,
1981
0
       error ) != 1 )
1982
0
  {
1983
0
    libcerror_error_set(
1984
0
     error,
1985
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1986
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1987
0
     "%s: unable to free local descriptor values.",
1988
0
     function );
1989
1990
0
    goto on_error;
1991
0
  }
1992
0
  return( 1 );
1993
1994
0
on_error:
1995
  /* Only when the embedded object data stream was not created the
1996
   * descriptor data list and cache are still owned by this function
1997
   * and must be freed here. When the stream was created it took
1998
   * ownership of the descriptor data list and cache (MANAGED) and
1999
   * frees them when the item is freed.
2000
   */
2001
0
  if( internal_item->embedded_object_data_stream == NULL )
2002
0
  {
2003
0
    if( embedded_object_data_cache != NULL )
2004
0
    {
2005
0
      libfcache_cache_free(
2006
0
       &embedded_object_data_cache,
2007
0
       NULL );
2008
0
    }
2009
0
    if( embedded_object_data_list != NULL )
2010
0
    {
2011
0
      libfdata_list_free(
2012
0
       &embedded_object_data_list,
2013
0
       NULL );
2014
0
    }
2015
0
  }
2016
0
  if( local_descriptor_value != NULL )
2017
0
  {
2018
0
    libpff_local_descriptor_value_free(
2019
0
     &local_descriptor_value,
2020
0
     NULL );
2021
0
  }
2022
0
  return( -1 );
2023
0
}
2024
2025
/* Retrieves the type
2026
 * Determines the item type if necessary
2027
 * Returns 1 if successful or -1 on error
2028
 */
2029
int libpff_item_get_type(
2030
     libpff_item_t *item,
2031
     uint8_t *item_type,
2032
     libcerror_error_t **error )
2033
16.1k
{
2034
16.1k
  libpff_internal_item_t *internal_item = NULL;
2035
16.1k
  static char *function                 = "libpff_item_get_type";
2036
2037
16.1k
  if( item == NULL )
2038
0
  {
2039
0
    libcerror_error_set(
2040
0
     error,
2041
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2042
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2043
0
     "%s: invalid item.",
2044
0
     function );
2045
2046
0
    return( -1 );
2047
0
  }
2048
16.1k
  internal_item = (libpff_internal_item_t *) item;
2049
2050
16.1k
  if( item_type == NULL )
2051
0
  {
2052
0
    libcerror_error_set(
2053
0
     error,
2054
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2055
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2056
0
     "%s: invalid item type.",
2057
0
     function );
2058
2059
0
    return( -1 );
2060
0
  }
2061
16.1k
  if( internal_item->type == LIBPFF_ITEM_TYPE_UNDEFINED )
2062
8.36k
  {
2063
8.36k
    if( libpff_internal_item_determine_type(
2064
8.36k
         internal_item,
2065
8.36k
         error ) != 1 )
2066
8.17k
    {
2067
8.17k
      libcerror_error_set(
2068
8.17k
       error,
2069
8.17k
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2070
8.17k
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2071
8.17k
       "%s: unable to determine item type.",
2072
8.17k
       function );
2073
2074
8.17k
      return( -1 );
2075
8.17k
    }
2076
8.36k
  }
2077
7.94k
  *item_type = internal_item->type;
2078
2079
7.94k
  return( 1 );
2080
16.1k
}
2081
2082
/* Retrieves the number of sub items from a item
2083
 * Returns 1 if successful or -1 on error
2084
 */
2085
int libpff_item_get_number_of_sub_items(
2086
     libpff_item_t *item,
2087
     int *number_of_sub_items,
2088
     libcerror_error_t **error )
2089
10.2k
{
2090
10.2k
  libpff_internal_item_t *internal_item = NULL;
2091
10.2k
  static char *function                 = "libpff_item_get_number_of_sub_items";
2092
2093
10.2k
  if( item == NULL )
2094
0
  {
2095
0
    libcerror_error_set(
2096
0
     error,
2097
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2098
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2099
0
     "%s: invalid item.",
2100
0
     function );
2101
2102
0
    return( -1 );
2103
0
  }
2104
10.2k
  internal_item = (libpff_internal_item_t *) item;
2105
2106
10.2k
  if( libcdata_tree_node_get_number_of_sub_nodes(
2107
10.2k
       internal_item->item_tree_node,
2108
10.2k
       number_of_sub_items,
2109
10.2k
       error ) != 1 )
2110
0
  {
2111
0
    libcerror_error_set(
2112
0
     error,
2113
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2114
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2115
0
     "%s: unable to retrieve number of sub items.",
2116
0
     function );
2117
2118
0
    return( -1 );
2119
0
  }
2120
10.2k
  return( 1 );
2121
10.2k
}
2122
2123
/* Retrieves the sub item for the specific index from a item
2124
 * Returns 1 if successful or -1 on error
2125
 */
2126
int libpff_item_get_sub_item(
2127
     libpff_item_t *item,
2128
     int sub_item_index,
2129
     libpff_item_t **sub_item,
2130
     libcerror_error_t **error )
2131
27.7k
{
2132
27.7k
  libcdata_tree_node_t *sub_item_tree_node      = NULL;
2133
27.7k
  libpff_internal_item_t *internal_item         = NULL;
2134
27.7k
  libpff_item_descriptor_t *sub_item_descriptor = NULL;
2135
27.7k
  static char *function                         = "libpff_item_get_sub_item";
2136
2137
27.7k
  if( item == NULL )
2138
0
  {
2139
0
    libcerror_error_set(
2140
0
     error,
2141
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2142
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2143
0
     "%s: invalid item.",
2144
0
     function );
2145
2146
0
    return( -1 );
2147
0
  }
2148
27.7k
  internal_item = (libpff_internal_item_t *) item;
2149
2150
27.7k
  if( sub_item == NULL )
2151
0
  {
2152
0
    libcerror_error_set(
2153
0
     error,
2154
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2155
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2156
0
     "%s: invalid sub item.",
2157
0
     function );
2158
2159
0
    return( -1 );
2160
0
  }
2161
27.7k
  if( *sub_item != NULL )
2162
0
  {
2163
0
    libcerror_error_set(
2164
0
     error,
2165
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2166
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2167
0
     "%s: sub item already set.",
2168
0
     function );
2169
2170
0
    return( -1 );
2171
0
  }
2172
27.7k
  if( libcdata_tree_node_get_sub_node_by_index(
2173
27.7k
       internal_item->item_tree_node,
2174
27.7k
             sub_item_index,
2175
27.7k
             &sub_item_tree_node,
2176
27.7k
       error ) != 1 )
2177
0
  {
2178
0
    libcerror_error_set(
2179
0
     error,
2180
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2181
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2182
0
     "%s: unable to retrieve sub item tree node.",
2183
0
     function );
2184
2185
0
    return( -1 );
2186
0
  }
2187
27.7k
  if( libcdata_tree_node_get_value(
2188
27.7k
       sub_item_tree_node,
2189
27.7k
       (intptr_t **) &sub_item_descriptor,
2190
27.7k
       error ) != 1 )
2191
0
  {
2192
0
    libcerror_error_set(
2193
0
     error,
2194
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2195
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2196
0
     "%s: unable to retrieve sub item descriptor.",
2197
0
     function );
2198
2199
0
    return( -1 );
2200
0
  }
2201
27.7k
  if( libpff_item_initialize(
2202
27.7k
       sub_item,
2203
27.7k
       internal_item->io_handle,
2204
27.7k
       internal_item->file_io_handle,
2205
27.7k
       internal_item->name_to_id_map_list,
2206
27.7k
       internal_item->descriptors_index,
2207
27.7k
       internal_item->offsets_index,
2208
27.7k
       internal_item->item_tree,
2209
27.7k
       sub_item_tree_node,
2210
27.7k
       LIBPFF_ITEM_FLAGS_DEFAULT,
2211
27.7k
       error ) != 1 )
2212
0
  {
2213
0
    libcerror_error_set(
2214
0
     error,
2215
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2216
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2217
0
     "%s: unable to initialize sub item.",
2218
0
     function );
2219
2220
0
    return( -1 );
2221
0
  }
2222
27.7k
  return( 1 );
2223
27.7k
}
2224
2225
/* Retrieves the sub item for the specific identifier from a item
2226
 * Returns 1 if successful, 0 if no such item or -1 on error
2227
 */
2228
int libpff_item_get_sub_item_by_identifier(
2229
     libpff_item_t *item,
2230
     uint32_t sub_item_identifier,
2231
     libpff_item_t **sub_item,
2232
     libcerror_error_t **error )
2233
0
{
2234
0
  libcdata_tree_node_t *sub_item_tree_node      = NULL;
2235
0
  libpff_internal_item_t *internal_item         = NULL;
2236
0
  libpff_item_descriptor_t *sub_item_descriptor = NULL;
2237
0
  static char *function                         = "libpff_item_get_sub_item_by_identifier";
2238
0
  uint8_t flags                                 = 0;
2239
0
  int result                                    = 0;
2240
2241
0
  if( item == NULL )
2242
0
  {
2243
0
    libcerror_error_set(
2244
0
     error,
2245
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2246
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2247
0
     "%s: invalid item.",
2248
0
     function );
2249
2250
0
    return( -1 );
2251
0
  }
2252
0
  internal_item = (libpff_internal_item_t *) item;
2253
2254
0
  if( sub_item == NULL )
2255
0
  {
2256
0
    libcerror_error_set(
2257
0
     error,
2258
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2259
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2260
0
     "%s: invalid sub item.",
2261
0
     function );
2262
2263
0
    return( -1 );
2264
0
  }
2265
0
  if( *sub_item != NULL )
2266
0
  {
2267
0
    libcerror_error_set(
2268
0
     error,
2269
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2270
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
2271
0
     "%s: sub item already set.",
2272
0
     function );
2273
2274
0
    return( -1 );
2275
0
  }
2276
0
  result = libpff_item_tree_get_sub_node_by_identifier(
2277
0
            internal_item->item_tree_node,
2278
0
                  sub_item_identifier,
2279
0
                  &sub_item_tree_node,
2280
0
            error );
2281
2282
0
  if( result == -1 )
2283
0
  {
2284
0
    libcerror_error_set(
2285
0
     error,
2286
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2287
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2288
0
     "%s: unable to retrieve sub item tree node: %" PRIu32 ".",
2289
0
     function,
2290
0
     sub_item_identifier );
2291
2292
0
    return( -1 );
2293
0
  }
2294
0
  else if( result == 0 )
2295
0
  {
2296
0
    return( 0 );
2297
0
  }
2298
0
  if( libcdata_tree_node_get_value(
2299
0
       sub_item_tree_node,
2300
0
       (intptr_t **) &sub_item_descriptor,
2301
0
       error ) != 1 )
2302
0
  {
2303
0
    libcerror_error_set(
2304
0
     error,
2305
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2306
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2307
0
     "%s: unable to retrieve sub item descriptor.",
2308
0
     function );
2309
2310
0
    return( -1 );
2311
0
  }
2312
0
  if( libpff_item_initialize(
2313
0
       sub_item,
2314
0
       internal_item->io_handle,
2315
0
       internal_item->file_io_handle,
2316
0
       internal_item->name_to_id_map_list,
2317
0
       internal_item->descriptors_index,
2318
0
       internal_item->offsets_index,
2319
0
       internal_item->item_tree,
2320
0
       sub_item_tree_node,
2321
0
       LIBPFF_ITEM_FLAGS_DEFAULT | flags,
2322
0
       error ) != 1 )
2323
0
  {
2324
0
    libcerror_error_set(
2325
0
     error,
2326
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2327
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2328
0
     "%s: unable to initialize sub item.",
2329
0
     function );
2330
2331
0
    return( -1 );
2332
0
  }
2333
0
  if( *sub_item == NULL )
2334
0
  {
2335
0
    libcerror_error_set(
2336
0
     error,
2337
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2338
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2339
0
     "%s: missing sub item.",
2340
0
     function );
2341
2342
0
    return( -1 );
2343
0
  }
2344
0
  if( ( flags & LIBPFF_ITEM_FLAG_MANAGED_ITEM_TREE_NODE ) != 0 )
2345
0
  {
2346
0
    if( internal_item->type != LIBPFF_ITEM_TYPE_FOLDER )
2347
0
    {
2348
0
      if( sub_item_identifier == LIBPFF_LOCAL_DESCRIPTOR_IDENTIFIER_ATTACHMENTS )
2349
0
      {
2350
0
        ( (libpff_internal_item_t *) *sub_item )->type = LIBPFF_ITEM_TYPE_ATTACHMENTS;
2351
0
      }
2352
0
      else if( sub_item_identifier == LIBPFF_LOCAL_DESCRIPTOR_IDENTIFIER_RECIPIENTS )
2353
0
      {
2354
0
        ( (libpff_internal_item_t *) *sub_item )->type = LIBPFF_ITEM_TYPE_RECIPIENTS;
2355
0
      }
2356
0
      else
2357
0
      {
2358
0
        ( (libpff_internal_item_t *) *sub_item )->type = LIBPFF_ITEM_TYPE_ATTACHMENT;
2359
0
      }
2360
0
    }
2361
0
  }
2362
0
  return( 1 );
2363
0
}
2364