Coverage Report

Created: 2026-08-31 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libpff/libpff/libpff_data_block.c
Line
Count
Source
1
/*
2
 * Data block 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 <types.h>
26
27
#include "libpff_checksum.h"
28
#include "libpff_compression.h"
29
#include "libpff_definitions.h"
30
#include "libpff_data_block.h"
31
#include "libpff_encryption.h"
32
#include "libpff_io_handle.h"
33
#include "libpff_libbfio.h"
34
#include "libpff_libcerror.h"
35
#include "libpff_libcnotify.h"
36
#include "libpff_libfcache.h"
37
#include "libpff_libfdata.h"
38
#include "libpff_unused.h"
39
40
#include "pff_block.h"
41
42
/* Creates a data block
43
 * Make sure the value data_block is referencing, is set to NULL
44
 * Returns 1 if successful or -1 on error
45
 */
46
int libpff_data_block_initialize(
47
     libpff_data_block_t **data_block,
48
     libpff_io_handle_t *io_handle,
49
     uint32_t descriptor_identifier,
50
     uint64_t data_identifier,
51
     libcerror_error_t **error )
52
185k
{
53
185k
  static char *function = "libpff_data_block_initialize";
54
55
185k
  if( data_block == NULL )
56
0
  {
57
0
    libcerror_error_set(
58
0
     error,
59
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
60
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
61
0
     "%s: invalid data block.",
62
0
     function );
63
64
0
    return( -1 );
65
0
  }
66
185k
  if( *data_block != NULL )
67
0
  {
68
0
    libcerror_error_set(
69
0
     error,
70
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
71
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
72
0
     "%s: invalid data block value already set.",
73
0
     function );
74
75
0
    return( -1 );
76
0
  }
77
185k
  if( io_handle == NULL )
78
0
  {
79
0
    libcerror_error_set(
80
0
     error,
81
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
82
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
83
0
     "%s: invalid IO handle.",
84
0
     function );
85
86
0
    return( -1 );
87
0
  }
88
185k
  *data_block = memory_allocate_structure(
89
185k
                 libpff_data_block_t );
90
91
185k
  if( *data_block == NULL )
92
0
  {
93
0
    libcerror_error_set(
94
0
     error,
95
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
96
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
97
0
     "%s: unable to create data block.",
98
0
     function );
99
100
0
    goto on_error;
101
0
  }
102
185k
  if( memory_set(
103
185k
       *data_block,
104
185k
       0,
105
185k
       sizeof( libpff_data_block_t ) ) == NULL )
106
0
  {
107
0
    libcerror_error_set(
108
0
     error,
109
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
110
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
111
0
     "%s: unable to clear data block.",
112
0
     function );
113
114
0
    goto on_error;
115
0
  }
116
185k
  ( *data_block )->io_handle             = io_handle;
117
185k
  ( *data_block )->descriptor_identifier = descriptor_identifier;
118
185k
  ( *data_block )->data_identifier       = data_identifier;
119
120
185k
  return( 1 );
121
122
0
on_error:
123
0
  if( *data_block != NULL )
124
0
  {
125
0
    memory_free(
126
0
     *data_block );
127
128
0
    *data_block = NULL;
129
0
  }
130
0
  return( -1 );
131
185k
}
132
133
/* Frees a data block
134
 * Returns 1 if successful or -1 on error
135
 */
136
int libpff_data_block_free(
137
     libpff_data_block_t **data_block,
138
     libcerror_error_t **error )
139
185k
{
140
185k
  static char *function = "libpff_data_block_free";
141
142
185k
  if( data_block == NULL )
143
0
  {
144
0
    libcerror_error_set(
145
0
     error,
146
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
147
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
148
0
     "%s: invalid data block.",
149
0
     function );
150
151
0
    return( -1 );
152
0
  }
153
185k
  if( *data_block != NULL )
154
185k
  {
155
185k
    if( ( *data_block )->data != NULL )
156
182k
    {
157
182k
      memory_free(
158
182k
       ( *data_block )->data );
159
182k
    }
160
185k
    memory_free(
161
185k
     *data_block );
162
163
185k
    *data_block = NULL;
164
185k
  }
165
185k
  return( 1 );
166
185k
}
167
168
/* Clones the data block
169
 * Returns 1 if successful or -1 on error
170
 */
171
int libpff_data_block_clone(
172
     libpff_data_block_t **destination_data_block,
173
     libpff_data_block_t *source_data_block,
174
     libcerror_error_t **error )
