Coverage Report

Created: 2026-03-05 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libewf/libewf/libewf_case_data.c
Line
Count
Source
1
/*
2
 * Case data functions
3
 *
4
 * Copyright (C) 2006-2025, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <memory.h>
24
#include <narrow_string.h>
25
#include <types.h>
26
27
#include "libewf_case_data.h"
28
#include "libewf_definitions.h"
29
#include "libewf_header_values.h"
30
#include "libewf_libcerror.h"
31
#include "libewf_libcnotify.h"
32
#include "libewf_libfvalue.h"
33
#include "libewf_libuna.h"
34
#include "libewf_media_values.h"
35
#include "libewf_value_table.h"
36
37
/* Generate an UTF-8 encoded case data string
38
 * Sets utf8_string and utf8_string_size
39
 * Returns 1 if successful or -1 on error
40
 */
41
int libewf_case_data_generate_utf8_string(
42
     uint8_t **utf8_string,
43
     size_t *utf8_string_size,
44
     libewf_media_values_t *media_values,
45
     libfvalue_table_t *header_values,
46
     time_t timestamp,
47
     uint8_t format,
48
     libcerror_error_t **error )
49
0
{
50
0
  uint8_t *generated_acquiry_date               = NULL;
51
0
  uint8_t *generated_system_date                = NULL;
52
0
  uint8_t *safe_utf8_string                     = NULL;
53
0
  static char *function                         = "libewf_case_data_generate_utf8_string";
54
0
  const char *newline_string                    = "\n";
55
0
  size_t acquiry_date_string_length             = 0;
56
0
  size_t acquiry_operating_system_string_length = 0;
57
0
  size_t acquiry_software_version_string_length = 0;
58
0
  size_t case_number_string_length              = 0;
59
0
  size_t description_string_length              = 0;
60
0
  size_t error_granularity_string_length        = 0;
61
0
  size_t evidence_number_string_length          = 0;
62
0
  size_t examiner_name_string_length            = 0;
63
0
  size_t generated_acquiry_date_size            = 0;
64
0
  size_t generated_system_date_size             = 0;
65
0
  size_t newline_string_length                  = 1;
66
0
  size_t notes_string_length                    = 0;
67
0
  size_t number_of_chunks_string_length         = 0;
68
0
  size_t safe_utf8_string_size                  = 0;
69
0
  size_t sectors_per_chunk_string_length        = 0;
70
0
  size_t system_date_string_length              = 0;
71
0
  size_t utf8_string_index                      = 0;
72
0
  uint64_t value_64bit                          = 0;
73
0
  int number_of_characters                      = 0;
74
0
  int number_of_tabs                            = 0;
75
0
  int result                                    = 0;
76
77
0
  if( utf8_string == 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 UTF-8 string.",
84
0
     function );
85
86
0
    return( -1 );
87
0
  }
88
0
  if( *utf8_string != NULL )
89
0
  {
90
0
    libcerror_error_set(
91
0
     error,
92
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
93
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
94
0
     "%s: UTF-8 string already set.",
95
0
     function );
96
97
0
    return( -1 );
98
0
  }
99
0
  if( utf8_string_size == NULL )
100
0
  {
101
0
    libcerror_error_set(
102
0
     error,
103
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
104
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
105
0
     "%s: invalid UTF-8 string size.",
106
0
     function );
107
108
0
    return( -1 );
109
0
  }
110
0
  if( media_values == NULL )
111
0
  {
112
0
    libcerror_error_set(
113
0
     error,
114
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
115
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
116
0
     "%s: invalid media values.",
117
0
     function );
118
119
0
    return( -1 );
120
0
  }
121
0
  if( format != LIBEWF_FORMAT_V2_ENCASE7 )
122
0
  {
123
0
    libcerror_error_set(
124
0
     error,
125
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
126
0
     LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
127
0
     "%s: unsupported format.",
128
0
     function );
129
130
0
    return( -1 );
131
0
  }
132
0
  if( libewf_value_table_get_value_utf8_string_length(
133
0
       header_values,
134
0
       (uint8_t *) "description",
135
0
       12,
136
0
       &description_string_length,
137
0
       error ) == -1 )
138
0
  {
139
0
    libcerror_error_set(
140
0
     error,
141
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
142
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
143
0
     "%s: unable to retrieve header value: description length.",
144
0
     function );
145
146
0
    goto on_error;
147
0
  }
148
0
  if( libewf_value_table_get_value_utf8_string_length(
149
0
       header_values,
150
0
       (uint8_t *) "case_number",
151
0
       12,
152
0
       &case_number_string_length,
153
0
       error ) == -1 )
154
0
  {
155
0
    libcerror_error_set(
156
0
     error,
157
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
158
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
159
0
     "%s: unable to retrieve header value: case_number length.",
160
0
     function );
161
162
0
    goto on_error;
163
0
  }
164
0
  if( libewf_value_table_get_value_utf8_string_length(
165
0
       header_values,
166
0
       (uint8_t *) "evidence_number",
167
0
       16,
168
0
       &evidence_number_string_length,
169
0
       error ) == -1 )
170
0
  {
171
0
    libcerror_error_set(
172
0
     error,
173
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
174
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
175
0
     "%s: unable to retrieve header value: evidence_number length.",
176
0
     function );
177
178
0
    goto on_error;
179
0
  }
180
0
  if( libewf_value_table_get_value_utf8_string_length(
181
0
       header_values,
182
0
       (uint8_t *) "examiner_name",
183
0
       14,
184
0
       &examiner_name_string_length,
185
0
       error ) == -1 )
186
0
  {
187
0
    libcerror_error_set(
188
0
     error,
189
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
190
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
191
0
     "%s: unable to retrieve header value: examiner_name length.",
192
0
     function );
193
194
0
    goto on_error;
195
0
  }
196
0
  if( libewf_value_table_get_value_utf8_string_length(
197
0
       header_values,
198
0
       (uint8_t *) "notes",
199
0
       6,
200
0
       &notes_string_length,
201
0
       error ) == -1 )
202
0
  {
203
0
    libcerror_error_set(
204
0
     error,
205
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
206
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
207
0
     "%s: unable to retrieve header value: notes length.",
208
0
     function );
209
210
0
    goto on_error;
211
0
  }
212
0
  if( libewf_value_table_get_value_utf8_string_length(
213
0
       header_values,
214
0
       (uint8_t *) "acquiry_software_version",
215
0
       25,
216
0
       &acquiry_software_version_string_length,
217
0
       error ) == -1 )
218
0
  {
219
0
    libcerror_error_set(
220
0
     error,
221
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
222
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
223
0
     "%s: unable to retrieve header value: acquiry_software_version length.",
224
0
     function );
225
226
0
    goto on_error;
227
0
  }
228
0
  if( libewf_value_table_get_value_utf8_string_length(
229
0
       header_values,
230
0
       (uint8_t *) "acquiry_operating_system",
231
0
       25,
232
0
       &acquiry_operating_system_string_length,
233
0
       error ) == -1 )
234
0
  {
235
0
    libcerror_error_set(
236
0
     error,
237
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
238
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
239
0
     "%s: unable to retrieve header value: acquiry_operating_system length.",
240
0
     function );
241
242
0
    goto on_error;
243
0
  }
244
0
  if( libewf_value_table_get_value_utf8_string_length(
245
0
       header_values,
246
0
       (uint8_t *) "acquiry_date",
247
0
       13,
248
0
       &acquiry_date_string_length,
249
0
       error ) == -1 )
250
0
  {
251
0
    libcerror_error_set(
252
0
     error,
253
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
254
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
255
0
     "%s: unable to retrieve header value: acquiry_date length.",
256
0
     function );
257
258
0
    goto on_error;
259
0
  }
260
0
  if( acquiry_date_string_length == 0 )
