Coverage Report

Created: 2026-07-25 07:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libcreg/libcreg/libcreg_data_block.c
Line
Count
Source
1
/*
2
 * Data block functions
3
 *
4
 * Copyright (C) 2013-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 "libcreg_data_block.h"
28
#include "libcreg_key_name_entry.h"
29
#include "libcreg_libbfio.h"
30
#include "libcreg_libcdata.h"
31
#include "libcreg_libcerror.h"
32
#include "libcreg_libcnotify.h"
33
#include "libcreg_unused.h"
34
35
#include "creg_data_block.h"
36
37
const char *creg_data_block_signature = "RGDB";
38
39
/* Creates a data block
40
 * Make sure the value data_block is referencing, is set to NULL
41
 * Returns 1 if successful or -1 on error
42
 */
43
int libcreg_data_block_initialize(
44
     libcreg_data_block_t **data_block,
45
     libcerror_error_t **error )
46
2.64M
{
47
2.64M
  static char *function = "libcreg_data_block_initialize";
48
49
2.64M
  if( data_block == NULL )
50
0
  {
51
0
    libcerror_error_set(
52
0
     error,
53
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
54
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
55
0
     "%s: invalid data block.",
56
0
     function );
57
58
0
    return( -1 );
59
0
  }
60
2.64M
  if( *data_block != NULL )
61
0
  {
62
0
    libcerror_error_set(
63
0
     error,
64
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
65
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
66
0
     "%s: invalid data block value already set.",
67
0
     function );
68
69
0
    return( -1 );
70
0
  }
71
2.64M
  *data_block = memory_allocate_structure(
72
2.64M
                 libcreg_data_block_t );
73
74
2.64M
  if( *data_block == NULL )
75
0
  {
76
0
    libcerror_error_set(
77
0
     error,
78
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
79
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
80
0
     "%s: unable to create data block.",
81
0
     function );
82
83
0
    goto on_error;
84
0
  }
85
2.64M
  if( memory_set(
86
2.64M
       *data_block,
87
2.64M
       0,
88
2.64M
       sizeof( libcreg_data_block_t ) ) == NULL )
89
0
  {
90
0
    libcerror_error_set(
91
0
     error,
92
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
93
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
94
0
     "%s: unable to clear data block.",
95
0
     function );
96
97
0
    memory_free(
98
0
     *data_block );
99
100
0
    *data_block = NULL;
101
102
0
    return( -1 );
103
0
  }
104
2.64M
  if( libcdata_array_initialize(
105
2.64M
       &( ( *data_block )->entries_array ),
106
2.64M
       0,
107
2.64M
       error ) != 1 )
108
0
  {
109
0
    libcerror_error_set(
110
0
     error,
111
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
112
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
113
0
     "%s: unable to create entries array.",
114
0
     function );
115
116
0
    goto on_error;
117
0
  }
118
2.64M
  return( 1 );
119
120
0
on_error:
121
0
  if( *data_block != NULL )
122
0
  {
123
0
    memory_free(
124
0
     *data_block );
125
126
0
    *data_block = NULL;
127
0
  }
128
0
  return( -1 );
129
2.64M
}
130
131
/* Frees a data block
132
 * Returns 1 if successful or -1 on error
133
 */
134
int libcreg_data_block_free(
135
     libcreg_data_block_t **data_block,
136
     libcerror_error_t **error )
137
2.64M
{
138
2.64M
  static char *function = "libcreg_data_block_free";
139
2.64M
  int result            = 1;
140
141
2.64M
  if( data_block == NULL )
142
0
  {
143
0
    libcerror_error_set(
144
0
     error,
145
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
146
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
147
0
     "%s: invalid data block.",
148
0
     function );
149
150
0
    return( -1 );
151
0
  }
152
2.64M
  if( *data_block != NULL )
153
2.64M
  {
154
2.64M
    if( libcdata_array_free(
155
2.64M
         &( ( *data_block )->entries_array ),
156
2.64M
         (int (*)(intptr_t **, libcerror_error_t **)) &libcreg_key_name_entry_free,
157
2.64M
         error ) != 1 )
158
0
    {
159
0
      libcerror_error_set(
160
0
       error,
161
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
162
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
163
0
       "%s: unable to free the entries array.",
164
0
       function );
165
166
0
      result = -1;
167
0
    }
168
2.64M
    if( ( *data_block )->data != NULL )
169
114
    {
170
114
      memory_free(
171
114
       ( *data_block )->data );
172
114
    }
173
2.64M
    memory_free(
174
2.64M
     *data_block );
175
176
2.64M
    *data_block = NULL;
177
2.64M
  }
178
2.64M
  return( result );
179
2.64M
}
180
181
/* Reads a data block header
182
 * Returns 1 if successful, 0 if no data block signature was found or -1 on error
183
 */