175
0
{
176
0
  static char *function = "libpff_data_block_clone";
177
178
0
  if( destination_data_block == NULL )
179
0
  {
180
0
    libcerror_error_set(
181
0
     error,
182
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
183
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
184
0
     "%s: invalid destination data block.",
185
0
     function );
186
187
0
    return( -1 );
188
0
  }
189
0
  if( *destination_data_block != NULL )
190
0
  {
191
0
    libcerror_error_set(
192
0
     error,
193
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
194
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
195
0
     "%s: invalid destination data block already set.",
196
0
     function );
197
198
0
    return( -1 );
199
0
  }
200
0
  if( source_data_block == NULL )
201
0
  {
202
0
    *destination_data_block = NULL;
203
204
0
    return( 1 );
205
0
  }
206
0
  if( libpff_data_block_initialize(
207
0
       destination_data_block,
208
0
       source_data_block->io_handle,
209
0
       source_data_block->descriptor_identifier,
210
0
       source_data_block->data_identifier,
211
0
       error ) != 1 )
212
0
  {
213
0
    libcerror_error_set(
214
0
     error,
215
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
216
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
217
0
     "%s: unable to create destination data block.",
218
0
     function );
219
220
0
    goto on_error;
221
0
  }
222
0
  if( *destination_data_block == NULL )
223
0
  {
224
0
    libcerror_error_set(
225
0
     error,
226
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
227
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
228
0
     "%s: missing destination data block.",
229
0
     function );
230
231
0
    goto on_error;
232
0
  }
233
0
  if( ( source_data_block->data != NULL )
234
0
   && ( source_data_block->data_size > 0 ) )
235
0
  {
236
0
    if( source_data_block->data_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
237
0
    {
238
0
      libcerror_error_set(
239
0
       error,
240
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
241
0
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
242
0
       "%s: invalid source data block - data size value exceeds maximum.",
243
0
       function );
244
245
0
      goto on_error;
246
0
    }
247
0
    ( *destination_data_block )->data = (uint8_t *) memory_allocate(
248
0
                                                     sizeof( uint8_t ) * source_data_block->data_size );
249
250
0
    if( ( *destination_data_block )->data == NULL )
251
0
    {
252
0
      libcerror_error_set(
253
0
       error,
254
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
255
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
256
0
       "%s: unable to create destination data block data.",
257
0
       function );
258
259
0
      goto on_error;
260
0
    }
261
0
    if( memory_copy(
262
0
         ( *destination_data_block )->data,
263
0
         source_data_block->data,
264
0
         source_data_block->data_size ) == NULL )
265
0
    {
266
0
      libcerror_error_set(
267
0
       error,
268
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
269
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
270
0
       "%s: unable to copy source data block data to destination.",
271
0
       function );
272
273
0
      goto on_error;
274
0
    }
275
0
    ( *destination_data_block )->data_size = source_data_block->data_size;
276
0
  }
277
0
  ( *destination_data_block )->flags = source_data_block->flags;
278
279
0
  return( 1 );
280
281
0
on_error:
282
0
  if( *destination_data_block != NULL )
283
0
  {
284
0
    libpff_data_block_free(
285
0
     destination_data_block,
286
0
     NULL );
287
0
  }
288
0
  return( -1 );
289
0
}
290
291
/* Reads the data block footer
292
 * Returns 1 if successful or -1 on error
293
 */
294
int libpff_data_block_read_footer_data(
295
     libpff_data_block_t *data_block,
296
     const uint8_t *data,
297
     size_t data_size,
298
     uint8_t file_type,
299
     libcerror_error_t **error )
300
182k
{
301
182k
  static char *function            = "libpff_data_block_read_footer_data";
302
182k
  size_t data_block_footer_size    = 0;
303
304
#if defined( HAVE_DEBUG_OUTPUT )
305
  uint64_t data_block_back_pointer = 0;
306
  uint32_t value_32bit             = 0;
307
  uint16_t value_16bit             = 0;
308
  uint16_t data_block_signature    = 0;
309
#endif
310
311
182k
  if( data_block == NULL )
312
0
  {
313
0
    libcerror_error_set(
314
0
     error,
315
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
316
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
317
0
     "%s: invalid data block.",
318
0
     function );
319
320
0
    return( -1 );
321
0
  }
322
182k
  if( data == NULL )
323
0
  {
324
0
    libcerror_error_set(
325
0
     error,
326
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
327
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
328
0
     "%s: invalid data.",
329
0
     function );
330
331
0
    return( -1 );
332
0
  }
333
182k
  if( data_size > (size_t) SSIZE_MAX )
334
0
  {
335
0
    libcerror_error_set(
336
0
     error,
337
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
338
0
     LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
339
0
     "%s: invalid data size value exceeds maximum.",
340
0
     function );
341
342
0
    return( -1 );
343
0
  }
344
182k
  if( ( file_type != LIBPFF_FILE_TYPE_32BIT )
345
154k
   && ( file_type != LIBPFF_FILE_TYPE_64BIT )
346
0
   && ( file_type != LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) )
347
0
  {
348
0
    libcerror_error_set(
349
0
     error,
350
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
351
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
352
0
     "%s: unsupported file type.",
353
0
     function );
354
355
0
    return( -1 );
356
0
  }
357
182k
  if( file_type == LIBPFF_FILE_TYPE_32BIT )
358
28.2k
  {
359
28.2k
    data_block_footer_size = sizeof( pff_block_footer_32bit_t );
360
28.2k
  }
361
154k
  else if( file_type == LIBPFF_FILE_TYPE_64BIT )
362
154k
  {
363
154k
    data_block_footer_size = sizeof( pff_block_footer_64bit_t );
364
154k
  }
365
0
  else if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE )
366
0
  {
367
0
    data_block_footer_size = sizeof( pff_block_footer_64bit_4k_page_t );
368
0
  }
369
182k
  if( data_size < data_block_footer_size )
370
0
  {
371
0
    libcerror_error_set(
372
0
     error,
373
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
374
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
375
0
     "%s: invalid data size value too small.",
376
0
     function );
377
378
0
    return( -1 );
379
0
  }
380
#if defined( HAVE_DEBUG_OUTPUT )
381
  if( libcnotify_verbose != 0 )
382
  {
383
    libcnotify_printf(
384
     "%s: data block footer data:\n",
385
     function );
386
    libcnotify_print_data(
387
     data,
388
     data_block_footer_size,
389
     0 );
390
  }
391
#endif
392
182k
  if( file_type == LIBPFF_FILE_TYPE_32BIT )
393
28.2k
  {
394
28.2k
    byte_stream_copy_to_uint16_little_endian(
395
28.2k
     ( (pff_block_footer_32bit_t *) data )->data_size,
396
28.2k
     data_block->data_size );
397
398
#if defined( HAVE_DEBUG_OUTPUT )
399
    byte_stream_copy_to_uint16_little_endian(
400
     ( (pff_block_footer_32bit_t *) data )->signature,
401
     data_block_signature );
402
403
    byte_stream_copy_to_uint32_little_endian(
404
     ( (pff_block_footer_32bit_t *) data )->back_pointer,
405
     data_block_back_pointer );
406
#endif
407
28.2k
    byte_stream_copy_to_uint32_little_endian(
408
28.2k
     ( (pff_block_footer_32bit_t *) data )->checksum,
409
28.2k
     data_block->stored_checksum );
410
411
28.2k
    data_block->uncompressed_data_size = data_block->data_size;
412
28.2k
  }
413
154k
  else if( file_type == LIBPFF_FILE_TYPE_64BIT )
414
154k
  {
415
154k
    byte_stream_copy_to_uint16_little_endian(
416
154k
     ( (pff_block_footer_64bit_t *) data )->data_size,
417
154k
     data_block->data_size );
418
419
#if defined( HAVE_DEBUG_OUTPUT )
420
    byte_stream_copy_to_uint16_little_endian(
421
     ( (pff_block_footer_64bit_t *) data )->signature,
422
     data_block_signature );
423
#endif
424
154k
    byte_stream_copy_to_uint32_little_endian(
425
154k
     ( (pff_block_footer_64bit_t *) data )->checksum,
426
154k
     data_block->stored_checksum );
427
428
#if defined( HAVE_DEBUG_OUTPUT )
429
    byte_stream_copy_to_uint64_little_endian(
430
     ( (pff_block_footer_64bit_t *) data )->back_pointer,
431
     data_block_back_pointer );
432
#endif
433
154k
    data_block->uncompressed_data_size = data_block->data_size;
434
154k
  }
435
0
  else if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE )
436
0
  {
437
0
    byte_stream_copy_to_uint16_little_endian(
438
0
     ( (pff_block_footer_64bit_4k_page_t *) data )->data_size,
439
0
     data_block->data_size );
440
441
#if defined( HAVE_DEBUG_OUTPUT )
442
    byte_stream_copy_to_uint16_little_endian(
443
     ( (pff_block_footer_64bit_4k_page_t *) data )->signature,
444
     data_block_signature );
445
#endif
446
0
    byte_stream_copy_to_uint32_little_endian(
447
0
     ( (pff_block_footer_64bit_4k_page_t *) data )->checksum,
448
0
     data_block->stored_checksum );
449
450
#if defined( HAVE_DEBUG_OUTPUT )
451
    byte_stream_copy_to_uint64_little_endian(
452
     ( (pff_block_footer_64bit_4k_page_t *) data )->back_pointer,
453
     data_block_back_pointer );
454
#endif
455
0
    byte_stream_copy_to_uint16_little_endian(
456
0
     ( (pff_block_footer_64bit_4k_page_t *) data )->uncompressed_data_size,
457
0
     data_block->uncompressed_data_size );
458
0
  }
459
#if defined( HAVE_DEBUG_OUTPUT )
460
  if( libcnotify_verbose != 0 )
461
  {
462
    libcnotify_printf(
463
     "%s: data size\t\t\t\t: %" PRIu32 "\n",
464
     function,
465
     data_block->data_size );
466
467
    libcnotify_printf(
468
     "%s: signature\t\t\t\t: 0x%04" PRIx16 "\n",
469
     function,
470
     data_block_signature );
471
472
    if( file_type == LIBPFF_FILE_TYPE_32BIT )
473
    {
474
      libcnotify_printf(
475
       "%s: back pointer\t\t\t: 0x%08" PRIx64 "\n",
476
       function,
477
       data_block_back_pointer );
478
479
      libcnotify_printf(
480
       "%s: data checksum\t\t\t: 0x%08" PRIx32 "\n",
481
       function,
482
       data_block->stored_checksum );
483
    }
484
    else if( ( file_type == LIBPFF_FILE_TYPE_64BIT )
485
          || ( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) )
486
    {
487
      libcnotify_printf(
488
       "%s: data checksum\t\t\t: 0x%08" PRIx32 "\n",
489
       function,
490
       data_block->stored_checksum );
491
492
      libcnotify_printf(
493
       "%s: back pointer\t\t\t: 0x%08" PRIx64 "\n",
494
       function,
495
       data_block_back_pointer );
496
    }
497
    if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE )
498
    {
499
      byte_stream_copy_to_uint16_little_endian(
500
       ( (pff_block_footer_64bit_4k_page_t *) data )->unknown1,
501
       value_16bit );
502
      libcnotify_printf(
503
       "%s: unknown1\t\t\t\t: 0x%04" PRIx16 "\n",
504
       function,
505
       value_16bit );
506
507
      libcnotify_printf(
508
       "%s: uncompressed data size\t\t: %" PRIu16 "\n",
509
       function,
510
       data_block->uncompressed_data_size );
511
512
      byte_stream_copy_to_uint32_little_endian(
513
       ( (pff_block_footer_64bit_4k_page_t *) data )->unknown2,
514
       value_32bit );
515
      libcnotify_printf(
516
       "%s: unknown2\t\t\t\t: 0x%08" PRIx32 "\n",
517
       function,
518
       value_32bit );
519
    }
520
    libcnotify_printf(
521
     "\n" );
522
  }
523
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
524
525
182k
  return( 1 );