261
0
  {
262
0
    result = libewf_generate_date_header2_value(
263
0
        timestamp,
264
0
        &generated_acquiry_date,
265
0
        &generated_acquiry_date_size,
266
0
        error );
267
268
0
    if( result != 1 )
269
0
    {
270
0
      libcerror_error_set(
271
0
       error,
272
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
273
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
274
0
       "%s: unable to generate acquiry date header value.",
275
0
       function );
276
277
#if defined( HAVE_VERBOSE_OUTPUT )
278
      if( libcnotify_verbose != 0 )
279
      {
280
        if( ( error != NULL )
281
         && ( *error != NULL ) )
282
        {
283
          libcnotify_print_error_backtrace(
284
           *error );
285
        }
286
      }
287
#endif
288
0
      libcerror_error_free(
289
0
       error );
290
0
    }
291
0
    else
292
0
    {
293
      /* Make sure to determine the actual length of the date time values string
294
       */
295
0
      acquiry_date_string_length = narrow_string_length(
296
0
                                    (char *) generated_acquiry_date );
297
0
    }
298
0
  }
299
0
  if( libewf_value_table_get_value_utf8_string_length(
300
0
       header_values,
301
0
       (uint8_t *) "system_date",
302
0
       12,
303
0
       &system_date_string_length,
304
0
       error ) == -1 )
305
0
  {
306
0
    libcerror_error_set(
307
0
     error,
308
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
309
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
310
0
     "%s: unable to retrieve header value: system_date length.",
311
0
     function );
312
313
0
    goto on_error;
314
0
  }
315
0
  if( system_date_string_length == 0 )
316
0
  {
317
0
    result = libewf_generate_date_header2_value(
318
0
        timestamp,
319
0
        &generated_system_date,
320
0
        &generated_system_date_size,
321
0
        error );
322
323
0
    if( result != 1 )
324
0
    {
325
0
      libcerror_error_set(
326
0
       error,
327
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
328
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
329
0
       "%s: unable to generate system date header value.",
330
0
       function );
331
332
#if defined( HAVE_VERBOSE_OUTPUT )
333
      if( libcnotify_verbose != 0 )
334
      {
335
        if( ( error != NULL )
336
         && ( *error != NULL ) )
337
        {
338
          libcnotify_print_error_backtrace(
339
           *error );
340
        }
341
      }
342
#endif
343
0
      libcerror_error_free(
344
0
       error );
345
0
    }
346
0
    else
347
0
    {
348
      /* Make sure to determine the actual length of the date time values string
349
       */
350
0
       system_date_string_length = narrow_string_length(
351
0
                                    (char *) generated_system_date );
352
0
    }
353
0
  }
354
  /* Determine the string size
355
   * Reserve space for:
356
   * 1 <newline>
357
   * main <newline>
358
   */
359
0
  safe_utf8_string_size = 5 + ( 2 * newline_string_length );
360
361
  /* Reserve space for:
362
   * nm <tab> cn <tab> en <tab> ex <tab> nt <tab> av <tab> os <tab> tt <tab> at <tab> tb <tab> cp <tab> sb <tab> gr <tab> wb <newline>
363
   */
364
0
  number_of_characters = 28;
365
0
  number_of_tabs       = 13;
366
367
0
  safe_utf8_string_size += number_of_characters + number_of_tabs + newline_string_length;
368
369
  /* Reserve space for the values
370
   */
371
0
  safe_utf8_string_size += description_string_length
372
0
                         + case_number_string_length
373
0
                         + evidence_number_string_length
374
0
                         + examiner_name_string_length
375
0
                         + notes_string_length
376
0
                         + acquiry_software_version_string_length
377
0
                         + acquiry_operating_system_string_length
378
0
                         + acquiry_date_string_length
379
0
                         + system_date_string_length;
380
381
  /* If we do a streamed write reserve space for the final number of chunks
382
   */
383
0
  if( media_values->media_size == 0 )
384
0
  {
385
0
    value_64bit   = 1;
386
0
    value_64bit <<= 63;
387
0
    value_64bit  -= 1;
388
0
  }
389
0
  else
390
0
  {
391
0
    value_64bit = media_values->number_of_chunks;
392
0
  }
393
0
  if( libfvalue_string_size_from_integer(
394
0
       &number_of_chunks_string_length,
395
0
       value_64bit,
396
0
       64,
397
0
       LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
398
0
       error ) != 1 )
399
0
  {
400
0
    libcerror_error_set(
401
0
     error,
402
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
403
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
404
0
     "%s: unable to retrieve string size of number of chunks.",
405
0
     function );
406
407
0
    goto on_error;
408
0
  }
409
0
  if( number_of_chunks_string_length > 0 )
410
0
  {
411
0
    number_of_chunks_string_length -= 1;
412
413
0
    safe_utf8_string_size += number_of_chunks_string_length;
414
0
  }
415
/* TODO: add support for the compression method: cp */
416
417
0
  if( libfvalue_string_size_from_integer(
418
0
       &sectors_per_chunk_string_length,
419
0
       media_values->sectors_per_chunk,
420
0
       32,
421
0
       LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
422
0
       error ) != 1 )
423
0
  {
424
0
    libcerror_error_set(
425
0
     error,
426
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
427
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
428
0
     "%s: unable to retrieve string size of sectors per chunk.",
429
0
     function );
430
431
0
    goto on_error;
432
0
  }
433
0
  if( sectors_per_chunk_string_length > 0 )
434
0
  {
435
0
    sectors_per_chunk_string_length -= 1;
436
437
0
    safe_utf8_string_size += sectors_per_chunk_string_length;
438
0
  }
439
0
  if( libfvalue_string_size_from_integer(
440
0
       &error_granularity_string_length,
441
0
       media_values->error_granularity,
442
0
       32,
443
0
       LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
444
0
       error ) != 1 )
445
0
  {
446
0
    libcerror_error_set(
447
0
     error,
448
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
449
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
450
0
     "%s: unable to retrieve string size of error granularity.",
451
0
     function );
452
453
0
    goto on_error;
454
0
  }
455
0
  if( error_granularity_string_length > 0 )
456
0
  {
457
0
    error_granularity_string_length -= 1;
458
459
0
    safe_utf8_string_size += error_granularity_string_length;
460
0
  }
461
/* TODO: add support for the write blocker type: wb */
462
463
  /* Reserve space for the tabs and 2 newlines
464
   */
465
0
  safe_utf8_string_size += number_of_tabs + ( 2 * newline_string_length );
466
467
  /* Reserve space for the end-of-string character
468
   */
469
0
  safe_utf8_string_size += 1;
470
471
0
  if( safe_utf8_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE )
472
0
  {
473
0
    libcerror_error_set(
474
0
     error,
475
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
476
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
477
0
     "%s: invalid UTF-8 string size value out of bounds.",
478
0
     function );
479
480
0
    goto on_error;
481
0
  }
482
  /* Determine the string
483
   */
484
0
  safe_utf8_string = (uint8_t *) memory_allocate(
485
0
                                  sizeof( uint8_t ) * safe_utf8_string_size );
486
487
0
  if( safe_utf8_string == NULL )
488
0
  {
489
0
    libcerror_error_set(
490
0
     error,
491
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
492
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
493
0
     "%s: unable to create UTF-8 string.",
494
0
     function );
495
496
0
    goto on_error;
497
0
  }
498
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '1';
499
500
0
  safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ];
501
502
0
  if( newline_string_length == 2 )
503
0
  {
504
0
    safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ];
505
0
  }
506
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'm';
507
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a';
508
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'i';
509
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n';
510
511
0
  safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ];
512
513
0
  if( newline_string_length == 2 )
514
0
  {
515
0
    safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ];
516
0
  }
517
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n';
518
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'm';
519
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
520
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'c';
521
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n';
522
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
523
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'e';
524
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n';
525
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
526
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'e';
527
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'x';
528
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
529
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'n';
530
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't';
531
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
532
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a';
533
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'v';
534
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
535
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'o';
536
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 's';
537
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
538
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't';
539
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't';
540
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
541
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'a';
542
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't';
543
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
544
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 't';
545
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'b';
546
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
547
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'c';
548
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'p';
549
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
550
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 's';
551
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'b';
552
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
553
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'g';
554
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'r';
555
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
556
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'w';
557
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) 'b';
558
559
0
  safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ];
560
561
0
  if( newline_string_length == 2 )
562
0
  {
563
0
    safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ];
564
0
  }
565
0
  if( description_string_length > 0 )
566
0
  {
567
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
568
0
         header_values,
569
0
         (uint8_t *) "description",
570
0
         12,
571
0
         safe_utf8_string,
572
0
         safe_utf8_string_size,
573
0
         &utf8_string_index,
574
0
         error ) != 1 )