184
int libcreg_data_block_read_header(
185
     libcreg_data_block_t *data_block,
186
     libbfio_handle_t *file_io_handle,
187
     off64_t file_offset,
188
     libcerror_error_t **error )
189
2.64M
{
190
2.64M
  creg_data_block_header_t data_block_header;
191
192
2.64M
  static char *function = "libcreg_data_block_read_header";
193
2.64M
  ssize_t read_count    = 0;
194
195
#if defined( HAVE_DEBUG_OUTPUT )
196
  uint16_t value_16bit  = 0;
197
#endif
198
199
2.64M
  if( data_block == NULL )
200
0
  {
201
0
    libcerror_error_set(
202
0
     error,
203
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
204
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
205
0
     "%s: invalid data block.",
206
0
     function );
207
208
0
    return( -1 );
209
0
  }
210
2.64M
  data_block->offset = file_offset;
211
212
#if defined( HAVE_DEBUG_OUTPUT )
213
  if( libcnotify_verbose != 0 )
214
  {
215
    libcnotify_printf(
216
     "%s: reading data block header at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
217
     function,
218
     file_offset,
219
     file_offset );
220
  }
221
#endif
222
2.64M
  read_count = libbfio_handle_read_buffer_at_offset(
223
2.64M
                file_io_handle,
224
2.64M
                (uint8_t *) &data_block_header,
225
2.64M
                sizeof( creg_data_block_header_t ),
226
2.64M
                file_offset,
227
2.64M
                error );
228
229
2.64M
  if( read_count != (ssize_t) sizeof( creg_data_block_header_t ) )
230
198
  {
231
198
    libcerror_error_set(
232
198
     error,
233
198
     LIBCERROR_ERROR_DOMAIN_IO,
234
198
     LIBCERROR_IO_ERROR_READ_FAILED,
235
198
     "%s: unable to read data block header data at offset: %" PRIi64 " (0x%08" PRIx64 ").",
236
198
     function,
237
198
     file_offset,
238
198
     file_offset );
239
240
198
    return( -1 );
241
198
  }
242
#if defined( HAVE_DEBUG_OUTPUT )
243
  if( libcnotify_verbose != 0 )
244
  {
245
    libcnotify_printf(
246
     "%s: data block header:\n",
247
     function );
248
    libcnotify_print_data(
249
     (uint8_t *) &data_block_header,
250
     sizeof( creg_data_block_header_t ),
251
     0 );
252
  }
253
#endif
254
2.64M
  if( memory_compare(
255
2.64M
       data_block_header.signature,
256
2.64M
       creg_data_block_signature,
257
2.64M
       4 ) != 0 )
258
274
  {
259
274
    return( 0 );
260
274
  }
261
2.64M
  byte_stream_copy_to_uint32_little_endian(
262
2.64M
   data_block_header.size,
263
2.64M
   data_block->size );
264
265
2.64M
  byte_stream_copy_to_uint32_little_endian(
266
2.64M
   data_block_header.unused_size,
267
2.64M
   data_block->unused_size );
268
269
2.64M
  byte_stream_copy_to_uint32_little_endian(
270
2.64M
   data_block_header.used_size,
271
2.64M
   data_block->used_size );
272
273
#if defined( HAVE_DEBUG_OUTPUT )
274
  if( libcnotify_verbose != 0 )
275
  {
276
    libcnotify_printf(
277
     "%s: signature\t\t\t\t: %c%c%c%c\n",
278
     function,
279
     data_block_header.signature[ 0 ],
280
     data_block_header.signature[ 1 ],
281
     data_block_header.signature[ 2 ],
282
     data_block_header.signature[ 3 ] );
283
284
    libcnotify_printf(
285
     "%s: size\t\t\t\t\t: %" PRIu32 "\n",
286
     function,
287
     data_block->size );
288
289
    libcnotify_printf(
290
     "%s: unused size\t\t\t\t: %" PRIu32 "\n",
291
     function,
292
     data_block->unused_size );
293
294
    byte_stream_copy_to_uint16_little_endian(
295
     data_block_header.unknown1,
296
     value_16bit );
297
    libcnotify_printf(
298
     "%s: unknown1\t\t\t\t: 0x%04" PRIx16 "\n",
299
     function,
300
     value_16bit );
301
302
    byte_stream_copy_to_uint16_little_endian(
303
     data_block_header.index,
304
     value_16bit );
305
    libcnotify_printf(
306
     "%s: index\t\t\t\t\t: %" PRIu16 "\n",
307
     function,
308
     value_16bit );
309
310
    libcnotify_printf(
311
     "%s: used size\t\t\t\t: %" PRIi32 "\n",
312
     function,
313
     (int32_t) data_block->used_size );
314
315
    byte_stream_copy_to_uint16_little_endian(
316
     data_block_header.unknown2,
317
     value_16bit );
318
    libcnotify_printf(
319
     "%s: unknown2\t\t\t\t: %" PRIu16 "\n",
320
     function,
321
     value_16bit );
322
323
    byte_stream_copy_to_uint16_little_endian(
324
     data_block_header.unknown3,
325
     value_16bit );
326
    libcnotify_printf(
327
     "%s: unknown3\t\t\t\t: %" PRIu16 "\n",
328
     function,
329
     value_16bit );
330
331
    libcnotify_printf(
332
     "%s: unknown3:\n",
333
     function );
334
    libcnotify_print_data(
335
     data_block_header.unknown4,
336
     8,
337
     0 );
338
  }
339
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
340
341
/* TODO check if unused_size + used_size == size */
342
2.64M
  return( 1 );
343
2.64M
}
344
345
/* Reads a data block and determines its entries
346
 * Returns 1 if successful or -1 on error
347
 */