526
182k
}
527
528
/* Reads the data block
529
 * Returns 1 if successful or -1 on error
530
 */
531
int libpff_data_block_read_file_io_handle(
532
     libpff_data_block_t *data_block,
533
     libbfio_handle_t *file_io_handle,
534
     off64_t file_offset,
535
     size32_t data_size,
536
     uint8_t file_type,
537
     libcerror_error_t **error )
538
185k
{
539
185k
  uint8_t *uncompressed_data            = NULL;
540
185k
  static char *function                 = "libpff_data_block_read_file_io_handle";
541
185k
  size_t data_block_footer_offset       = 0;
542
185k
  size_t uncompressed_data_size         = 0;
543
185k
  ssize_t read_count                    = 0;
544
185k
  uint64_t data_block_back_pointer      = 0;
545
185k
  uint32_t calculated_checksum          = 0;
546
185k
  uint32_t data_block_data_size         = 0;
547
185k
  uint32_t data_block_increment_size    = 0;
548
185k
  uint32_t data_block_footer_size       = 0;
549
185k
  uint32_t maximum_data_block_size      = 0;
550
551
#if defined( HAVE_VERBOSE_OUTPUT )
552
  size_t data_block_padding_size        = 0;
553
  uint32_t maximum_data_block_data_size = 0;
554
#endif
555
556
185k
  if( data_block == NULL )
557
0
  {
558
0
    libcerror_error_set(
559
0
     error,
560
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
561
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
562
0
     "%s: invalid data block.",
563
0
     function );
564
565
0
    return( -1 );
566
0
  }
567
185k
  if( data_block->data != NULL )
568
0
  {
569
0
    libcerror_error_set(
570
0
     error,
571
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
572
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
573
0
     "%s: invalid data block - data value already set.",
574
0
     function );
575
576
0
    return( -1 );
577
0
  }
578
185k
  if( ( file_type != LIBPFF_FILE_TYPE_32BIT )
579
157k
   && ( file_type != LIBPFF_FILE_TYPE_64BIT )
580
0
   && ( file_type != LIBPFF_FILE_TYPE_64BIT_4K_PAGE ) )
581
0
  {
582
0
    libcerror_error_set(
583
0
     error,
584
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
585
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
586
0
     "%s: unsupported file type.",
587
0
     function );
588
589
0
    return( -1 );
590
0
  }
591
#if UINT32_MAX > SSIZE_MAX
592
  if( data_size > (size32_t) SSIZE_MAX )
593
  {
594
    libcerror_error_set(
595
     error,
596
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
597
     LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
598
     "%s: data size value exceeds maximum.",
599
     function );
600
601
    return( -1 );
602
  }
603
#endif
604
185k
  if( data_size != 0 )
605
184k
  {
606
184k
    if( file_type == LIBPFF_FILE_TYPE_32BIT )
607
28.4k
    {
608
28.4k
      data_block_footer_size    = (uint32_t) sizeof( pff_block_footer_32bit_t );
609
28.4k
      data_block_increment_size = 64;
610
28.4k
      maximum_data_block_size   = 8192;
611
28.4k
    }
612
156k
    else if( file_type == LIBPFF_FILE_TYPE_64BIT )
613
156k
    {
614
156k
      data_block_footer_size    = (uint32_t) sizeof( pff_block_footer_64bit_t );
615
156k
      data_block_increment_size = 64;
616
156k
      maximum_data_block_size   = 8192;
617
156k
    }
618
0
    else if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE )
619
0
    {
620
0
      data_block_footer_size    = (uint32_t) sizeof( pff_block_footer_64bit_4k_page_t );
621
0
      data_block_increment_size = 512;
622
/* TODO: this value is currently assumed based on the 512 x 8 = 4k page */
623
0
      maximum_data_block_size   = 65536;
624
0
    }
625
#if defined( HAVE_VERBOSE_OUTPUT )
626
    maximum_data_block_data_size = maximum_data_block_size - data_block_footer_size;
627
#endif
628
184k
    data_block_data_size = (uint32_t) data_size / data_block_increment_size;
629
630
184k
    if( ( (uint32_t) data_size % data_block_increment_size ) != 0 )
631
75.3k
    {
632
75.3k
      data_block_data_size += 1;
633
75.3k
    }
634
184k
    data_block_data_size *= data_block_increment_size;
635
636
184k
    if( ( data_block_data_size - (uint32_t) data_size ) < data_block_footer_size )
637
118k
    {
638
118k
      data_block_data_size += data_block_increment_size;
639
118k
    }
640
184k
    if( ( data_block_data_size == 0 )
641
184k
     || ( data_block_data_size > maximum_data_block_size ) )
642
623
    {
643
623
      libcerror_error_set(
644
623
       error,
645
623
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
646
623
       LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
647
623
       "%s: invalid data block data size value out of bounds.",
648
623
       function );
649
650
623
      goto on_error;
651
623
    }
652
183k
    data_block->data = (uint8_t *) memory_allocate(
653
183k
                                    sizeof( uint8_t ) * data_block_data_size );
654
655
183k
    if( data_block->data == NULL )
656
0
    {
657
0
      libcerror_error_set(
658
0
       error,
659
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
660
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
661
0
       "%s: unable to create data block data.",
662
0
       function );
663
664
0
      goto on_error;
665
0
    }
666
183k
    data_block->data_size = data_block_data_size;
667
668
#if defined( HAVE_DEBUG_OUTPUT )
669
    if( libcnotify_verbose != 0 )
670
    {
671
      libcnotify_printf(
672
       "%s: reading data block at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
673
       function,
674
       file_offset,
675
       file_offset );
676
    }
677
#endif
678
183k
    read_count = libbfio_handle_read_buffer_at_offset(
679
183k
                  file_io_handle,
680
183k
                  data_block->data,
681
183k
                  data_block->data_size,
682
183k
                  file_offset,
683
183k
                  error );
684
685
183k
    if( read_count != (ssize_t) data_block->data_size )
686
1.17k
    {
687
1.17k
      libcerror_error_set(
688
1.17k
       error,
689
1.17k
       LIBCERROR_ERROR_DOMAIN_IO,
690
1.17k
       LIBCERROR_IO_ERROR_READ_FAILED,
691
1.17k
       "%s: unable to read data block data at offset: %" PRIi64 " (0x%08" PRIx64 ").",
692
1.17k
       function,
693
1.17k
       file_offset,
694
1.17k
       file_offset );
695
696
1.17k
      goto on_error;
697
1.17k
    }
698
182k
    data_block_footer_offset = data_block->data_size - data_block_footer_size;
699
700
#if defined( HAVE_DEBUG_OUTPUT )
701
    if( libcnotify_verbose != 0 )
702
    {
703
      data_block_padding_size = data_block_footer_offset - data_size;
704
705
      libcnotify_printf(
706
       "%s: data block padding size\t\t: %" PRIzd "\n",
707
       function,
708
       data_block_padding_size );
709
710
      libcnotify_printf(
711
       "%s: data block padding:\n",
712
       function );
713
      libcnotify_print_data(
714
       &( data_block->data[ data_size ] ),
715
       data_block_padding_size,
716
       LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
717
    }
718
#endif
719
182k
    if( libpff_data_block_read_footer_data(
720
182k
         data_block,
721
182k
         &( data_block->data[ data_block_footer_offset ] ),
722
182k
         data_block_footer_size,
723
182k
         file_type,
724
182k
         error ) != 1 )
725
0
    {
726
0
      libcerror_error_set(
727
0
       error,
728
0
       LIBCERROR_ERROR_DOMAIN_IO,
729
0
       LIBCERROR_IO_ERROR_READ_FAILED,
730
0
       "%s: unable to read data block footer.",
731
0
       function );
732
733
0
      goto on_error;
734
0
    }
735
#if defined( HAVE_VERBOSE_OUTPUT )
736
    if( libcnotify_verbose != 0 )
737
    {
738
      if( data_block->data_size > maximum_data_block_data_size )
739
      {
740
        libcnotify_printf(
741
         "%s: data size: %" PRIu32 " exceeds format specified maximum: %" PRIu32 ".\n",
742
         function,
743
         data_block->data_size,
744
                                 maximum_data_block_data_size );
745
      }
746
    }
747
#endif
748
182k
    if( file_type == LIBPFF_FILE_TYPE_64BIT_4K_PAGE )
749
0
    {
750
0
      if( ( data_block->data_size != 0 )
751
0
       && ( data_block->uncompressed_data_size != 0 )
752
0
       && ( data_block->data_size != data_block->uncompressed_data_size ) )
753
0
      {
754
0
        data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_COMPRESSED;
755
0
      }
756
0
    }
757
182k
    if( ( data_block->flags & LIBPFF_DATA_BLOCK_FLAG_VALIDATED ) == 0 )
758
182k
    {
759
182k
      if( data_block->data_size != 0 )
760
179k
      {
761
179k
        if( (size32_t) data_block->data_size != data_size )
762
506
        {
763
/* TODO flag size mismatch and error tollerance */
764
506
          data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_SIZE_MISMATCH;
765
766
506
          libcerror_error_set(
767
506
           error,
768
506
           LIBCERROR_ERROR_DOMAIN_INPUT,
769
506
           LIBCERROR_INPUT_ERROR_VALUE_MISMATCH,
770
506
           "%s: mismatch in data size ( %" PRIu32 " != %" PRIu32 " ).",
771
506
           function,
772
506
           data_block->data_size,
773
506
           data_size );
774
775
506
          goto on_error;
776
506
        }
777
179k
      }
778
182k
      if( data_block->stored_checksum != 0 )
779
153k
      {
780
153k
        if( libpff_checksum_calculate_weak_crc32(
781
153k
             &calculated_checksum,
782
153k
             data_block->data,
783
153k
             (size_t) data_size,
784
153k
             0,
785
153k
             error ) != 1 )
786
0
        {
787
0
          libcerror_error_set(
788
0
           error,
789
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
790
0
           LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
791
0
           "%s: unable to calculate weak CRC-32.",
792
0
           function );
793
794
0
          goto on_error;
795
0
        }
796
153k
        if( data_block->stored_checksum != calculated_checksum )
797
151k
        {
798
#if defined( HAVE_DEBUG_OUTPUT )
799
          if( libcnotify_verbose != 0 )
800
          {
801
            libcnotify_printf(
802
             "%s: mismatch in data block checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).\n",
803
             function,
804
             data_block->stored_checksum,
805
             calculated_checksum );
806
          }
807
#endif
808
151k
          data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_CRC_MISMATCH;
809
810
/* TODO smart error handling */
811
151k
        }
812
153k
      }
813
182k
      if( data_block_back_pointer != 0 )
814
0
      {
815
0
        if( data_block->data_identifier != data_block_back_pointer )
816
0
        {
817
#if defined( HAVE_DEBUG_OUTPUT )
818
          if( libcnotify_verbose != 0 )
819
          {
820
            libcnotify_printf(
821
             "%s: mismatch in data identifier: %" PRIu64 " (0x%08" PRIx64 ") and back pointer: 0x%08" PRIx64 ".\n",
822
             function,
823
             data_block->data_identifier,
824
             data_block->data_identifier,
825
             data_block_back_pointer );
826
          }
827
#endif
828
0
          data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_IDENTIFIER_MISMATCH;
829
830
/* TODO smart error handling */
831
0
        }
832
0
      }
833
182k
      data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_VALIDATED;
834
182k
    }
835
/* TODO refactor after testing */
836
182k
    if( ( data_block->flags & LIBPFF_DATA_BLOCK_FLAG_COMPRESSED ) != 0 )
837
0
    {
838
0
      uncompressed_data_size = (size_t) data_block->uncompressed_data_size;
839
840
0
      if( ( uncompressed_data_size == 0 )
841
0
       || ( uncompressed_data_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
842
0
      {
843
0
        libcerror_error_set(
844
0
         error,
845
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
846
0
         LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
847
0
         "%s: invalid uncompressed data size value out of bounds.",
848
0
         function );
849
850
0
        goto on_error;
851
0
      }
852
0
      uncompressed_data = (uint8_t *) memory_allocate(
853
0
                                       sizeof( uint8_t ) * uncompressed_data_size );
854
855
0
      if( uncompressed_data == NULL )
856
0
      {
857
0
        libcerror_error_set(
858
0
         error,
859
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
860
0
         LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
861
0
         "%s: unable to create uncompressed data.",
862
0
         function );
863
864
0
        goto on_error;
865
0
      }
866
0
      if( libpff_decompress_data(
867
0
           data_block->data,
868
0
           (size_t) data_block->data_size,
869
0
           LIBPFF_COMPRESSION_METHOD_DEFLATE,
870
0
           uncompressed_data,
871
0
           &uncompressed_data_size,
872
0
           error ) != 1 )
873
0
      {
874
0
        libcerror_error_set(
875
0
         error,
876
0
         LIBCERROR_ERROR_DOMAIN_COMPRESSION,
877
0
         LIBCERROR_COMPRESSION_ERROR_DECOMPRESS_FAILED,
878
0
         "%s: unable to decompress data block data.",
879
0
         function );
880
881
0
        goto on_error;
882
0
      }
883
0
      memory_free(
884
0
       data_block->data );
885
886
0
      data_block->data      = uncompressed_data;
887
0
      data_block->data_size = data_block->uncompressed_data_size;
888
0
      uncompressed_data     = NULL;
889
0
    }
890
182k
  }
891
183k
  return( 1 );
892
893
2.30k
on_error:
894
2.30k
  if( uncompressed_data != NULL )
895
0
  {
896
0
    memory_free(
897
0
     uncompressed_data );
898
0
  }
899
2.30k
  if( data_block->data != NULL )
900
1.68k
  {
901
1.68k
    memory_free(
902
1.68k
     data_block->data );
903
904
1.68k
    data_block->data = NULL;
905
1.68k
  }
906
2.30k
  data_block->data_size = 0;
907
908
2.30k
  return( -1 );
909
185k
}
910
911
/* Reads the data block element data
912
 * Callback for the descriptor data list
913
 * Returns the number of bytes read if successful or -1 on error
914
 */
915
int libpff_data_block_read_element_data(
916
     libpff_data_block_t *data_block,
917
     libbfio_handle_t *file_io_handle,
918
     libfdata_list_element_t *list_element,
919
     libfcache_cache_t *cache,
920
     int element_file_index LIBPFF_ATTRIBUTE_UNUSED,
921
     off64_t element_offset,
922
     size64_t element_size,
923
     uint32_t element_flags LIBPFF_ATTRIBUTE_UNUSED,
924
     uint8_t read_flags,
925
     libcerror_error_t **error )
926
1
{
927
1
  static char *function = "libpff_data_block_read_element_data";
928
929
1
  LIBPFF_UNREFERENCED_PARAMETER( element_file_index )
930
1
  LIBPFF_UNREFERENCED_PARAMETER( element_flags )
931
932
1
  if( data_block == NULL )
933
0
  {
934
0
    libcerror_error_set(
935
0
     error,
936
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
937
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
938
0
     "%s: invalid data block.",
939
0
     function );
940
941
0
    return( -1 );
942
0
  }
943
1
  if( data_block->io_handle == NULL )
944
0
  {
945
0
    libcerror_error_set(
946
0
     error,
947
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
948
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
949
0
     "%s: invalid data block - missing IO handle.",
950
0
     function );
951
952
0
    return( -1 );
953
0
  }
954
1
  if( element_size > (size64_t) UINT32_MAX )
955
0
  {
956
0
    libcerror_error_set(
957
0
     error,
958
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
959
0
     LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
960
0
     "%s: invalid element size value exceeds maximum.\n",
961
0
     function );
962
963
0
    return( -1 );
964
0
  }
965
1
  if( data_block->data == NULL )
966
0
  {
967
0
    if( libpff_data_block_read_file_io_handle(
968
0
         data_block,
969
0
         file_io_handle,
970
0
         element_offset,
971
0
         (size32_t) element_size,
972
0
         data_block->io_handle->file_type,
973
0
         error ) != 1 )
974
0
    {
975
0
      libcerror_error_set(
976
0
       error,
977
0
       LIBCERROR_ERROR_DOMAIN_IO,
978
0
       LIBCERROR_IO_ERROR_READ_FAILED,
979
0
       "%s: unable to read data block data.",
980
0
       function );
981
982
0
      return( -1 );
983
0
    }
984
0
    if( libpff_data_block_decrypt_data(
985
0
         data_block,
986
0
         read_flags,
987
0
         error ) != 1 )
988
0
    {
989
0
      libcerror_error_set(
990
0
       error,
991
0
       LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
992
0
       LIBCERROR_ENCRYPTION_ERROR_DECRYPT_FAILED,
993
0
       "%s: unable to decrypt data block data.",
994
0
       function );
995
996
0
      return( -1 );
997
0
    }
998
0
  }
999
  /* The data block is managed by the list and should not be managed by the cache as well
1000
   */
1001
1
  if( libfdata_list_element_set_element_value(
1002
1
       list_element,
1003
1
       (intptr_t *) file_io_handle,
1004
1
       (libfdata_cache_t *) cache,
1005
1
       (intptr_t *) data_block,
1006
1
       (int (*)(intptr_t **, libcerror_error_t **)) &libpff_data_block_free,
1007
1
       LIBFDATA_LIST_ELEMENT_VALUE_FLAG_NON_MANAGED,
1008
1
       error ) != 1 )
1009
0
  {
1010
0
    libcerror_error_set(
1011
0
     error,
1012
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1013
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1014
0
     "%s: unable to set data block as element value.",
1015
0
     function );
1016
1017
0
    return( -1 );
1018
0
  }
1019
1
  return( 1 );
1020
1
}
1021
1022
/* Decrypts the data block data
1023
 * Returns 1 if successful or -1 on error
1024
 */
1025
int libpff_data_block_decrypt_data(
1026
     libpff_data_block_t *data_block,
1027
     uint8_t read_flags,
1028
     libcerror_error_t **error )
1029
7.44k
{
1030
7.44k
  static char *function        = "libpff_data_block_decrypt_data";
1031
7.44k
  ssize_t process_count        = 0;
1032
7.44k
  uint8_t decrypt_data         = 0;
1033
7.44k
  uint8_t encryption_type      = 0;
1034
7.44k
  uint8_t force_decryption     = 0;
1035
7.44k
  uint8_t node_identifier_type = 0;
1036
7.44k
  uint8_t node_contains_table  = 0;
1037
1038
7.44k
  if( data_block == NULL )
1039
0
  {
1040
0
    libcerror_error_set(
1041
0
     error,
1042
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1043
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1044
0
     "%s: invalid data block.",
1045
0
     function );
1046
1047
0
    return( -1 );
1048
0
  }
1049
7.44k
  if( data_block->io_handle == NULL )
1050
0
  {
1051
0
    libcerror_error_set(
1052
0
     error,
1053
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1054
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1055
0
     "%s: invalid data block - missing IO handle.",
1056
0
     function );
1057
1058
0
    return( -1 );
1059
0
  }
1060
7.44k
  if( data_block->data == NULL )
1061
0
  {
1062
0
    libcerror_error_set(
1063
0
     error,
1064
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1065
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1066
0
     "%s: invalid data block - missing data.",
1067
0
     function );
1068
1069
0
    return( -1 );
1070
0
  }
1071
7.44k
  encryption_type = data_block->io_handle->encryption_type;
1072
1073
  /* Check if internal (unencrypted) flag in the (data) offset index identifier is not set
1074
   */
1075
7.44k
  if( ( data_block->data_identifier & LIBPFF_OFFSET_INDEX_IDENTIFIER_FLAG_INTERNAL ) == 0 )
1076
6.16k
  {
1077
6.16k
    decrypt_data = 1;
1078
6.16k
  }
1079
  /* Check if data is encrypted
1080
   * Some 'invalid' files have an encryption type of none but contain encrypted data
1081
   * Although they are considered invalid by Outlook it is still possilble to read them
1082
   */
1083
7.44k
  if( ( encryption_type == LIBPFF_ENCRYPTION_TYPE_NONE )
1084
3.94k
   && ( ( read_flags & LIBPFF_READ_FLAG_IGNORE_FORCE_DECRYPTION ) == 0 )
1085
3.94k
   && ( data_block->data_size > 4 ) )
1086
3.63k
  {
1087
3.63k
    node_identifier_type = (uint8_t) ( data_block->descriptor_identifier & 0x0000001fUL );
1088
1089
    /* Check if the node identifier type consists of a table
1090
     */
1091
3.63k
    if( ( ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_INTERNAL )
1092
2.67k
      && ( ( data_block->descriptor_identifier == LIBPFF_DESCRIPTOR_IDENTIFIER_MESSAGE_STORE )
1093
2.67k
        || ( data_block->descriptor_identifier == LIBPFF_DESCRIPTOR_IDENTIFIER_NAME_TO_ID_MAP )
1094
4
        || ( data_block->descriptor_identifier == LIBPFF_DESCRIPTOR_IDENTIFIER_UNKNOWN_2049 )
1095
4
        || ( data_block->descriptor_identifier == LIBPFF_DESCRIPTOR_IDENTIFIER_UNKNOWN_2081 )
1096
4
        || ( data_block->descriptor_identifier == LIBPFF_DESCRIPTOR_IDENTIFIER_UNKNOWN_2113 )
1097
4
        || ( data_block->descriptor_identifier == LIBPFF_DESCRIPTOR_IDENTIFIER_UNKNOWN_3073 ) ) )
1098
969
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_FOLDER )
1099
967
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_SEARCH_FOLDER )
1100
958
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_MESSAGE )
1101
956
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_ASSOCIATED_CONTENT )
1102
933
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_SUB_FOLDERS )
1103
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_SUB_MESSAGES )
1104
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_SUB_ASSOCIATED_CONTENTS )
1105
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_SEARCH_CONTENTS_TABLE )
1106
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_ATTACHMENTS )
1107
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_RECIPIENTS )
1108
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_UNKNOWN_1718 )
1109
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_UNKNOWN_1751 )
1110
931
     || ( node_identifier_type == LIBPFF_NODE_IDENTIFIER_TYPE_UNKNOWN_1784 ) )