575
0
    {
576
0
      libcerror_error_set(
577
0
       error,
578
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
579
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
580
0
       "%s: unable to copy header value: case_number to string.",
581
0
       function );
582
583
0
      goto on_error;
584
0
    }
585
0
  }
586
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
587
588
0
  if( case_number_string_length > 0 )
589
0
  {
590
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
591
0
         header_values,
592
0
         (uint8_t *) "case_number",
593
0
         12,
594
0
         safe_utf8_string,
595
0
         safe_utf8_string_size,
596
0
         &utf8_string_index,
597
0
         error ) != 1 )
598
0
    {
599
0
      libcerror_error_set(
600
0
       error,
601
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
602
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
603
0
       "%s: unable to copy header value: case_number to string.",
604
0
       function );
605
606
0
      goto on_error;
607
0
    }
608
0
  }
609
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
610
611
0
  if( evidence_number_string_length > 0 )
612
0
  {
613
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
614
0
         header_values,
615
0
         (uint8_t *) "evidence_number",
616
0
         16,
617
0
         safe_utf8_string,
618
0
         safe_utf8_string_size,
619
0
         &utf8_string_index,
620
0
         error ) != 1 )
621
0
    {
622
0
      libcerror_error_set(
623
0
       error,
624
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
625
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
626
0
       "%s: unable to copy header value: evidence_number to string.",
627
0
       function );
628
629
0
      goto on_error;
630
0
    }
631
0
  }
632
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
633
634
0
  if( examiner_name_string_length > 0 )
635
0
  {
636
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
637
0
         header_values,
638
0
         (uint8_t *) "examiner_name",
639
0
         14,
640
0
         safe_utf8_string,
641
0
         safe_utf8_string_size,
642
0
         &utf8_string_index,
643
0
         error ) != 1 )
644
0
    {
645
0
      libcerror_error_set(
646
0
       error,
647
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
648
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
649
0
       "%s: unable to copy header value: examiner_name to string.",
650
0
       function );
651
652
0
      goto on_error;
653
0
    }
654
0
  }
655
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
656
657
0
  if( notes_string_length > 0 )
658
0
  {
659
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
660
0
         header_values,
661
0
         (uint8_t *) "notes",
662
0
         6,
663
0
         safe_utf8_string,
664
0
         safe_utf8_string_size,
665
0
         &utf8_string_index,
666
0
         error ) != 1 )
667
0
    {
668
0
      libcerror_error_set(
669
0
       error,
670
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
671
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
672
0
       "%s: unable to copy header value: notes to string.",
673
0
       function );
674
675
0
      goto on_error;
676
0
    }
677
0
  }
678
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
679
680
0
  if( acquiry_software_version_string_length > 0 )
681
0
  {
682
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
683
0
         header_values,
684
0
         (uint8_t *) "acquiry_software_version",
685
0
         25,
686
0
         safe_utf8_string,
687
0
         safe_utf8_string_size,
688
0
         &utf8_string_index,
689
0
         error ) != 1 )
690
0
    {
691
0
      libcerror_error_set(
692
0
       error,
693
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
694
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
695
0
       "%s: unable to copy header value: acquiry_software_version to string.",
696
0
       function );
697
698
0
      goto on_error;
699
0
    }
700
0
  }
701
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
702
703
0
  if( acquiry_operating_system_string_length > 0 )
704
0
  {
705
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
706
0
         header_values,
707
0
         (uint8_t *) "acquiry_operating_system",
708
0
         25,
709
0
         safe_utf8_string,
710
0
         safe_utf8_string_size,
711
0
         &utf8_string_index,
712
0
         error ) != 1 )
713
0
    {
714
0
      libcerror_error_set(
715
0
       error,
716
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
717
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
718
0
       "%s: unable to copy header value: acquiry_operating_system to string.",
719
0
       function );
720
721
0
      goto on_error;
722
0
    }
723
0
  }
724
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
725
726
0
  if( generated_acquiry_date == NULL )
727
0
  {
728
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
729
0
         header_values,
730
0
         (uint8_t *) "acquiry_date",
731
0
         13,
732
0
         safe_utf8_string,
733
0
         safe_utf8_string_size,
734
0
         &utf8_string_index,
735
0
         error ) != 1 )
736
0
    {
737
0
      libcerror_error_set(
738
0
       error,
739
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
740
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
741
0
       "%s: unable to copy header value: acquiry_date to string.",
742
0
       function );
743
744
0
      goto on_error;
745
0
    }
746
0
  }
747
0
  else
748
0
  {
749
0
    if( narrow_string_copy(
750
0
         (char *) &( safe_utf8_string[ utf8_string_index ] ),
751
0
         (char *) generated_acquiry_date,
752
0
         acquiry_date_string_length ) == NULL )
753
0
    {
754
0
      libcerror_error_set(
755
0
       error,
756
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
757
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
758
0
       "%s: unable to copy generated acquiry date string.",
759
0
       function );
760
761
0
      goto on_error;
762
0
    }
763
0
    utf8_string_index += acquiry_date_string_length;
764
765
0
    memory_free(
766
0
     generated_acquiry_date );
767
768
0
    generated_acquiry_date = NULL;
769
0
  }
770
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
771
772
0
  if( generated_system_date == NULL )
773
0
  {
774
0
    if( libewf_value_table_get_value_copy_to_utf8_string_with_index(
775
0
         header_values,
776
0
         (uint8_t *) "system_date",
777
0
         12,
778
0
         safe_utf8_string,
779
0
         safe_utf8_string_size,
780
0
         &utf8_string_index,
781
0
         error ) != 1 )
782
0
    {
783
0
      libcerror_error_set(
784
0
       error,
785
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
786
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
787
0
       "%s: unable to copy header value: system_date to string.",
788
0
       function );
789
790
0
      goto on_error;
791
0
    }
792
0
  }
793
0
  else
794
0
  {
795
0
    if( narrow_string_copy(
796
0
         (char *) &( safe_utf8_string[ utf8_string_index ] ),
797
0
         (char *) generated_system_date,
798
0
         system_date_string_length ) == NULL )
799
0
    {
800
0
      libcerror_error_set(
801
0
       error,
802
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
803
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
804
0
       "%s: unable to copy generated system date string.",
805
0
       function );
806
807
0
      goto on_error;
808
0
    }
809
0
    utf8_string_index += system_date_string_length;
810
811
0
    memory_free(
812
0
     generated_system_date );
813
814
0
    generated_system_date = NULL;
815
0
  }
816
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
817
818
0
  if( number_of_chunks_string_length > 0 )
819
0
  {
820
    /* If we do a streamed write reserve space for the final number of chunks
821
     */
822
0
    if( media_values->media_size == 0 )
823
0
    {
824
0
      value_64bit   = 1;
825
0
      value_64bit <<= 63;
826
0
      value_64bit  -= 1;
827
0
    }
828
0
    else
829
0
    {
830
0
      value_64bit = media_values->number_of_chunks;
831
0
    }
832
0
    if( libfvalue_utf8_string_with_index_copy_from_integer(
833
0
         safe_utf8_string,
834
0
         safe_utf8_string_size,
835
0
         &utf8_string_index,
836
0
         value_64bit,
837
0
         64,
838
0
         LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
839
0
         error ) != 1 )
840
0
    {
841
0
      libcerror_error_set(
842
0
       error,
843
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
844
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
845
0
       "%s: unable to copy number of chunks to string.",
846
0
       function );
847
848
0
      goto on_error;
849
0
    }
850
0
    utf8_string_index--;
851
0
  }
852
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
853
854
/* TODO: add support for the compression method: cp */
855
856
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
857
858
0
  if( sectors_per_chunk_string_length > 0 )
859
0
  {
860
0
    if( libfvalue_utf8_string_with_index_copy_from_integer(
861
0
         safe_utf8_string,
862
0
         safe_utf8_string_size,
863
0
         &utf8_string_index,
864
0
         media_values->sectors_per_chunk,
865
0
         32,
866
0
         LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
867
0
         error ) != 1 )
868
0
    {
869
0
      libcerror_error_set(
870
0
       error,
871
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
872
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
873
0
       "%s: unable to copy sectors per chunk to string.",
874
0
       function );
875
876
0
      goto on_error;
877
0
    }
878
0
    utf8_string_index--;
879
0
  }