348
int libcreg_data_block_read_entries(
349
     libcreg_data_block_t *data_block,
350
     libbfio_handle_t *file_io_handle,
351
     int ascii_codepage,
352
     libcerror_error_t **error )
353
967
{
354
967
  libcreg_key_name_entry_t *key_name_entry = NULL;
355
967
  static char *function                    = "libcreg_data_block_read_entries";
356
967
  size_t data_offset                       = 0;
357
967
  size_t key_name_entry_size               = 0;
358
967
  ssize_t read_count                       = 0;
359
967
  int entry_index                          = 0;
360
967
  int result                               = 0;
361
362
967
  if( data_block == NULL )
363
0
  {
364
0
    libcerror_error_set(
365
0
     error,
366
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
367
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
368
0
     "%s: invalid data block.",
369
0
     function );
370
371
0
    return( -1 );
372
0
  }
373
967
  if( data_block->data != NULL )
374
0
  {
375
0
    libcerror_error_set(
376
0
     error,
377
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
378
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
379
0
     "%s: invalid data block - data already set.",
380
0
     function );
381
382
0
    return( -1 );
383
0
  }
384
967
  if( ( data_block->size == 0 )
385
967
   || ( data_block->size > (uint32_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
386
69
  {
387
69
    libcerror_error_set(
388
69
     error,
389
69
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
390
69
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
391
69
     "%s: invalid data block - size value out of bounds.",
392
69
     function );
393
394
69
    return( -1 );
395
69
  }
396
898
  data_block->data_size = (size_t) data_block->size - sizeof( creg_data_block_header_t );
397
398
898
  data_block->data = (uint8_t *) memory_allocate(
399
898
                                  sizeof( uint8_t ) * data_block->data_size );
400
401
898
  if( data_block->data == NULL )
402
7
  {
403
7
    libcerror_error_set(
404
7
     error,
405
7
     LIBCERROR_ERROR_DOMAIN_MEMORY,
406
7
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
407
7
     "%s: unable to create data block data.",
408
7
     function );
409
410
7
    goto on_error;
411
7
  }
412
891
  read_count = libbfio_handle_read_buffer(
413
891
                file_io_handle,
414
891
                data_block->data,
415
891
                data_block->data_size,
416
891
                error );
417
418
891
  if( read_count != (ssize_t) data_block->data_size )
419
146
  {
420
146
    libcerror_error_set(
421
146
     error,
422
146
     LIBCERROR_ERROR_DOMAIN_IO,
423
146
     LIBCERROR_IO_ERROR_READ_FAILED,
424
146
     "%s: unable to read data block data.",
425
146
     function );
426
427
146
    goto on_error;
428
146
  }
429
4.90k
  while( data_offset < data_block->data_size )
430
4.79k
  {
431
4.79k
    if( libcreg_key_name_entry_initialize(
432
4.79k
         &key_name_entry,
433
4.79k
         error ) != 1 )
434
0
    {
435
0
      libcerror_error_set(
436
0
       error,
437
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
438
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
439
0
       "%s: unable to create key name entry.",
440
0
       function );
441
442
0
      goto on_error;
443
0
    }
444
4.79k
    key_name_entry->offset = data_block->offset + sizeof( creg_data_block_header_t ) + data_offset;
445
446
#if defined( HAVE_DEBUG_OUTPUT )
447
    if( libcnotify_verbose != 0 )
448
    {
449
      libcnotify_printf(
450
       "%s: reading key name entry at offset: %" PRIu32 " (0x%08" PRIx32 ")\n",
451
       function,
452
       key_name_entry->offset,
453
       key_name_entry->offset );
454
    }
455
#endif
456
4.79k
    result = libcreg_key_name_entry_read_data(
457
4.79k
              key_name_entry,
458
4.79k
              &( ( data_block->data )[ data_offset ] ),
459
4.79k
              data_block->data_size - data_offset,
460
4.79k
              ascii_codepage,
461
4.79k
              error );
462
463
4.79k
    if( result == -1 )
464
631
    {
465
631
      libcerror_error_set(
466
631
       error,
467
631
       LIBCERROR_ERROR_DOMAIN_IO,
468
631
       LIBCERROR_IO_ERROR_READ_FAILED,
469
631
       "%s: unable to read key name entry at offset: %" PRIu32 " (0x%08" PRIx32 ").",
470
631
       function,
471
631
       key_name_entry->offset,
472
631
       key_name_entry->offset );
473
474
631
      goto on_error;
475
631
    }
476
4.16k
    key_name_entry_size = key_name_entry->size;
477
478
4.16k
    if( result == 0 )
479
532
    {
480
532
      if( key_name_entry_size <= ( data_block->data_size - data_offset ) )
481
532
      {
482
532
        result = 1;
483
532
      }
484
532
      if( libcreg_key_name_entry_free(
485
532
           &key_name_entry,
486
532
           error ) != 1 )
487
0
      {
488
0
        libcerror_error_set(
489
0
         error,
490
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
491
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
492
0
         "%s: unable to free key name entry.",
493
0
         function );
494
495
0
        goto on_error;
496
0
      }
497
532
    }
498
4.16k
    if( result == 0 )
499
0
    {
500
0
      break;
501
0
    }
502
4.16k
    data_offset += key_name_entry_size;
503
504
4.16k
    if( key_name_entry != NULL )
505
3.62k
    {
506
3.62k
      if( libcdata_array_append_entry(
507
3.62k
           data_block->entries_array,
508
3.62k
           &entry_index,
509
3.62k
           (intptr_t *) key_name_entry,
510
3.62k
           error ) != 1 )
511
0
      {
512
0
        libcerror_error_set(
513
0
         error,
514
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
515
0
         LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
516
0
         "%s: unable to append key name entry: %d.",
517
0
         function,
518
0
         key_name_entry );
519
520
0
        goto on_error;
521
0
      }
522
3.62k
      key_name_entry = NULL;
523
3.62k
    }
524
4.16k
  }
525
#if defined( HAVE_DEBUG_OUTPUT )
526
  if( libcnotify_verbose != 0 )
527
  {
528
    if( data_offset < data_block->data_size )
529
    {
530
      libcnotify_printf(
531
       "%s: trailing data:\n",
532
       function );
533
      libcnotify_print_data(
534
       &( ( data_block->data )[ data_offset ] ),
535
       data_block->data_size - data_offset,
536
       LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
537
    }
538
    else
539
    {
540
      libcnotify_printf(
541
       "\n" );
542
    }
543
  }
544
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
545
546
114
  return( 1 );
547
548
784
on_error:
549
784
  if( key_name_entry != NULL )
550
631
  {
551
631
    libcreg_key_name_entry_free(
552
631
     &key_name_entry,
553
631
     NULL );
554
631
  }
555
784
  if( data_block->entries_array != NULL )
556
784
  {
557
784
    libcdata_array_clear(
558
784
     data_block->entries_array,
559
784
     (int (*)(intptr_t **, libcerror_error_t **)) &libcreg_key_name_entry_free,
560
784
     NULL );
561
784
  }
562
784
  if( data_block->data != NULL )
563
777
  {
564
777
    memory_free(
565
777
     data_block->data );
566
567
777
    data_block->data = NULL;
568
777
  }
569
784
  data_block->data_size = 0;
570
571
784
  return( -1 );
572
745
}
573
574
/* Retrieves the number of key name entries
575
 * Returns 1 if successful or -1 on error
576
 */
577
int libcreg_data_block_get_number_of_entries(
578
     libcreg_data_block_t *data_block,
579
     int *number_of_entries,
580
     libcerror_error_t **error )
581
0
{
582
0
  static char *function = "libcreg_data_block_get_number_of_entries";
583
584
0
  if( data_block == NULL )
585
0
  {
586
0
    libcerror_error_set(
587
0
     error,
588
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
589
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
590
0
     "%s: invalid data block.",
591
0
     function );
592
593
0
    return( -1 );
594
0
  }
595
0
  if( libcdata_array_get_number_of_entries(
596
0
       data_block->entries_array,
597
0
       number_of_entries,
598
0
       error ) != 1 )
599
0
  {
600
0
    libcerror_error_set(
601
0
     error,
602
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
603
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
604
0
     "%s: unable to retrieve number of entries.",
605
0
     function );
606
607
0
    return( -1 );
608
0
  }
609
0
  return( 1 );
610
0
}
611
612
/* Retrieves a specific key name entry
613
 * Returns 1 if successful, 0 if no such entry or -1 on error
614
 */
615
int libcreg_data_block_get_entry_by_identifier(
616
     libcreg_data_block_t *data_block,
617
     uint16_t identifier,
618
     libcreg_key_name_entry_t **key_name_entry,
619
     int ascii_codepage LIBCREG_ATTRIBUTE_UNUSED,
620
     libcerror_error_t **error )
621
132
{
622
132
  libcreg_key_name_entry_t *safe_key_name_entry = NULL;
623
132
  static char *function                         = "libcreg_data_block_get_entry_by_identifier";
624
132
  int entry_index                               = 0;
625
132
  int number_of_entries                         = 0;
626
627
132
  LIBCREG_UNREFERENCED_PARAMETER( ascii_codepage )
628
629
132
  if( data_block == NULL )
630
0
  {
631
0
    libcerror_error_set(
632
0
     error,
633
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
634
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
635
0
     "%s: invalid data block.",
636
0
     function );
637
638
0
    return( -1 );
639
0
  }
640
132
  if( data_block->data == NULL )
641
0
  {
642
0
    libcerror_error_set(
643
0
     error,
644
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
645
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
646
0
     "%s: invalid data block - missing data.",
647
0
     function );
648
649
0
    return( -1 );
650
0
  }
651
132
  if( key_name_entry == NULL )
652
0
  {
653
0
    libcerror_error_set(
654
0
     error,
655
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
656
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
657
0
     "%s: invalid key name entry.",
658
0
     function );
659
660
0
    return( -1 );
661
0
  }
662
132
  if( libcdata_array_get_number_of_entries(
663
132
       data_block->entries_array,
664
132
       &number_of_entries,
665
132
       error ) != 1 )
666
0
  {
667
0
    libcerror_error_set(
668
0
     error,
669
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
670
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
671
0
     "%s: unable to retrieve number of entries.",
672
0
     function );
673
674
0
    return( -1 );
675
0
  }
676
132
  for( entry_index = 0;
677
1.52k
       entry_index < number_of_entries;
678
1.39k
       entry_index++ )
679
1.44k
  {
680
1.44k
    if( libcdata_array_get_entry_by_index(
681
1.44k
         data_block->entries_array,
682
1.44k
         entry_index,
683
1.44k
         (intptr_t **) &safe_key_name_entry,
684
1.44k
         error ) != 1 )
685
0
    {
686
0
      libcerror_error_set(
687
0
       error,
688
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
689
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
690
0
       "%s: unable to retrieve key name entry: %d.",
691
0
       function,
692
0
       entry_index );
693
694
0
      return( -1 );
695
0
    }
696
1.44k
    if( safe_key_name_entry == NULL )
697
0
    {
698
0
      libcerror_error_set(
699
0
       error,
700
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
701
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
702
0
       "%s: invalid data block - missing key name entry: %d.",
703
0
       function,
704
0
       entry_index );
705
706
0
      return( -1 );
707
0
    }
708
1.44k
    if( safe_key_name_entry->index == identifier )
709
53
    {
710
53
      *key_name_entry = safe_key_name_entry;
711
712
53
      return( 1 );
713
53
    }
714
1.44k
  }
715
79
  return( 0 );
716
132
}
717