1111
2.70k
    {
1112
2.70k
      node_contains_table = 1;
1113
2.70k
    }
1114
3.63k
    if( node_contains_table != 0 )
1115
2.70k
    {
1116
      /* Test if the data contains an unencrypted table
1117
       * a table consists of 0xec in the third byte
1118
       * and 0x6c, 0x7c, 0x8c, 0x9c, 0xa5, 0xac, 0xbc, 0xcc in the fourth
1119
       */
1120
2.70k
      if( ( data_block->data[ 2 ] != 0xec )
1121
487
       || ( ( data_block->data[ 3 ] != 0x6c )
1122
474
        &&  ( data_block->data[ 3 ] != 0x7c )
1123
394
        &&  ( data_block->data[ 3 ] != 0x8c )
1124
365
        &&  ( data_block->data[ 3 ] != 0x9c )
1125
351
        &&  ( data_block->data[ 3 ] != 0xa5 )
1126
186
        &&  ( data_block->data[ 3 ] != 0xac )
1127
159
        &&  ( data_block->data[ 3 ] != 0xbc )
1128
87
        &&  ( data_block->data[ 3 ] != 0xcc ) ) )
1129
2.30k
      {
1130
#if defined( HAVE_DEBUG_OUTPUT )
1131
        if( libcnotify_verbose != 0 )
1132
        {
1133
          libcnotify_printf(
1134
           "%s: table signature missing trying to force decryption.\n",
1135
           function );
1136
        }
1137
#endif
1138
2.30k
        force_decryption   = 1;
1139
2.30k
        encryption_type    = LIBPFF_ENCRYPTION_TYPE_COMPRESSIBLE;
1140
2.30k
        decrypt_data       = 1;
1141
2.30k
        data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_DECRYPTION_FORCED;
1142
2.30k
      }
1143
2.70k
    }