880
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
881
882
0
  if( error_granularity_string_length > 0 )
883
0
  {
884
0
    if( libfvalue_utf8_string_with_index_copy_from_integer(
885
0
         safe_utf8_string,
886
0
         safe_utf8_string_size,
887
0
         &utf8_string_index,
888
0
         media_values->error_granularity,
889
0
         32,
890
0
         LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
891
0
         error ) != 1 )
892
0
    {
893
0
      libcerror_error_set(
894
0
       error,
895
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
896
0
       LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
897
0
       "%s: unable to copy error granularity to string.",
898
0
       function );
899
900
0
      goto on_error;
901
0
    }
902
0
    utf8_string_index--;
903
0
  }
904
0
  safe_utf8_string[ utf8_string_index++ ] = (uint8_t) '\t';
905
906
/* TODO: add support for the write blocker type: wb */
907
908
0
  safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ];
909
910
0
  if( newline_string_length == 2 )
911
0
  {
912
0
    safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ];
913
0
  }
914
0
  safe_utf8_string[ utf8_string_index++ ] = newline_string[ 0 ];
915
916
0
  if( newline_string_length == 2 )
917
0
  {
918
0
    safe_utf8_string[ utf8_string_index++ ] = newline_string[ 1 ];
919
0
  }
920
0
  safe_utf8_string[ utf8_string_index++ ] = 0;
921
922
0
  *utf8_string      = safe_utf8_string;
923
0
  *utf8_string_size = safe_utf8_string_size;
924
925
0
  return( 1 );
926
927
0
on_error:
928
0
  if( generated_acquiry_date != NULL )
929
0
  {
930
0
    memory_free(
931
0
     generated_acquiry_date );
932
0
  }
933
0
  if( generated_system_date != NULL )
934
0
  {
935
0
    memory_free(
936
0
     generated_system_date );
937
0
  }
938
0
  if( safe_utf8_string != NULL )
939
0
  {
940
0
    memory_free(
941
0
     safe_utf8_string );
942
0
  }
943
0
  return( -1 );
944
0
}
945
946
/* Generate case data
947
 * Sets case_data and case_data_size
948
 * Returns 1 if successful or -1 on error
949
 */
950
int libewf_case_data_generate(
951
     uint8_t **case_data,
952
     size_t *case_data_size,
953
     libewf_media_values_t *media_values,
954
     libfvalue_table_t *header_values,
955
     time_t timestamp,
956
     uint8_t format,
957
     libcerror_error_t **error )
