1 /*
2  * Metadata functions
3  *
4  * Copyright (c) 2006-2014, 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_codepage.h"
28 #include "libewf_date_time_values.h"
29 #include "libewf_definitions.h"
30 #include "libewf_handle.h"
31 #include "libewf_hash_values.h"
32 #include "libewf_header_values.h"
33 #include "libewf_libcdata.h"
34 #include "libewf_libcerror.h"
35 #include "libewf_libcnotify.h"
36 #include "libewf_libfvalue.h"
37 #include "libewf_metadata.h"
38 #include "libewf_sector_range.h"
39 #include "libewf_segment_file_handle.h"
40 #include "libewf_types.h"
41 
42 #include "ewf_definitions.h"
43 
44 /* Retrieves the number of sectors per chunk
45  * Returns 1 if successful or -1 on error
46  */
libewf_handle_get_sectors_per_chunk(libewf_handle_t * handle,uint32_t * sectors_per_chunk,libcerror_error_t ** error)47 int libewf_handle_get_sectors_per_chunk(
48      libewf_handle_t *handle,
49      uint32_t *sectors_per_chunk,
50      libcerror_error_t **error )
51 {
52 	libewf_internal_handle_t *internal_handle = NULL;
53 	static char *function                     = "libewf_handle_get_sectors_per_chunk";
54 
55 	if( handle == NULL )
56 	{
57 		libcerror_error_set(
58 		 error,
59 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
60 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
61 		 "%s: invalid handle.",
62 		 function );
63 
64 		return( -1 );
65 	}
66 	internal_handle = (libewf_internal_handle_t *) handle;
67 
68 	if( internal_handle->media_values == NULL )
69 	{
70 		libcerror_error_set(
71 		 error,
72 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
73 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
74 		 "%s: invalid handle - missing media values.",
75 		 function );
76 
77 		return( -1 );
78 	}
79 	if( sectors_per_chunk == NULL )
80 	{
81 		libcerror_error_set(
82 		 error,
83 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
84 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
85 		 "%s: invalid sectors per chunk.",
86 		 function );
87 
88 		return( -1 );
89 	}
90 	if( internal_handle->media_values->sectors_per_chunk > (uint32_t) INT32_MAX )
91 	{
92 		libcerror_error_set(
93 		 error,
94 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
95 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
96 		 "%s: invalid sectors per chunk value exceeds maximum.",
97 		 function );
98 
99 		return( -1 );
100 	}
101 	*sectors_per_chunk = internal_handle->media_values->sectors_per_chunk;
102 
103 	return( 1 );
104 }
105 
106 /* Sets the number of sectors per chunk
107  * Returns 1 if successful or -1 on error
108  */
libewf_handle_set_sectors_per_chunk(libewf_handle_t * handle,uint32_t sectors_per_chunk,libcerror_error_t ** error)109 int libewf_handle_set_sectors_per_chunk(
110      libewf_handle_t *handle,
111      uint32_t sectors_per_chunk,
112      libcerror_error_t **error )
113 {
114 	libewf_internal_handle_t *internal_handle = NULL;
115 	static char *function                     = "libewf_handle_set_sectors_per_chunk";
116 
117 	if( handle == NULL )
118 	{
119 		libcerror_error_set(
120 		 error,
121 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
122 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
123 		 "%s: invalid handle.",
124 		 function );
125 
126 		return( -1 );
127 	}
128 	internal_handle = (libewf_internal_handle_t *) handle;
129 
130 	if( internal_handle->media_values == NULL )
131 	{
132 		libcerror_error_set(
133 		 error,
134 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
135 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
136 		 "%s: invalid handle - missing media values.",
137 		 function );
138 
139 		return( -1 );
140 	}
141 	if( ( internal_handle->read_io_handle != NULL )
142 	 || ( internal_handle->write_io_handle == NULL )
143 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
144 	{
145 		libcerror_error_set(
146 		 error,
147 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
148 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
149 		 "%s: sectors per chunk cannot be changed.",
150 		 function );
151 
152 		return( -1 );
153 	}
154 	if( libewf_internal_handle_set_media_values(
155 	     internal_handle,
156 	     sectors_per_chunk,
157 	     internal_handle->media_values->bytes_per_sector,
158 	     internal_handle->media_values->media_size,
159 	     error ) != 1 )
160 	{
161 		libcerror_error_set(
162 		 error,
163 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
164 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
165 		 "%s: unable to set media values.",
166 		 function );
167 
168 		return( -1 );
169 	}
170 	return( 1 );
171 }
172 
173 /* Retrieves the number of bytes per sector
174  * Returns 1 if successful or -1 on error
175  */
libewf_handle_get_bytes_per_sector(libewf_handle_t * handle,uint32_t * bytes_per_sector,libcerror_error_t ** error)176 int libewf_handle_get_bytes_per_sector(
177      libewf_handle_t *handle,
178      uint32_t *bytes_per_sector,
179      libcerror_error_t **error )
180 {
181 	libewf_internal_handle_t *internal_handle = NULL;
182 	static char *function                     = "libewf_handle_get_bytes_per_sector";
183 
184 	if( handle == NULL )
185 	{
186 		libcerror_error_set(
187 		 error,
188 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
189 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
190 		 "%s: invalid handle.",
191 		 function );
192 
193 		return( -1 );
194 	}
195 	internal_handle = (libewf_internal_handle_t *) handle;
196 
197 	if( internal_handle->media_values == NULL )
198 	{
199 		libcerror_error_set(
200 		 error,
201 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
202 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
203 		 "%s: invalid handle - missing media values.",
204 		 function );
205 
206 		return( -1 );
207 	}
208 	if( bytes_per_sector == NULL )
209 	{
210 		libcerror_error_set(
211 		 error,
212 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
213 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
214 		 "%s: invalid bytes per sector.",
215 		 function );
216 
217 		return( -1 );
218 	}
219 	if( internal_handle->media_values->bytes_per_sector > (uint32_t) INT32_MAX )
220 	{
221 		libcerror_error_set(
222 		 error,
223 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
224 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
225 		 "%s: invalid bytes per sector value exceeds maximum.",
226 		 function );
227 
228 		return( -1 );
229 	}
230 	*bytes_per_sector = internal_handle->media_values->bytes_per_sector;
231 
232 	return( 1 );
233 }
234 
235 /* Sets the number of bytes per sector
236  * Returns 1 if successful or -1 on error
237  */
libewf_handle_set_bytes_per_sector(libewf_handle_t * handle,uint32_t bytes_per_sector,libcerror_error_t ** error)238 int libewf_handle_set_bytes_per_sector(
239      libewf_handle_t *handle,
240      uint32_t bytes_per_sector,
241      libcerror_error_t **error )
242 {
243 	libewf_internal_handle_t *internal_handle = NULL;
244 	static char *function                     = "libewf_handle_set_bytes_per_sector";
245 
246 	if( handle == NULL )
247 	{
248 		libcerror_error_set(
249 		 error,
250 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
251 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
252 		 "%s: invalid handle.",
253 		 function );
254 
255 		return( -1 );
256 	}
257 	internal_handle = (libewf_internal_handle_t *) handle;
258 
259 	if( internal_handle->media_values == NULL )
260 	{
261 		libcerror_error_set(
262 		 error,
263 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
264 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
265 		 "%s: invalid handle - missing media values.",
266 		 function );
267 
268 		return( -1 );
269 	}
270 	if( ( internal_handle->read_io_handle != NULL )
271 	 || ( internal_handle->write_io_handle == NULL )
272 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
273 	{
274 		libcerror_error_set(
275 		 error,
276 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
277 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
278 		 "%s: bytes per sector cannot be changed.",
279 		 function );
280 
281 		return( -1 );
282 	}
283 	if( libewf_internal_handle_set_media_values(
284 	     internal_handle,
285 	     internal_handle->media_values->sectors_per_chunk,
286 	     bytes_per_sector,
287 	     internal_handle->media_values->media_size,
288 	     error ) != 1 )
289 	{
290 		libcerror_error_set(
291 		 error,
292 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
293 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
294 		 "%s: unable to set media values.",
295 		 function );
296 
297 		return( -1 );
298 	}
299 	return( 1 );
300 }
301 
302 /* Retrieves the number of sectors
303  * Returns 1 if successful or -1 on error
304  */
libewf_handle_get_number_of_sectors(libewf_handle_t * handle,uint64_t * number_of_sectors,libcerror_error_t ** error)305 int libewf_handle_get_number_of_sectors(
306      libewf_handle_t *handle,
307      uint64_t *number_of_sectors,
308      libcerror_error_t **error )
309 {
310 	libewf_internal_handle_t *internal_handle = NULL;
311 	static char *function                     = "libewf_handle_get_number_of_sectors";
312 
313 	if( handle == NULL )
314 	{
315 		libcerror_error_set(
316 		 error,
317 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
318 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
319 		 "%s: invalid handle.",
320 		 function );
321 
322 		return( -1 );
323 	}
324 	internal_handle = (libewf_internal_handle_t *) handle;
325 
326 	if( internal_handle->media_values == NULL )
327 	{
328 		libcerror_error_set(
329 		 error,
330 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
331 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
332 		 "%s: invalid handle - missing media values.",
333 		 function );
334 
335 		return( -1 );
336 	}
337 	if( number_of_sectors == NULL )
338 	{
339 		libcerror_error_set(
340 		 error,
341 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
342 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
343 		 "%s: invalid bytes per sector.",
344 		 function );
345 
346 		return( -1 );
347 	}
348 	if( internal_handle->media_values->number_of_sectors > (uint64_t) INT64_MAX )
349 	{
350 		libcerror_error_set(
351 		 error,
352 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
353 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
354 		 "%s: invalid number of sectors value exceeds maximum.",
355 		 function );
356 
357 		return( -1 );
358 	}
359 	*number_of_sectors = internal_handle->media_values->number_of_sectors;
360 
361 	return( 1 );
362 }
363 
364 /* Retrieves the chunk size
365  * Returns 1 if successful or -1 on error
366  */
libewf_handle_get_chunk_size(libewf_handle_t * handle,size32_t * chunk_size,libcerror_error_t ** error)367 int libewf_handle_get_chunk_size(
368      libewf_handle_t *handle,
369      size32_t *chunk_size,
370      libcerror_error_t **error )
371 {
372 	libewf_internal_handle_t *internal_handle = NULL;
373 	static char *function                     = "libewf_handle_get_chunk_size";
374 
375 	if( handle == NULL )
376 	{
377 		libcerror_error_set(
378 		 error,
379 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
380 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
381 		 "%s: invalid handle.",
382 		 function );
383 
384 		return( -1 );
385 	}
386 	internal_handle = (libewf_internal_handle_t *) handle;
387 
388 	if( internal_handle->media_values == NULL )
389 	{
390 		libcerror_error_set(
391 		 error,
392 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
393 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
394 		 "%s: invalid handle - missing media values.",
395 		 function );
396 
397 		return( -1 );
398 	}
399 	if( chunk_size == NULL )
400 	{
401 		libcerror_error_set(
402 		 error,
403 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
404 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
405 		 "%s: invalid chunk size.",
406 		 function );
407 
408 		return( -1 );
409 	}
410 	if( internal_handle->media_values->chunk_size > (size32_t) INT32_MAX )
411 	{
412 		libcerror_error_set(
413 		 error,
414 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
415 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
416 		 "%s: invalid chunk size value exceeds maximum.",
417 		 function );
418 
419 		return( -1 );
420 	}
421 	*chunk_size = internal_handle->media_values->chunk_size;
422 
423 	return( 1 );
424 }
425 
426 /* Retrieves the error granularity
427  * Returns 1 if successful or -1 on error
428  */
libewf_handle_get_error_granularity(libewf_handle_t * handle,uint32_t * error_granularity,libcerror_error_t ** error)429 int libewf_handle_get_error_granularity(
430      libewf_handle_t *handle,
431      uint32_t *error_granularity,
432      libcerror_error_t **error )
433 {
434 	libewf_internal_handle_t *internal_handle = NULL;
435 	static char *function                     = "libewf_handle_get_error_granularity";
436 
437 	if( handle == NULL )
438 	{
439 		libcerror_error_set(
440 		 error,
441 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
442 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
443 		 "%s: invalid handle.",
444 		 function );
445 
446 		return( -1 );
447 	}
448 	internal_handle = (libewf_internal_handle_t *) handle;
449 
450 	if( internal_handle->media_values == NULL )
451 	{
452 		libcerror_error_set(
453 		 error,
454 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
455 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
456 		 "%s: invalid handle - missing media values.",
457 		 function );
458 
459 		return( -1 );
460 	}
461 	if( error_granularity == NULL )
462 	{
463 		libcerror_error_set(
464 		 error,
465 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
466 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
467 		 "%s: invalid error granularity.",
468 		 function );
469 
470 		return( -1 );
471 	}
472 	if( internal_handle->media_values->error_granularity > (uint32_t) INT32_MAX )
473 	{
474 		libcerror_error_set(
475 		 error,
476 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
477 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
478 		 "%s: invalid error granularity value exceeds maximum.",
479 		 function );
480 
481 		return( -1 );
482 	}
483 	*error_granularity = internal_handle->media_values->error_granularity;
484 
485 	return( 1 );
486 }
487 
488 /* Sets the error granularity
489  * Returns 1 if successful or -1 on error
490  */
libewf_handle_set_error_granularity(libewf_handle_t * handle,uint32_t error_granularity,libcerror_error_t ** error)491 int libewf_handle_set_error_granularity(
492      libewf_handle_t *handle,
493      uint32_t error_granularity,
494      libcerror_error_t **error )
495 {
496 	libewf_internal_handle_t *internal_handle = NULL;
497 	static char *function                     = "libewf_handle_set_error_granularity";
498 
499 	if( handle == NULL )
500 	{
501 		libcerror_error_set(
502 		 error,
503 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
504 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
505 		 "%s: invalid handle.",
506 		 function );
507 
508 		return( -1 );
509 	}
510 	internal_handle = (libewf_internal_handle_t *) handle;
511 
512 	if( internal_handle->media_values == NULL )
513 	{
514 		libcerror_error_set(
515 		 error,
516 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
517 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
518 		 "%s: invalid handle - missing media values.",
519 		 function );
520 
521 		return( -1 );
522 	}
523 	if( ( internal_handle->write_io_handle == NULL )
524 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
525 	{
526 		libcerror_error_set(
527 		 error,
528 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
529 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
530 		 "%s: error granularity cannot be changed.",
531 		 function );
532 
533 		return( -1 );
534 	}
535 	internal_handle->media_values->error_granularity = error_granularity;
536 
537 	return( 1 );
538 }
539 
540 /* Retrieves the compression values
541  * Returns 1 if successful or -1 on error
542  */
libewf_handle_get_compression_values(libewf_handle_t * handle,int8_t * compression_level,uint8_t * compression_flags,libcerror_error_t ** error)543 int libewf_handle_get_compression_values(
544      libewf_handle_t *handle,
545      int8_t *compression_level,
546      uint8_t *compression_flags,
547      libcerror_error_t **error )
548 {
549 	libewf_internal_handle_t *internal_handle = NULL;
550 	static char *function                     = "libewf_handle_get_compression_values";
551 
552 	if( handle == NULL )
553 	{
554 		libcerror_error_set(
555 		 error,
556 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
557 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
558 		 "%s: invalid handle.",
559 		 function );
560 
561 		return( -1 );
562 	}
563 	internal_handle = (libewf_internal_handle_t *) handle;
564 
565 	if( internal_handle->io_handle == NULL )
566 	{
567 		libcerror_error_set(
568 		 error,
569 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
570 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
571 		 "%s: invalid handle - missing IO handle.",
572 		 function );
573 
574 		return( -1 );
575 	}
576 	if( compression_level == NULL )
577 	{
578 		libcerror_error_set(
579 		 error,
580 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
581 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
582 		 "%s: invalid compression level.",
583 		 function );
584 
585 		return( -1 );
586 	}
587 	if( compression_flags == NULL )
588 	{
589 		libcerror_error_set(
590 		 error,
591 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
592 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
593 		 "%s: invalid compression flags.",
594 		 function );
595 
596 		return( -1 );
597 	}
598 	*compression_level = internal_handle->io_handle->compression_level;
599 	*compression_flags = internal_handle->io_handle->compression_flags;
600 
601 	return( 1 );
602 }
603 
604 /* Sets the compression values
605  * Returns 1 if successful or -1 on error
606  */
libewf_handle_set_compression_values(libewf_handle_t * handle,int8_t compression_level,uint8_t compression_flags,libcerror_error_t ** error)607 int libewf_handle_set_compression_values(
608      libewf_handle_t *handle,
609      int8_t compression_level,
610      uint8_t compression_flags ,
611      libcerror_error_t **error )
612 {
613 	libewf_internal_handle_t *internal_handle = NULL;
614 	static char *function                     = "libewf_handle_set_compression_values";
615 
616 	if( handle == NULL )
617 	{
618 		libcerror_error_set(
619 		 error,
620 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
621 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
622 		 "%s: invalid handle.",
623 		 function );
624 
625 		return( -1 );
626 	}
627 	internal_handle = (libewf_internal_handle_t *) handle;
628 
629 	if( internal_handle->io_handle == NULL )
630 	{
631 		libcerror_error_set(
632 		 error,
633 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
634 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
635 		 "%s: invalid handle - missing IO handle.",
636 		 function );
637 
638 		return( -1 );
639 	}
640 	if( ( internal_handle->write_io_handle == NULL )
641 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
642 	{
643 		libcerror_error_set(
644 		 error,
645 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
646 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
647 		 "%s: compression values cannot be changed.",
648 		 function );
649 
650 		return( -1 );
651 	}
652 	if( ( compression_level != EWF_COMPRESSION_NONE )
653 	 && ( compression_level != EWF_COMPRESSION_FAST )
654 	 && ( compression_level != EWF_COMPRESSION_BEST ) )
655 	{
656 		libcerror_error_set(
657 		 error,
658 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
659 		 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
660 		 "%s: unsupported compression level.",
661 		 function );
662 
663 		return( -1 );
664 	}
665 	internal_handle->io_handle->compression_level = compression_level;
666 	internal_handle->io_handle->compression_flags = compression_flags;
667 
668 	return( 1 );
669 }
670 
671 /* Retrieves the size of the contained media data
672  * Returns 1 if successful or -1 on error
673  */
libewf_handle_get_media_size(libewf_handle_t * handle,size64_t * media_size,libcerror_error_t ** error)674 int libewf_handle_get_media_size(
675      libewf_handle_t *handle,
676      size64_t *media_size,
677      libcerror_error_t **error )
678 {
679 	libewf_internal_handle_t *internal_handle = NULL;
680 	static char *function                     = "libewf_handle_get_media_size";
681 
682 	if( handle == NULL )
683 	{
684 		libcerror_error_set(
685 		 error,
686 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
687 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
688 		 "%s: invalid handle.",
689 		 function );
690 
691 		return( -1 );
692 	}
693 	internal_handle = (libewf_internal_handle_t *) handle;
694 
695 	if( internal_handle->media_values == NULL )
696 	{
697 		libcerror_error_set(
698 		 error,
699 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
700 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
701 		 "%s: invalid handle - missing media values.",
702 		 function );
703 
704 		return( -1 );
705 	}
706 	if( media_size == NULL )
707 	{
708 		libcerror_error_set(
709 		 error,
710 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
711 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
712 		 "%s: invalid media size.",
713 		 function );
714 
715 		return( -1 );
716 	}
717 	*media_size = internal_handle->media_values->media_size;
718 
719 	return( 1 );
720 }
721 
722 /* Sets the media size
723  * Returns 1 if successful or -1 on error
724  */
libewf_handle_set_media_size(libewf_handle_t * handle,size64_t media_size,libcerror_error_t ** error)725 int libewf_handle_set_media_size(
726      libewf_handle_t *handle,
727      size64_t media_size,
728      libcerror_error_t **error )
729 {
730 	libewf_internal_handle_t *internal_handle = NULL;
731 	static char *function                     = "libewf_handle_set_media_size";
732 
733 	if( handle == NULL )
734 	{
735 		libcerror_error_set(
736 		 error,
737 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
738 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
739 		 "%s: invalid handle.",
740 		 function );
741 
742 		return( -1 );
743 	}
744 	internal_handle = (libewf_internal_handle_t *) handle;
745 
746 	if( internal_handle->media_values == NULL )
747 	{
748 		libcerror_error_set(
749 		 error,
750 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
751 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
752 		 "%s: invalid handle - missing media values.",
753 		 function );
754 
755 		return( -1 );
756 	}
757 	if( ( internal_handle->read_io_handle != NULL )
758 	 || ( internal_handle->write_io_handle == NULL )
759 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
760 	{
761 		libcerror_error_set(
762 		 error,
763 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
764 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
765 		 "%s: media size cannot be changed.",
766 		 function );
767 
768 		return( -1 );
769 	}
770 	if( libewf_internal_handle_set_media_values(
771 	     internal_handle,
772 	     internal_handle->media_values->sectors_per_chunk,
773 	     internal_handle->media_values->bytes_per_sector,
774 	     media_size,
775 	     error ) != 1 )
776 	{
777 		libcerror_error_set(
778 		 error,
779 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
780 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
781 		 "%s: unable to set media values.",
782 		 function );
783 
784 		return( -1 );
785 	}
786 	return( 1 );
787 }
788 
789 /* Retrieves the media type value
790  * Returns 1 if successful or -1 on error
791  */
libewf_handle_get_media_type(libewf_handle_t * handle,uint8_t * media_type,libcerror_error_t ** error)792 int libewf_handle_get_media_type(
793      libewf_handle_t *handle,
794      uint8_t *media_type,
795      libcerror_error_t **error )
796 {
797 	libewf_internal_handle_t *internal_handle = NULL;
798 	static char *function                     = "libewf_handle_get_media_type";
799 
800 	if( handle == NULL )
801 	{
802 		libcerror_error_set(
803 		 error,
804 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
805 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
806 		 "%s: invalid handle.",
807 		 function );
808 
809 		return( -1 );
810 	}
811 	internal_handle = (libewf_internal_handle_t *) handle;
812 
813 	if( internal_handle->media_values == NULL )
814 	{
815 		libcerror_error_set(
816 		 error,
817 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
818 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
819 		 "%s: invalid handle - missing media values.",
820 		 function );
821 
822 		return( -1 );
823 	}
824 	if( internal_handle->media_values->media_type > (uint8_t) INT8_MAX )
825 	{
826 		libcerror_error_set(
827 		 error,
828 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
829 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
830 		 "%s: invalid media type value exceeds maximum.",
831 		 function );
832 
833 		return( -1 );
834 	}
835 	if( media_type == NULL )
836 	{
837 		libcerror_error_set(
838 		 error,
839 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
840 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
841 		 "%s: invalid media type.",
842 		 function );
843 
844 		return( -1 );
845 	}
846 	*media_type = internal_handle->media_values->media_type;
847 
848 	return( 1 );
849 }
850 
851 /* Sets the media type
852  * Returns 1 if successful or -1 on error
853  */
libewf_handle_set_media_type(libewf_handle_t * handle,uint8_t media_type,libcerror_error_t ** error)854 int libewf_handle_set_media_type(
855      libewf_handle_t *handle,
856      uint8_t media_type,
857      libcerror_error_t **error )
858 {
859 	libewf_internal_handle_t *internal_handle = NULL;
860 	static char *function                     = "libewf_handle_set_media_type";
861 
862 	if( handle == NULL )
863 	{
864 		libcerror_error_set(
865 		 error,
866 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
867 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
868 		 "%s: invalid handle.",
869 		 function );
870 
871 		return( -1 );
872 	}
873 	internal_handle = (libewf_internal_handle_t *) handle;
874 
875 	if( internal_handle->media_values == NULL )
876 	{
877 		libcerror_error_set(
878 		 error,
879 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
880 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
881 		 "%s: invalid handle - missing media values.",
882 		 function );
883 
884 		return( -1 );
885 	}
886 	if( ( internal_handle->read_io_handle != NULL )
887 	 || ( internal_handle->write_io_handle == NULL )
888 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
889 	{
890 		libcerror_error_set(
891 		 error,
892 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
893 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
894 		 "%s: media type cannot be changed.",
895 		 function );
896 
897 		return( -1 );
898 	}
899 	internal_handle->media_values->media_type = media_type;
900 
901 	return( 1 );
902 }
903 
904 /* Retrieves the media flags
905  * Returns 1 if successful or -1 on error
906  */
libewf_handle_get_media_flags(libewf_handle_t * handle,uint8_t * media_flags,libcerror_error_t ** error)907 int libewf_handle_get_media_flags(
908      libewf_handle_t *handle,
909      uint8_t *media_flags,
910      libcerror_error_t **error )
911 {
912 	libewf_internal_handle_t *internal_handle = NULL;
913 	static char *function                     = "libewf_handle_get_media_flags";
914 
915 	if( handle == NULL )
916 	{
917 		libcerror_error_set(
918 		 error,
919 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
920 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
921 		 "%s: invalid handle.",
922 		 function );
923 
924 		return( -1 );
925 	}
926 	internal_handle = (libewf_internal_handle_t *) handle;
927 
928 	if( internal_handle->media_values == NULL )
929 	{
930 		libcerror_error_set(
931 		 error,
932 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
933 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
934 		 "%s: invalid handle - missing media values.",
935 		 function );
936 
937 		return( -1 );
938 	}
939 	if( internal_handle->media_values->media_flags > (uint8_t) INT8_MAX )
940 	{
941 		libcerror_error_set(
942 		 error,
943 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
944 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
945 		 "%s: invalid media flags value exceeds maximum.",
946 		 function );
947 
948 		return( -1 );
949 	}
950 	if( media_flags == NULL )
951 	{
952 		libcerror_error_set(
953 		 error,
954 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
955 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
956 		 "%s: invalid media flags.",
957 		 function );
958 
959 		return( -1 );
960 	}
961 	*media_flags = internal_handle->media_values->media_flags;
962 
963 	return( 1 );
964 }
965 
966 /* Sets the media flags
967  * Returns 1 if successful or -1 on error
968  */
libewf_handle_set_media_flags(libewf_handle_t * handle,uint8_t media_flags,libcerror_error_t ** error)969 int libewf_handle_set_media_flags(
970      libewf_handle_t *handle,
971      uint8_t media_flags,
972      libcerror_error_t **error )
973 {
974 	libewf_internal_handle_t *internal_handle = NULL;
975 	static char *function                     = "libewf_handle_set_media_flags";
976 
977 	if( handle == NULL )
978 	{
979 		libcerror_error_set(
980 		 error,
981 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
982 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
983 		 "%s: invalid handle.",
984 		 function );
985 
986 		return( -1 );
987 	}
988 	internal_handle = (libewf_internal_handle_t *) handle;
989 
990 	if( internal_handle->media_values == NULL )
991 	{
992 		libcerror_error_set(
993 		 error,
994 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
995 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
996 		 "%s: invalid handle - missing media values.",
997 		 function );
998 
999 		return( -1 );
1000 	}
1001 	if( ( internal_handle->read_io_handle != NULL )
1002 	 || ( internal_handle->write_io_handle == NULL )
1003 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
1004 	{
1005 		libcerror_error_set(
1006 		 error,
1007 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1008 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1009 		 "%s: media flags cannot be changed.",
1010 		 function );
1011 
1012 		return( -1 );
1013 	}
1014 	internal_handle->media_values->media_flags = media_flags;
1015 
1016 	/* Make sure the lowest bit is always set
1017 	 */
1018 	internal_handle->media_values->media_flags |= 0x01;
1019 
1020 	return( 1 );
1021 }
1022 
1023 /* Retrieves the format type value
1024  * Returns 1 if successful or -1 on error
1025  */
libewf_handle_get_format(libewf_handle_t * handle,uint8_t * format,libcerror_error_t ** error)1026 int libewf_handle_get_format(
1027      libewf_handle_t *handle,
1028      uint8_t *format,
1029      libcerror_error_t **error )
1030 {
1031 	libewf_internal_handle_t *internal_handle = NULL;
1032 	static char *function                     = "libewf_handle_get_format";
1033 
1034 	if( handle == NULL )
1035 	{
1036 		libcerror_error_set(
1037 		 error,
1038 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1039 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1040 		 "%s: invalid handle.",
1041 		 function );
1042 
1043 		return( -1 );
1044 	}
1045 	internal_handle = (libewf_internal_handle_t *) handle;
1046 
1047 	if( internal_handle->io_handle == NULL )
1048 	{
1049 		libcerror_error_set(
1050 		 error,
1051 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1052 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1053 		 "%s: invalid handle - missing IO handle.",
1054 		 function );
1055 
1056 		return( -1 );
1057 	}
1058 	if( internal_handle->media_values == NULL )
1059 	{
1060 		libcerror_error_set(
1061 		 error,
1062 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1063 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1064 		 "%s: invalid handle - missing media values.",
1065 		 function );
1066 
1067 		return( -1 );
1068 	}
1069 	if( internal_handle->io_handle->format > (uint8_t) INT8_MAX )
1070 	{
1071 		libcerror_error_set(
1072 		 error,
1073 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1074 		 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
1075 		 "%s: invalid format value exceeds maximum.",
1076 		 function );
1077 
1078 		return( -1 );
1079 	}
1080 	if( format == NULL )
1081 	{
1082 		libcerror_error_set(
1083 		 error,
1084 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1085 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1086 		 "%s: invalid format.",
1087 		 function );
1088 
1089 		return( -1 );
1090 	}
1091 	*format = internal_handle->io_handle->format;
1092 
1093 	return( 1 );
1094 }
1095 
1096 /* Sets the output format
1097  * Returns 1 if successful or -1 on error
1098  */
libewf_handle_set_format(libewf_handle_t * handle,uint8_t format,libcerror_error_t ** error)1099 int libewf_handle_set_format(
1100      libewf_handle_t *handle,
1101      uint8_t format,
1102      libcerror_error_t **error )
1103 {
1104 	libewf_internal_handle_t *internal_handle = NULL;
1105 	static char *function                     = "libewf_handle_set_format";
1106 
1107 	if( handle == NULL )
1108 	{
1109 		libcerror_error_set(
1110 		 error,
1111 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1112 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1113 		 "%s: invalid handle.",
1114 		 function );
1115 
1116 		return( -1 );
1117 	}
1118 	internal_handle = (libewf_internal_handle_t *) handle;
1119 
1120 	if( ( internal_handle->read_io_handle != NULL )
1121 	 || ( internal_handle->write_io_handle == NULL )
1122 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
1123 	{
1124 		libcerror_error_set(
1125 		 error,
1126 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1127 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1128 		 "%s: format cannot be changed.",
1129 		 function );
1130 
1131 		return( -1 );
1132 	}
1133 	if( libewf_internal_handle_set_format(
1134 	     internal_handle,
1135 	     format,
1136 	     error ) != 1 )
1137 	{
1138 		libcerror_error_set(
1139 		 error,
1140 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1141 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1142 		 "%s: unable to set format.",
1143 		 function );
1144 
1145 		return( -1 );
1146 	}
1147 	return( 1 );
1148 }
1149 
1150 /* Retrieves the segment file set identifier
1151  * The identifier is a GUID and is 16 bytes of size
1152  * Returns 1 if successful or -1 on error
1153  */
libewf_handle_get_segment_file_set_identifier(libewf_handle_t * handle,uint8_t * set_identifier,size_t size,libcerror_error_t ** error)1154 int libewf_handle_get_segment_file_set_identifier(
1155      libewf_handle_t *handle,
1156      uint8_t *set_identifier,
1157      size_t size,
1158      libcerror_error_t **error )
1159 {
1160 	libewf_internal_handle_t *internal_handle = NULL;
1161 	static char *function                     = "libewf_handle_get_segment_file_set_identifier";
1162 
1163 	if( handle == NULL )
1164 	{
1165 		libcerror_error_set(
1166 		 error,
1167 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1168 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1169 		 "%s: invalid handle.",
1170 		 function );
1171 
1172 		return( -1 );
1173 	}
1174 	internal_handle = (libewf_internal_handle_t *) handle;
1175 
1176 	if( internal_handle->media_values == NULL )
1177 	{
1178 		libcerror_error_set(
1179 		 error,
1180 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1181 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1182 		 "%s: invalid handle - missing media values.",
1183 		 function );
1184 
1185 		return( -1 );
1186 	}
1187 	if( set_identifier == NULL )
1188 	{
1189 		libcerror_error_set(
1190 		 error,
1191 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1192 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1193 		 "%s: invalid set identifier.",
1194 		 function );
1195 
1196 		return( -1 );
1197 	}
1198 	if( size < 16 )
1199 	{
1200 		libcerror_error_set(
1201 		 error,
1202 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1203 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1204 		 "%s: set identifier too small.",
1205 		 function );
1206 
1207 		return( -1 );
1208 	}
1209 	if( memory_copy(
1210 	     set_identifier,
1211 	     internal_handle->media_values->guid,
1212 	     16 ) == NULL )
1213 	{
1214 		libcerror_error_set(
1215 		 error,
1216 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1217 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1218 		 "%s: unable to copy set identifier.",
1219 		 function );
1220 
1221 		return( -1 );
1222 	}
1223 	return( 1 );
1224 }
1225 
1226 /* Sets the segment file set identifier
1227  * The identifier is a GUID and is 16 bytes of size
1228  * Returns 1 if successful or -1 on error
1229  */
libewf_handle_set_segment_file_set_identifier(libewf_handle_t * handle,const uint8_t * set_identifier,size_t size,libcerror_error_t ** error)1230 int libewf_handle_set_segment_file_set_identifier(
1231      libewf_handle_t *handle,
1232      const uint8_t *set_identifier,
1233      size_t size,
1234      libcerror_error_t **error )
1235 {
1236 	libewf_internal_handle_t *internal_handle = NULL;
1237 	static char *function                     = "libewf_handle_set_segment_file_set_identifier";
1238 
1239 	if( handle == NULL )
1240 	{
1241 		libcerror_error_set(
1242 		 error,
1243 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1244 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1245 		 "%s: invalid handle.",
1246 		 function );
1247 
1248 		return( -1 );
1249 	}
1250 	internal_handle = (libewf_internal_handle_t *) handle;
1251 
1252 	if( internal_handle->media_values == NULL )
1253 	{
1254 		libcerror_error_set(
1255 		 error,
1256 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1257 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1258 		 "%s: invalid handle - missing media values.",
1259 		 function );
1260 
1261 		return( -1 );
1262 	}
1263 	if( set_identifier == NULL )
1264 	{
1265 		libcerror_error_set(
1266 		 error,
1267 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1268 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1269 		 "%s: invalid set identifier.",
1270 		 function );
1271 
1272 		return( -1 );
1273 	}
1274 	if( size < 16 )
1275 	{
1276 		libcerror_error_set(
1277 		 error,
1278 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1279 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1280 		 "%s: set identifier too small.",
1281 		 function );
1282 
1283 		return( -1 );
1284 	}
1285 	if( ( internal_handle->read_io_handle != NULL )
1286 	 || ( internal_handle->write_io_handle == NULL )
1287 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
1288 	{
1289 		libcerror_error_set(
1290 		 error,
1291 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1292 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1293 		 "%s: set identifier cannot be changed.",
1294 		 function );
1295 
1296 		return( -1 );
1297 	}
1298 	if( memory_copy(
1299 	     internal_handle->media_values->guid,
1300 	     set_identifier,
1301 	     16 ) == NULL )
1302 	{
1303 		libcerror_error_set(
1304 		 error,
1305 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1306 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1307 		 "%s: unable to copy set identifier.",
1308 		 function );
1309 
1310 		return( -1 );
1311 	}
1312 	return( 1 );
1313 }
1314 
1315 /* Retrieves the MD5 hash
1316  * Returns 1 if successful, 0 if value not present or -1 on error
1317  */
libewf_handle_get_md5_hash(libewf_handle_t * handle,uint8_t * md5_hash,size_t size,libcerror_error_t ** error)1318 int libewf_handle_get_md5_hash(
1319      libewf_handle_t *handle,
1320      uint8_t *md5_hash,
1321      size_t size,
1322      libcerror_error_t **error )
1323 {
1324 	libewf_internal_handle_t *internal_handle = NULL;
1325 	static char *function                     = "libewf_handle_get_md5_hash";
1326 
1327 	if( handle == NULL )
1328 	{
1329 		libcerror_error_set(
1330 		 error,
1331 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1332 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1333 		 "%s: invalid handle.",
1334 		 function );
1335 
1336 		return( -1 );
1337 	}
1338 	internal_handle = (libewf_internal_handle_t *) handle;
1339 
1340 	if( internal_handle->hash_sections == NULL )
1341 	{
1342 		libcerror_error_set(
1343 		 error,
1344 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1345 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1346 		 "%s: invalid handle - missing hash sections.",
1347 		 function );
1348 
1349 		return( -1 );
1350 	}
1351 	if( ( ( internal_handle->hash_sections->md5_hash_set == 0 )
1352 	  || ( internal_handle->hash_sections->md5_digest_set == 0 ) )
1353 	 && ( internal_handle->hash_values != NULL ) )
1354 	{
1355 		if( libewf_hash_values_generate_md5_hash(
1356 		     internal_handle->hash_values,
1357 		     internal_handle->hash_sections->md5_hash,
1358 		     16,
1359 		     &( internal_handle->hash_sections->md5_hash_set ),
1360 		     error ) != 1 )
1361 		{
1362 			libcerror_error_set(
1363 			 error,
1364 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1365 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1366 			 "%s: unable to parse MD5 hash value for its value.",
1367 			 function );
1368 
1369 			return( -1 );
1370 		}
1371 	}
1372 	if( ( internal_handle->hash_sections->md5_hash_set == 0 )
1373 	 && ( internal_handle->hash_sections->md5_digest_set == 0 ) )
1374 	{
1375 		return( 0 );
1376 	}
1377 	if( md5_hash == NULL )
1378 	{
1379 		libcerror_error_set(
1380 		 error,
1381 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1382 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1383 		 "%s: invalid MD5 hash.",
1384 		 function );
1385 
1386 		return( -1 );
1387 	}
1388 	if( size < 16 )
1389 	{
1390 		libcerror_error_set(
1391 		 error,
1392 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1393 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1394 		 "%s: MD5 hash too small.",
1395 		 function );
1396 
1397 		return( -1 );
1398 	}
1399 	if( internal_handle->hash_sections->md5_hash_set == 0 )
1400 	{
1401 		if( memory_copy(
1402 		     md5_hash,
1403 		     internal_handle->hash_sections->md5_digest,
1404 		     16 ) == NULL )
1405 		{
1406 			libcerror_error_set(
1407 			 error,
1408 			 LIBCERROR_ERROR_DOMAIN_MEMORY,
1409 			 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1410 			 "%s: unable to set MD5 hash.",
1411 			 function );
1412 
1413 			return( -1 );
1414 		}
1415 	}
1416 	else
1417 	{
1418 		if( memory_copy(
1419 		     md5_hash,
1420 		     internal_handle->hash_sections->md5_hash,
1421 		     16 ) == NULL )
1422 		{
1423 			libcerror_error_set(
1424 			 error,
1425 			 LIBCERROR_ERROR_DOMAIN_MEMORY,
1426 			 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1427 			 "%s: unable to set MD5 hash.",
1428 			 function );
1429 
1430 			return( -1 );
1431 		}
1432 	}
1433 	return( 1 );
1434 }
1435 
1436 /* Sets the MD5 hash
1437  * Returns 1 if successful or -1 on error
1438  */
libewf_handle_set_md5_hash(libewf_handle_t * handle,uint8_t * md5_hash,size_t size,libcerror_error_t ** error)1439 int libewf_handle_set_md5_hash(
1440      libewf_handle_t *handle,
1441      uint8_t *md5_hash,
1442      size_t size,
1443      libcerror_error_t **error )
1444 {
1445 	libewf_internal_handle_t *internal_handle = NULL;
1446 	static char *function                     = "libewf_handle_set_md5_hash";
1447 
1448 	if( handle == NULL )
1449 	{
1450 		libcerror_error_set(
1451 		 error,
1452 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1453 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1454 		 "%s: invalid handle.",
1455 		 function );
1456 
1457 		return( -1 );
1458 	}
1459 	internal_handle = (libewf_internal_handle_t *) handle;
1460 
1461 	if( internal_handle->hash_sections == NULL )
1462 	{
1463 		libcerror_error_set(
1464 		 error,
1465 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1466 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1467 		 "%s: invalid handle - missing hash sections.",
1468 		 function );
1469 
1470 		return( -1 );
1471 	}
1472 	if( ( internal_handle->read_io_handle != NULL )
1473 	 || ( internal_handle->hash_sections->md5_hash_set )
1474 	 || ( internal_handle->hash_sections->md5_digest_set ) )
1475 	{
1476 		libcerror_error_set(
1477 		 error,
1478 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1479 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1480 		 "%s: md5 hash cannot be changed.",
1481 		 function );
1482 
1483 		return( -1 );
1484 	}
1485 	if( md5_hash == NULL )
1486 	{
1487 		libcerror_error_set(
1488 		 error,
1489 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1490 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1491 		 "%s: invalid MD5 hash.",
1492 		 function );
1493 
1494 		return( -1 );
1495 	}
1496 	if( size < 16 )
1497 	{
1498 		libcerror_error_set(
1499 		 error,
1500 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1501 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1502 		 "%s: MD5 hash too small.",
1503 		 function );
1504 
1505 		return( -1 );
1506 	}
1507 	if( memory_copy(
1508 	     internal_handle->hash_sections->md5_hash,
1509 	     md5_hash,
1510 	     16 ) == NULL )
1511 	{
1512 		libcerror_error_set(
1513 		 error,
1514 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1515 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1516 		 "%s: unable to set MD5 hash.",
1517 		 function );
1518 
1519 		return( -1 );
1520 	}
1521 	if( memory_copy(
1522 	     internal_handle->hash_sections->md5_digest,
1523 	     md5_hash,
1524 	     16 ) == NULL )
1525 	{
1526 		libcerror_error_set(
1527 		 error,
1528 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1529 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1530 		 "%s: unable to set MD5 hash.",
1531 		 function );
1532 
1533 		return( -1 );
1534 	}
1535 	if( internal_handle->hash_values == NULL )
1536 	{
1537 		if( libewf_hash_values_initialize(
1538 		     &( internal_handle->hash_values ),
1539 		     error ) != 1 )
1540 		{
1541 			libcerror_error_set(
1542 			 error,
1543 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1544 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1545 			 "%s: unable to create hash values.",
1546 			 function );
1547 
1548 			return( -1 );
1549 		}
1550 		internal_handle->hash_values_parsed = 1;
1551 	}
1552 	if( libewf_hash_values_parse_md5_hash(
1553 	     internal_handle->hash_values,
1554 	     md5_hash,
1555 	     16,
1556 	     error ) != 1 )
1557 	{
1558 		libcerror_error_set(
1559 		 error,
1560 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1561 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1562 		 "%s: unable to parse MD5 hash for its value.",
1563 		 function );
1564 
1565 		return( -1 );
1566 	}
1567 	internal_handle->hash_sections->md5_hash_set   = 1;
1568 	internal_handle->hash_sections->md5_digest_set = 1;
1569 
1570 	return( 1 );
1571 }
1572 
1573 /* Retrieves the SHA1 hash
1574  * Returns 1 if successful, 0 if value not present or -1 on error
1575  */
libewf_handle_get_sha1_hash(libewf_handle_t * handle,uint8_t * sha1_hash,size_t size,libcerror_error_t ** error)1576 int libewf_handle_get_sha1_hash(
1577      libewf_handle_t *handle,
1578      uint8_t *sha1_hash,
1579      size_t size,
1580      libcerror_error_t **error )
1581 {
1582 	libewf_internal_handle_t *internal_handle = NULL;
1583 	static char *function                     = "libewf_handle_get_sha1_hash";
1584 
1585 	if( handle == NULL )
1586 	{
1587 		libcerror_error_set(
1588 		 error,
1589 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1590 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1591 		 "%s: invalid handle.",
1592 		 function );
1593 
1594 		return( -1 );
1595 	}
1596 	internal_handle = (libewf_internal_handle_t *) handle;
1597 
1598 	if( internal_handle->hash_sections == NULL )
1599 	{
1600 		libcerror_error_set(
1601 		 error,
1602 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1603 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1604 		 "%s: invalid handle - missing hash sections.",
1605 		 function );
1606 
1607 		return( -1 );
1608 	}
1609 	if( ( internal_handle->hash_sections->sha1_digest_set == 0 )
1610 	 && ( internal_handle->hash_values != NULL ) )
1611 	{
1612 		if( libewf_hash_values_generate_sha1_hash(
1613 		     internal_handle->hash_values,
1614 		     internal_handle->hash_sections->sha1_digest,
1615 		     20,
1616 		     &( internal_handle->hash_sections->sha1_digest_set ),
1617 		     error ) != 1 )
1618 		{
1619 			libcerror_error_set(
1620 			 error,
1621 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1622 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1623 			 "%s: unable to parse MD5 hash value for its value.",
1624 			 function );
1625 
1626 			return( -1 );
1627 		}
1628 	}
1629 	if( internal_handle->hash_sections->sha1_digest_set == 0 )
1630 	{
1631 		return( 0 );
1632 	}
1633 	if( sha1_hash == NULL )
1634 	{
1635 		libcerror_error_set(
1636 		 error,
1637 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1638 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1639 		 "%s: invalid SHA1 hash.",
1640 		 function );
1641 
1642 		return( -1 );
1643 	}
1644 	if( size < 20 )
1645 	{
1646 		libcerror_error_set(
1647 		 error,
1648 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1649 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1650 		 "%s: SHA1 hash too small.",
1651 		 function );
1652 
1653 		return( -1 );
1654 	}
1655 	if( memory_copy(
1656 	     sha1_hash,
1657 	     internal_handle->hash_sections->sha1_digest,
1658 	     20 ) == NULL )
1659 	{
1660 		libcerror_error_set(
1661 		 error,
1662 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1663 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1664 		 "%s: unable to set MD5 hash.",
1665 		 function );
1666 
1667 		return( -1 );
1668 	}
1669 	return( 1 );
1670 }
1671 
1672 /* Sets the SHA1 hash
1673  * Returns 1 if successful or -1 on error
1674  */
libewf_handle_set_sha1_hash(libewf_handle_t * handle,uint8_t * sha1_hash,size_t size,libcerror_error_t ** error)1675 int libewf_handle_set_sha1_hash(
1676      libewf_handle_t *handle,
1677      uint8_t *sha1_hash,
1678      size_t size,
1679      libcerror_error_t **error )
1680 {
1681 	libewf_internal_handle_t *internal_handle = NULL;
1682 	static char *function                     = "libewf_handle_set_sha1_hash";
1683 
1684 	if( handle == NULL )
1685 	{
1686 		libcerror_error_set(
1687 		 error,
1688 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1689 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1690 		 "%s: invalid handle.",
1691 		 function );
1692 
1693 		return( -1 );
1694 	}
1695 	internal_handle = (libewf_internal_handle_t *) handle;
1696 
1697 	if( internal_handle->hash_sections == NULL )
1698 	{
1699 		libcerror_error_set(
1700 		 error,
1701 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1702 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1703 		 "%s: invalid handle - missing hash sections.",
1704 		 function );
1705 
1706 		return( -1 );
1707 	}
1708 	if( ( internal_handle->read_io_handle != NULL )
1709 	 || ( internal_handle->hash_sections->sha1_digest_set ) )
1710 	{
1711 		libcerror_error_set(
1712 		 error,
1713 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1714 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1715 		 "%s: sha1 hash cannot be changed.",
1716 		 function );
1717 
1718 		return( -1 );
1719 	}
1720 	if( sha1_hash == NULL )
1721 	{
1722 		libcerror_error_set(
1723 		 error,
1724 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1725 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1726 		 "%s: invalid SHA1 hash.",
1727 		 function );
1728 
1729 		return( -1 );
1730 	}
1731 	if( size < 20 )
1732 	{
1733 		libcerror_error_set(
1734 		 error,
1735 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1736 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
1737 		 "%s: SHA1 hash too small.",
1738 		 function );
1739 
1740 		return( -1 );
1741 	}
1742 	if( memory_copy(
1743 	     internal_handle->hash_sections->sha1_digest,
1744 	     sha1_hash,
1745 	     20 ) == NULL )
1746 	{
1747 		libcerror_error_set(
1748 		 error,
1749 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1750 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1751 		 "%s: unable to set SHA1 hash.",
1752 		 function );
1753 
1754 		return( -1 );
1755 	}
1756 	if( internal_handle->hash_values == NULL )
1757 	{
1758 		if( libewf_hash_values_initialize(
1759 		     &( internal_handle->hash_values ),
1760 		     error ) != 1 )
1761 		{
1762 			libcerror_error_set(
1763 			 error,
1764 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1765 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1766 			 "%s: unable to create hash values.",
1767 			 function );
1768 
1769 			return( -1 );
1770 		}
1771 		internal_handle->hash_values_parsed = 1;
1772 	}
1773 	if( libewf_hash_values_parse_sha1_hash(
1774 	     internal_handle->hash_values,
1775 	     sha1_hash,
1776 	     20,
1777 	     error ) != 1 )
1778 	{
1779 		libcerror_error_set(
1780 		 error,
1781 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1782 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1783 		 "%s: unable to parse SHA1 hash for its value.",
1784 		 function );
1785 
1786 		return( -1 );
1787 	}
1788 	internal_handle->hash_sections->sha1_digest_set = 1;
1789 
1790 	return( 1 );
1791 }
1792 
1793 /* Retrieves the number of chunks written
1794  * Returns 1 if successful or -1 on error
1795  */
libewf_handle_get_number_of_chunks_written(libewf_handle_t * handle,uint32_t * number_of_chunks,libcerror_error_t ** error)1796 int libewf_handle_get_number_of_chunks_written(
1797      libewf_handle_t *handle,
1798      uint32_t *number_of_chunks,
1799      libcerror_error_t **error )
1800 {
1801 	libewf_internal_handle_t *internal_handle = NULL;
1802 	static char *function                     = "libewf_handle_get_number_of_chunks_written";
1803 
1804 	if( handle == NULL )
1805 	{
1806 		libcerror_error_set(
1807 		 error,
1808 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1809 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1810 		 "%s: invalid handle.",
1811 		 function );
1812 
1813 		return( -1 );
1814 	}
1815 	internal_handle = (libewf_internal_handle_t *) handle;
1816 
1817 	if( internal_handle->write_io_handle == NULL )
1818 	{
1819 		libcerror_error_set(
1820 		 error,
1821 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1822 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1823 		 "%s: invalid handle - missing subhandle write.",
1824 		 function );
1825 
1826 		return( -1 );
1827 	}
1828 	if( number_of_chunks == NULL )
1829 	{
1830 		libcerror_error_set(
1831 		 error,
1832 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1833 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1834 		 "%s: invalid number of chunks.",
1835 		 function );
1836 
1837 		return( -1 );
1838 	}
1839 	*number_of_chunks = internal_handle->write_io_handle->number_of_chunks_written;
1840 
1841 	return( 1 );
1842 }
1843 
1844 /* Sets the read zero chunk on error
1845  * The chunk is not zeroed if read raw is used
1846  * Returns 1 if successful or -1 on error
1847  */
libewf_handle_set_read_zero_chunk_on_error(libewf_handle_t * handle,uint8_t zero_on_error,libcerror_error_t ** error)1848 int libewf_handle_set_read_zero_chunk_on_error(
1849      libewf_handle_t *handle,
1850      uint8_t zero_on_error,
1851      libcerror_error_t **error )
1852 {
1853 	libewf_internal_handle_t *internal_handle = NULL;
1854 	static char *function                     = "libewf_handle_set_read_zero_chunk_on_error";
1855 
1856 	if( handle == NULL )
1857 	{
1858 		libcerror_error_set(
1859 		 error,
1860 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1861 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1862 		 "%s: invalid handle.",
1863 		 function );
1864 
1865 		return( -1 );
1866 	}
1867 	internal_handle = (libewf_internal_handle_t *) handle;
1868 
1869 	if( internal_handle->read_io_handle == NULL )
1870 	{
1871 		libcerror_error_set(
1872 		 error,
1873 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1874 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1875 		 "%s: invalid handle - missing read IO handle.",
1876 		 function );
1877 
1878 		return( -1 );
1879 	}
1880 	internal_handle->read_io_handle->zero_on_error = zero_on_error;
1881 
1882 	return( 1 );
1883 }
1884 
1885 /* Copies the media values from the source to the destination handle
1886  * Returns 1 if successful or -1 on error
1887  */
libewf_handle_copy_media_values(libewf_handle_t * destination_handle,libewf_handle_t * source_handle,libcerror_error_t ** error)1888 int libewf_handle_copy_media_values(
1889      libewf_handle_t *destination_handle,
1890      libewf_handle_t *source_handle,
1891      libcerror_error_t **error )
1892 {
1893 	libewf_internal_handle_t *internal_destination_handle = NULL;
1894 	libewf_internal_handle_t *internal_source_handle      = NULL;
1895 	static char *function                                 = "libewf_handle_copy_media_values";
1896 
1897 	if( destination_handle == NULL )
1898 	{
1899 		libcerror_error_set(
1900 		 error,
1901 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1902 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1903 		 "%s: invalid destination handle.",
1904 		 function );
1905 
1906 		return( -1 );
1907 	}
1908 	if( source_handle == NULL )
1909 	{
1910 		libcerror_error_set(
1911 		 error,
1912 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1913 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1914 		 "%s: invalid source handle.",
1915 		 function );
1916 
1917 		return( -1 );
1918 	}
1919 	internal_destination_handle = (libewf_internal_handle_t *) destination_handle;
1920 	internal_source_handle      = (libewf_internal_handle_t *) source_handle;
1921 
1922 	if( internal_source_handle->media_values == NULL )
1923 	{
1924 		libcerror_error_set(
1925 		 error,
1926 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1927 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1928 		 "%s: invalid source handle - missing media values.",
1929 		 function );
1930 
1931 		return( -1 );
1932 	}
1933 	if( internal_destination_handle->media_values == NULL )
1934 	{
1935 		libcerror_error_set(
1936 		 error,
1937 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1938 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1939 		 "%s: invalid destination handle - missing media values.",
1940 		 function );
1941 
1942 		return( -1 );
1943 	}
1944 	if( memory_copy(
1945 	     internal_destination_handle->media_values,
1946 	     internal_source_handle->media_values,
1947 	     sizeof( libewf_media_values_t ) ) == NULL )
1948 	{
1949 		libcerror_error_set(
1950 		 error,
1951 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
1952 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
1953 		 "%s: unable to copy media values.",
1954 		 function );
1955 
1956 		return( -1 );
1957 	}
1958 	return( 1 );
1959 }
1960 
1961 /* Retrieves the number of acquiry errors
1962  * Returns 1 if successful or -1 on error
1963  */
libewf_handle_get_number_of_acquiry_errors(libewf_handle_t * handle,uint32_t * number_of_errors,libcerror_error_t ** error)1964 int libewf_handle_get_number_of_acquiry_errors(
1965      libewf_handle_t *handle,
1966      uint32_t *number_of_errors,
1967      libcerror_error_t **error )
1968 {
1969 	libewf_internal_handle_t *internal_handle = NULL;
1970 	static char *function                     = "libewf_handle_get_number_of_acquiry_errors";
1971 	int number_of_elements                    = 0;
1972 
1973 	if( handle == NULL )
1974 	{
1975 		libcerror_error_set(
1976 		 error,
1977 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1978 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1979 		 "%s: invalid handle.",
1980 		 function );
1981 
1982 		return( -1 );
1983 	}
1984 	internal_handle = (libewf_internal_handle_t *) handle;
1985 
1986 	if( number_of_errors == NULL )
1987 	{
1988 		libcerror_error_set(
1989 		 error,
1990 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1991 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1992 		 "%s: invalid number of errors.",
1993 		 function );
1994 
1995 		return( -1 );
1996 	}
1997 	if( libcdata_range_list_get_number_of_elements(
1998 	     internal_handle->acquiry_errors,
1999 	     &number_of_elements,
2000 	     error ) != 1 )
2001 	{
2002 		libcerror_error_set(
2003 		 error,
2004 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2005 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2006 		 "%s: unable to retrieve number of elements from acquiry errors range list.",
2007 		 function );
2008 
2009 		return( -1 );
2010 	}
2011 	if( number_of_elements < 0 )
2012 	{
2013 		libcerror_error_set(
2014 		 error,
2015 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2016 		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
2017 		 "%s: invalid number of elements value out of bounds.",
2018 		 function );
2019 
2020 		return( -1 );
2021 	}
2022 	*number_of_errors = (uint32_t) number_of_elements;
2023 
2024 	return( 1 );
2025 }
2026 
2027 /* Retrieves an acquiry error
2028  * Returns 1 if successful or -1 on error
2029  */
libewf_handle_get_acquiry_error(libewf_handle_t * handle,uint32_t index,uint64_t * start_sector,uint64_t * number_of_sectors,libcerror_error_t ** error)2030 int libewf_handle_get_acquiry_error(
2031      libewf_handle_t *handle,
2032      uint32_t index,
2033      uint64_t *start_sector,
2034      uint64_t *number_of_sectors,
2035      libcerror_error_t **error )
2036 {
2037 	libewf_internal_handle_t *internal_handle = NULL;
2038 	static char *function                     = "libewf_handle_get_acquiry_error";
2039 	intptr_t *value                           = NULL;
2040 
2041 	if( handle == NULL )
2042 	{
2043 		libcerror_error_set(
2044 		 error,
2045 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2046 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2047 		 "%s: invalid handle.",
2048 		 function );
2049 
2050 		return( -1 );
2051 	}
2052 	internal_handle = (libewf_internal_handle_t *) handle;
2053 
2054 	if( libcdata_range_list_get_range_by_index(
2055 	     internal_handle->acquiry_errors,
2056 	     (int) index,
2057 	     start_sector,
2058 	     number_of_sectors,
2059 	     &value,
2060 	     error ) != 1 )
2061 	{
2062 		libcerror_error_set(
2063 		 error,
2064 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2065 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2066 		 "%s: unable to retrieve acquiry error: %" PRIu32 ".",
2067 		 function,
2068 		 index );
2069 
2070 		return( -1 );
2071 	}
2072 	return( 1 );
2073 }
2074 
2075 /* Append an acquiry error
2076  * Returns 1 if successful or -1 on error
2077  */
libewf_handle_append_acquiry_error(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)2078 int libewf_handle_append_acquiry_error(
2079      libewf_handle_t *handle,
2080      uint64_t start_sector,
2081      uint64_t number_of_sectors,
2082      libcerror_error_t **error )
2083 {
2084 	libewf_internal_handle_t *internal_handle = NULL;
2085 	static char *function                     = "libewf_handle_append_acquiry_error";
2086 	int result                                = 0;
2087 
2088 	if( handle == NULL )
2089 	{
2090 		libcerror_error_set(
2091 		 error,
2092 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2093 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2094 		 "%s: invalid handle.",
2095 		 function );
2096 
2097 		return( -1 );
2098 	}
2099 	internal_handle = (libewf_internal_handle_t *) handle;
2100 
2101 	result = libcdata_range_list_insert_range(
2102 	          internal_handle->acquiry_errors,
2103 	          start_sector,
2104 	          number_of_sectors,
2105 	          NULL,
2106 	          NULL,
2107 	          NULL,
2108 	          error );
2109 
2110 	if( result == -1 )
2111 	{
2112 		libcerror_error_set(
2113 		 error,
2114 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2115 		 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2116 		 "%s: unable to append acquiry error.",
2117 		 function );
2118 
2119 		return( -1 );
2120 	}
2121 	return( 1 );
2122 }
2123 
2124 /* Retrieves the number of checksum errors
2125  * Returns 1 if successful or -1 on error
2126  */
libewf_handle_get_number_of_checksum_errors(libewf_handle_t * handle,uint32_t * number_of_errors,libcerror_error_t ** error)2127 int libewf_handle_get_number_of_checksum_errors(
2128      libewf_handle_t *handle,
2129      uint32_t *number_of_errors,
2130      libcerror_error_t **error )
2131 {
2132 	libewf_internal_handle_t *internal_handle = NULL;
2133 	static char *function                     = "libewf_handle_get_number_of_checksum_errors";
2134 	int number_of_elements                    = 0;
2135 
2136 	if( handle == NULL )
2137 	{
2138 		libcerror_error_set(
2139 		 error,
2140 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2141 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2142 		 "%s: invalid handle.",
2143 		 function );
2144 
2145 		return( -1 );
2146 	}
2147 	internal_handle = (libewf_internal_handle_t *) handle;
2148 
2149 	if( internal_handle->read_io_handle == NULL )
2150 	{
2151 		libcerror_error_set(
2152 		 error,
2153 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2154 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2155 		 "%s: invalid handle - missing read IO handle.",
2156 		 function );
2157 
2158 		return( -1 );
2159 	}
2160 	if( number_of_errors == NULL )
2161 	{
2162 		libcerror_error_set(
2163 		 error,
2164 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2165 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2166 		 "%s: invalid number of errors.",
2167 		 function );
2168 
2169 		return( -1 );
2170 	}
2171 	if( libcdata_range_list_get_number_of_elements(
2172 	     internal_handle->read_io_handle->checksum_errors,
2173 	     &number_of_elements,
2174 	     error ) != 1 )
2175 	{
2176 		libcerror_error_set(
2177 		 error,
2178 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2179 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2180 		 "%s: unable to retrieve number of elements from checksum errors range list.",
2181 		 function );
2182 
2183 		return( -1 );
2184 	}
2185 	if( number_of_elements < 0 )
2186 	{
2187 		libcerror_error_set(
2188 		 error,
2189 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2190 		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
2191 		 "%s: invalid number of elements value out of bounds.",
2192 		 function );
2193 
2194 		return( -1 );
2195 	}
2196 	*number_of_errors = (uint32_t) number_of_elements;
2197 
2198 	return( 1 );
2199 }
2200 
2201 /* Retrieves a checksum error
2202  * Returns 1 if successful or -1 on error
2203  */
libewf_handle_get_checksum_error(libewf_handle_t * handle,uint32_t index,uint64_t * start_sector,uint64_t * number_of_sectors,libcerror_error_t ** error)2204 int libewf_handle_get_checksum_error(
2205      libewf_handle_t *handle,
2206      uint32_t index,
2207      uint64_t *start_sector,
2208      uint64_t *number_of_sectors,
2209      libcerror_error_t **error )
2210 {
2211 	libewf_internal_handle_t *internal_handle = NULL;
2212 	static char *function                     = "libewf_handle_get_checksum_error";
2213 	intptr_t *value                           = NULL;
2214 
2215 	if( handle == NULL )
2216 	{
2217 		libcerror_error_set(
2218 		 error,
2219 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2220 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2221 		 "%s: invalid handle.",
2222 		 function );
2223 
2224 		return( -1 );
2225 	}
2226 	internal_handle = (libewf_internal_handle_t *) handle;
2227 
2228 	if( internal_handle->read_io_handle == NULL )
2229 	{
2230 		libcerror_error_set(
2231 		 error,
2232 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2233 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2234 		 "%s: invalid handle - missing read IO handle.",
2235 		 function );
2236 
2237 		return( -1 );
2238 	}
2239 	if( libcdata_range_list_get_range_by_index(
2240 	     internal_handle->read_io_handle->checksum_errors,
2241 	     (int) index,
2242 	     start_sector,
2243 	     number_of_sectors,
2244 	     &value,
2245 	     error ) != 1 )
2246 	{
2247 		libcerror_error_set(
2248 		 error,
2249 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2250 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2251 		 "%s: unable to retrieve checksum error: %" PRIu32 ".",
2252 		 function,
2253 		 index );
2254 
2255 		return( -1 );
2256 	}
2257 	return( 1 );
2258 }
2259 
2260 /* Append a checksum error
2261  * Returns 1 if successful or -1 on error
2262  */
libewf_handle_append_checksum_error(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)2263 int libewf_handle_append_checksum_error(
2264      libewf_handle_t *handle,
2265      uint64_t start_sector,
2266      uint64_t number_of_sectors,
2267      libcerror_error_t **error )
2268 {
2269 	libewf_internal_handle_t *internal_handle = NULL;
2270 	static char *function                     = "libewf_handle_append_checksum_error";
2271 	int result                                = 0;
2272 
2273 	if( handle == NULL )
2274 	{
2275 		libcerror_error_set(
2276 		 error,
2277 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2278 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2279 		 "%s: invalid handle.",
2280 		 function );
2281 
2282 		return( -1 );
2283 	}
2284 	internal_handle = (libewf_internal_handle_t *) handle;
2285 
2286 	if( internal_handle->read_io_handle == NULL )
2287 	{
2288 		libcerror_error_set(
2289 		 error,
2290 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2291 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2292 		 "%s: invalid handle - missing read IO handle.",
2293 		 function );
2294 
2295 		return( -1 );
2296 	}
2297 	result = libcdata_range_list_insert_range(
2298 	          internal_handle->read_io_handle->checksum_errors,
2299 	          start_sector,
2300 	          number_of_sectors,
2301 	          NULL,
2302 	          NULL,
2303 	          NULL,
2304 	          error );
2305 
2306 	if( result == -1 )
2307 	{
2308 		libcerror_error_set(
2309 		 error,
2310 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2311 		 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2312 		 "%s: unable to append checksum error.",
2313 		 function );
2314 
2315 		return( -1 );
2316 	}
2317 	return( 1 );
2318 }
2319 
2320 /* Retrieves the number of sessions
2321  * Returns 1 if successful or -1 on error
2322  */
libewf_handle_get_number_of_sessions(libewf_handle_t * handle,uint32_t * number_of_sessions,libcerror_error_t ** error)2323 int libewf_handle_get_number_of_sessions(
2324      libewf_handle_t *handle,
2325      uint32_t *number_of_sessions,
2326      libcerror_error_t **error )
2327 {
2328 	libewf_internal_handle_t *internal_handle = NULL;
2329 	static char *function                     = "libewf_handle_get_number_of_sessions";
2330 	int number_of_entries                     = 0;
2331 
2332 	if( handle == NULL )
2333 	{
2334 		libcerror_error_set(
2335 		 error,
2336 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2337 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2338 		 "%s: invalid handle.",
2339 		 function );
2340 
2341 		return( -1 );
2342 	}
2343 	internal_handle = (libewf_internal_handle_t *) handle;
2344 
2345 	if( number_of_sessions == NULL )
2346 	{
2347 		libcerror_error_set(
2348 		 error,
2349 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2350 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2351 		 "%s: invalid number of sessions.",
2352 		 function );
2353 
2354 		return( -1 );
2355 	}
2356 	if( libcdata_array_get_number_of_entries(
2357 	     internal_handle->sessions,
2358 	     &number_of_entries,
2359 	     error ) != 1 )
2360 	{
2361 		libcerror_error_set(
2362 		 error,
2363 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2364 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2365 		 "%s: unable to retrieve number of entries from sessions array.",
2366 		 function );
2367 
2368 		return( -1 );
2369 	}
2370 	if( number_of_entries < 0 )
2371 	{
2372 		libcerror_error_set(
2373 		 error,
2374 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2375 		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
2376 		 "%s: invalid number of elements value out of bounds.",
2377 		 function );
2378 
2379 		return( -1 );
2380 	}
2381 	*number_of_sessions = (uint32_t) number_of_entries;
2382 
2383 	return( 1 );
2384 }
2385 
2386 /* Retrieves a session
2387  * Returns 1 if successful or -1 on error
2388  */
libewf_handle_get_session(libewf_handle_t * handle,uint32_t index,uint64_t * start_sector,uint64_t * number_of_sectors,libcerror_error_t ** error)2389 int libewf_handle_get_session(
2390      libewf_handle_t *handle,
2391      uint32_t index,
2392      uint64_t *start_sector,
2393      uint64_t *number_of_sectors,
2394      libcerror_error_t **error )
2395 {
2396 	libewf_internal_handle_t *internal_handle = NULL;
2397 	libewf_sector_range_t *sector_range       = NULL;
2398 	static char *function                     = "libewf_handle_get_session";
2399 
2400 	if( handle == NULL )
2401 	{
2402 		libcerror_error_set(
2403 		 error,
2404 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2405 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2406 		 "%s: invalid handle.",
2407 		 function );
2408 
2409 		return( -1 );
2410 	}
2411 	internal_handle = (libewf_internal_handle_t *) handle;
2412 
2413 	if( libcdata_array_get_entry_by_index(
2414 	     internal_handle->sessions,
2415 	     (int) index,
2416 	     (intptr_t **) &sector_range,
2417 	     error ) != 1 )
2418 	{
2419 		libcerror_error_set(
2420 		 error,
2421 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2422 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2423 		 "%s: unable to retrieve session sector range: %" PRIu32 " from array.",
2424 		 function,
2425 		 index );
2426 
2427 		return( -1 );
2428 	}
2429 	if( libewf_sector_range_get(
2430 	     sector_range,
2431 	     start_sector,
2432 	     number_of_sectors,
2433 	     error ) != 1 )
2434 	{
2435 		libcerror_error_set(
2436 		 error,
2437 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2438 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2439 		 "%s: unable to retrieve session: %" PRIu32 " sector range.",
2440 		 function,
2441 		 index );
2442 
2443 		return( -1 );
2444 	}
2445 	return( 1 );
2446 }
2447 
2448 /* Appends a session
2449  * Returns 1 if successful or -1 on error
2450  */
libewf_handle_append_session(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)2451 int libewf_handle_append_session(
2452      libewf_handle_t *handle,
2453      uint64_t start_sector,
2454      uint64_t number_of_sectors,
2455      libcerror_error_t **error )
2456 {
2457 	libewf_internal_handle_t *internal_handle = NULL;
2458 	libewf_sector_range_t *sector_range       = NULL;
2459 	static char *function                     = "libewf_handle_append_session";
2460 	int entry_index                           = 0;
2461 
2462 	if( handle == NULL )
2463 	{
2464 		libcerror_error_set(
2465 		 error,
2466 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2467 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2468 		 "%s: invalid handle.",
2469 		 function );
2470 
2471 		return( -1 );
2472 	}
2473 	internal_handle = (libewf_internal_handle_t *) handle;
2474 
2475 	if( libewf_sector_range_initialize(
2476 	     &sector_range,
2477 	     error ) != 1 )
2478 	{
2479 		libcerror_error_set(
2480 		 error,
2481 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2482 		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2483 		 "%s: unable to create session sector range.",
2484 		 function );
2485 
2486 		goto on_error;
2487 	}
2488 	if( libewf_sector_range_set(
2489 	     sector_range,
2490 	     start_sector,
2491 	     number_of_sectors,
2492 	     error ) != 1 )
2493 	{
2494 		libcerror_error_set(
2495 		 error,
2496 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2497 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2498 		 "%s: unable to set session sector range.",
2499 		 function );
2500 
2501 		goto on_error;
2502 	}
2503 	if( libcdata_array_append_entry(
2504 	     internal_handle->sessions,
2505 	     &entry_index,
2506 	     (intptr_t *) sector_range,
2507 	     error ) != 1 )
2508 	{
2509 		libcerror_error_set(
2510 		 error,
2511 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2512 		 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2513 		 "%s: unable to append session sector range to array.",
2514 		 function );
2515 
2516 		goto on_error;
2517 	}
2518 	return( 1 );
2519 
2520 on_error:
2521 	if( sector_range != NULL )
2522 	{
2523 		libewf_sector_range_free(
2524 		 &sector_range,
2525 		 NULL );
2526 	}
2527 	return( -1 );
2528 }
2529 
2530 /* Retrieves the number of tracks
2531  * Returns 1 if successful or -1 on error
2532  */
libewf_handle_get_number_of_tracks(libewf_handle_t * handle,uint32_t * number_of_tracks,libcerror_error_t ** error)2533 int libewf_handle_get_number_of_tracks(
2534      libewf_handle_t *handle,
2535      uint32_t *number_of_tracks,
2536      libcerror_error_t **error )
2537 {
2538 	libewf_internal_handle_t *internal_handle = NULL;
2539 	static char *function                     = "libewf_handle_get_number_of_tracks";
2540 	int number_of_entries                     = 0;
2541 
2542 	if( handle == NULL )
2543 	{
2544 		libcerror_error_set(
2545 		 error,
2546 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2547 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2548 		 "%s: invalid handle.",
2549 		 function );
2550 
2551 		return( -1 );
2552 	}
2553 	internal_handle = (libewf_internal_handle_t *) handle;
2554 
2555 	if( number_of_tracks == NULL )
2556 	{
2557 		libcerror_error_set(
2558 		 error,
2559 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2560 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2561 		 "%s: invalid number of tracks.",
2562 		 function );
2563 
2564 		return( -1 );
2565 	}
2566 	if( libcdata_array_get_number_of_entries(
2567 	     internal_handle->tracks,
2568 	     &number_of_entries,
2569 	     error ) != 1 )
2570 	{
2571 		libcerror_error_set(
2572 		 error,
2573 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2574 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2575 		 "%s: unable to retrieve number of entries from tracks array.",
2576 		 function );
2577 
2578 		return( -1 );
2579 	}
2580 	if( number_of_entries < 0 )
2581 	{
2582 		libcerror_error_set(
2583 		 error,
2584 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2585 		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
2586 		 "%s: invalid number of elements value out of bounds.",
2587 		 function );
2588 
2589 		return( -1 );
2590 	}
2591 	*number_of_tracks = (uint32_t) number_of_entries;
2592 
2593 	return( 1 );
2594 }
2595 
2596 /* Retrieves a track
2597  * Returns 1 if successful or -1 on error
2598  */
libewf_handle_get_track(libewf_handle_t * handle,uint32_t index,uint64_t * start_sector,uint64_t * number_of_sectors,libcerror_error_t ** error)2599 int libewf_handle_get_track(
2600      libewf_handle_t *handle,
2601      uint32_t index,
2602      uint64_t *start_sector,
2603      uint64_t *number_of_sectors,
2604      libcerror_error_t **error )
2605 {
2606 	libewf_internal_handle_t *internal_handle = NULL;
2607 	libewf_sector_range_t *sector_range       = NULL;
2608 	static char *function                     = "libewf_handle_get_track";
2609 
2610 	if( handle == NULL )
2611 	{
2612 		libcerror_error_set(
2613 		 error,
2614 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2615 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2616 		 "%s: invalid handle.",
2617 		 function );
2618 
2619 		return( -1 );
2620 	}
2621 	internal_handle = (libewf_internal_handle_t *) handle;
2622 
2623 	if( libcdata_array_get_entry_by_index(
2624 	     internal_handle->tracks,
2625 	     (int) index,
2626 	     (intptr_t **) &sector_range,
2627 	     error ) != 1 )
2628 	{
2629 		libcerror_error_set(
2630 		 error,
2631 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2632 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2633 		 "%s: unable to retrieve track sector range: %" PRIu32 " from array.",
2634 		 function,
2635 		 index );
2636 
2637 		return( -1 );
2638 	}
2639 	if( libewf_sector_range_get(
2640 	     sector_range,
2641 	     start_sector,
2642 	     number_of_sectors,
2643 	     error ) != 1 )
2644 	{
2645 		libcerror_error_set(
2646 		 error,
2647 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2648 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2649 		 "%s: unable to retrieve track: %" PRIu32 " sector range.",
2650 		 function,
2651 		 index );
2652 
2653 		return( -1 );
2654 	}
2655 	return( 1 );
2656 }
2657 
2658 /* Appends a track
2659  * Returns 1 if successful or -1 on error
2660  */
libewf_handle_append_track(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)2661 int libewf_handle_append_track(
2662      libewf_handle_t *handle,
2663      uint64_t start_sector,
2664      uint64_t number_of_sectors,
2665      libcerror_error_t **error )
2666 {
2667 	libewf_internal_handle_t *internal_handle = NULL;
2668 	libewf_sector_range_t *sector_range       = NULL;
2669 	static char *function                     = "libewf_handle_append_track";
2670 	int entry_index                           = 0;
2671 
2672 	if( handle == NULL )
2673 	{
2674 		libcerror_error_set(
2675 		 error,
2676 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2677 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2678 		 "%s: invalid handle.",
2679 		 function );
2680 
2681 		return( -1 );
2682 	}
2683 	internal_handle = (libewf_internal_handle_t *) handle;
2684 
2685 	if( libewf_sector_range_initialize(
2686 	     &sector_range,
2687 	     error ) != 1 )
2688 	{
2689 		libcerror_error_set(
2690 		 error,
2691 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2692 		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2693 		 "%s: unable to create track sector range.",
2694 		 function );
2695 
2696 		goto on_error;
2697 	}
2698 	if( libewf_sector_range_set(
2699 	     sector_range,
2700 	     start_sector,
2701 	     number_of_sectors,
2702 	     error ) != 1 )
2703 	{
2704 		libcerror_error_set(
2705 		 error,
2706 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2707 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2708 		 "%s: unable to set track sector range.",
2709 		 function );
2710 
2711 		goto on_error;
2712 	}
2713 	if( libcdata_array_append_entry(
2714 	     internal_handle->tracks,
2715 	     &entry_index,
2716 	     (intptr_t *) sector_range,
2717 	     error ) != 1 )
2718 	{
2719 		libcerror_error_set(
2720 		 error,
2721 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2722 		 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2723 		 "%s: unable to append track sector range to array.",
2724 		 function );
2725 
2726 		goto on_error;
2727 	}
2728 	return( 1 );
2729 
2730 on_error:
2731 	if( sector_range != NULL )
2732 	{
2733 		libewf_sector_range_free(
2734 		 &sector_range,
2735 		 NULL );
2736 	}
2737 	return( -1 );
2738 }
2739 
2740 /* Retrieves the header codepage
2741  * Returns 1 if successful or -1 on error
2742  */
libewf_handle_get_header_codepage(libewf_handle_t * handle,int * header_codepage,libcerror_error_t ** error)2743 int libewf_handle_get_header_codepage(
2744      libewf_handle_t *handle,
2745      int *header_codepage,
2746      libcerror_error_t **error )
2747 {
2748 	libewf_internal_handle_t *internal_handle = NULL;
2749 	static char *function                     = "libewf_handle_get_header_codepage";
2750 
2751 	if( handle == NULL )
2752 	{
2753 		libcerror_error_set(
2754 		 error,
2755 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2756 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2757 		 "%s: invalid handle.",
2758 		 function );
2759 
2760 		return( -1 );
2761 	}
2762 	internal_handle = (libewf_internal_handle_t *) handle;
2763 
2764 	if( internal_handle->io_handle == NULL )
2765 	{
2766 		libcerror_error_set(
2767 		 error,
2768 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2769 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2770 		 "%s: invalid handle - missing IO handle.",
2771 		 function );
2772 
2773 		return( -1 );
2774 	}
2775 	if( header_codepage == NULL )
2776 	{
2777 		libcerror_error_set(
2778 		 error,
2779 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2780 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2781 		 "%s: invalid header codepage.",
2782 		 function );
2783 
2784 		return( -1 );
2785 	}
2786 	*header_codepage = internal_handle->io_handle->header_codepage;
2787 
2788 	return( 1 );
2789 }
2790 
2791 /* Sets the header codepage
2792  * Returns 1 if successful or -1 on error
2793  */
libewf_handle_set_header_codepage(libewf_handle_t * handle,int header_codepage,libcerror_error_t ** error)2794 int libewf_handle_set_header_codepage(
2795      libewf_handle_t *handle,
2796      int header_codepage,
2797      libcerror_error_t **error )
2798 {
2799 	libewf_internal_handle_t *internal_handle = NULL;
2800 	static char *function                     = "libewf_handle_set_header_codepage";
2801 
2802 	if( handle == NULL )
2803 	{
2804 		libcerror_error_set(
2805 		 error,
2806 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2807 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2808 		 "%s: invalid handle.",
2809 		 function );
2810 
2811 		return( -1 );
2812 	}
2813 	internal_handle = (libewf_internal_handle_t *) handle;
2814 
2815 	if( internal_handle->io_handle == NULL )
2816 	{
2817 		libcerror_error_set(
2818 		 error,
2819 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2820 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2821 		 "%s: invalid handle - missing IO handle.",
2822 		 function );
2823 
2824 		return( -1 );
2825 	}
2826 	if( ( header_codepage != LIBEWF_CODEPAGE_ASCII )
2827 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_874 )
2828 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_932 )
2829 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_936 )
2830 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1250 )
2831 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1251 )
2832 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1252 )
2833 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1253 )
2834 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1254 )
2835 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1255 )
2836 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1256 )
2837 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1257 )
2838 	 && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1258 ) )
2839 	{
2840 		libcerror_error_set(
2841 		 error,
2842 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2843 		 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
2844 		 "%s: unsupported header codepage.",
2845 		 function );
2846 
2847 		return( -1 );
2848 	}
2849 	internal_handle->io_handle->header_codepage = header_codepage;
2850 
2851 	return( 1 );
2852 }
2853 
2854 /* Retrieves the header value date format
2855  * Returns 1 if successful or -1 on error
2856  */
libewf_handle_get_header_values_date_format(libewf_handle_t * handle,int * date_format,libcerror_error_t ** error)2857 int libewf_handle_get_header_values_date_format(
2858      libewf_handle_t *handle,
2859      int *date_format,
2860      libcerror_error_t **error )
2861 {
2862 	libewf_internal_handle_t *internal_handle = NULL;
2863 	static char *function                     = "libewf_handle_get_header_values_date_format";
2864 
2865 	if( handle == NULL )
2866 	{
2867 		libcerror_error_set(
2868 		 error,
2869 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2870 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2871 		 "%s: invalid handle.",
2872 		 function );
2873 
2874 		return( -1 );
2875 	}
2876 	internal_handle = (libewf_internal_handle_t *) handle;
2877 
2878 	if( internal_handle->header_sections == NULL )
2879 	{
2880 		libcerror_error_set(
2881 		 error,
2882 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2883 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2884 		 "%s: invalid handle - missing header sections.",
2885 		 function );
2886 
2887 		return( -1 );
2888 	}
2889 	if( date_format == NULL )
2890 	{
2891 		libcerror_error_set(
2892 		 error,
2893 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2894 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2895 		 "%s: invalid date format.",
2896 		 function );
2897 
2898 		return( -1 );
2899 	}
2900 	*date_format = internal_handle->date_format;
2901 
2902 	return( 1 );
2903 }
2904 
2905 /* Sets the header values date format
2906  * Returns 1 if successful or -1 on error
2907  */
libewf_handle_set_header_values_date_format(libewf_handle_t * handle,int date_format,libcerror_error_t ** error)2908 int libewf_handle_set_header_values_date_format(
2909      libewf_handle_t *handle,
2910      int date_format,
2911      libcerror_error_t **error )
2912 {
2913 	libewf_internal_handle_t *internal_handle = NULL;
2914 	static char *function                     = "libewf_handle_set_header_values_date_format";
2915 
2916 	if( handle == NULL )
2917 	{
2918 		libcerror_error_set(
2919 		 error,
2920 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2921 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2922 		 "%s: invalid handle.",
2923 		 function );
2924 
2925 		return( -1 );
2926 	}
2927 	internal_handle = (libewf_internal_handle_t *) handle;
2928 
2929 	if( internal_handle->header_sections == NULL )
2930 	{
2931 		libcerror_error_set(
2932 		 error,
2933 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2934 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2935 		 "%s: invalid handle - missing header sections.",
2936 		 function );
2937 
2938 		return( -1 );
2939 	}
2940 	if( ( date_format != LIBEWF_DATE_FORMAT_CTIME )
2941 	 && ( date_format != LIBEWF_DATE_FORMAT_DAYMONTH )
2942 	 && ( date_format != LIBEWF_DATE_FORMAT_MONTHDAY )
2943 	 && ( date_format != LIBEWF_DATE_FORMAT_ISO8601 ) )
2944 	{
2945 		libcerror_error_set(
2946 		 error,
2947 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2948 		 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
2949 		 "%s: unsupported date format.",
2950 		 function );
2951 
2952 		return( -1 );
2953 	}
2954 	internal_handle->date_format = date_format;
2955 
2956 	return( 1 );
2957 }
2958 
2959 /* Retrieves the number of header values
2960  * Returns 1 if successful, 0 if no header values are present or -1 on error
2961  */
libewf_handle_get_number_of_header_values(libewf_handle_t * handle,uint32_t * number_of_values,libcerror_error_t ** error)2962 int libewf_handle_get_number_of_header_values(
2963      libewf_handle_t *handle,
2964      uint32_t *number_of_values,
2965      libcerror_error_t **error )
2966 {
2967 	libewf_internal_handle_t *internal_handle = NULL;
2968 	static char *function                     = "libewf_handle_get_number_of_header_values";
2969 	int number_of_header_values               = 0;
2970 
2971 	if( handle == NULL )
2972 	{
2973 		libcerror_error_set(
2974 		 error,
2975 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2976 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2977 		 "%s: invalid handle.",
2978 		 function );
2979 
2980 		return( -1 );
2981 	}
2982 	internal_handle = (libewf_internal_handle_t *) handle;
2983 
2984 	if( number_of_values == NULL )
2985 	{
2986 		libcerror_error_set(
2987 		 error,
2988 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2989 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2990 		 "%s: invalid number of values.",
2991 		 function );
2992 
2993 		return( -1 );
2994 	}
2995 	if( internal_handle->header_values_parsed == 0 )
2996 	{
2997 		if( libewf_handle_parse_header_values(
2998 		     internal_handle,
2999 		     error ) != 1 )
3000 		{
3001 			libcerror_error_set(
3002 			 error,
3003 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3004 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3005 			 "%s: unable to parse header values.",
3006 			 function );
3007 
3008 			return( -1 );
3009 		}
3010 		internal_handle->header_values_parsed = 1;
3011 	}
3012 	if( internal_handle->header_values == NULL )
3013 	{
3014 		return( 0 );
3015 	}
3016 	if( libfvalue_table_get_number_of_values(
3017 	     internal_handle->header_values,
3018 	     &number_of_header_values,
3019 	     error ) != 1 )
3020 	{
3021 		libcerror_error_set(
3022 		 error,
3023 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3024 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3025 		 "%s: unable to retrieve number of header values.",
3026 		 function );
3027 
3028 		return( -1 );
3029 	}
3030 	if( number_of_header_values < 0 )
3031 	{
3032 		libcerror_error_set(
3033 		 error,
3034 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3035 		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
3036 		 "%s: invalid number of header values value out of bounds.",
3037 		 function );
3038 
3039 		return( -1 );
3040 	}
3041 	*number_of_values = (uint32_t) number_of_header_values;
3042 
3043 	return( 1 );
3044 }
3045 
3046 /* Retrieves the size of the value identifier of a specific index
3047  * The identifier size includes the end of string character
3048  * Returns 1 if successful, 0 if no header values are present or -1 on error
3049  */
libewf_handle_get_header_value_identifier_size(libewf_handle_t * handle,uint32_t index,size_t * identifier_size,libcerror_error_t ** error)3050 int libewf_handle_get_header_value_identifier_size(
3051      libewf_handle_t *handle,
3052      uint32_t index,
3053      size_t *identifier_size,
3054      libcerror_error_t **error )
3055 {
3056 	libewf_internal_handle_t *internal_handle = NULL;
3057 	libfvalue_value_t *header_value           = NULL;
3058 	uint8_t *header_value_identifier          = NULL;
3059 	static char *function                     = "libewf_handle_get_header_value_identifier_size";
3060 
3061 	if( handle == NULL )
3062 	{
3063 		libcerror_error_set(
3064 		 error,
3065 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3066 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3067 		 "%s: invalid handle.",
3068 		 function );
3069 
3070 		return( -1 );
3071 	}
3072 	internal_handle = (libewf_internal_handle_t *) handle;
3073 
3074 	if( internal_handle->header_values_parsed == 0 )
3075 	{
3076 		if( libewf_handle_parse_header_values(
3077 		     internal_handle,
3078 		     error ) != 1 )
3079 		{
3080 			libcerror_error_set(
3081 			 error,
3082 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3083 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3084 			 "%s: unable to parse header values.",
3085 			 function );
3086 
3087 			return( -1 );
3088 		}
3089 		internal_handle->header_values_parsed = 1;
3090 	}
3091 	if( internal_handle->header_values == NULL )
3092 	{
3093 		return( 0 );
3094 	}
3095 	if( libfvalue_table_get_value_by_index(
3096 	     internal_handle->header_values,
3097 	     (int) index,
3098 	     &header_value,
3099 	     error ) != 1 )
3100 	{
3101 		libcerror_error_set(
3102 		 error,
3103 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3104 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3105 		 "%s: unable to retrieve header value: %" PRIu32 ".",
3106 		 function,
3107 		 index );
3108 
3109 		return( -1 );
3110 	}
3111 	if( libfvalue_value_get_identifier(
3112 	     header_value,
3113 	     &header_value_identifier,
3114 	     identifier_size,
3115 	     error ) != 1 )
3116 	{
3117 		libcerror_error_set(
3118 		 error,
3119 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3120 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3121 		 "%s: unable to retrieve header value identifier size.",
3122 		 function );
3123 
3124 		return( -1 );
3125 	}
3126 	return( 1 );
3127 }
3128 
3129 /* Retrieves the header value identifier of a specific index
3130  * The identifier size should include the end of string character
3131  * Returns 1 if successful, 0 if no header values are present or -1 on error
3132  */
libewf_handle_get_header_value_identifier(libewf_handle_t * handle,uint32_t index,uint8_t * identifier,size_t identifier_size,libcerror_error_t ** error)3133 int libewf_handle_get_header_value_identifier(
3134      libewf_handle_t *handle,
3135      uint32_t index,
3136      uint8_t *identifier,
3137      size_t identifier_size,
3138      libcerror_error_t **error )
3139 {
3140 	libewf_internal_handle_t *internal_handle = NULL;
3141 	libfvalue_value_t *header_value           = NULL;
3142 	uint8_t *header_value_identifier          = NULL;
3143 	static char *function                     = "libewf_handle_get_header_value_identifier";
3144 	size_t header_value_identifier_size       = 0;
3145 
3146 	if( handle == NULL )
3147 	{
3148 		libcerror_error_set(
3149 		 error,
3150 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3151 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3152 		 "%s: invalid handle.",
3153 		 function );
3154 
3155 		return( -1 );
3156 	}
3157 	internal_handle = (libewf_internal_handle_t *) handle;
3158 
3159 	if( internal_handle->header_values_parsed == 0 )
3160 	{
3161 		if( libewf_handle_parse_header_values(
3162 		     internal_handle,
3163 		     error ) != 1 )
3164 		{
3165 			libcerror_error_set(
3166 			 error,
3167 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3168 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3169 			 "%s: unable to parse header values.",
3170 			 function );
3171 
3172 			return( -1 );
3173 		}
3174 		internal_handle->header_values_parsed = 1;
3175 	}
3176 	if( internal_handle->header_values == NULL )
3177 	{
3178 		return( 0 );
3179 	}
3180 	if( libfvalue_table_get_value_by_index(
3181 	     internal_handle->header_values,
3182 	     (int) index,
3183 	     &header_value,
3184 	     error ) != 1 )
3185 	{
3186 		libcerror_error_set(
3187 		 error,
3188 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3189 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3190 		 "%s: unable to retrieve header value: %" PRIu32 ".",
3191 		 function,
3192 		 index );
3193 
3194 		return( -1 );
3195 	}
3196 	if( libfvalue_value_get_identifier(
3197 	     header_value,
3198 	     &header_value_identifier,
3199 	     &header_value_identifier_size,
3200 	     error ) != 1 )
3201 	{
3202 		libcerror_error_set(
3203 		 error,
3204 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3205 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3206 		 "%s: unable to retrieve header value identifier size.",
3207 		 function );
3208 
3209 		return( -1 );
3210 	}
3211 	if( identifier_size < header_value_identifier_size )
3212 	{
3213 		libcerror_error_set(
3214 		 error,
3215 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3216 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
3217 		 "%s: identifier size too small.",
3218 		 function );
3219 
3220 		return( -1 );
3221 	}
3222 	if( memory_copy(
3223 	     identifier,
3224 	     header_value_identifier,
3225 	     header_value_identifier_size ) == NULL )
3226 	{
3227 		libcerror_error_set(
3228 		 error,
3229 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
3230 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
3231 		 "%s: unable to copy identifier.",
3232 		 function );
3233 
3234 		return( -1 );
3235 	}
3236 	return( 1 );
3237 }
3238 
3239 /* Retrieves the size of the UTF-8 encoded header value of an identifier
3240  * The string size includes the end of string character
3241  * Returns 1 if successful, 0 if value not present or -1 on error
3242  */
libewf_handle_get_utf8_header_value_size(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,size_t * utf8_string_size,libcerror_error_t ** error)3243 int libewf_handle_get_utf8_header_value_size(
3244      libewf_handle_t *handle,
3245      const uint8_t *identifier,
3246      size_t identifier_length,
3247      size_t *utf8_string_size,
3248      libcerror_error_t **error )
3249 {
3250 	uint8_t date_time_string[ 64 ];
3251 
3252 	libewf_internal_handle_t *internal_handle = NULL;
3253 	libfvalue_value_t *header_value           = NULL;
3254 	uint8_t *header_value_data                = NULL;
3255 	static char *function                     = "libewf_handle_get_utf8_header_value_size";
3256 	size_t date_time_string_size              = 64;
3257 	size_t header_value_data_size             = 0;
3258 	size_t string_index                       = 0;
3259 	int encoding                              = 0;
3260 	int result                                = 0;
3261 
3262 	if( handle == NULL )
3263 	{
3264 		libcerror_error_set(
3265 		 error,
3266 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3267 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3268 		 "%s: invalid handle.",
3269 		 function );
3270 
3271 		return( -1 );
3272 	}
3273 	internal_handle = (libewf_internal_handle_t *) handle;
3274 
3275 	if( identifier == NULL )
3276 	{
3277 		libcerror_error_set(
3278 		 error,
3279 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3280 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3281 		 "%s: invalid indentifier.",
3282 		 function );
3283 
3284 		return( -1 );
3285 	}
3286 	if( internal_handle->header_values_parsed == 0 )
3287 	{
3288 		if( libewf_handle_parse_header_values(
3289 		     internal_handle,
3290 		     error ) != 1 )
3291 		{
3292 			libcerror_error_set(
3293 			 error,
3294 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3295 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3296 			 "%s: unable to parse header values.",
3297 			 function );
3298 
3299 			return( -1 );
3300 		}
3301 		internal_handle->header_values_parsed = 1;
3302 	}
3303 	if( internal_handle->header_values == NULL )
3304 	{
3305 		return( 0 );
3306 	}
3307 	if( ( identifier_length == 16 )
3308 	 && ( narrow_string_compare(
3309 	       (char *) identifier,
3310 	       "compression_type",
3311 	       16 ) == 0 ) )
3312 	{
3313 		result = libfvalue_table_get_value_by_identifier(
3314 		          internal_handle->header_values,
3315 		          (uint8_t *) "compression_level",
3316 		          18,
3317 		          &header_value,
3318 		          0,
3319 		          error );
3320 	}
3321 	else
3322 	{
3323 		result = libfvalue_table_get_value_by_identifier(
3324 		          internal_handle->header_values,
3325 		          identifier,
3326 		          identifier_length + 1,
3327 		          &header_value,
3328 		          0,
3329 		          error );
3330 	}
3331 	if( result == -1 )
3332 	{
3333 		libcerror_error_set(
3334 		 error,
3335 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3336 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3337 		 "%s: unable to retrieve header value: %s.",
3338 		 function,
3339 		 (char *) identifier );
3340 
3341 		return( -1 );
3342 	}
3343 	else if( result == 0 )
3344 	{
3345 		return( 0 );
3346 	}
3347 	result = libfvalue_value_has_data(
3348 		  header_value,
3349 		  error );
3350 
3351 	if( result == -1 )
3352 	{
3353 		libcerror_error_set(
3354 		 error,
3355 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3356 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3357 		 "%s: unable to determine if header value has data.",
3358 		 function );
3359 
3360 		return( -1 );
3361 	}
3362 	else if( result == 0 )
3363 	{
3364 		return( 0 );
3365 	}
3366 	if( ( ( identifier_length == 11 )
3367 	   && ( narrow_string_compare(
3368 		 (char *) identifier,
3369 		 "system_date",
3370 		 11 ) == 0 ) )
3371 	 || ( ( identifier_length == 12 )
3372 	   && ( narrow_string_compare(
3373 		 (char *) identifier,
3374 		 "acquiry_date",
3375 		 12 ) == 0 ) ) )
3376 	{
3377 		if( libfvalue_value_get_data(
3378 		     header_value,
3379 		     &header_value_data,
3380 		     &header_value_data_size,
3381 		     &encoding,
3382 		     error ) != 1 )
3383 		{
3384 			libcerror_error_set(
3385 			 error,
3386 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3387 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3388 			 "%s: unable to retrieve header value data.",
3389 			 function );
3390 
3391 			return( -1 );
3392 		}
3393 		if( libewf_date_time_values_copy_to_utf8_string(
3394 		     header_value_data,
3395 		     header_value_data_size,
3396 		     internal_handle->date_format,
3397 		     date_time_string,
3398 		     date_time_string_size,
3399 		     error ) != 1 )
3400 		{
3401 			libcerror_error_set(
3402 			 error,
3403 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3404 			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3405 			 "%s: unable to copy header value data to date time string.",
3406 			 function );
3407 
3408 			return( -1 );
3409 		}
3410 		if( utf8_string_size == NULL )
3411 		{
3412 			libcerror_error_set(
3413 			 error,
3414 			 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3415 			 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3416 			 "%s: invalid UTF-8 string size.",
3417 			 function );
3418 
3419 			return( -1 );
3420 		}
3421 		for( string_index = 0;
3422 		     string_index < date_time_string_size;
3423 		     string_index++ )
3424 		{
3425 			if( date_time_string[ string_index ] == 0 )
3426 			{
3427 				break;
3428 			}
3429 		}
3430 		*utf8_string_size = 1 + string_index;
3431 	}
3432 	else
3433 	{
3434 		if( libfvalue_value_get_utf8_string_size(
3435 		     header_value,
3436 		     0,
3437 		     utf8_string_size,
3438 		     error ) != 1 )
3439 		{
3440 			libcerror_error_set(
3441 			 error,
3442 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3443 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3444 			 "%s: unable to retrieve UTF-8 string size of header value.",
3445 			 function );
3446 
3447 			return( -1 );
3448 		}
3449 	}
3450 	return( 1 );
3451 }
3452 
3453 /* Retrieves the UTF-8 encoded header value of an identifier
3454  * The string size should include the end of string character
3455  * Returns 1 if successful, 0 if value not present or -1 on error
3456  */
libewf_handle_get_utf8_header_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,uint8_t * utf8_string,size_t utf8_string_size,libcerror_error_t ** error)3457 int libewf_handle_get_utf8_header_value(
3458      libewf_handle_t *handle,
3459      const uint8_t *identifier,
3460      size_t identifier_length,
3461      uint8_t *utf8_string,
3462      size_t utf8_string_size,
3463      libcerror_error_t **error )
3464 {
3465 	libewf_internal_handle_t *internal_handle = NULL;
3466 	libfvalue_value_t *header_value           = NULL;
3467 	uint8_t *header_value_data                = NULL;
3468 	static char *function                     = "libewf_handle_get_utf8_header_value";
3469 	size_t header_value_data_size             = 0;
3470 	int encoding                              = 0;
3471 	int result                                = 0;
3472 
3473 	if( handle == NULL )
3474 	{
3475 		libcerror_error_set(
3476 		 error,
3477 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3478 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3479 		 "%s: invalid handle.",
3480 		 function );
3481 
3482 		return( -1 );
3483 	}
3484 	internal_handle = (libewf_internal_handle_t *) handle;
3485 
3486 	if( identifier == NULL )
3487 	{
3488 		libcerror_error_set(
3489 		 error,
3490 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3491 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3492 		 "%s: invalid indentifier.",
3493 		 function );
3494 
3495 		return( -1 );
3496 	}
3497 	if( internal_handle->header_values_parsed == 0 )
3498 	{
3499 		if( libewf_handle_parse_header_values(
3500 		     internal_handle,
3501 		     error ) != 1 )
3502 		{
3503 			libcerror_error_set(
3504 			 error,
3505 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3506 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3507 			 "%s: unable to parse header values.",
3508 			 function );
3509 
3510 			return( -1 );
3511 		}
3512 		internal_handle->header_values_parsed = 1;
3513 	}
3514 	if( internal_handle->header_values == NULL )
3515 	{
3516 		return( 0 );
3517 	}
3518 	if( ( identifier_length == 16 )
3519 	 && ( narrow_string_compare(
3520 	       (char *) identifier,
3521 	       "compression_type",
3522 	       16 ) == 0 ) )
3523 	{
3524 		result = libfvalue_table_get_value_by_identifier(
3525 		          internal_handle->header_values,
3526 		          (uint8_t *) "compression_level",
3527 		          18,
3528 		          &header_value,
3529 		          0,
3530 		          error );
3531 	}
3532 	else
3533 	{
3534 		result = libfvalue_table_get_value_by_identifier(
3535 		          internal_handle->header_values,
3536 		          identifier,
3537 		          identifier_length + 1,
3538 		          &header_value,
3539 		          0,
3540 		          error );
3541 	}
3542 	if( result == -1 )
3543 	{
3544 		libcerror_error_set(
3545 		 error,
3546 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3547 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3548 		 "%s: unable to retrieve header value: %s.",
3549 		 function,
3550 		 (char *) identifier );
3551 
3552 		return( -1 );
3553 	}
3554 	else if( result == 0 )
3555 	{
3556 		return( 0 );
3557 	}
3558 	result = libfvalue_value_has_data(
3559 		  header_value,
3560 		  error );
3561 
3562 	if( result == -1 )
3563 	{
3564 		libcerror_error_set(
3565 		 error,
3566 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3567 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3568 		 "%s: unable to determine if header value has data.",
3569 		 function );
3570 
3571 		return( -1 );
3572 	}
3573 	else if( result == 0 )
3574 	{
3575 		return( 0 );
3576 	}
3577 	if( ( ( identifier_length == 11 )
3578 	   && ( narrow_string_compare(
3579 		 (char *) identifier,
3580 		 "system_date",
3581 		 11 ) == 0 ) )
3582 	 || ( ( identifier_length == 12 )
3583 	   && ( narrow_string_compare(
3584 		 (char *) identifier,
3585 		 "acquiry_date",
3586 		 12 ) == 0 ) ) )
3587 	{
3588 		if( libfvalue_value_get_data(
3589 		     header_value,
3590 		     &header_value_data,
3591 		     &header_value_data_size,
3592 		     &encoding,
3593 		     error ) != 1 )
3594 		{
3595 			libcerror_error_set(
3596 			 error,
3597 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3598 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3599 			 "%s: unable to retrieve header value data.",
3600 			 function );
3601 
3602 			return( -1 );
3603 		}
3604 		if( libewf_date_time_values_copy_to_utf8_string(
3605 		     header_value_data,
3606 		     header_value_data_size,
3607 		     internal_handle->date_format,
3608 		     utf8_string,
3609 		     utf8_string_size,
3610 		     error ) != 1 )
3611 		{
3612 			libcerror_error_set(
3613 			 error,
3614 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3615 			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3616 			 "%s: unable to copy header value data to UTF-8 string.",
3617 			 function );
3618 
3619 			return( -1 );
3620 		}
3621 	}
3622 	else
3623 	{
3624 		if( libfvalue_value_copy_to_utf8_string(
3625 		     header_value,
3626 		     0,
3627 		     utf8_string,
3628 		     utf8_string_size,
3629 		     error ) != 1 )
3630 		{
3631 			libcerror_error_set(
3632 			 error,
3633 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3634 			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3635 			 "%s: unable to copy header value to UTF-8 string.",
3636 			 function );
3637 
3638 			return( -1 );
3639 		}
3640 	}
3641 	return( 1 );
3642 }
3643 
3644 /* Sets the UTF-8 encoded header value specified by the identifier
3645  * Returns 1 if successful or -1 on error
3646  */
libewf_handle_set_utf8_header_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,const uint8_t * utf8_string,size_t utf8_string_length,libcerror_error_t ** error)3647 int libewf_handle_set_utf8_header_value(
3648      libewf_handle_t *handle,
3649      const uint8_t *identifier,
3650      size_t identifier_length,
3651      const uint8_t *utf8_string,
3652      size_t utf8_string_length,
3653      libcerror_error_t **error )
3654 {
3655 	libewf_internal_handle_t *internal_handle = NULL;
3656 	libfvalue_value_t *header_value           = NULL;
3657 	static char *function                     = "libewf_handle_set_utf8_header_value";
3658 	int result                                = 0;
3659 
3660 	if( handle == NULL )
3661 	{
3662 		libcerror_error_set(
3663 		 error,
3664 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3665 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3666 		 "%s: invalid handle.",
3667 		 function );
3668 
3669 		return( -1 );
3670 	}
3671 	internal_handle = (libewf_internal_handle_t *) handle;
3672 
3673 	if( ( internal_handle->read_io_handle != NULL )
3674 	 || ( internal_handle->write_io_handle == NULL )
3675 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
3676 	{
3677 		libcerror_error_set(
3678 		 error,
3679 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3680 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3681 		 "%s: header value cannot be changed.",
3682 		 function );
3683 
3684 		return( -1 );
3685 	}
3686 	if( identifier == NULL )
3687 	{
3688 		libcerror_error_set(
3689 		 error,
3690 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3691 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3692 		 "%s: invalid identifier.",
3693 		 function );
3694 
3695 		return( -1 );
3696 	}
3697 	if( internal_handle->header_values == NULL )
3698 	{
3699 		if( libewf_header_values_initialize(
3700 		     &( internal_handle->header_values ),
3701 		     error ) != 1 )
3702 		{
3703 			libcerror_error_set(
3704 			 error,
3705 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3706 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
3707 			 "%s: unable to create header values.",
3708 			 function );
3709 
3710 			return( -1 );
3711 		}
3712 	}
3713 	result = libfvalue_table_get_value_by_identifier(
3714 	          internal_handle->header_values,
3715 	          identifier,
3716 	          identifier_length + 1,
3717 	          &header_value,
3718 	          0,
3719 	          error );
3720 
3721 	if( result == -1 )
3722 	{
3723 		libcerror_error_set(
3724 		 error,
3725 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3726 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3727 		 "%s: unable to retrieve header value: %s.",
3728 		 function,
3729 		 (char *) identifier );
3730 
3731 		return( -1 );
3732 	}
3733 	else if( result == 0 )
3734 	{
3735 		if( libfvalue_value_type_initialize(
3736 		     &header_value,
3737 		     LIBFVALUE_VALUE_TYPE_STRING_UTF8,
3738 		     error ) != 1 )
3739 		{
3740 			libcerror_error_set(
3741 			 error,
3742 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3743 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
3744 			 "%s: unable to create header value.",
3745 			 function );
3746 
3747 			return( -1 );
3748 		}
3749 		if( libfvalue_value_set_identifier(
3750 		     header_value,
3751 		     identifier,
3752 		     identifier_length + 1,
3753 		     LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
3754 		     error ) != 1 )
3755 		{
3756 			libcerror_error_set(
3757 			 error,
3758 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3759 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3760 			 "%s: unable to set header value: %s identifier.",
3761 			 function,
3762 			 (char *) identifier );
3763 
3764 			libfvalue_value_free(
3765 			 &header_value,
3766 			 NULL );
3767 
3768 			return( -1 );
3769 		}
3770 		if( libfvalue_table_set_value(
3771 		     internal_handle->header_values,
3772 		     header_value,
3773 		     error ) != 1 )
3774 		{
3775 			libcerror_error_set(
3776 			 error,
3777 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3778 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3779 			 "%s: unable to set header value: %s in table.",
3780 			 function,
3781 			 (char *) identifier );
3782 
3783 			libfvalue_value_free(
3784 			 &header_value,
3785 			 NULL );
3786 
3787 			return( -1 );
3788 		}
3789 	}
3790 	if( libfvalue_value_copy_from_utf8_string(
3791 	     header_value,
3792 	     0,
3793 	     utf8_string,
3794 	     utf8_string_length,
3795 	     error ) != 1 )
3796 	{
3797 		libcerror_error_set(
3798 		 error,
3799 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3800 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3801 		 "%s: unable to copy header value from UTF-8 string.",
3802 		 function );
3803 
3804 		return( -1 );
3805 	}
3806 	return( 1 );
3807 }
3808 
3809 /* Retrieves the size of the UTF-16 encoded header value of an identifier
3810  * The string size includes the end of string character
3811  * Returns 1 if successful, 0 if value not present or -1 on error
3812  */
libewf_handle_get_utf16_header_value_size(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,size_t * utf16_string_size,libcerror_error_t ** error)3813 int libewf_handle_get_utf16_header_value_size(
3814      libewf_handle_t *handle,
3815      const uint8_t *identifier,
3816      size_t identifier_length,
3817      size_t *utf16_string_size,
3818      libcerror_error_t **error )
3819 {
3820 	uint16_t date_time_string[ 64 ];
3821 
3822 	libewf_internal_handle_t *internal_handle = NULL;
3823 	libfvalue_value_t *header_value           = NULL;
3824 	uint8_t *header_value_data                = NULL;
3825 	static char *function                     = "libewf_handle_get_utf8_header_value_size";
3826 	size_t date_time_string_size              = 64;
3827 	size_t header_value_data_size             = 0;
3828 	size_t string_index                       = 0;
3829 	int encoding                              = 0;
3830 	int result                                = 0;
3831 
3832 	if( handle == NULL )
3833 	{
3834 		libcerror_error_set(
3835 		 error,
3836 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3837 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3838 		 "%s: invalid handle.",
3839 		 function );
3840 
3841 		return( -1 );
3842 	}
3843 	internal_handle = (libewf_internal_handle_t *) handle;
3844 
3845 	if( identifier == NULL )
3846 	{
3847 		libcerror_error_set(
3848 		 error,
3849 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3850 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3851 		 "%s: invalid indentifier.",
3852 		 function );
3853 
3854 		return( -1 );
3855 	}
3856 	if( internal_handle->header_values_parsed == 0 )
3857 	{
3858 		if( libewf_handle_parse_header_values(
3859 		     internal_handle,
3860 		     error ) != 1 )
3861 		{
3862 			libcerror_error_set(
3863 			 error,
3864 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3865 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3866 			 "%s: unable to parse header values.",
3867 			 function );
3868 
3869 			return( -1 );
3870 		}
3871 		internal_handle->header_values_parsed = 1;
3872 	}
3873 	if( internal_handle->header_values == NULL )
3874 	{
3875 		return( 0 );
3876 	}
3877 	if( ( identifier_length == 16 )
3878 	 && ( narrow_string_compare(
3879 	       (char *) identifier,
3880 	       "compression_type",
3881 	       16 ) == 0 ) )
3882 	{
3883 		result = libfvalue_table_get_value_by_identifier(
3884 		          internal_handle->header_values,
3885 		          (uint8_t *) "compression_level",
3886 		          18,
3887 		          &header_value,
3888 		          0,
3889 		          error );
3890 	}
3891 	else
3892 	{
3893 		result = libfvalue_table_get_value_by_identifier(
3894 		          internal_handle->header_values,
3895 		          identifier,
3896 		          identifier_length + 1,
3897 		          &header_value,
3898 		          0,
3899 		          error );
3900 	}
3901 	if( result == -1 )
3902 	{
3903 		libcerror_error_set(
3904 		 error,
3905 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3906 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3907 		 "%s: unable to retrieve header value: %s.",
3908 		 function,
3909 		 (char *) identifier );
3910 
3911 		return( -1 );
3912 	}
3913 	else if( result == 0 )
3914 	{
3915 		return( 0 );
3916 	}
3917 	result = libfvalue_value_has_data(
3918 		  header_value,
3919 		  error );
3920 
3921 	if( result == -1 )
3922 	{
3923 		libcerror_error_set(
3924 		 error,
3925 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3926 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3927 		 "%s: unable to determine if header value has data.",
3928 		 function );
3929 
3930 		return( -1 );
3931 	}
3932 	else if( result == 0 )
3933 	{
3934 		return( 0 );
3935 	}
3936 	if( ( ( identifier_length == 11 )
3937 	   && ( narrow_string_compare(
3938 		 (char *) identifier,
3939 		 "system_date",
3940 		 11 ) == 0 ) )
3941 	 || ( ( identifier_length == 12 )
3942 	   && ( narrow_string_compare(
3943 		 (char *) identifier,
3944 		 "acquiry_date",
3945 		 12 ) == 0 ) ) )
3946 	{
3947 		if( libfvalue_value_get_data(
3948 		     header_value,
3949 		     &header_value_data,
3950 		     &header_value_data_size,
3951 		     &encoding,
3952 		     error ) != 1 )
3953 		{
3954 			libcerror_error_set(
3955 			 error,
3956 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3957 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3958 			 "%s: unable to retrieve header value data.",
3959 			 function );
3960 
3961 			return( -1 );
3962 		}
3963 		if( libewf_date_time_values_copy_to_utf16_string(
3964 		     header_value_data,
3965 		     header_value_data_size,
3966 		     internal_handle->date_format,
3967 		     date_time_string,
3968 		     date_time_string_size,
3969 		     error ) != 1 )
3970 		{
3971 			libcerror_error_set(
3972 			 error,
3973 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3974 			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3975 			 "%s: unable to copy header value data to date time string.",
3976 			 function );
3977 
3978 			return( -1 );
3979 		}
3980 		if( utf16_string_size == NULL )
3981 		{
3982 			libcerror_error_set(
3983 			 error,
3984 			 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3985 			 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3986 			 "%s: invalid UTF-16 string size.",
3987 			 function );
3988 
3989 			return( -1 );
3990 		}
3991 		for( string_index = 0;
3992 		     string_index < date_time_string_size;
3993 		     string_index++ )
3994 		{
3995 			if( date_time_string[ string_index ] == 0 )
3996 			{
3997 				break;
3998 			}
3999 		}
4000 		*utf16_string_size = 1 + string_index;
4001 	}
4002 	else
4003 	{
4004 		if( libfvalue_value_get_utf16_string_size(
4005 		     header_value,
4006 		     0,
4007 		     utf16_string_size,
4008 		     error ) != 1 )
4009 		{
4010 			libcerror_error_set(
4011 			 error,
4012 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4013 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4014 			 "%s: unable to retrieve UTF-16 string size of header value.",
4015 			 function );
4016 
4017 			return( -1 );
4018 		}
4019 	}
4020 	return( 1 );
4021 }
4022 
4023 /* Retrieves the UTF-16 encoded header value of an identifier
4024  * The string size should include the end of string character
4025  * Returns 1 if successful, 0 if value not present or -1 on error
4026  */
libewf_handle_get_utf16_header_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,uint16_t * utf16_string,size_t utf16_string_size,libcerror_error_t ** error)4027 int libewf_handle_get_utf16_header_value(
4028      libewf_handle_t *handle,
4029      const uint8_t *identifier,
4030      size_t identifier_length,
4031      uint16_t *utf16_string,
4032      size_t utf16_string_size,
4033      libcerror_error_t **error )
4034 {
4035 	libewf_internal_handle_t *internal_handle = NULL;
4036 	libfvalue_value_t *header_value           = NULL;
4037 	uint8_t *header_value_data                = NULL;
4038 	static char *function                     = "libewf_handle_get_utf16_header_value";
4039 	size_t header_value_data_size             = 0;
4040 	int encoding                              = 0;
4041 	int result                                = 0;
4042 
4043 	if( handle == NULL )
4044 	{
4045 		libcerror_error_set(
4046 		 error,
4047 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4048 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4049 		 "%s: invalid handle.",
4050 		 function );
4051 
4052 		return( -1 );
4053 	}
4054 	internal_handle = (libewf_internal_handle_t *) handle;
4055 
4056 	if( identifier == NULL )
4057 	{
4058 		libcerror_error_set(
4059 		 error,
4060 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4061 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4062 		 "%s: invalid indentifier.",
4063 		 function );
4064 
4065 		return( -1 );
4066 	}
4067 	if( internal_handle->header_values_parsed == 0 )
4068 	{
4069 		if( libewf_handle_parse_header_values(
4070 		     internal_handle,
4071 		     error ) != 1 )
4072 		{
4073 			libcerror_error_set(
4074 			 error,
4075 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4076 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4077 			 "%s: unable to parse header values.",
4078 			 function );
4079 
4080 			return( -1 );
4081 		}
4082 		internal_handle->header_values_parsed = 1;
4083 	}
4084 	if( internal_handle->header_values == NULL )
4085 	{
4086 		return( 0 );
4087 	}
4088 	if( ( identifier_length == 16 )
4089 	 && ( narrow_string_compare(
4090 	       (char *) identifier,
4091 	       "compression_type",
4092 	       16 ) == 0 ) )
4093 	{
4094 		result = libfvalue_table_get_value_by_identifier(
4095 		          internal_handle->header_values,
4096 		          (uint8_t *) "compression_level",
4097 		          18,
4098 		          &header_value,
4099 		          0,
4100 		          error );
4101 	}
4102 	else
4103 	{
4104 		result = libfvalue_table_get_value_by_identifier(
4105 		          internal_handle->header_values,
4106 		          identifier,
4107 		          identifier_length + 1,
4108 		          &header_value,
4109 		          0,
4110 		          error );
4111 	}
4112 	if( result == -1 )
4113 	{
4114 		libcerror_error_set(
4115 		 error,
4116 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4117 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4118 		 "%s: unable to retrieve header value: %s.",
4119 		 function,
4120 		 (char *) identifier );
4121 
4122 		return( -1 );
4123 	}
4124 	else if( result == 0 )
4125 	{
4126 		return( 0 );
4127 	}
4128 	result = libfvalue_value_has_data(
4129 		  header_value,
4130 		  error );
4131 
4132 	if( result == -1 )
4133 	{
4134 		libcerror_error_set(
4135 		 error,
4136 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4137 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4138 		 "%s: unable to determine if header value has data.",
4139 		 function );
4140 
4141 		return( -1 );
4142 	}
4143 	else if( result == 0 )
4144 	{
4145 		return( 0 );
4146 	}
4147 	if( ( ( identifier_length == 11 )
4148 	   && ( narrow_string_compare(
4149 		 (char *) identifier,
4150 		 "system_date",
4151 		 11 ) == 0 ) )
4152 	 || ( ( identifier_length == 12 )
4153 	   && ( narrow_string_compare(
4154 		 (char *) identifier,
4155 		 "acquiry_date",
4156 		 12 ) == 0 ) ) )
4157 	{
4158 		if( libfvalue_value_get_data(
4159 		     header_value,
4160 		     &header_value_data,
4161 		     &header_value_data_size,
4162 		     &encoding,
4163 		     error ) != 1 )
4164 		{
4165 			libcerror_error_set(
4166 			 error,
4167 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4168 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4169 			 "%s: unable to retrieve header value data.",
4170 			 function );
4171 
4172 			return( -1 );
4173 		}
4174 		if( libewf_date_time_values_copy_to_utf16_string(
4175 		     header_value_data,
4176 		     header_value_data_size,
4177 		     internal_handle->date_format,
4178 		     utf16_string,
4179 		     utf16_string_size,
4180 		     error ) != 1 )
4181 		{
4182 			libcerror_error_set(
4183 			 error,
4184 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4185 			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4186 			 "%s: unable to copy header value data to UTF-16 string.",
4187 			 function );
4188 
4189 			return( -1 );
4190 		}
4191 	}
4192 	else
4193 	{
4194 		if( libfvalue_value_copy_to_utf16_string(
4195 		     header_value,
4196 		     0,
4197 		     utf16_string,
4198 		     utf16_string_size,
4199 		     error ) != 1 )
4200 		{
4201 			libcerror_error_set(
4202 			 error,
4203 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4204 			 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4205 			 "%s: unable to copy header value to UTF-16 string.",
4206 			 function );
4207 
4208 			return( -1 );
4209 		}
4210 	}
4211 	return( 1 );
4212 }
4213 
4214 /* Sets the UTF-16 encoded header value specified by the identifier
4215  * Returns 1 if successful or -1 on error
4216  */
libewf_handle_set_utf16_header_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,const uint16_t * utf16_string,size_t utf16_string_length,libcerror_error_t ** error)4217 int libewf_handle_set_utf16_header_value(
4218      libewf_handle_t *handle,
4219      const uint8_t *identifier,
4220      size_t identifier_length,
4221      const uint16_t *utf16_string,
4222      size_t utf16_string_length,
4223      libcerror_error_t **error )
4224 {
4225 	libewf_internal_handle_t *internal_handle = NULL;
4226 	libfvalue_value_t *header_value           = NULL;
4227 	static char *function                     = "libewf_handle_set_utf16_header_value";
4228 	int result                                = 0;
4229 
4230 	if( handle == NULL )
4231 	{
4232 		libcerror_error_set(
4233 		 error,
4234 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4235 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4236 		 "%s: invalid handle.",
4237 		 function );
4238 
4239 		return( -1 );
4240 	}
4241 	internal_handle = (libewf_internal_handle_t *) handle;
4242 
4243 	if( ( internal_handle->read_io_handle != NULL )
4244 	 || ( internal_handle->write_io_handle == NULL )
4245 	 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
4246 	{
4247 		libcerror_error_set(
4248 		 error,
4249 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4250 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4251 		 "%s: header value cannot be changed.",
4252 		 function );
4253 
4254 		return( -1 );
4255 	}
4256 	if( identifier == NULL )
4257 	{
4258 		libcerror_error_set(
4259 		 error,
4260 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4261 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4262 		 "%s: invalid identifier.",
4263 		 function );
4264 
4265 		return( -1 );
4266 	}
4267 	if( internal_handle->header_values == NULL )
4268 	{
4269 		if( libewf_header_values_initialize(
4270 		     &( internal_handle->header_values ),
4271 		     error ) != 1 )
4272 		{
4273 			libcerror_error_set(
4274 			 error,
4275 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4276 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
4277 			 "%s: unable to create header values.",
4278 			 function );
4279 
4280 			return( -1 );
4281 		}
4282 	}
4283 	result = libfvalue_table_get_value_by_identifier(
4284 	          internal_handle->header_values,
4285 	          identifier,
4286 	          identifier_length + 1,
4287 	          &header_value,
4288 	          0,
4289 	          error );
4290 
4291 	if( result == -1 )
4292 	{
4293 		libcerror_error_set(
4294 		 error,
4295 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4296 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4297 		 "%s: unable to retrieve header value: %s.",
4298 		 function,
4299 		 (char *) identifier );
4300 
4301 		return( -1 );
4302 	}
4303 	else if( result == 0 )
4304 	{
4305 		if( libfvalue_value_type_initialize(
4306 		     &header_value,
4307 		     LIBFVALUE_VALUE_TYPE_STRING_UTF8,
4308 		     error ) != 1 )
4309 		{
4310 			libcerror_error_set(
4311 			 error,
4312 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4313 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
4314 			 "%s: unable to create header value.",
4315 			 function );
4316 
4317 			return( -1 );
4318 		}
4319 		if( libfvalue_value_set_identifier(
4320 		     header_value,
4321 		     identifier,
4322 		     identifier_length + 1,
4323 		     LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
4324 		     error ) != 1 )
4325 		{
4326 			libcerror_error_set(
4327 			 error,
4328 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4329 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4330 			 "%s: unable to set header value: %s identifier.",
4331 			 function,
4332 			 (char *) identifier );
4333 
4334 			libfvalue_value_free(
4335 			 &header_value,
4336 			 NULL );
4337 
4338 			return( -1 );
4339 		}
4340 		if( libfvalue_table_set_value(
4341 		     internal_handle->header_values,
4342 		     header_value,
4343 		     error ) != 1 )
4344 		{
4345 			libcerror_error_set(
4346 			 error,
4347 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4348 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4349 			 "%s: unable to set header value: %s in table.",
4350 			 function,
4351 			 (char *) identifier );
4352 
4353 			libfvalue_value_free(
4354 			 &header_value,
4355 			 NULL );
4356 
4357 			return( -1 );
4358 		}
4359 	}
4360 	if( libfvalue_value_copy_from_utf16_string(
4361 	     header_value,
4362 	     0,
4363 	     utf16_string,
4364 	     utf16_string_length,
4365 	     error ) != 1 )
4366 	{
4367 		libcerror_error_set(
4368 		 error,
4369 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4370 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4371 		 "%s: unable to copy header value from UTF-16 string.",
4372 		 function );
4373 
4374 		return( -1 );
4375 	}
4376 	return( 1 );
4377 }
4378 
4379 /* Copies the header values from the source to the destination handle
4380  * Returns 1 if successful or -1 on error
4381  */
libewf_handle_copy_header_values(libewf_handle_t * destination_handle,libewf_handle_t * source_handle,libcerror_error_t ** error)4382 int libewf_handle_copy_header_values(
4383      libewf_handle_t *destination_handle,
4384      libewf_handle_t *source_handle,
4385      libcerror_error_t **error )
4386 {
4387 	libewf_internal_handle_t *internal_destination_handle = NULL;
4388 	libewf_internal_handle_t *internal_source_handle      = NULL;
4389 	static char *function                                 = "libewf_handle_copy_header_values";
4390 
4391 	if( destination_handle == NULL )
4392 	{
4393 		libcerror_error_set(
4394 		 error,
4395 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4396 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4397 		 "%s: invalid destination handle.",
4398 		 function );
4399 
4400 		return( -1 );
4401 	}
4402 	if( source_handle == NULL )
4403 	{
4404 		libcerror_error_set(
4405 		 error,
4406 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4407 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4408 		 "%s: invalid source handle.",
4409 		 function );
4410 
4411 		return( -1 );
4412 	}
4413 	internal_destination_handle = (libewf_internal_handle_t *) destination_handle;
4414 	internal_source_handle      = (libewf_internal_handle_t *) source_handle;
4415 
4416 	if( internal_source_handle->header_values_parsed == 0 )
4417 	{
4418 		if( libewf_handle_parse_header_values(
4419 		     internal_source_handle,
4420 		     error ) != 1 )
4421 		{
4422 			libcerror_error_set(
4423 			 error,
4424 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4425 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4426 			 "%s: unable to parse source handle header values.",
4427 			 function );
4428 
4429 			return( -1 );
4430 		}
4431 		internal_source_handle->header_values_parsed = 1;
4432 	}
4433 	if( internal_source_handle->header_values == NULL )
4434 	{
4435 		libcerror_error_set(
4436 		 error,
4437 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4438 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4439 		 "%s: invalid source handle - missing header values.",
4440 		 function );
4441 
4442 		return( -1 );
4443 	}
4444 	if( internal_destination_handle->header_values == NULL )
4445 	{
4446 		if( libewf_header_values_initialize(
4447 		     &( internal_destination_handle->header_values ),
4448 		     error ) != 1 )
4449 		{
4450 			libcerror_error_set(
4451 			 error,
4452 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4453 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
4454 			 "%s: unable to create header values.",
4455 			 function );
4456 
4457 			return( -1 );
4458 		}
4459 	}
4460 	if( libewf_header_values_copy(
4461 	     internal_destination_handle->header_values,
4462 	     internal_source_handle->header_values,
4463 	     error ) != 1 )
4464 	{
4465 		libcerror_error_set(
4466 		 error,
4467 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4468 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
4469 		 "%s: unable to copy header values.",
4470 		 function );
4471 
4472 		return( -1 );
4473 	}
4474 	internal_destination_handle->header_values_parsed = 1;
4475 
4476 	return( 1 );
4477 }
4478 
4479 /* Parses the header values from the header, header2 and/or xheader section
4480  * Will parse all the available headers in order mentioned above
4481  * Returns 1 if successful or -1 on error
4482  */
libewf_handle_parse_header_values(libewf_internal_handle_t * internal_handle,libcerror_error_t ** error)4483 int libewf_handle_parse_header_values(
4484      libewf_internal_handle_t *internal_handle,
4485      libcerror_error_t **error )
4486 {
4487 	libfvalue_value_t *header_value = NULL;
4488 	uint8_t *header_value_data      = NULL;
4489 	static char *function           = "libewf_handle_parse_header_values";
4490 	size_t header_value_data_size   = 0;
4491 	int encoding                    = 0;
4492 	int result                      = 0;
4493 	int result_header               = 1;
4494 	int result_header2              = 1;
4495 	int result_xheader              = 1;
4496 
4497 	if( internal_handle == NULL )
4498 	{
4499 		libcerror_error_set(
4500 		 error,
4501 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4502 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4503 		 "%s: invalid handle.",
4504 		 function );
4505 
4506 		return( -1 );
4507 	}
4508 	if( internal_handle->io_handle == NULL )
4509 	{
4510 		libcerror_error_set(
4511 		 error,
4512 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4513 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4514 		 "%s: invalid handle - missing IO handle.",
4515 		 function );
4516 
4517 		return( -1 );
4518 	}
4519 	if( internal_handle->header_sections == NULL )
4520 	{
4521 		libcerror_error_set(
4522 		 error,
4523 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4524 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
4525 		 "%s: invalid handle - missing header sections.",
4526 		 function );
4527 
4528 		return( -1 );
4529 	}
4530 	if( internal_handle->header_values == NULL )
4531 	{
4532 		if( libewf_header_values_initialize(
4533 		     &( internal_handle->header_values ),
4534 		     error ) != 1 )
4535 		{
4536 			libcerror_error_set(
4537 			 error,
4538 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4539 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
4540 			 "%s: unable to create header values.",
4541 			 function );
4542 
4543 			return( -1 );
4544 		}
4545 	}
4546 	if( internal_handle->header_sections->header != NULL )
4547 	{
4548 		if( libewf_header_values_parse_header(
4549 		     internal_handle->header_values,
4550 		     internal_handle->header_sections->header,
4551 		     internal_handle->header_sections->header_size,
4552 		     internal_handle->io_handle->header_codepage,
4553 		     &( internal_handle->io_handle->format ),
4554 		     error ) != 1 )
4555 		{
4556 			libcerror_error_set(
4557 			 error,
4558 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4559 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4560 			 "%s: unable to parse header.",
4561 			 function );
4562 
4563 			result_header = -1;
4564 		}
4565 	}
4566 	if( internal_handle->header_sections->header2 != NULL )
4567 	{
4568 		if( libewf_header_values_parse_header2(
4569 		     internal_handle->header_values,
4570 		     internal_handle->header_sections->header2,
4571 		     internal_handle->header_sections->header2_size,
4572 		     &( internal_handle->io_handle->format ),
4573 		     error ) != 1 )
4574 		{
4575 			libcerror_error_set(
4576 			 error,
4577 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4578 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4579 			 "%s: unable to parse header2.",
4580 			 function );
4581 
4582 			result_header2 = -1;
4583 		}
4584 	}
4585 	if( internal_handle->header_sections->xheader != NULL )
4586 	{
4587 		if( libewf_header_values_parse_xheader(
4588 		     internal_handle->header_values,
4589 		     internal_handle->header_sections->xheader,
4590 		     internal_handle->header_sections->xheader_size,
4591 		     error ) != 1 )
4592 		{
4593 			libcerror_error_set(
4594 			 error,
4595 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4596 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4597 			 "%s: unable to parse xheader.",
4598 			 function );
4599 
4600 			result_xheader = -1;
4601 		}
4602 	}
4603 	if( ( result_header != 1 )
4604 	 && ( result_header2 != 1 )
4605 	 && ( result_xheader != 1 ) )
4606 	{
4607 		return( -1 );
4608 	}
4609 	if( ( result_header != 1 )
4610 	 || ( result_header2 != 1 )
4611 	 || ( result_xheader != 1 ) )
4612 	{
4613 #if defined( HAVE_DEBUG_OUTPUT )
4614 		if( libcnotify_verbose != 0 )
4615 		{
4616 			if( ( error != NULL )
4617 			 && ( *error != NULL ) )
4618 			{
4619 				libcnotify_print_error_backtrace(
4620 				 *error );
4621 			}
4622 		}
4623 #endif
4624 		libcerror_error_free(
4625 		 error );
4626 	}
4627 	/* The EnCase2 and EnCase3 format are the same
4628 	 * only the acquiry software version provides insight in which version of EnCase was used
4629 	 */
4630 	if( internal_handle->io_handle->format == LIBEWF_FORMAT_ENCASE2 )
4631 	{
4632 		result = libfvalue_table_get_value_by_identifier(
4633 			  internal_handle->header_values,
4634 			  (uint8_t *) "acquiry_software_version",
4635 			  25,
4636 			  &header_value,
4637 			  0,
4638 			  error );
4639 
4640 		if( result == -1 )
4641 		{
4642 			libcerror_error_set(
4643 			 error,
4644 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4645 			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4646 			 "%s: unable to retrieve header value: acquiry_software_version.",
4647 			 function );
4648 
4649 			return( -1 );
4650 		}
4651 		else if( result != 0 )
4652 		{
4653 			if( libfvalue_value_get_data(
4654 			     header_value,
4655 			     &header_value_data,
4656 			     &header_value_data_size,
4657 			     &encoding,
4658 			     error ) != 1 )
4659 			{
4660 				libcerror_error_set(
4661 				 error,
4662 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4663 				 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4664 				 "%s: unable to retrieve header value data.",
4665 				 function );
4666 
4667 				return( -1 );
4668 			}
4669 			if( header_value_data[ 0 ] == (uint8_t) '3' )
4670 			{
4671 				internal_handle->io_handle->format = LIBEWF_FORMAT_ENCASE3;
4672 			}
4673 		}
4674 	}
4675 	return( 1 );
4676 }
4677 
4678 /* Retrieves the number of hash values
4679  * Returns 1 if successful, 0 if no hash values are present or -1 on error
4680  */
libewf_handle_get_number_of_hash_values(libewf_handle_t * handle,uint32_t * number_of_values,libcerror_error_t ** error)4681 int libewf_handle_get_number_of_hash_values(
4682      libewf_handle_t *handle,
4683      uint32_t *number_of_values,
4684      libcerror_error_t **error )
4685 {
4686 	libewf_internal_handle_t *internal_handle = NULL;
4687 	static char *function                     = "libewf_handle_get_number_of_hash_values";
4688 	int number_of_hash_values                 = 0;
4689 
4690 	if( handle == NULL )
4691 	{
4692 		libcerror_error_set(
4693 		 error,
4694 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4695 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4696 		 "%s: invalid handle.",
4697 		 function );
4698 
4699 		return( -1 );
4700 	}
4701 	internal_handle = (libewf_internal_handle_t *) handle;
4702 
4703 	if( number_of_values == NULL )
4704 	{
4705 		libcerror_error_set(
4706 		 error,
4707 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4708 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4709 		 "%s: invalid number of values.",
4710 		 function );
4711 
4712 		return( -1 );
4713 	}
4714 	if( internal_handle->hash_values_parsed == 0 )
4715 	{
4716 		if( libewf_handle_parse_hash_values(
4717 		     internal_handle,
4718 		     error ) != 1 )
4719 		{
4720 			libcerror_error_set(
4721 			 error,
4722 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4723 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4724 			 "%s: unable to parse hash values.",
4725 			 function );
4726 
4727 			return( -1 );
4728 		}
4729 		internal_handle->hash_values_parsed = 1;
4730 	}
4731 	if( internal_handle->hash_values == NULL )
4732 	{
4733 		return( 0 );
4734 	}
4735 	if( libfvalue_table_get_number_of_values(
4736 	     internal_handle->hash_values,
4737 	     &number_of_hash_values,
4738 	     error ) != 1 )
4739 	{
4740 		libcerror_error_set(
4741 		 error,
4742 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4743 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4744 		 "%s: unable to retrieve number of hash values.",
4745 		 function );
4746 
4747 		return( -1 );
4748 	}
4749 	if( number_of_hash_values < 0 )
4750 	{
4751 		libcerror_error_set(
4752 		 error,
4753 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4754 		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
4755 		 "%s: invalid number of hash values value out of bounds.",
4756 		 function );
4757 
4758 		return( -1 );
4759 	}
4760 	*number_of_values = (uint32_t) number_of_hash_values;
4761 
4762 	return( 1 );
4763 }
4764 
4765 /* Retrieves the size of the hash value identifier of a specific index
4766  * The identifier size includes the end of string character
4767  * Returns 1 if successful, 0 if if no hash values are present or -1 on error
4768  */
libewf_handle_get_hash_value_identifier_size(libewf_handle_t * handle,uint32_t index,size_t * identifier_size,libcerror_error_t ** error)4769 int libewf_handle_get_hash_value_identifier_size(
4770      libewf_handle_t *handle,
4771      uint32_t index,
4772      size_t *identifier_size,
4773      libcerror_error_t **error )
4774 {
4775 	libewf_internal_handle_t *internal_handle = NULL;
4776 	libfvalue_value_t *hash_value             = NULL;
4777 	uint8_t *hash_value_identifier            = NULL;
4778 	static char *function                     = "libewf_handle_get_hash_value_identifier_size";
4779 
4780 	if( handle == NULL )
4781 	{
4782 		libcerror_error_set(
4783 		 error,
4784 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4785 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4786 		 "%s: invalid handle.",
4787 		 function );
4788 
4789 		return( -1 );
4790 	}
4791 	internal_handle = (libewf_internal_handle_t *) handle;
4792 
4793 	if( internal_handle->hash_values_parsed == 0 )
4794 	{
4795 		if( libewf_handle_parse_hash_values(
4796 		     internal_handle,
4797 		     error ) != 1 )
4798 		{
4799 			libcerror_error_set(
4800 			 error,
4801 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4802 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4803 			 "%s: unable to parse hash values.",
4804 			 function );
4805 
4806 			return( -1 );
4807 		}
4808 		internal_handle->hash_values_parsed = 1;
4809 	}
4810 	if( internal_handle->hash_values == NULL )
4811 	{
4812 		return( 0 );
4813 	}
4814 	if( libfvalue_table_get_value_by_index(
4815 	     internal_handle->hash_values,
4816 	     (int) index,
4817 	     &hash_value,
4818 	     error ) != 1 )
4819 	{
4820 		libcerror_error_set(
4821 		 error,
4822 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4823 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4824 		 "%s: unable to retrieve hash value: %" PRIu32 ".",
4825 		 function,
4826 		 index );
4827 
4828 		return( -1 );
4829 	}
4830 	if( libfvalue_value_get_identifier(
4831 	     hash_value,
4832 	     &hash_value_identifier,
4833 	     identifier_size,
4834 	     error ) != 1 )
4835 	{
4836 		libcerror_error_set(
4837 		 error,
4838 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4839 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4840 		 "%s: unable to retrieve hash value identifier size.",
4841 		 function );
4842 
4843 		return( -1 );
4844 	}
4845 	return( 1 );
4846 }
4847 
4848 /* Retrieves the hash value identifier of a specific index
4849  * The identifier size should include the end of string character
4850  * Returns 1 if successful, 0 if no hash values are present or -1 on error
4851  */
libewf_handle_get_hash_value_identifier(libewf_handle_t * handle,uint32_t index,uint8_t * identifier,size_t identifier_size,libcerror_error_t ** error)4852 int libewf_handle_get_hash_value_identifier(
4853      libewf_handle_t *handle,
4854      uint32_t index,
4855      uint8_t *identifier,
4856      size_t identifier_size,
4857      libcerror_error_t **error )
4858 {
4859 	libewf_internal_handle_t *internal_handle = NULL;
4860 	libfvalue_value_t *hash_value             = NULL;
4861 	uint8_t *hash_value_identifier            = NULL;
4862 	static char *function                     = "libewf_handle_get_hash_value_identifier";
4863 	size_t hash_value_identifier_size         = 0;
4864 
4865 	if( handle == NULL )
4866 	{
4867 		libcerror_error_set(
4868 		 error,
4869 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4870 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4871 		 "%s: invalid handle.",
4872 		 function );
4873 
4874 		return( -1 );
4875 	}
4876 	internal_handle = (libewf_internal_handle_t *) handle;
4877 
4878 	if( internal_handle->hash_values_parsed == 0 )
4879 	{
4880 		if( libewf_handle_parse_hash_values(
4881 		     internal_handle,
4882 		     error ) != 1 )
4883 		{
4884 			libcerror_error_set(
4885 			 error,
4886 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4887 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4888 			 "%s: unable to parse hash values.",
4889 			 function );
4890 
4891 			return( -1 );
4892 		}
4893 		internal_handle->hash_values_parsed = 1;
4894 	}
4895 	if( internal_handle->hash_values == NULL )
4896 	{
4897 		return( 0 );
4898 	}
4899 	if( libfvalue_table_get_value_by_index(
4900 	     internal_handle->hash_values,
4901 	     (int) index,
4902 	     &hash_value,
4903 	     error ) != 1 )
4904 	{
4905 		libcerror_error_set(
4906 		 error,
4907 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4908 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4909 		 "%s: unable to retrieve hash value: %" PRIu32 ".",
4910 		 function,
4911 		 index );
4912 
4913 		return( -1 );
4914 	}
4915 	if( libfvalue_value_get_identifier(
4916 	     hash_value,
4917 	     &hash_value_identifier,
4918 	     &hash_value_identifier_size,
4919 	     error ) != 1 )
4920 	{
4921 		libcerror_error_set(
4922 		 error,
4923 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4924 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
4925 		 "%s: unable to retrieve hash value identifier size.",
4926 		 function );
4927 
4928 		return( -1 );
4929 	}
4930 	if( identifier_size < hash_value_identifier_size )
4931 	{
4932 		libcerror_error_set(
4933 		 error,
4934 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4935 		 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
4936 		 "%s: identifier size too small.",
4937 		 function );
4938 
4939 		return( -1 );
4940 	}
4941 	if( memory_copy(
4942 	     identifier,
4943 	     hash_value_identifier,
4944 	     hash_value_identifier_size ) == NULL )
4945 	{
4946 		libcerror_error_set(
4947 		 error,
4948 		 LIBCERROR_ERROR_DOMAIN_MEMORY,
4949 		 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
4950 		 "%s: unable to copy identifier.",
4951 		 function );
4952 
4953 		return( -1 );
4954 	}
4955 	return( 1 );
4956 }
4957 
4958 /* Retrieves the size of the UTF-8 encoded hash value of an identifier
4959  * The string size includes the end of string character
4960  * Returns 1 if successful, 0 if value not present or -1 on error
4961  */
libewf_handle_get_utf8_hash_value_size(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,size_t * utf8_string_size,libcerror_error_t ** error)4962 int libewf_handle_get_utf8_hash_value_size(
4963      libewf_handle_t *handle,
4964      const uint8_t *identifier,
4965      size_t identifier_length,
4966      size_t *utf8_string_size,
4967      libcerror_error_t **error )
4968 {
4969 	libewf_internal_handle_t *internal_handle = NULL;
4970 	libfvalue_value_t *hash_value             = NULL;
4971 	static char *function                     = "libewf_handle_get_utf8_hash_value_size";
4972 	int result                                = 0;
4973 
4974 	if( handle == NULL )
4975 	{
4976 		libcerror_error_set(
4977 		 error,
4978 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4979 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4980 		 "%s: invalid handle.",
4981 		 function );
4982 
4983 		return( -1 );
4984 	}
4985 	internal_handle = (libewf_internal_handle_t *) handle;
4986 
4987 	if( identifier == NULL )
4988 	{
4989 		libcerror_error_set(
4990 		 error,
4991 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4992 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4993 		 "%s: invalid indentifier.",
4994 		 function );
4995 
4996 		return( -1 );
4997 	}
4998 	if( internal_handle->hash_values_parsed == 0 )
4999 	{
5000 		if( libewf_handle_parse_hash_values(
5001 		     internal_handle,
5002 		     error ) != 1 )
5003 		{
5004 			libcerror_error_set(
5005 			 error,
5006 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5007 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5008 			 "%s: unable to parse hash values.",
5009 			 function );
5010 
5011 			return( -1 );
5012 		}
5013 		internal_handle->hash_values_parsed = 1;
5014 	}
5015 	if( internal_handle->hash_values == NULL )
5016 	{
5017 		return( 0 );
5018 	}
5019 	result = libfvalue_table_get_value_by_identifier(
5020 	          internal_handle->hash_values,
5021 	          identifier,
5022 	          identifier_length + 1,
5023 	          &hash_value,
5024 	          0,
5025 	          error );
5026 
5027 	if( result == -1 )
5028 	{
5029 		libcerror_error_set(
5030 		 error,
5031 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5032 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5033 		 "%s: unable to retrieve hash value: %s.",
5034 		 function,
5035 		 (char *) identifier );
5036 
5037 		return( -1 );
5038 	}
5039 	else if( result == 0 )
5040 	{
5041 		return( 0 );
5042 	}
5043 	result = libfvalue_value_has_data(
5044 		  hash_value,
5045 		  error );
5046 
5047 	if( result == -1 )
5048 	{
5049 		libcerror_error_set(
5050 		 error,
5051 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5052 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5053 		 "%s: unable to determine if hash value has data.",
5054 		 function );
5055 
5056 		return( -1 );
5057 	}
5058 	else if( result == 0 )
5059 	{
5060 		return( 0 );
5061 	}
5062 	if( libfvalue_value_get_utf8_string_size(
5063 	     hash_value,
5064 	     0,
5065 	     utf8_string_size,
5066 	     error ) != 1 )
5067 	{
5068 		libcerror_error_set(
5069 		 error,
5070 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5071 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5072 		 "%s: unable to retrieve UTF-8 string size of hash value.",
5073 		 function );
5074 
5075 		return( -1 );
5076 	}
5077 	return( 1 );
5078 }
5079 
5080 /* Retrieves the UTF-8 encoded hash value of an identifier
5081  * The string size should include the end of string character
5082  * Returns 1 if successful, 0 if value not present or -1 on error
5083  */
libewf_handle_get_utf8_hash_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,uint8_t * utf8_string,size_t utf8_string_size,libcerror_error_t ** error)5084 int libewf_handle_get_utf8_hash_value(
5085      libewf_handle_t *handle,
5086      const uint8_t *identifier,
5087      size_t identifier_length,
5088      uint8_t *utf8_string,
5089      size_t utf8_string_size,
5090      libcerror_error_t **error )
5091 {
5092 	libewf_internal_handle_t *internal_handle = NULL;
5093 	libfvalue_value_t *hash_value             = NULL;
5094 	static char *function                     = "libewf_handle_get_utf8_hash_value";
5095 	int result                                = 0;
5096 
5097 	if( handle == NULL )
5098 	{
5099 		libcerror_error_set(
5100 		 error,
5101 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5102 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5103 		 "%s: invalid handle.",
5104 		 function );
5105 
5106 		return( -1 );
5107 	}
5108 	internal_handle = (libewf_internal_handle_t *) handle;
5109 
5110 	if( identifier == NULL )
5111 	{
5112 		libcerror_error_set(
5113 		 error,
5114 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5115 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5116 		 "%s: invalid indentifier.",
5117 		 function );
5118 
5119 		return( -1 );
5120 	}
5121 	if( internal_handle->hash_values_parsed == 0 )
5122 	{
5123 		if( libewf_handle_parse_hash_values(
5124 		     internal_handle,
5125 		     error ) != 1 )
5126 		{
5127 			libcerror_error_set(
5128 			 error,
5129 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5130 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5131 			 "%s: unable to parse hash values.",
5132 			 function );
5133 
5134 			return( -1 );
5135 		}
5136 		internal_handle->hash_values_parsed = 1;
5137 	}
5138 	if( internal_handle->hash_values == NULL )
5139 	{
5140 		return( 0 );
5141 	}
5142 	result = libfvalue_table_get_value_by_identifier(
5143 	          internal_handle->hash_values,
5144 	          identifier,
5145 	          identifier_length + 1,
5146 	          &hash_value,
5147 	          0,
5148 	          error );
5149 
5150 	if( result == -1 )
5151 	{
5152 		libcerror_error_set(
5153 		 error,
5154 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5155 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5156 		 "%s: unable to retrieve hash value: %s.",
5157 		 function,
5158 		 (char *) identifier );
5159 
5160 		return( -1 );
5161 	}
5162 	else if( result == 0 )
5163 	{
5164 		return( 0 );
5165 	}
5166 	result = libfvalue_value_has_data(
5167 		  hash_value,
5168 		  error );
5169 
5170 	if( result == -1 )
5171 	{
5172 		libcerror_error_set(
5173 		 error,
5174 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5175 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5176 		 "%s: unable to determine if hash value has data.",
5177 		 function );
5178 
5179 		return( -1 );
5180 	}
5181 	else if( result == 0 )
5182 	{
5183 		return( 0 );
5184 	}
5185 	if( libfvalue_value_copy_to_utf8_string(
5186 	     hash_value,
5187 	     0,
5188 	     utf8_string,
5189 	     utf8_string_size,
5190 	     error ) != 1 )
5191 	{
5192 		libcerror_error_set(
5193 		 error,
5194 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5195 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
5196 		 "%s: unable to copy hash value to UTF-8 string.",
5197 		 function );
5198 
5199 		return( -1 );
5200 	}
5201 	return( 1 );
5202 }
5203 
5204 /* Sets the UTF-8 encoded hash value specified by the identifier
5205  * Returns 1 if successful or -1 on error
5206  */
libewf_handle_set_utf8_hash_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,const uint8_t * utf8_string,size_t utf8_string_length,libcerror_error_t ** error)5207 int libewf_handle_set_utf8_hash_value(
5208      libewf_handle_t *handle,
5209      const uint8_t *identifier,
5210      size_t identifier_length,
5211      const uint8_t *utf8_string,
5212      size_t utf8_string_length,
5213      libcerror_error_t **error )
5214 {
5215 	libewf_internal_handle_t *internal_handle = NULL;
5216 	libfvalue_value_t *hash_value             = NULL;
5217 	static char *function                     = "libewf_handle_set_utf8_hash_value";
5218 	int result                                = 0;
5219 
5220 	if( handle == NULL )
5221 	{
5222 		libcerror_error_set(
5223 		 error,
5224 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5225 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5226 		 "%s: invalid handle.",
5227 		 function );
5228 
5229 		return( -1 );
5230 	}
5231 	internal_handle = (libewf_internal_handle_t *) handle;
5232 
5233 	if( internal_handle->io_handle == NULL )
5234 	{
5235 		libcerror_error_set(
5236 		 error,
5237 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5238 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
5239 		 "%s: invalid handle - missing IO handle.",
5240 		 function );
5241 
5242 		return( -1 );
5243 	}
5244 	if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 )
5245 	 && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) )
5246 	{
5247 		libcerror_error_set(
5248 		 error,
5249 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5250 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5251 		 "%s: hash value cannot be changed.",
5252 		 function );
5253 
5254 		return( -1 );
5255 	}
5256 	if( identifier == NULL )
5257 	{
5258 		libcerror_error_set(
5259 		 error,
5260 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5261 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5262 		 "%s: invalid identifier.",
5263 		 function );
5264 
5265 		return( -1 );
5266 	}
5267 	if( internal_handle->hash_values == NULL )
5268 	{
5269 		if( libewf_hash_values_initialize(
5270 		     &( internal_handle->hash_values ),
5271 		     error ) != 1 )
5272 		{
5273 			libcerror_error_set(
5274 			 error,
5275 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5276 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
5277 			 "%s: unable to create hash values.",
5278 			 function );
5279 
5280 			return( -1 );
5281 		}
5282 		internal_handle->hash_values_parsed = 1;
5283 	}
5284 	result = libfvalue_table_get_value_by_identifier(
5285 	          internal_handle->hash_values,
5286 	          identifier,
5287 	          identifier_length + 1,
5288 	          &hash_value,
5289 	          0,
5290 	          error );
5291 
5292 	if( result == -1 )
5293 	{
5294 		libcerror_error_set(
5295 		 error,
5296 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5297 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5298 		 "%s: unable to retrieve hash value: %s.",
5299 		 function,
5300 		 (char *) identifier );
5301 
5302 		return( -1 );
5303 	}
5304 	else if( result == 0 )
5305 	{
5306 		if( libfvalue_value_type_initialize(
5307 		     &hash_value,
5308 		     LIBFVALUE_VALUE_TYPE_STRING_UTF8,
5309 		     error ) != 1 )
5310 		{
5311 			libcerror_error_set(
5312 			 error,
5313 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5314 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
5315 			 "%s: unable to create hash value.",
5316 			 function );
5317 
5318 			return( -1 );
5319 		}
5320 		if( libfvalue_value_set_identifier(
5321 		     hash_value,
5322 		     identifier,
5323 		     identifier_length + 1,
5324 		     LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
5325 		     error ) != 1 )
5326 		{
5327 			libcerror_error_set(
5328 			 error,
5329 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5330 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5331 			 "%s: unable to set hash value: %s identifier.",
5332 			 function,
5333 			 (char *) identifier );
5334 
5335 			libfvalue_value_free(
5336 			 &hash_value,
5337 			 NULL );
5338 
5339 			return( -1 );
5340 		}
5341 		if( libfvalue_table_set_value(
5342 		     internal_handle->hash_values,
5343 		     hash_value,
5344 		     error ) != 1 )
5345 		{
5346 			libcerror_error_set(
5347 			 error,
5348 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5349 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5350 			 "%s: unable to set hash value: %s in table.",
5351 			 function,
5352 			 (char *) identifier );
5353 
5354 			libfvalue_value_free(
5355 			 &hash_value,
5356 			 NULL );
5357 
5358 			return( -1 );
5359 		}
5360 	}
5361 	if( libfvalue_value_copy_from_utf8_string(
5362 	     hash_value,
5363 	     0,
5364 	     utf8_string,
5365 	     utf8_string_length,
5366 	     error ) != 1 )
5367 	{
5368 		libcerror_error_set(
5369 		 error,
5370 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5371 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
5372 		 "%s: unable to copy hash value from UTF-8 string.",
5373 		 function );
5374 
5375 		return( -1 );
5376 	}
5377 	if( internal_handle->hash_sections != NULL )
5378 	{
5379 		if( ( identifier_length == 3 )
5380 		 && ( narrow_string_compare(
5381 		       (char *) identifier,
5382 		       "MD5",
5383 		       identifier_length ) == 0 ) )
5384 		{
5385 			if( libewf_hash_values_generate_md5_hash(
5386 			     internal_handle->hash_values,
5387 			     internal_handle->hash_sections->md5_hash,
5388 			     16,
5389 			     &( internal_handle->hash_sections->md5_hash_set ),
5390 			     error ) != 1 )
5391 			{
5392 				libcerror_error_set(
5393 				 error,
5394 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5395 				 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5396 				 "%s: unable to parse MD5 hash value for its value.",
5397 				 function );
5398 
5399 				return( -1 );
5400 			}
5401 			if( libewf_hash_values_generate_md5_hash(
5402 			     internal_handle->hash_values,
5403 			     internal_handle->hash_sections->md5_digest,
5404 			     16,
5405 			     &( internal_handle->hash_sections->md5_digest_set ),
5406 			     error ) != 1 )
5407 			{
5408 				libcerror_error_set(
5409 				 error,
5410 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5411 				 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5412 				 "%s: unable to parse MD5 hash value for its value.",
5413 				 function );
5414 
5415 				return( -1 );
5416 			}
5417 		}
5418 		else if( ( identifier_length == 4 )
5419 		      && ( narrow_string_compare(
5420 		            (char *) identifier,
5421 		            "SHA1",
5422 		            identifier_length ) == 0 ) )
5423 		{
5424 			if( libewf_hash_values_generate_sha1_hash(
5425 			     internal_handle->hash_values,
5426 			     internal_handle->hash_sections->sha1_digest,
5427 			     20,
5428 			     &( internal_handle->hash_sections->sha1_digest_set ),
5429 			     error ) != 1 )
5430 			{
5431 				libcerror_error_set(
5432 				 error,
5433 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5434 				 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5435 				 "%s: unable to parse SHA1 hash value for its value.",
5436 				 function );
5437 
5438 				return( -1 );
5439 			}
5440 		}
5441 	}
5442 	return( 1 );
5443 }
5444 
5445 /* Retrieves the size of the UTF-16 encoded hash value of an identifier
5446  * The string size includes the end of string character
5447  * Returns 1 if successful, 0 if value not present or -1 on error
5448  */
libewf_handle_get_utf16_hash_value_size(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,size_t * utf16_string_size,libcerror_error_t ** error)5449 int libewf_handle_get_utf16_hash_value_size(
5450      libewf_handle_t *handle,
5451      const uint8_t *identifier,
5452      size_t identifier_length,
5453      size_t *utf16_string_size,
5454      libcerror_error_t **error )
5455 {
5456 	libewf_internal_handle_t *internal_handle = NULL;
5457 	libfvalue_value_t *hash_value             = NULL;
5458 	static char *function                     = "libewf_handle_get_utf16_hash_value_size";
5459 	int result                                = 0;
5460 
5461 	if( handle == NULL )
5462 	{
5463 		libcerror_error_set(
5464 		 error,
5465 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5466 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5467 		 "%s: invalid handle.",
5468 		 function );
5469 
5470 		return( -1 );
5471 	}
5472 	internal_handle = (libewf_internal_handle_t *) handle;
5473 
5474 	if( identifier == NULL )
5475 	{
5476 		libcerror_error_set(
5477 		 error,
5478 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5479 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5480 		 "%s: invalid indentifier.",
5481 		 function );
5482 
5483 		return( -1 );
5484 	}
5485 	if( internal_handle->hash_values_parsed == 0 )
5486 	{
5487 		if( libewf_handle_parse_hash_values(
5488 		     internal_handle,
5489 		     error ) != 1 )
5490 		{
5491 			libcerror_error_set(
5492 			 error,
5493 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5494 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5495 			 "%s: unable to parse hash values.",
5496 			 function );
5497 
5498 			return( -1 );
5499 		}
5500 		internal_handle->hash_values_parsed = 1;
5501 	}
5502 	if( internal_handle->hash_values == NULL )
5503 	{
5504 		return( 0 );
5505 	}
5506 	result = libfvalue_table_get_value_by_identifier(
5507 	          internal_handle->hash_values,
5508 	          identifier,
5509 	          identifier_length + 1,
5510 	          &hash_value,
5511 	          0,
5512 	          error );
5513 
5514 	if( result == -1 )
5515 	{
5516 		libcerror_error_set(
5517 		 error,
5518 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5519 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5520 		 "%s: unable to retrieve hash value: %s.",
5521 		 function,
5522 		 (char *) identifier );
5523 
5524 		return( -1 );
5525 	}
5526 	else if( result == 0 )
5527 	{
5528 		return( 0 );
5529 	}
5530 	result = libfvalue_value_has_data(
5531 		  hash_value,
5532 		  error );
5533 
5534 	if( result == -1 )
5535 	{
5536 		libcerror_error_set(
5537 		 error,
5538 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5539 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5540 		 "%s: unable to determine if hash value has data.",
5541 		 function );
5542 
5543 		return( -1 );
5544 	}
5545 	else if( result == 0 )
5546 	{
5547 		return( 0 );
5548 	}
5549 	if( libfvalue_value_get_utf16_string_size(
5550 	     hash_value,
5551 	     0,
5552 	     utf16_string_size,
5553 	     error ) != 1 )
5554 	{
5555 		libcerror_error_set(
5556 		 error,
5557 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5558 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5559 		 "%s: unable to retrieve UTF-16 string size of hash value.",
5560 		 function );
5561 
5562 		return( -1 );
5563 	}
5564 	return( 1 );
5565 }
5566 
5567 /* Retrieves the UTF-16 encoded hash value of an identifier
5568  * The string size should include the end of string character
5569  * Returns 1 if successful, 0 if value not present or -1 on error
5570  */
libewf_handle_get_utf16_hash_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,uint16_t * utf16_string,size_t utf16_string_size,libcerror_error_t ** error)5571 int libewf_handle_get_utf16_hash_value(
5572      libewf_handle_t *handle,
5573      const uint8_t *identifier,
5574      size_t identifier_length,
5575      uint16_t *utf16_string,
5576      size_t utf16_string_size,
5577      libcerror_error_t **error )
5578 {
5579 	libewf_internal_handle_t *internal_handle = NULL;
5580 	libfvalue_value_t *hash_value             = NULL;
5581 	static char *function                     = "libewf_handle_get_utf16_hash_value";
5582 	int result                                = 0;
5583 
5584 	if( handle == NULL )
5585 	{
5586 		libcerror_error_set(
5587 		 error,
5588 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5589 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5590 		 "%s: invalid handle.",
5591 		 function );
5592 
5593 		return( -1 );
5594 	}
5595 	internal_handle = (libewf_internal_handle_t *) handle;
5596 
5597 	if( identifier == NULL )
5598 	{
5599 		libcerror_error_set(
5600 		 error,
5601 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5602 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5603 		 "%s: invalid indentifier.",
5604 		 function );
5605 
5606 		return( -1 );
5607 	}
5608 	if( internal_handle->hash_values_parsed == 0 )
5609 	{
5610 		if( libewf_handle_parse_hash_values(
5611 		     internal_handle,
5612 		     error ) != 1 )
5613 		{
5614 			libcerror_error_set(
5615 			 error,
5616 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5617 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5618 			 "%s: unable to parse hash values.",
5619 			 function );
5620 
5621 			return( -1 );
5622 		}
5623 		internal_handle->hash_values_parsed = 1;
5624 	}
5625 	if( internal_handle->hash_values == NULL )
5626 	{
5627 		return( 0 );
5628 	}
5629 	result = libfvalue_table_get_value_by_identifier(
5630 	          internal_handle->hash_values,
5631 	          identifier,
5632 	          identifier_length + 1,
5633 	          &hash_value,
5634 	          0,
5635 	          error );
5636 
5637 	if( result == -1 )
5638 	{
5639 		libcerror_error_set(
5640 		 error,
5641 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5642 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5643 		 "%s: unable to retrieve hash value: %s.",
5644 		 function,
5645 		 (char *) identifier );
5646 
5647 		return( -1 );
5648 	}
5649 	else if( result == 0 )
5650 	{
5651 		return( 0 );
5652 	}
5653 	result = libfvalue_value_has_data(
5654 		  hash_value,
5655 		  error );
5656 
5657 	if( result == -1 )
5658 	{
5659 		libcerror_error_set(
5660 		 error,
5661 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5662 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5663 		 "%s: unable to determine if hash value has data.",
5664 		 function );
5665 
5666 		return( -1 );
5667 	}
5668 	else if( result == 0 )
5669 	{
5670 		return( 0 );
5671 	}
5672 	if( libfvalue_value_copy_to_utf16_string(
5673 	     hash_value,
5674 	     0,
5675 	     utf16_string,
5676 	     utf16_string_size,
5677 	     error ) != 1 )
5678 	{
5679 		libcerror_error_set(
5680 		 error,
5681 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5682 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
5683 		 "%s: unable to copy hash value to UTF-16 string.",
5684 		 function );
5685 
5686 		return( -1 );
5687 	}
5688 	return( 1 );
5689 }
5690 
5691 /* Sets the UTF-16 encoded hash value specified by the identifier
5692  * Returns 1 if successful or -1 on error
5693  */
libewf_handle_set_utf16_hash_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,const uint16_t * utf16_string,size_t utf16_string_length,libcerror_error_t ** error)5694 int libewf_handle_set_utf16_hash_value(
5695      libewf_handle_t *handle,
5696      const uint8_t *identifier,
5697      size_t identifier_length,
5698      const uint16_t *utf16_string,
5699      size_t utf16_string_length,
5700      libcerror_error_t **error )
5701 {
5702 	libewf_internal_handle_t *internal_handle = NULL;
5703 	libfvalue_value_t *hash_value             = NULL;
5704 	static char *function                     = "libewf_handle_set_utf16_hash_value";
5705 	int result                                = 0;
5706 
5707 	if( handle == NULL )
5708 	{
5709 		libcerror_error_set(
5710 		 error,
5711 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5712 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5713 		 "%s: invalid handle.",
5714 		 function );
5715 
5716 		return( -1 );
5717 	}
5718 	internal_handle = (libewf_internal_handle_t *) handle;
5719 
5720 	if( internal_handle->io_handle == NULL )
5721 	{
5722 		libcerror_error_set(
5723 		 error,
5724 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5725 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
5726 		 "%s: invalid handle - missing IO handle.",
5727 		 function );
5728 
5729 		return( -1 );
5730 	}
5731 	if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 )
5732 	 && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) )
5733 	{
5734 		libcerror_error_set(
5735 		 error,
5736 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5737 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5738 		 "%s: hash value cannot be changed.",
5739 		 function );
5740 
5741 		return( -1 );
5742 	}
5743 	if( identifier == NULL )
5744 	{
5745 		libcerror_error_set(
5746 		 error,
5747 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5748 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5749 		 "%s: invalid identifier.",
5750 		 function );
5751 
5752 		return( -1 );
5753 	}
5754 	if( internal_handle->hash_values == NULL )
5755 	{
5756 		if( libewf_hash_values_initialize(
5757 		     &( internal_handle->hash_values ),
5758 		     error ) != 1 )
5759 		{
5760 			libcerror_error_set(
5761 			 error,
5762 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5763 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
5764 			 "%s: unable to create hash values.",
5765 			 function );
5766 
5767 			return( -1 );
5768 		}
5769 		internal_handle->hash_values_parsed = 1;
5770 	}
5771 	result = libfvalue_table_get_value_by_identifier(
5772 	          internal_handle->hash_values,
5773 	          identifier,
5774 	          identifier_length + 1,
5775 	          &hash_value,
5776 	          0,
5777 	          error );
5778 
5779 	if( result == -1 )
5780 	{
5781 		libcerror_error_set(
5782 		 error,
5783 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5784 		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
5785 		 "%s: unable to retrieve hash value: %s.",
5786 		 function,
5787 		 (char *) identifier );
5788 
5789 		return( -1 );
5790 	}
5791 	else if( result == 0 )
5792 	{
5793 		if( libfvalue_value_type_initialize(
5794 		     &hash_value,
5795 		     LIBFVALUE_VALUE_TYPE_STRING_UTF8,
5796 		     error ) != 1 )
5797 		{
5798 			libcerror_error_set(
5799 			 error,
5800 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5801 			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
5802 			 "%s: unable to create hash value.",
5803 			 function );
5804 
5805 			return( -1 );
5806 		}
5807 		if( libfvalue_value_set_identifier(
5808 		     hash_value,
5809 		     identifier,
5810 		     identifier_length + 1,
5811 		     LIBFVALUE_VALUE_IDENTIFIER_FLAG_MANAGED,
5812 		     error ) != 1 )
5813 		{
5814 			libcerror_error_set(
5815 			 error,
5816 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5817 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5818 			 "%s: unable to set hash value: %s identifier.",
5819 			 function,
5820 			 (char *) identifier );
5821 
5822 			libfvalue_value_free(
5823 			 &hash_value,
5824 			 NULL );
5825 
5826 			return( -1 );
5827 		}
5828 		if( libfvalue_table_set_value(
5829 		     internal_handle->hash_values,
5830 		     hash_value,
5831 		     error ) != 1 )
5832 		{
5833 			libcerror_error_set(
5834 			 error,
5835 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5836 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5837 			 "%s: unable to set hash value: %s in table.",
5838 			 function,
5839 			 (char *) identifier );
5840 
5841 			libfvalue_value_free(
5842 			 &hash_value,
5843 			 NULL );
5844 
5845 			return( -1 );
5846 		}
5847 	}
5848 	if( libfvalue_value_copy_from_utf16_string(
5849 	     hash_value,
5850 	     0,
5851 	     utf16_string,
5852 	     utf16_string_length,
5853 	     error ) != 1 )
5854 	{
5855 		libcerror_error_set(
5856 		 error,
5857 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5858 		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
5859 		 "%s: unable to copy hash value from UTF-16 string.",
5860 		 function );
5861 
5862 		return( -1 );
5863 	}
5864 	if( internal_handle->hash_sections != NULL )
5865 	{
5866 		if( ( identifier_length == 3 )
5867 		 && ( narrow_string_compare(
5868 		       (char *) identifier,
5869 		       "MD5",
5870 		       identifier_length ) == 0 ) )
5871 		{
5872 			if( libewf_hash_values_generate_md5_hash(
5873 			     internal_handle->hash_values,
5874 			     internal_handle->hash_sections->md5_hash,
5875 			     16,
5876 			     &( internal_handle->hash_sections->md5_hash_set ),
5877 			     error ) != 1 )
5878 			{
5879 				libcerror_error_set(
5880 				 error,
5881 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5882 				 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5883 				 "%s: unable to parse MD5 hash value for its value.",
5884 				 function );
5885 
5886 				return( -1 );
5887 			}
5888 			if( libewf_hash_values_generate_md5_hash(
5889 			     internal_handle->hash_values,
5890 			     internal_handle->hash_sections->md5_digest,
5891 			     16,
5892 			     &( internal_handle->hash_sections->md5_digest_set ),
5893 			     error ) != 1 )
5894 			{
5895 				libcerror_error_set(
5896 				 error,
5897 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5898 				 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5899 				 "%s: unable to parse MD5 hash value for its value.",
5900 				 function );
5901 
5902 				return( -1 );
5903 			}
5904 		}
5905 		else if( ( identifier_length == 4 )
5906 		      && ( narrow_string_compare(
5907 		            (char *) identifier,
5908 		            "SHA1",
5909 		            identifier_length ) == 0 ) )
5910 		{
5911 			if( libewf_hash_values_generate_sha1_hash(
5912 			     internal_handle->hash_values,
5913 			     internal_handle->hash_sections->sha1_digest,
5914 			     20,
5915 			     &( internal_handle->hash_sections->sha1_digest_set ),
5916 			     error ) != 1 )
5917 			{
5918 				libcerror_error_set(
5919 				 error,
5920 				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5921 				 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5922 				 "%s: unable to parse SHA1 hash value for its value.",
5923 				 function );
5924 
5925 				return( -1 );
5926 			}
5927 		}
5928 	}
5929 	return( 1 );
5930 }
5931 
5932 /* Parses the hash values from the hash, digest and/or xhash section
5933  * Returns 1 if successful or -1 on error
5934  */
libewf_handle_parse_hash_values(libewf_internal_handle_t * internal_handle,libcerror_error_t ** error)5935 int libewf_handle_parse_hash_values(
5936      libewf_internal_handle_t *internal_handle,
5937      libcerror_error_t **error )
5938 {
5939 	static char *function = "libewf_handle_parse_hash_values";
5940 	int result            = 1;
5941 
5942 	if( internal_handle == NULL )
5943 	{
5944 		libcerror_error_set(
5945 		 error,
5946 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
5947 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
5948 		 "%s: invalid handle.",
5949 		 function );
5950 
5951 		return( -1 );
5952 	}
5953 	if( internal_handle->hash_sections == NULL )
5954 	{
5955 		libcerror_error_set(
5956 		 error,
5957 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5958 		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
5959 		 "%s: invalid handle - missing hash sections.",
5960 		 function );
5961 
5962 		return( -1 );
5963 	}
5964 	if( internal_handle->hash_values != NULL )
5965 	{
5966 		libcerror_error_set(
5967 		 error,
5968 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5969 		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
5970 		 "%s: invalid handle - hash sections already set.",
5971 		 function );
5972 
5973 		return( -1 );
5974 	}
5975 	if( libewf_hash_values_initialize(
5976 	     &( internal_handle->hash_values ),
5977 	     error ) != 1 )
5978 	{
5979 		libcerror_error_set(
5980 		 error,
5981 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5982 		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
5983 		 "%s: unable to create hash values.",
5984 		 function );
5985 
5986 		return( -1 );
5987 	}
5988 	if( ( internal_handle->hash_sections->md5_hash_set != 0 )
5989 	 && ( libewf_hash_values_parse_md5_hash(
5990 	       internal_handle->hash_values,
5991 	       internal_handle->hash_sections->md5_hash,
5992 	       16,
5993 	       error ) != 1 ) )
5994 	{
5995 		libcerror_error_set(
5996 		 error,
5997 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
5998 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
5999 		 "%s: unable to parse MD5 hash for its value.",
6000 		 function );
6001 
6002 		result = -1;
6003 	}
6004 	if( ( internal_handle->hash_sections->md5_digest_set != 0 )
6005 	 || ( internal_handle->hash_sections->sha1_digest_set != 0 ) )
6006 	{
6007 		if( ( internal_handle->hash_sections->md5_digest_set != 0 )
6008 		 && ( libewf_hash_values_parse_md5_hash(
6009 		       internal_handle->hash_values,
6010 		       internal_handle->hash_sections->md5_digest,
6011 		       16,
6012 		       error ) != 1 ) )
6013 		{
6014 			libcerror_error_set(
6015 			 error,
6016 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
6017 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
6018 			 "%s: unable to parse MD5 hash for its value.",
6019 			 function );
6020 
6021 			result = -1;
6022 		}
6023 		if( ( internal_handle->hash_sections->sha1_digest_set != 0 )
6024 		 && ( libewf_hash_values_parse_sha1_hash(
6025 		       internal_handle->hash_values,
6026 		       internal_handle->hash_sections->sha1_digest,
6027 		       20,
6028 		       error ) != 1 ) )
6029 		{
6030 			libcerror_error_set(
6031 			 error,
6032 			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
6033 			 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
6034 			 "%s: unable to parse SHA1 hash for its value.",
6035 			 function );
6036 
6037 			result = -1;
6038 		}
6039 	}
6040 	if( ( internal_handle->hash_sections->xhash != NULL )
6041 	 && ( libewf_hash_values_parse_xhash(
6042 	       internal_handle->hash_values,
6043 	       internal_handle->hash_sections->xhash,
6044 	       internal_handle->hash_sections->xhash_size,
6045 	       error ) != 1 ) )
6046 	{
6047 		libcerror_error_set(
6048 		 error,
6049 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
6050 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
6051 		 "%s: unable to parse xhash for values.",
6052 		 function );
6053 
6054 		result = -1;
6055 	}
6056 	if( result != 1 )
6057 	{
6058 		return( -1 );
6059 	}
6060 	return( 1 );
6061 }
6062 
6063