1144
931
    else if( data_block->io_handle->force_decryption == 1 )
1145
212
    {
1146
      /* Check if the internal (unencrypted) flag in (data) offset index identifier is not set
1147
       */
1148
212
      if( ( data_block->data_identifier & LIBPFF_OFFSET_INDEX_IDENTIFIER_FLAG_INTERNAL ) == 0 )
1149
97
      {
1150
#if defined( HAVE_DEBUG_OUTPUT )
1151
        if( libcnotify_verbose != 0 )
1152
        {
1153
          libcnotify_printf(
1154
           "%s: decryption forced.\n",
1155
           function );
1156
        }
1157
#endif
1158
97
        encryption_type    = LIBPFF_ENCRYPTION_TYPE_COMPRESSIBLE;
1159
97
        decrypt_data       = 1;
1160
97
        data_block->flags |= LIBPFF_DATA_BLOCK_FLAG_DECRYPTION_FORCED;
1161
97
      }
1162
212
    }
1163
3.63k
  }
1164
7.44k
  if( decrypt_data != 0 )
1165
6.19k
  {
1166
6.19k
    process_count = libpff_encryption_decrypt(
1167
6.19k
         encryption_type,
1168
6.19k
         (uint32_t) data_block->data_identifier,
1169
6.19k
         data_block->data,
1170
6.19k
         (size_t) data_block->data_size,
1171
6.19k
         error );
1172
1173
6.19k
    if( process_count != (ssize_t) data_block->data_size )
1174
0
    {
1175
0
      libcerror_error_set(
1176
0
       error,
1177
0
       LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
1178
0
       LIBCERROR_ENCRYPTION_ERROR_DECRYPT_FAILED,
1179
0
       "%s: unable to decrypt data block data.",
1180
0
       function );
1181
1182
0
      return( -1 );
1183
0
    }
1184
6.19k
    if( force_decryption != 0 )
1185
2.30k
    {
1186
      /* Test if the data contains an unencrypted table
1187
       * a table consists of 0xec in the third byte
1188
       * and 0x6c, 0x7c, 0x8c, 0x9c, 0xa5, 0xac, 0xbc, 0xcc in the fourth
1189
       */
1190
2.30k
      if( ( data_block->data[ 2 ] == 0xec )
1191
2.13k
       && ( ( data_block->data[ 3 ] == 0x6c )
1192
2.12k
        ||  ( data_block->data[ 3 ] == 0x7c )
1193
513
        ||  ( data_block->data[ 3 ] == 0x8c )
1194
460
        ||  ( data_block->data[ 3 ] == 0x9c )
1195
457
        ||  ( data_block->data[ 3 ] == 0xa5 )
1196
454
        ||  ( data_block->data[ 3 ] == 0xac )
1197
451
        ||  ( data_block->data[ 3 ] == 0xbc )
1198
93
        ||  ( data_block->data[ 3 ] == 0xcc ) ) )
1199
2.04k
      {
1200
#if defined( HAVE_DEBUG_OUTPUT )
1201
        if( libcnotify_verbose != 0 )
1202
        {
1203
          libcnotify_printf(
1204
           "%s: compressible encrypted data detected while encryption type is none - decryption forced.\n",
1205
           function );
1206
        }
1207
#endif
1208
2.04k
        data_block->io_handle->force_decryption = 1;
1209
2.04k
      }
1210
2.30k
    }
1211
6.19k
  }
1212
7.44k
  return( 1 );
1213
7.44k
}
1214