958
0
{
959
0
  uint8_t *safe_case_data    = NULL;
960
0
  uint8_t *utf8_string       = NULL;
961
0
  static char *function      = "libewf_case_data_generate";
962
0
  size_t safe_case_data_size = 0;
963
0
  size_t utf8_string_size    = 0;
964
965
0
  if( case_data == NULL )
966
0
  {
967
0
    libcerror_error_set(
968
0
     error,
969
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
970
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
971
0
     "%s: invalid case data.",
972
0
     function );
973
974
0
    return( -1 );
975
0
  }
976
0
  if( *case_data != NULL )
977
0
  {
978
0
    libcerror_error_set(
979
0
     error,
980
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
981
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
982
0
     "%s: case data already created.",
983
0
     function );
984
985
0
    return( -1 );
986
0
  }
987
0
  if( case_data_size == NULL )
988
0
  {
989
0
    libcerror_error_set(
990
0
     error,
991
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
992
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
993
0
     "%s: invalid case data size.",
994
0
     function );
995
996
0
    return( -1 );
997
0
  }
998
0
  if( libewf_case_data_generate_utf8_string(
999
0
       &utf8_string,
1000
0
       &utf8_string_size,
1001
0
       media_values,
1002
0
       header_values,
1003
0
       timestamp,
1004
0
       format,
1005
0
       error ) != 1 )
1006
0
  {
1007
0
    libcerror_error_set(
1008
0
     error,
1009
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1010
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1011
0
     "%s: unable to create UTF-8 case data string.",
1012
0
     function );
1013
1014
0
    goto on_error;
1015
0
  }
1016
#if defined( HAVE_DEBUG_OUTPUT )
1017
  if( libcnotify_verbose != 0 )
1018
  {
1019
    libcnotify_printf(
1020
    "%s: case data string:\n%s",
1021
     function,
1022
     utf8_string );
1023
  }
1024
#endif
1025
0
  if( libuna_utf16_stream_size_from_utf8(
1026
0
       utf8_string,
1027
0
       utf8_string_size,
1028
0
       &safe_case_data_size,
1029
0
       error ) != 1 )
1030
0
  {
1031
0
    libcerror_error_set(
1032
0
     error,
1033
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
1034
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
1035
0
     "%s: unable to determine case data size.",
1036
0
     function );
1037
1038
0
    goto on_error;
1039
0
  }
1040
0
  if( ( safe_case_data_size == 0 )
1041
0
   || ( safe_case_data_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
1042
0
  {
1043
0
    libcerror_error_set(
1044
0
     error,
1045
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1046
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
1047
0
     "%s: invalid case data size value out of bounds.",
1048
0
     function );
1049
1050
0
    goto on_error;
1051
0
  }
1052
0
  safe_case_data = (uint8_t *) memory_allocate(
1053
0
                                sizeof( uint8_t ) * safe_case_data_size );
1054
1055
0
  if( safe_case_data == NULL )
1056
0
  {
1057
0
    libcerror_error_set(
1058
0
     error,
1059
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
1060
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
1061
0
     "%s: unable to create case data.",
1062
0
     function );
1063
1064
0
    goto on_error;
1065
0
  }
1066
0
  if( libuna_utf16_stream_copy_from_utf8(
1067
0
       safe_case_data,
1068
0
       safe_case_data_size,
1069
0
       LIBUNA_ENDIAN_LITTLE,
1070
0
       utf8_string,
1071
0
       utf8_string_size,
1072
0
       error ) != 1 )
1073
0
  {
1074
0
    libcerror_error_set(
1075
0
     error,
1076
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
1077
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
1078
0
     "%s: unable to set case data.",
1079
0
     function );
1080
1081
0
    goto on_error;
1082
0
  }
1083
0
  memory_free(
1084
0
   utf8_string );
1085
1086
0
  *case_data      = safe_case_data;
1087
0
  *case_data_size = safe_case_data_size;
1088
1089
0
  return( 1 );
1090
1091
0
on_error:
1092
0
  if( utf8_string != NULL )
1093
0
  {
1094
0
    memory_free(
1095
0
     utf8_string );
1096
0
  }
1097
0
  if( safe_case_data != NULL )
1098
0
  {
1099
0
    memory_free(
1100
0
     safe_case_data );
1101
0
  }
1102
0
  return( -1 );
1103
0
}
1104
1105
/* Parses an UTF-8 encoded case data string
1106
 * Returns 1 if successful or -1 on error
1107
 */
1108
int libewf_case_data_parse_utf8_string(
1109
     const uint8_t *utf8_string,
1110
     size_t utf8_string_size,
1111
     libewf_media_values_t *media_values,
1112
     libfvalue_table_t *header_values,
1113
     uint8_t *format,
1114
     libcerror_error_t **error )
1115
0
{
1116
0
  libfvalue_split_utf8_string_t *lines  = NULL;
1117
0
  libfvalue_split_utf8_string_t *types  = NULL;
1118
0
  libfvalue_split_utf8_string_t *values = NULL;
1119
0
  uint8_t *line_string                  = NULL;
1120
0
  uint8_t *type_string                  = NULL;
1121
0
  uint8_t *value_string                 = NULL;
1122
0
  static char *function                 = "libewf_case_data_parse_utf8_string";
1123
0
  size_t line_string_size               = 0;
1124
0
  size_t type_string_size               = 0;
1125
0
  size_t value_string_size              = 0;
1126
0
  int number_of_lines                   = 0;
1127
0
  int number_of_types                   = 0;
1128
0
  int number_of_values                  = 0;
1129
0
  int value_index                       = 0;
1130
1131
0
  if( utf8_string == NULL )
1132
0
  {
1133
0
    libcerror_error_set(
1134
0
     error,
1135
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1136
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1137
0
     "%s: invalid UTF-8 string.",
1138
0
     function );
1139
1140
0
    return( -1 );
1141
0
  }
1142
0
  if( format == NULL )
1143
0
  {
1144
0
    libcerror_error_set(
1145
0
     error,
1146
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1147
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1148
0
     "%s: invalid format.",
1149
0
     function );
1150
1151
0
    return( -1 );
1152
0
  }
1153
0
  if( libfvalue_utf8_string_split(
1154
0
       utf8_string,
1155
0
       utf8_string_size,
1156
0
       (uint8_t) '\n',
1157
0
       &lines,
1158
0
       error ) != 1 )
1159
0
  {
1160
0
    libcerror_error_set(
1161
0
     error,
1162
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1163
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1164
0
     "%s: unable to split UTF-8 string into lines.",
1165
0
     function );
1166
1167
0
    goto on_error;
1168
0
  }
1169
0
  if( libfvalue_split_utf8_string_get_number_of_segments(
1170
0
       lines,
1171
0
       &number_of_lines,
1172
0
       error ) != 1 )
1173
0
  {
1174
0
    libcerror_error_set(
1175
0
     error,
1176
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1177
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1178
0
     "%s: unable to retrieve number of lines",
1179
0
     function );
1180
1181
0
    goto on_error;
1182
0
  }
1183
0
  if( number_of_lines > 0 )
1184
0
  {
1185
0
    if( libfvalue_split_utf8_string_get_segment_by_index(
1186
0
         lines,
1187
0
         0,
1188
0
         &line_string,
1189
0
         &line_string_size,
1190
0
         error ) != 1 )
1191
0
    {
1192
0
      libcerror_error_set(
1193
0
       error,
1194
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1195
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1196
0
       "%s: unable to retrieve line string: 0.",
1197
0
       function );
1198
1199
0
      goto on_error;
1200
0
    }
1201
0
    if( line_string == NULL )
1202
0
    {
1203
0
      libcerror_error_set(
1204
0
       error,
1205
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1206
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1207
0
       "%s: missing line string: 0.",
1208
0
       function );
1209
1210
0
      goto on_error;
1211
0
    }
1212
0
    if( ( line_string == NULL )
1213
0
     || ( line_string_size < 2 )
1214
0
     || ( line_string[ 0 ] == 0 ) )
1215
0
    {
1216
0
      libcerror_error_set(
1217
0
       error,
1218
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1219
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1220
0
       "%s: missing line string: 0.",
1221
0
       function );
1222
1223
0
      goto on_error;
1224
0
    }
1225
    /* Remove trailing carriage return
1226
     */
1227
0
    else if( line_string[ line_string_size - 2 ] == (uint8_t) '\r' )
1228
0
    {
1229
0
      line_string[ line_string_size - 2 ] = 0;
1230
1231
0
      line_string_size -= 1;
1232
0
    }
1233
0
    if( line_string_size != 2 )
1234
0
    {
1235
0
      libcerror_error_set(
1236
0
       error,
1237
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1238
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1239
0
       "%s: unsupported line string: 0.",
1240
0
       function );
1241
1242
0
      goto on_error;
1243
0
    }
1244
0
    if( line_string[ 0 ] != (uint8_t) '1' )
1245
0
    {
1246
0
      libcerror_error_set(
1247
0
       error,
1248
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1249
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1250
0
       "%s: unsupported line string: 0.",
1251
0
       function );
1252
1253
0
      goto on_error;
1254
0
    }
1255
0
    if( libfvalue_split_utf8_string_get_segment_by_index(
1256
0
         lines,
1257
0
         1,
1258
0
         &line_string,
1259
0
         &line_string_size,
1260
0
         error ) != 1 )
1261
0
    {
1262
0
      libcerror_error_set(
1263
0
       error,
1264
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1265
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1266
0
       "%s: unable to retrieve line string: 1.",
1267
0
       function );
1268
1269
0
      goto on_error;
1270
0
    }
1271
0
    if( line_string == NULL )
1272
0
    {
1273
0
      libcerror_error_set(
1274
0
       error,
1275
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1276
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1277
0
       "%s: missing line string: 1.",
1278
0
       function );
1279
1280
0
      goto on_error;
1281
0
    }
1282
0
    if( ( line_string == NULL )
1283
0
     || ( line_string_size < 5 )
1284
0
     || ( line_string[ 0 ] == 0 ) )
1285
0
    {
1286
0
      libcerror_error_set(
1287
0
       error,
1288
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1289
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1290
0
       "%s: missing line string: 1.",
1291
0
       function );
1292
1293
0
      goto on_error;
1294
0
    }
1295
    /* Remove trailing carriage return
1296
     */
1297
0
    else if( line_string[ line_string_size - 2 ] == (uint8_t) '\r' )
1298
0
    {
1299
0
      line_string[ line_string_size - 2 ] = 0;
1300
1301
0
      line_string_size -= 1;
1302
0
    }
1303
0
    if( line_string_size != 5 )
1304
0
    {
1305
0
      libcerror_error_set(
1306
0
       error,
1307
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1308
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1309
0
       "%s: unsupported line string: 1.",
1310
0
       function );
1311
1312
0
      goto on_error;
1313
0
    }
1314
0
    if( ( line_string[ 0 ] != (uint8_t) 'm' )
1315
0
     || ( line_string[ 1 ] != (uint8_t) 'a' )
1316
0
     || ( line_string[ 2 ] != (uint8_t) 'i' )
1317
0
     || ( line_string[ 3 ] != (uint8_t) 'n' ) )
1318
0
    {
1319
0
      libcerror_error_set(
1320
0
       error,
1321
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1322
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1323
0
       "%s: unsupported line string: 1.",
1324
0
       function );
1325
1326
0
      goto on_error;
1327
0
    }
1328
0
    *format = LIBEWF_FORMAT_V2_ENCASE7;
1329
1330
0
    if( libfvalue_split_utf8_string_get_segment_by_index(
1331
0
         lines,
1332
0
         2,
1333
0
         &line_string,
1334
0
         &line_string_size,
1335
0
         error ) != 1 )
1336
0
    {
1337
0
      libcerror_error_set(
1338
0
       error,
1339
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1340
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1341
0
       "%s: unable to retrieve line string: 2.",
1342
0
       function );
1343
1344
0
      goto on_error;
1345
0
    }
1346
0
    if( libfvalue_utf8_string_split(
1347
0
         line_string,
1348
0
         line_string_size,
1349
0
         (uint8_t) '\t',
1350
0
         &types,
1351
0
         error ) != 1 )
1352
0
    {
1353
0
      libcerror_error_set(
1354
0
       error,
1355
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1356
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1357
0
       "%s: unable to split case data string into types.",
1358
0
       function );
1359
1360
0
      goto on_error;
1361
0
    }
1362
0
    if( libfvalue_split_utf8_string_get_number_of_segments(
1363
0
         types,
1364
0
         &number_of_types,
1365
0
         error ) != 1 )
1366
0
    {
1367
0
      libcerror_error_set(
1368
0
       error,
1369
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1370
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1371
0
       "%s: unable to retrieve number of types",
1372
0
       function );
1373
1374
0
      goto on_error;
1375
0
    }
1376
0
    if( libfvalue_split_utf8_string_get_segment_by_index(
1377
0
         lines,
1378
0
         3,
1379
0
         &line_string,
1380
0
         &line_string_size,
1381
0
         error ) != 1 )
1382
0
    {
1383
0
      libcerror_error_set(
1384
0
       error,
1385
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1386
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1387
0
       "%s: unable to retrieve line string: 3.",
1388
0
       function );
1389
1390
0
      goto on_error;
1391
0
    }
1392
0
    if( libfvalue_utf8_string_split(
1393
0
         line_string,
1394
0
         line_string_size,
1395
0
         (uint8_t) '\t',
1396
0
         &values,
1397
0
         error ) != 1 )
1398
0
    {
1399
0
      libcerror_error_set(
1400
0
       error,
1401
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1402
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1403
0
       "%s: unable to split case data string into values.",
1404
0
       function );
1405
1406
0
      goto on_error;
1407
0
    }
1408
0
    if( libfvalue_split_utf8_string_get_number_of_segments(
1409
0
         values,
1410
0
         &number_of_values,
1411
0
         error ) != 1 )
1412
0
    {
1413
0
      libcerror_error_set(
1414
0
       error,
1415
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1416
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1417
0
       "%s: unable to retrieve number of values",
1418
0
       function );
1419
1420
0
      goto on_error;
1421
0
    }
1422
#if defined( HAVE_VERBOSE_OUTPUT )
1423
    if( number_of_types != number_of_values )
1424
    {
1425
      if( libcnotify_verbose != 0 )
1426
      {
1427
        libcnotify_printf(
1428
        "%s: mismatch in number of types and values.\n",
1429
         function );
1430
      }
1431
    }
1432
#endif
1433
0
    for( value_index = 0;
1434
0
         value_index < number_of_types;
1435
0
         value_index++ )
1436
0
    {
1437
0
      if( libfvalue_split_utf8_string_get_segment_by_index(
1438
0
           types,
1439
0
           value_index,
1440
0
           &type_string,
1441
0
           &type_string_size,
1442
0
           error ) != 1 )
1443
0
      {
1444
0
        libcerror_error_set(
1445
0
         error,
1446
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
1447
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1448
0
         "%s: unable to retrieve type string: %d.",
1449
0
         function,
1450
0
         value_index );
1451
1452
0
        goto on_error;
1453
0
      }
1454
0
      if( value_index >= number_of_values )
1455
0
      {
1456
0
        value_string      = NULL;
1457
0
        value_string_size = 0;
1458
0
      }
1459
0
      else if( libfvalue_split_utf8_string_get_segment_by_index(
1460
0
                values,
1461
0
                value_index,
1462
0
                &value_string,
1463
0
                &value_string_size,
1464
0
                error ) != 1 )
1465
0
      {
1466
0
        libcerror_error_set(
1467
0
         error,
1468
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
1469
0
         LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1470
0
         "%s: unable to retrieve value string: %d.",
1471
0
         function,
1472
0
         value_index );
1473
1474
0
        goto on_error;
1475
0
      }
1476
0
      if( libewf_case_data_parse_utf8_string_value(
1477
0
           type_string,
1478
0
           type_string_size,
1479
0
           value_string,
1480
0
           value_string_size,
1481
0
           value_index,
1482
0
           media_values,
1483
0
           header_values,
1484
0
           error ) != 1 )
1485
0
      {
1486
0
        libcerror_error_set(
1487
0
         error,
1488
0
         LIBCERROR_ERROR_DOMAIN_CONVERSION,
1489
0
         LIBCERROR_CONVERSION_ERROR_GENERIC,
1490
0
         "%s: unable to parse UTF-8 string value: %d.",
1491
0
         function,
1492
0
         value_index );
1493
1494
0
        goto on_error;
1495
0
      }
1496
0
    }
1497
0
    if( libfvalue_split_utf8_string_free(
1498
0
         &values,
1499
0
         error ) != 1 )
1500
0
    {
1501
0
      libcerror_error_set(
1502
0
       error,
1503
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1504
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1505
0
       "%s: unable to free split values.",
1506
0
       function );
1507
1508
0
      goto on_error;
1509
0
    }
1510
0
    if( libfvalue_split_utf8_string_free(
1511
0
         &types,
1512
0
         error ) != 1 )
1513
0
    {
1514
0
      libcerror_error_set(
1515
0
       error,
1516
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1517
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1518
0
       "%s: unable to free split types.",
1519
0
       function );
1520
1521
0
      goto on_error;
1522
0
    }
1523
0
  }
1524
0
  if( libfvalue_split_utf8_string_free(
1525
0
       &lines,
1526
0
       error ) != 1 )
1527
0
  {
1528
0
    libcerror_error_set(
1529
0
     error,
1530
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1531
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
1532
0
     "%s: unable to free split lines.",
1533
0
     function );
1534
1535
0
    goto on_error;
1536
0
  }
1537
#if defined( HAVE_DEBUG_OUTPUT )
1538
  if( libcnotify_verbose != 0 )
1539
  {
1540
    libcnotify_printf(
1541
    "\n" );
1542
  }
1543
#endif
1544
0
  return( 1 );
1545
1546
0
on_error:
1547
0
  if( values != NULL )
1548
0
  {
1549
0
    libfvalue_split_utf8_string_free(
1550
0
     &values,
1551
0
     NULL );
1552
0
  }
1553
0
  if( types != NULL )
1554
0
  {
1555
0
    libfvalue_split_utf8_string_free(
1556
0
     &types,
1557
0
     NULL );
1558
0
  }
1559
0
  if( lines != NULL )
1560
0
  {
1561
0
    libfvalue_split_utf8_string_free(
1562
0
     &lines,
1563
0
     NULL );
1564
0
  }
1565
0
  return( -1 );
1566
0
}
1567
1568
/* Parses an UTF-8 encoded case data string value
1569
 * Returns 1 if successful or -1 on error
1570
 */
1571
int libewf_case_data_parse_utf8_string_value(
1572
     uint8_t *type_string,
1573
     size_t type_string_size,
1574
     uint8_t *value_string,
1575
     size_t value_string_size,
1576
     int value_index,
1577
     libewf_media_values_t *media_values,
1578
     libfvalue_table_t *header_values,
1579
     libcerror_error_t **error )
1580
0
{
1581
0
  uint8_t *date_time_values_string    = NULL;
1582
0
  uint8_t *identifier                 = NULL;
1583
0
  static char *function               = "libewf_case_data_parse_utf8_string_value";
1584
0
  size_t date_time_values_string_size = 0;
1585
0
  size_t identifier_size              = 0;
1586
0
  uint64_t value_64bit                = 0;
1587
1588
0
  if( ( type_string == NULL )
1589
0
   || ( type_string_size < 2 )
1590
0
   || ( type_string[ 0 ] == 0 ) )
1591
0
  {
1592
0
    libcerror_error_set(
1593
0
     error,
1594
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1595
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1596
0
     "%s: missing type string: %d.",
1597
0
     function,
1598
0
     value_index );
1599
1600
0
    goto on_error;
1601
0
  }
1602
0
  if( media_values == NULL )
1603
0
  {
1604
0
    libcerror_error_set(
1605
0
     error,
1606
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1607
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1608
0
     "%s: invalid media values.",
1609
0
     function );
1610
1611
0
    return( -1 );
1612
0
  }
1613
0
  if( header_values == NULL )
1614
0
  {
1615
0
    libcerror_error_set(
1616
0
     error,
1617
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1618
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1619
0
     "%s: invalid header values.",
1620
0
     function );
1621
1622
0
    return( -1 );
1623
0
  }
1624
  /* Remove trailing carriage return
1625
   */
1626
0
  if( type_string[ type_string_size - 2 ] == (uint8_t) '\r' )
1627
0
  {
1628
0
    type_string[ type_string_size - 2 ] = 0;
1629
1630
0
    type_string_size -= 1;
1631
0
  }
1632
0
  if( ( value_string == NULL )
1633
0
   || ( value_string_size < 2 )
1634
0
   || ( value_string[ 0 ] == 0 ) )
1635
0
  {
1636
0
    value_string      = NULL;
1637
0
    value_string_size = 0;
1638
0
  }
1639
  /* Remove trailing carriage return
1640
   */
1641
0
  else if( value_string[ value_string_size - 2 ] == (uint8_t) '\r' )
1642
0
  {
1643
0
    value_string[ value_string_size - 2 ] = 0;
1644
1645
0
    value_string_size -= 1;
1646
0
  }
1647
#if defined( HAVE_VERBOSE_OUTPUT )
1648
  if( libcnotify_verbose != 0 )
1649
  {
1650
    libcnotify_printf(
1651
     "%s: type: %s with value: %s.\n",
1652
     function,
1653
     (char *) type_string,
1654
     (char *) value_string );
1655
  }
1656
#endif
1657
  /* Ignore empty values
1658
   */
1659
0
  if( value_string == NULL )
1660
0
  {
1661
0
    return( 1 );
1662
0
  }
1663
0
  identifier      = NULL;
1664
0
  identifier_size = 0;
1665
1666
0
  if( type_string_size == 3 )
1667
0
  {
1668
0
    if( ( type_string[ 0 ] == (uint8_t) 'a' )
1669
0
     && ( type_string[ 1 ] == (uint8_t) 'v' ) )
1670
0
    {
1671
0
      identifier      = (uint8_t *) "acquiry_software_version";
1672
0
      identifier_size = 25;
1673
0
    }
1674
0
    else if( ( type_string[ 0 ] == (uint8_t) 'a' )
1675
0
          && ( type_string[ 1 ] == (uint8_t) 't' ) )
1676
0
    {
1677
0
      if( libewf_convert_date_header2_value(
1678
0
           value_string,
1679
0
           value_string_size,
1680
0
           &date_time_values_string,
1681
0
           &date_time_values_string_size,
1682
0
           error ) != 1 )
1683
0
      {
1684
0
        libcerror_error_set(
1685
0
         error,
1686
0
         LIBCERROR_ERROR_DOMAIN_CONVERSION,
1687
0
         LIBCERROR_CONVERSION_ERROR_GENERIC,
1688
0
         "%s: unable to create date time values string.",
1689
0
         function );
1690
1691
#if defined( HAVE_DEBUG_OUTPUT )
1692
        if( libcnotify_verbose != 0 )
1693
        {
1694
          if( ( error != NULL )
1695
           && ( *error != NULL ) )
1696
          {
1697
            libcnotify_print_error_backtrace(
1698
             *error );
1699
          }
1700
        }
1701
#endif
1702
0
        libcerror_error_free(
1703
0
         error );
1704
0
      }
1705
0
      if( date_time_values_string != NULL )
1706
0
      {
1707
0
        value_string      = date_time_values_string;
1708
0
        value_string_size = 1 + narrow_string_length(
1709
0
                               (char *) date_time_values_string );
1710
1711
0
        identifier      = (uint8_t *) "acquiry_date";
1712
0
        identifier_size = 13;
1713
0
      }
1714
0
    }
1715
0
    else if( ( type_string[ 0 ] == (uint8_t) 'c' )
1716
0
          && ( type_string[ 1 ] == (uint8_t) 'n' ) )
1717
0
    {
1718
0
      identifier      = (uint8_t *) "case_number";
1719
0
      identifier_size = 12;
1720
0
    }
1721
0
    else if( ( type_string[ 0 ] == (uint8_t) 'c' )
1722
0
          && ( type_string[ 1 ] == (uint8_t) 'p' ) )
1723
0
    {
1724
0
      if( libfvalue_utf8_string_copy_to_integer(
1725
0
           value_string,
1726
0
           value_string_size,
1727
0
           &value_64bit,
1728
0
           32,
1729
0
           LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1730
0
           error ) != 1 )
1731
0
      {
1732
0
        libcerror_error_set(
1733
0
         error,
1734
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
1735
0
         LIBCERROR_MEMORY_ERROR_SET_FAILED,
1736
0
         "%s: unable to set compression method.",
1737
0
         function );
1738
1739
0
        goto on_error;
1740
0
      }
1741
0
      if( value_64bit == 0 )
1742
0
      {
1743
0
        value_string      = (uint8_t *) "none";
1744
0
        value_string_size = 5;
1745
0
      }
1746
0
      else if( value_64bit == 1 )
1747
0
      {
1748
0
        value_string      = (uint8_t *) "deflate";
1749
0
        value_string_size = 8;
1750
0
      }
1751
0
      else if( value_64bit == 2 )
1752
0
      {
1753
0
        value_string      = (uint8_t *) "bzip2";
1754
0
        value_string_size = 6;
1755
0
      }
1756
#if defined( HAVE_DEBUG_OUTPUT )
1757
      else
1758
      {
1759
        if( libcnotify_verbose != 0 )
1760
        {
1761
          libcnotify_printf(
1762
          "%s: unsupported compression method: %" PRIu64 ".\n",
1763
           function,
1764
           value_64bit );
1765
        }
1766
      }
1767
#endif
1768
0
      identifier      = (uint8_t *) "compression_method";
1769
0
      identifier_size = 19;
1770
0
    }
1771
0
    else if( ( type_string[ 0 ] == (uint8_t) 'e' )
1772
0
          && ( type_string[ 1 ] == (uint8_t) 'n' ) )
1773
0
    {
1774
0
      identifier      = (uint8_t *) "evidence_number";
1775
0
      identifier_size = 16;
1776
0
    }
1777
0
    else if( ( type_string[ 0 ] == (uint8_t) 'e' )
1778
0
          && ( type_string[ 1 ] == (uint8_t) 'x' ) )
1779
0
    {
1780
0
      identifier      = (uint8_t *) "examiner_name";
1781
0
      identifier_size = 14;
1782
0
    }
1783
0
    else if( ( type_string[ 0 ] == (uint8_t) 'g' )
1784
0
          && ( type_string[ 1 ] == (uint8_t) 'r' ) )
1785
0
    {
1786
0
      if( libfvalue_utf8_string_copy_to_integer(
1787
0
           value_string,
1788
0
           value_string_size,
1789
0
           &value_64bit,
1790
0
           32,
1791
0
           LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1792
0
           error ) != 1 )
1793
0
      {
1794
0
        libcerror_error_set(
1795
0
         error,
1796
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
1797
0
         LIBCERROR_MEMORY_ERROR_SET_FAILED,
1798
0
         "%s: unable to set error granularity.",
1799
0
         function );
1800
1801
0
        goto on_error;
1802
0
      }
1803
0
      media_values->error_granularity = (uint32_t) value_64bit;
1804
0
    }
1805
0
    else if( ( type_string[ 0 ] == (uint8_t) 'n' )
1806
0
          && ( type_string[ 1 ] == (uint8_t) 'm' ) )
1807
0
    {
1808
0
      identifier      = (uint8_t *) "description";
1809
0
      identifier_size = 12;
1810
0
    }
1811
0
    else if( ( type_string[ 0 ] == (uint8_t) 'n' )
1812
0
          && ( type_string[ 1 ] == (uint8_t) 't' ) )
1813
0
    {
1814
0
      identifier      = (uint8_t *) "notes";
1815
0
      identifier_size = 6;
1816
0
    }
1817
0
    else if( ( type_string[ 0 ] == (uint8_t) 'o' )
1818
0
          && ( type_string[ 1 ] == (uint8_t) 's' ) )
1819
0
    {
1820
0
      identifier      = (uint8_t *) "acquiry_operating_system";
1821
0
      identifier_size = 25;
1822
0
    }
1823
0
    else if( ( type_string[ 0 ] == (uint8_t) 's' )
1824
0
          && ( type_string[ 1 ] == (uint8_t) 'b' ) )
1825
0
    {
1826
0
      if( libfvalue_utf8_string_copy_to_integer(
1827
0
           value_string,
1828
0
           value_string_size,
1829
0
           &value_64bit,
1830
0
           32,
1831
0
           LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1832
0
           error ) != 1 )
1833
0
      {
1834
0
        libcerror_error_set(
1835
0
         error,
1836
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
1837
0
         LIBCERROR_MEMORY_ERROR_SET_FAILED,
1838
0
         "%s: unable to set sectors per chunk.",
1839
0
         function );
1840
1841
0
        goto on_error;
1842
0
      }
1843
0
      media_values->sectors_per_chunk = (uint32_t) value_64bit;
1844
0
    }
1845
0
    else if( ( type_string[ 0 ] == (uint8_t) 't' )
1846
0
          && ( type_string[ 1 ] == (uint8_t) 'b' ) )
1847
0
    {
1848
0
      if( libfvalue_utf8_string_copy_to_integer(
1849
0
           value_string,
1850
0
           value_string_size,
1851
0
           &value_64bit,
1852
0
           64,
1853
0
           LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1854
0
           error ) != 1 )
1855
0
      {
1856
0
        libcerror_error_set(
1857
0
         error,
1858
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
1859
0
         LIBCERROR_MEMORY_ERROR_SET_FAILED,
1860
0
         "%s: unable to set number of chunks.",
1861
0
         function );
1862
1863
0
        goto on_error;
1864
0
      }
1865
0
      media_values->number_of_chunks = value_64bit;
1866
0
    }
1867
0
    else if( ( type_string[ 0 ] == (uint8_t) 't' )
1868
0
          && ( type_string[ 1 ] == (uint8_t) 't' ) )
1869
0
    {
1870
0
      if( libewf_convert_date_header2_value(
1871
0
           value_string,
1872
0
           value_string_size,
1873
0
           &date_time_values_string,
1874
0
           &date_time_values_string_size,
1875
0
           error ) != 1 )
1876
0
      {
1877
0
        libcerror_error_set(
1878
0
         error,
1879
0
         LIBCERROR_ERROR_DOMAIN_CONVERSION,
1880
0
         LIBCERROR_CONVERSION_ERROR_GENERIC,
1881
0
         "%s: unable to create date time values string.",
1882
0
         function );
1883
1884
#if defined( HAVE_DEBUG_OUTPUT )
1885
        if( libcnotify_verbose != 0 )
1886
        {
1887
          if( ( error != NULL )
1888
           && ( *error != NULL ) )
1889
          {
1890
            libcnotify_print_error_backtrace(
1891
             *error );
1892
          }
1893
        }
1894
#endif
1895
0
        libcerror_error_free(
1896
0
         error );
1897
0
      }
1898
0
      if( date_time_values_string != NULL )
1899
0
      {
1900
0
        value_string      = date_time_values_string;
1901
0
        value_string_size = 1 + narrow_string_length(
1902
0
                                 (char *) date_time_values_string );
1903
1904
0
        identifier      = (uint8_t *) "system_date";
1905
0
        identifier_size = 12;
1906
0
      }
1907
0
    }
1908
0
    else if( ( type_string[ 0 ] == (uint8_t) 'w' )
1909
0
          && ( type_string[ 1 ] == (uint8_t) 'b' ) )
1910
0
    {
1911
0
      if( libfvalue_utf8_string_copy_to_integer(
1912
0
           value_string,
1913
0
           value_string_size,
1914
0
           &value_64bit,
1915
0
           32,
1916
0
           LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1917
0
           error ) != 1 )
1918
0
      {
1919
0
        libcerror_error_set(
1920
0
         error,
1921
0
         LIBCERROR_ERROR_DOMAIN_MEMORY,
1922
0
         LIBCERROR_MEMORY_ERROR_SET_FAILED,
1923
0
         "%s: unable to set write blocker type.",
1924
0
         function );
1925
1926
0
        goto on_error;
1927
0
      }
1928
      /* The EnCase specification indicates these are flags and not an enumeration
1929
       */
1930
0
      if( ( value_64bit & 0x00000001 ) != 0 )
1931
0
      {
1932
0
        media_values->media_flags |= LIBEWF_MEDIA_FLAG_FASTBLOC;
1933
0
      }
1934
0
      if( ( value_64bit & 0x00000002 ) != 0 )
1935
0
      {
1936
0
        media_values->media_flags |= LIBEWF_MEDIA_FLAG_TABLEAU;
1937
0
      }
1938
#if defined( HAVE_DEBUG_OUTPUT )
1939
      if( ( value_64bit & ~( 0x00000003 ) ) != 0 )
1940
      {
1941
        if( libcnotify_verbose != 0 )
1942
        {
1943
          libcnotify_printf(
1944
          "%s: unsupported write blocker type.\n",
1945
           function );
1946
        }
1947
      }
1948
#endif
1949
0
    }
1950
0
  }
1951
0
  if( identifier != NULL )
1952
0
  {
1953
0
    if( libewf_value_table_set_value_by_identifier(
1954
0
         header_values,
1955
0
         identifier,
1956
0
         identifier_size,
1957
0
         value_string,
1958
0
         value_string_size,
1959
0
         error ) != 1 )
1960
0
    {
1961
0
      libcerror_error_set(
1962
0
       error,
1963
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1964
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1965
0
       "%s: unable to set header value: %s.",
1966
0
       function,
1967
0
       (char *) identifier );
1968
1969
0
      goto on_error;
1970
0
    }
1971
0
  }
1972
0
  if( date_time_values_string != NULL )
1973
0
  {
1974
0
    memory_free(
1975
0
     date_time_values_string );
1976
1977
0
    date_time_values_string = NULL;
1978
0
  }
1979
0
  return( 1 );
1980
1981
0
on_error:
1982
0
  if( date_time_values_string != NULL )
1983
0
  {
1984
0
    memory_free(
1985
0
     date_time_values_string );
1986
0
  }
1987
0
  return( -1 );
1988
0
}
1989
1990
/* Parses EWF version 2 case data
1991
 * Returns 1 if successful or -1 on error
1992
 */
1993
int libewf_case_data_parse(
1994
     const uint8_t *case_data,
1995
     size_t case_data_size,
1996
     libewf_media_values_t *media_values,
1997
     libfvalue_table_t *header_values,
1998
     uint8_t *format,
1999
     libcerror_error_t **error )
2000
0
{
2001
0
  uint8_t *utf8_string    = NULL;
2002
0
  static char *function   = "libewf_case_data_parse";
2003
0
  size_t utf8_string_size = 0;
2004
2005
0
  if( case_data == NULL )
2006
0
  {
2007
0
    libcerror_error_set(
2008
0
     error,
2009
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2010
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2011
0
     "%s: invalid case data.",
2012
0
     function );
2013
2014
0
    return( -1 );
2015
0
  }
2016
0
  if( libuna_utf8_string_size_from_utf16_stream(
2017
0
       case_data,
2018
0
       case_data_size,
2019
0
       0,
2020
0
       &utf8_string_size,
2021
0
       error ) != 1 )
2022
0
  {
2023
0
    libcerror_error_set(
2024
0
     error,
2025
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
2026
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
2027
0
     "%s: unable to determine UTF-8 string size.",
2028
0
     function );
2029
2030
0
    goto on_error;
2031
0
  }
2032
0
  if( ( utf8_string_size == 0 )
2033
0
   || ( utf8_string_size > MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
2034
0
  {
2035
0
    libcerror_error_set(
2036
0
     error,
2037
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2038
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
2039
0
     "%s: invalid UTF-8 string size value out of bounds.",
2040
0
     function );
2041
2042
0
    goto on_error;
2043
0
  }
2044
0
  utf8_string = (uint8_t *) memory_allocate(
2045
0
                             sizeof( uint8_t ) * utf8_string_size );
2046
2047
0
  if( utf8_string == NULL )
2048
0
  {
2049
0
    libcerror_error_set(
2050
0
     error,
2051
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
2052
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
2053
0
     "%s: unable to create UTF-8 string.",
2054
0
     function );
2055
2056
0
    goto on_error;
2057
0
  }
2058
0
  if( libuna_utf8_string_copy_from_utf16_stream(
2059
0
       utf8_string,
2060
0
       utf8_string_size,
2061
0
       case_data,
2062
0
       case_data_size,
2063
0
       0,
2064
0
       error ) != 1 )
2065
0
  {
2066
0
    libcerror_error_set(
2067
0
     error,
2068
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2069
0
     LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2070
0
     "%s: unable to copy case data to UTF-8 string.",
2071
0
     function );
2072
2073
0
    goto on_error;
2074
0
  }
2075
#if defined( HAVE_DEBUG_OUTPUT )
2076
  if( libcnotify_verbose != 0 )
2077
  {
2078
    libcnotify_printf(
2079
    "%s: case data string:\n%s",
2080
     function,
2081
     utf8_string );
2082
  }
2083
#endif
2084
0
  if( libewf_case_data_parse_utf8_string(
2085
0
       utf8_string,
2086
0
       utf8_string_size,
2087
0
       media_values,
2088
0
       header_values,
2089
0
       format,
2090
0
       error ) != 1 )
2091
0
  {
2092
0
    libcerror_error_set(
2093
0
     error,
2094
0
     LIBCERROR_ERROR_DOMAIN_CONVERSION,
2095
0
     LIBCERROR_CONVERSION_ERROR_GENERIC,
2096
0
     "%s: unable to parse UTF-8 string.",
2097
0
     function );
2098
2099
0
    goto on_error;
2100
0
  }
2101
0
  memory_free(
2102
0
   utf8_string );
2103
2104
0
  return( 1 );
2105
2106
0
on_error:
2107
0
  if( utf8_string != NULL )
2108
0
  {
2109
0
    memory_free(
2110
0
     utf8_string );
2111
0
  }
2112
0
  return( -1 );
2113
0
}
2114