1 /*
2  * User input functions for the ewftools
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 <file_stream.h>
24 #include <memory.h>
25 #include <narrow_string.h>
26 #include <system_string.h>
27 #include <types.h>
28 #include <wide_string.h>
29 
30 #if defined( HAVE_STDLIB_H ) || defined( WINAPI )
31 #include <stdlib.h>
32 #endif
33 
34 #if defined( HAVE_STRING_H ) || defined( WINAPI )
35 #include <string.h>
36 #endif
37 
38 #include "byte_size_string.h"
39 #include "ewfinput.h"
40 #include "ewftools_libcerror.h"
41 #include "ewftools_libewf.h"
42 #include "ewftools_system_string.h"
43 
44 /* Input selection defintions
45  */
46 system_character_t *ewfinput_compression_methods[ 1 ] = {
47 	_SYSTEM_STRING( "deflate" ) };
48 
49 system_character_t *ewfinput_compression_levels[ 4 ] = {
50 	_SYSTEM_STRING( "none" ),
51 	_SYSTEM_STRING( "empty-block" ),
52 	_SYSTEM_STRING( "fast" ),
53 	_SYSTEM_STRING( "best" ) };
54 
55 system_character_t *ewfinput_format_types[ 12 ] = {
56 	_SYSTEM_STRING( "ewf" ),
57 	_SYSTEM_STRING( "smart" ),
58 	_SYSTEM_STRING( "ftk" ),
59 	_SYSTEM_STRING( "encase1" ),
60 	_SYSTEM_STRING( "encase2" ),
61 	_SYSTEM_STRING( "encase3" ),
62 	_SYSTEM_STRING( "encase4" ),
63 	_SYSTEM_STRING( "encase5" ),
64 	_SYSTEM_STRING( "encase6" ),
65 	_SYSTEM_STRING( "linen5" ),
66 	_SYSTEM_STRING( "linen6" ),
67 	_SYSTEM_STRING( "ewfx" ) };
68 
69 system_character_t *ewfinput_media_types[ 4 ] = {
70 	_SYSTEM_STRING( "fixed" ),
71 	_SYSTEM_STRING( "removable" ),
72 	_SYSTEM_STRING( "optical" ),
73 	_SYSTEM_STRING( "memory" ) };
74 
75 system_character_t *ewfinput_media_flags[ 2 ] = {
76 	_SYSTEM_STRING( "logical" ),
77 	_SYSTEM_STRING( "physical" ) };
78 
79 system_character_t *ewfinput_sector_per_block_sizes[ 12 ] = {
80 	_SYSTEM_STRING( "16" ),
81 	_SYSTEM_STRING( "32" ),
82 	_SYSTEM_STRING( "64" ),
83 	_SYSTEM_STRING( "128" ),
84 	_SYSTEM_STRING( "256" ),
85 	_SYSTEM_STRING( "512" ),
86 	_SYSTEM_STRING( "1024" ),
87 	_SYSTEM_STRING( "2048" ),
88 	_SYSTEM_STRING( "4096" ),
89 	_SYSTEM_STRING( "8192" ),
90 	_SYSTEM_STRING( "16384" ),
91 	_SYSTEM_STRING( "32768" ) };
92 
93 system_character_t *ewfinput_yes_no[ 2 ] = {
94 	_SYSTEM_STRING( "yes" ),
95 	_SYSTEM_STRING( "no" ) };
96 
97 /* Determines the EWF format from a string
98  * Returns 1 if successful, 0 if unsupported value or -1 on error
99  */
ewfinput_determine_ewf_format(const system_character_t * string,uint8_t * ewf_format,libcerror_error_t ** error)100 int ewfinput_determine_ewf_format(
101      const system_character_t *string,
102      uint8_t *ewf_format,
103      libcerror_error_t **error )
104 {
105 	static char *function = "ewfinput_determine_ewf_format";
106 	size_t string_length  = 0;
107 	int result            = 0;
108 
109 	if( string == NULL )
110 	{
111 		libcerror_error_set(
112 		 error,
113 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
114 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
115 		 "%s: invalid string.",
116 		 function );
117 
118 		return( -1 );
119 	}
120 	if( ewf_format == NULL )
121 	{
122 		libcerror_error_set(
123 		 error,
124 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
125 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
126 		 "%s: invalid libewf format.",
127 		 function );
128 
129 		return( -1 );
130 	}
131 	string_length = system_string_length(
132 	                 string );
133 
134 	if( string_length == 3 )
135 	{
136 		if( system_string_compare(
137 		     string,
138 		     _SYSTEM_STRING( "ewf" ),
139 		     3 ) == 0 )
140 		{
141 			*ewf_format = LIBEWF_FORMAT_EWF;
142 			result      = 1;
143 		}
144 		else if( system_string_compare(
145 		          string,
146 		          _SYSTEM_STRING( "ftk" ),
147 		          3 ) == 0 )
148 		{
149 			*ewf_format = LIBEWF_FORMAT_FTK;
150 			result      = 1;
151 		}
152 	}
153 	else if( string_length == 4 )
154 	{
155 		if( system_string_compare(
156 		     string,
157 		     _SYSTEM_STRING( "ewfx" ),
158 		     4 ) == 0 )
159 		{
160 			*ewf_format = LIBEWF_FORMAT_EWFX;
161 			result      = 1;
162 		}
163 	}
164 	else if( string_length == 5 )
165 	{
166 		if( system_string_compare(
167 		     string,
168 		     _SYSTEM_STRING( "smart" ),
169 		     5 ) == 0 )
170 		{
171 			*ewf_format = LIBEWF_FORMAT_SMART;
172 			result      = 1;
173 		}
174 	}
175 	else if( string_length == 6 )
176 	{
177 		if( system_string_compare(
178 		     string,
179 		     _SYSTEM_STRING( "linen" ),
180 		     5 ) == 0 )
181 		{
182 			if( string[ 5 ] == (system_character_t) '5' )
183 			{
184 				*ewf_format = LIBEWF_FORMAT_LINEN5;
185 				result      = 1;
186 			}
187 			else if( string[ 5 ] == (system_character_t) '6' )
188 			{
189 				*ewf_format = LIBEWF_FORMAT_LINEN6;
190 				result      = 1;
191 			}
192 		}
193 	}
194 	else if( string_length == 7 )
195 	{
196 		if( system_string_compare(
197 		     string,
198 		     _SYSTEM_STRING( "encase" ),
199 		     6 ) == 0 )
200 		{
201 			if( string[ 6 ] == (system_character_t) '1' )
202 			{
203 				*ewf_format = LIBEWF_FORMAT_ENCASE1;
204 				result      = 1;
205 			}
206 			else if( string[ 6 ] == (system_character_t) '2' )
207 			{
208 				*ewf_format = LIBEWF_FORMAT_ENCASE2;
209 				result      = 1;
210 			}
211 			else if( string[ 6 ] == (system_character_t) '3' )
212 			{
213 				*ewf_format = LIBEWF_FORMAT_ENCASE3;
214 				result      = 1;
215 			}
216 			else if( string[ 6 ] == (system_character_t) '4' )
217 			{
218 				*ewf_format = LIBEWF_FORMAT_ENCASE4;
219 				result      = 1;
220 			}
221 			else if( string[ 6 ] == (system_character_t) '5' )
222 			{
223 				*ewf_format = LIBEWF_FORMAT_ENCASE5;
224 				result      = 1;
225 			}
226 			else if( string[ 6 ] == (system_character_t) '6' )
227 			{
228 				*ewf_format = LIBEWF_FORMAT_ENCASE6;
229 				result      = 1;
230 			}
231 		}
232 	}
233 	return( result );
234 }
235 
236 /* Determines the sectors per chunk value from a string
237  * Returns 1 if successful, 0 if unsupported value or -1 on error
238  */
ewfinput_determine_sectors_per_chunk(const system_character_t * string,uint32_t * sectors_per_chunk,libcerror_error_t ** error)239 int ewfinput_determine_sectors_per_chunk(
240      const system_character_t *string,
241      uint32_t *sectors_per_chunk,
242      libcerror_error_t **error )
243 {
244 	static char *function = "ewfinput_determine_sectors_per_chunk";
245 	size_t string_length  = 0;
246 	int result            = -1;
247 
248 	if( string == NULL )
249 	{
250 		libcerror_error_set(
251 		 error,
252 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
253 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
254 		 "%s: invalid string.",
255 		 function );
256 
257 		return( -1 );
258 	}
259 	if( sectors_per_chunk == NULL )
260 	{
261 		libcerror_error_set(
262 		 error,
263 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
264 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
265 		 "%s: invalid sectors per chunk.",
266 		 function );
267 
268 		return( -1 );
269 	}
270 	string_length = system_string_length(
271 	                 string );
272 
273 	if( string_length == 2 )
274 	{
275 		if( system_string_compare(
276 		     string,
277 		     _SYSTEM_STRING( "16" ),
278 		     2 ) == 0 )
279 		{
280 			*sectors_per_chunk = 16;
281 			result             = 1;
282 		}
283 		else if( system_string_compare(
284 		          string,
285 		          _SYSTEM_STRING( "32" ),
286 		          2 ) == 0 )
287 		{
288 			*sectors_per_chunk = 32;
289 			result             = 1;
290 		}
291 		else if( system_string_compare(
292 		          string,
293 		          _SYSTEM_STRING( "64" ),
294 		          2 ) == 0 )
295 		{
296 			*sectors_per_chunk = 64;
297 			result             = 1;
298 		}
299 	}
300 	else if( string_length == 3 )
301 	{
302 		if( system_string_compare(
303 		     string,
304 		     _SYSTEM_STRING( "128" ),
305 		     3 ) == 0 )
306 		{
307 			*sectors_per_chunk = 128;
308 			result             = 1;
309 		}
310 		else if( system_string_compare(
311 			  string,
312 			  _SYSTEM_STRING( "256" ),
313 			  3 ) == 0 )
314 		{
315 			*sectors_per_chunk = 256;
316 			result             = 1;
317 		}
318 		else if( system_string_compare(
319 			  string,
320 			  _SYSTEM_STRING( "512" ),
321 			  3 ) == 0 )
322 		{
323 			*sectors_per_chunk = 512;
324 			result             = 1;
325 		}
326 	}
327 	else if( string_length == 4 )
328 	{
329 		if( system_string_compare(
330 		     string,
331 		     _SYSTEM_STRING( "1024" ),
332 		     4 ) == 0 )
333 		{
334 			*sectors_per_chunk = 1024;
335 			result             = 1;
336 		}
337 		else if( system_string_compare(
338 			  string,
339 			  _SYSTEM_STRING( "2048" ),
340 			  4 ) == 0 )
341 		{
342 			*sectors_per_chunk = 2048;
343 			result             = 1;
344 		}
345 		else if( system_string_compare(
346 			  string,
347 			  _SYSTEM_STRING( "4096" ),
348 			  4 ) == 0 )
349 		{
350 			*sectors_per_chunk = 4096;
351 			result             = 1;
352 		}
353 		else if( system_string_compare(
354 			  string,
355 			  _SYSTEM_STRING( "8192" ),
356 			  4 ) == 0 )
357 		{
358 			*sectors_per_chunk = 8192;
359 			result             = 1;
360 		}
361 	}
362 	else if( string_length == 5 )
363 	{
364 		if( system_string_compare(
365 		     string,
366 		     _SYSTEM_STRING( "16384" ),
367 		     5 ) == 0 )
368 		{
369 			*sectors_per_chunk = 16384;
370 			result             = 1;
371 		}
372 		else if( system_string_compare(
373 		          string,
374 		          _SYSTEM_STRING( "32768" ),
375 		          5 ) == 0 )
376 		{
377 			*sectors_per_chunk = 32768;
378 			result             = 1;
379 		}
380 	}
381 	return( result );
382 }
383 
384 /* Determines the compression method from a string
385  * Returns 1 if successful, 0 if unsupported value or -1 on error
386  */
ewfinput_determine_compression_method(const system_character_t * string,uint16_t * compression_method,libcerror_error_t ** error)387 int ewfinput_determine_compression_method(
388      const system_character_t *string,
389      uint16_t *compression_method,
390      libcerror_error_t **error )
391 {
392 	static char *function = "ewfinput_determine_compression_method";
393 	size_t string_length  = 0;
394 	int result            = 0;
395 
396 	if( string == NULL )
397 	{
398 		libcerror_error_set(
399 		 error,
400 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
401 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
402 		 "%s: invalid string.",
403 		 function );
404 
405 		return( -1 );
406 	}
407 	if( compression_method == NULL )
408 	{
409 		libcerror_error_set(
410 		 error,
411 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
412 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
413 		 "%s: invalid compression method.",
414 		 function );
415 
416 		return( -1 );
417 	}
418 	string_length = system_string_length(
419 	                 string );
420 
421 	if( string_length == 7 )
422 	{
423 		if( system_string_compare(
424 		     string,
425 		     _SYSTEM_STRING( "deflate" ),
426 		     7 ) == 0 )
427 		{
428 			*compression_method = LIBEWF_COMPRESSION_METHOD_DEFLATE;
429 			result              = 1;
430 		}
431 	}
432 	return( result );
433 }
434 
435 /* Determines the compression values from a string
436  * Returns 1 if successful, 0 if unsupported value or -1 on error
437  */
ewfinput_determine_compression_values(const system_character_t * string,int8_t * compression_level,uint8_t * compression_flags,libcerror_error_t ** error)438 int ewfinput_determine_compression_values(
439      const system_character_t *string,
440      int8_t *compression_level,
441      uint8_t *compression_flags,
442      libcerror_error_t **error )
443 {
444 	static char *function = "ewfinput_determine_compression_values";
445 	size_t string_length  = 0;
446 	int result            = 0;
447 
448 	if( string == NULL )
449 	{
450 		libcerror_error_set(
451 		 error,
452 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
453 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
454 		 "%s: invalid string.",
455 		 function );
456 
457 		return( -1 );
458 	}
459 	if( compression_level == NULL )
460 	{
461 		libcerror_error_set(
462 		 error,
463 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
464 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
465 		 "%s: invalid compression level.",
466 		 function );
467 
468 		return( -1 );
469 	}
470 	if( compression_flags == NULL )
471 	{
472 		libcerror_error_set(
473 		 error,
474 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
475 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
476 		 "%s: invalid compression flags.",
477 		 function );
478 
479 		return( -1 );
480 	}
481 	string_length = system_string_length(
482 	                 string );
483 
484 	if( string_length == 4 )
485 	{
486 		if( system_string_compare(
487 		     string,
488 		     _SYSTEM_STRING( "none" ),
489 		     4 ) == 0 )
490 		{
491 			*compression_level = LIBEWF_COMPRESSION_NONE;
492 			*compression_flags = 0;
493 			result             = 1;
494 		}
495 		else if( system_string_compare(
496 			  string,
497 			  _SYSTEM_STRING( "fast" ),
498 			  4 ) == 0 )
499 		{
500 			*compression_level = LIBEWF_COMPRESSION_FAST;
501 			*compression_flags = 0;
502 			result             = 1;
503 		}
504 		else if( system_string_compare(
505 			  string,
506 			  _SYSTEM_STRING( "best" ),
507 			  4 ) == 0 )
508 		{
509 			*compression_level = LIBEWF_COMPRESSION_BEST;
510 			*compression_flags = 0;
511 			result             = 1;
512 		}
513 	}
514 	else if( string_length == 11 )
515 	{
516 		if( system_string_compare(
517 		     string,
518 		     _SYSTEM_STRING( "empty-block" ),
519 		     11 ) == 0 )
520 		{
521 			*compression_level = LIBEWF_COMPRESSION_NONE;
522 			*compression_flags = LIBEWF_COMPRESS_FLAG_USE_EMPTY_BLOCK_COMPRESSION;
523 			result             = 1;
524 		}
525 		else if( system_string_compare(
526 			  string,
527 			  _SYSTEM_STRING( "empty_block" ),
528 			  11 ) == 0 )
529 		{
530 			*compression_level = LIBEWF_COMPRESSION_NONE;
531 			*compression_flags = LIBEWF_COMPRESS_FLAG_USE_EMPTY_BLOCK_COMPRESSION;
532 			result             = 1;
533 		}
534 	}
535 	return( result );
536 }
537 
538 /* Determines the media type value from a string
539  * Returns 1 if successful, 0 if unsupported value or -1 on error
540  */
ewfinput_determine_media_type(const system_character_t * string,uint8_t * media_type,libcerror_error_t ** error)541 int ewfinput_determine_media_type(
542      const system_character_t *string,
543      uint8_t *media_type,
544      libcerror_error_t **error )
545 {
546 	static char *function = "ewfinput_determine_media_type";
547 	size_t string_length  = 0;
548 	int result            = 0;
549 
550 	if( string == NULL )
551 	{
552 		libcerror_error_set(
553 		 error,
554 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
555 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
556 		 "%s: invalid string.",
557 		 function );
558 
559 		return( -1 );
560 	}
561 	if( media_type == NULL )
562 	{
563 		libcerror_error_set(
564 		 error,
565 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
566 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
567 		 "%s: invalid media type.",
568 		 function );
569 
570 		return( -1 );
571 	}
572 	string_length = system_string_length(
573 	                 string );
574 
575 	if( string_length == 5 )
576 	{
577 		if( system_string_compare(
578 		     string,
579 		     _SYSTEM_STRING( "fixed" ),
580 			  5 ) == 0 )
581 		{
582 			*media_type = LIBEWF_MEDIA_TYPE_FIXED;
583 			result      = 1;
584 		}
585 	}
586 	else if( string_length == 5 )
587 	{
588 		if( system_string_compare(
589 		     string,
590 		     _SYSTEM_STRING( "memory" ),
591 		     6 ) == 0 )
592 		{
593 			*media_type = LIBEWF_MEDIA_TYPE_MEMORY;
594 			result      = 1;
595 		}
596 	}
597 	else if( string_length == 7 )
598 	{
599 		if( system_string_compare(
600 		     string,
601 		     _SYSTEM_STRING( "optical" ),
602 		     7 ) == 0 )
603 		{
604 			*media_type = LIBEWF_MEDIA_TYPE_OPTICAL;
605 			result      = 1;
606 		}
607 	}
608 	else if( string_length == 9 )
609 	{
610 		if( system_string_compare(
611 		     string,
612 		     _SYSTEM_STRING( "removable" ),
613 		     9 ) == 0 )
614 		{
615 			*media_type = LIBEWF_MEDIA_TYPE_REMOVABLE;
616 			result      = 1;
617 		}
618 	}
619 	return( result );
620 }
621 
622 /* Determines the media flags value from a string
623  * Returns 1 if successful or -1 on error
624  */
ewfinput_determine_media_flags(const system_character_t * string,uint8_t * media_flags,libcerror_error_t ** error)625 int ewfinput_determine_media_flags(
626      const system_character_t *string,
627      uint8_t *media_flags,
628      libcerror_error_t **error )
629 {
630 	static char *function = "ewfinput_determine_media_flags";
631 	int result            = -1;
632 
633 	if( string == NULL )
634 	{
635 		libcerror_error_set(
636 		 error,
637 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
638 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
639 		 "%s: invalid string.",
640 		 function );
641 
642 		return( -1 );
643 	}
644 	if( media_flags == NULL )
645 	{
646 		libcerror_error_set(
647 		 error,
648 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
649 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
650 		 "%s: invalid media flags.",
651 		 function );
652 
653 		return( -1 );
654 	}
655 	if( system_string_compare(
656 	     string,
657 	     _SYSTEM_STRING( "logical" ),
658 	     7 ) == 0 )
659 	{
660 		*media_flags &= ~LIBEWF_MEDIA_FLAG_PHYSICAL;
661 		result        = 1;
662 	}
663 	else if( system_string_compare(
664 	          string,
665 	          _SYSTEM_STRING( "physical" ),
666 	          8 ) == 0 )
667 	{
668 		*media_flags |= LIBEWF_MEDIA_FLAG_PHYSICAL;
669 		result        = 1;
670 	}
671 	else if( system_string_compare(
672 	          string,
673 	          _SYSTEM_STRING( "fastbloc" ),
674 	          8 ) == 0 )
675 	{
676 		*media_flags |= LIBEWF_MEDIA_FLAG_FASTBLOC;
677 		result        = 1;
678 	}
679 	else if( system_string_compare(
680 	          string,
681 	          _SYSTEM_STRING( "tableau" ),
682 	          8 ) == 0 )
683 	{
684 		*media_flags |= LIBEWF_MEDIA_FLAG_TABLEAU;
685 		result        = 1;
686 	}
687 	return( result );
688 }
689 
690 /* Determines the codepage from a string
691  * Returns 1 if successful, 0 if unsupported value or -1 on error
692  */
ewfinput_determine_header_codepage(const system_character_t * string,int * header_codepage,libcerror_error_t ** error)693 int ewfinput_determine_header_codepage(
694      const system_character_t *string,
695      int *header_codepage,
696      libcerror_error_t **error )
697 {
698 	static char *function = "ewfinput_determine_header_codepage";
699 	size_t string_length  = 0;
700 	int result            = -1;
701 
702 	if( string == NULL )
703 	{
704 		libcerror_error_set(
705 		 error,
706 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
707 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
708 		 "%s: invalid string.",
709 		 function );
710 
711 		return( -1 );
712 	}
713 	if( header_codepage == NULL )
714 	{
715 		libcerror_error_set(
716 		 error,
717 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
718 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
719 		 "%s: invalid header codepage.",
720 		 function );
721 
722 		return( -1 );
723 	}
724 	string_length = system_string_length(
725 	                 string );
726 
727 	if( string_length == 5 )
728 	{
729 		if( system_string_compare(
730 		     string,
731 		     _SYSTEM_STRING( "ascii" ),
732 		     5 ) == 0 )
733 		{
734 			*header_codepage = LIBEWF_CODEPAGE_ASCII;
735 			result           = 1;
736 		}
737 	}
738 #if defined( HAVE_ISO_CODEPAGES )
739 	if( ( string_length == 10 )
740 	 || ( string_length == 11 ) )
741 	{
742 		if( system_string_compare(
743 		     string,
744 		     _SYSTEM_STRING( "iso" ),
745 		     3 ) == 0 )
746 		{
747 			if( ( string[ 3 ] != '-' )
748 			 && ( string[ 3 ] != '_' ) )
749 			{
750 			}
751 			else if( system_string_compare(
752 				  &( string[ 4 ] ),
753 				  _SYSTEM_STRING( "8859" ),
754 				  4 ) == 0 )
755 			{
756 				if( ( string[ 8 ] != '-' )
757 				 && ( string[ 8 ] != '_' ) )
758 				{
759 				}
760 				else if( string_length == 10 )
761 				{
762 					if( system_string_compare(
763 					     &( string[ 9 ] ),
764 					     _SYSTEM_STRING( "1" ),
765 					     1 ) == 0 )
766 					{
767 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_1;
768 						result           = 1;
769 					}
770 					else if( system_string_compare(
771 						  &( string[ 9 ] ),
772 						  _SYSTEM_STRING( "2" ),
773 						  1 ) == 0 )
774 					{
775 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_2;
776 						result           = 1;
777 					}
778 					else if( system_string_compare(
779 						  &( string[ 9 ] ),
780 						  _SYSTEM_STRING( "3" ),
781 						  1 ) == 0 )
782 					{
783 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_3;
784 						result           = 1;
785 					}
786 					else if( system_string_compare(
787 						  &( string[ 9 ] ),
788 						  _SYSTEM_STRING( "4" ),
789 						  1 ) == 0 )
790 					{
791 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_4;
792 						result           = 1;
793 					}
794 					else if( system_string_compare(
795 						  &( string[ 9 ] ),
796 						  _SYSTEM_STRING( "5" ),
797 						  1 ) == 0 )
798 					{
799 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_5;
800 						result           = 1;
801 					}
802 					else if( system_string_compare(
803 						  &( string[ 9 ] ),
804 						  _SYSTEM_STRING( "6" ),
805 						  1 ) == 0 )
806 					{
807 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_6;
808 						result           = 1;
809 					}
810 					else if( system_string_compare(
811 						  &( string[ 9 ] ),
812 						  _SYSTEM_STRING( "7" ),
813 						  1 ) == 0 )
814 					{
815 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_7;
816 						result           = 1;
817 					}
818 					else if( system_string_compare(
819 						  &( string[ 9 ] ),
820 						  _SYSTEM_STRING( "8" ),
821 						  1 ) == 0 )
822 					{
823 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_8;
824 						result           = 1;
825 					}
826 					else if( system_string_compare(
827 						  &( string[ 9 ] ),
828 						  _SYSTEM_STRING( "9" ),
829 						  1 ) == 0 )
830 					{
831 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_9;
832 						result           = 1;
833 					}
834 				}
835 				else if( string_length == 11 )
836 				{
837 					if( system_string_compare(
838 					     &( string[ 9 ] ),
839 					     _SYSTEM_STRING( "10" ),
840 					     2 ) == 0 )
841 					{
842 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_10;
843 						result           = 1;
844 					}
845 					else if( system_string_compare(
846 						  &( string[ 9 ] ),
847 						  _SYSTEM_STRING( "11" ),
848 						  2 ) == 0 )
849 					{
850 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_11;
851 						result           = 1;
852 					}
853 					else if( system_string_compare(
854 						  &( string[ 9 ] ),
855 						  _SYSTEM_STRING( "13" ),
856 						  2 ) == 0 )
857 					{
858 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_13;
859 						result           = 1;
860 					}
861 					else if( system_string_compare(
862 						  &( string[ 9 ] ),
863 						  _SYSTEM_STRING( "14" ),
864 						  2 ) == 0 )
865 					{
866 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_14;
867 						result           = 1;
868 					}
869 					else if( system_string_compare(
870 						  &( string[ 9 ] ),
871 						  _SYSTEM_STRING( "15" ),
872 						  2 ) == 0 )
873 					{
874 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_15;
875 						result           = 1;
876 					}
877 					else if( system_string_compare(
878 						  &( string[ 9 ] ),
879 						  _SYSTEM_STRING( "16" ),
880 						  2 ) == 0 )
881 					{
882 						*header_codepage = LIBEWF_CODEPAGE_ISO_8859_16;
883 						result           = 1;
884 					}
885 				}
886 			}
887 		}
888 	}
889 #endif
890 	if( ( string_length == 11 )
891 	 || ( string_length == 12 ) )
892 	{
893 		if( system_string_compare(
894 		     string,
895 		     _SYSTEM_STRING( "windows" ),
896 		     7 ) == 0 )
897 		{
898 			if( ( string[ 7 ] != '-' )
899 			 && ( string[ 7 ] != '_' ) )
900 			{
901 			}
902 			else if( string_length == 11 )
903 			{
904 				if( system_string_compare(
905 				     &( string[ 8 ] ),
906 				     _SYSTEM_STRING( "874" ),
907 				     3 ) == 0 )
908 				{
909 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_874;
910 					result           = 1;
911 				}
912 				else if( system_string_compare(
913 				          &( string[ 8 ] ),
914 				          _SYSTEM_STRING( "932" ),
915 				          3 ) == 0 )
916 				{
917 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_932;
918 					result           = 1;
919 				}
920 				else if( system_string_compare(
921 				          &( string[ 8 ] ),
922 				          _SYSTEM_STRING( "936" ),
923 				          3 ) == 0 )
924 				{
925 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_936;
926 					result           = 1;
927 				}
928 			}
929 			else if( string_length == 12 )
930 			{
931 				if( system_string_compare(
932 				     &( string[ 8 ] ),
933 				     _SYSTEM_STRING( "1250" ),
934 				     4 ) == 0 )
935 				{
936 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1250;
937 					result           = 1;
938 				}
939 				else if( system_string_compare(
940 					  &( string[ 8 ] ),
941 					  _SYSTEM_STRING( "1251" ),
942 					  4 ) == 0 )
943 				{
944 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1251;
945 					result           = 1;
946 				}
947 				else if( system_string_compare(
948 					  &( string[ 8 ] ),
949 					  _SYSTEM_STRING( "1252" ),
950 					  4 ) == 0 )
951 				{
952 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1252;
953 					result           = 1;
954 				}
955 				else if( system_string_compare(
956 					  &( string[ 8 ] ),
957 					  _SYSTEM_STRING( "1253" ),
958 					  4 ) == 0 )
959 				{
960 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1253;
961 					result           = 1;
962 				}
963 				else if( system_string_compare(
964 					  &( string[ 8 ] ),
965 					  _SYSTEM_STRING( "1253" ),
966 					  4 ) == 0 )
967 				{
968 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1253;
969 					result           = 1;
970 				}
971 				else if( system_string_compare(
972 					  &( string[ 8 ] ),
973 					  _SYSTEM_STRING( "1254" ),
974 					  4 ) == 0 )
975 				{
976 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1254;
977 					result           = 1;
978 				}
979 				else if( system_string_compare(
980 					  &( string[ 8 ] ),
981 					  _SYSTEM_STRING( "1255" ),
982 					  4 ) == 0 )
983 				{
984 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1255;
985 					result           = 1;
986 				}
987 				else if( system_string_compare(
988 					  &( string[ 8 ] ),
989 					  _SYSTEM_STRING( "1256" ),
990 					  4 ) == 0 )
991 				{
992 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1256;
993 					result           = 1;
994 				}
995 				else if( system_string_compare(
996 					  &( string[ 8 ] ),
997 					  _SYSTEM_STRING( "1257" ),
998 					  4 ) == 0 )
999 				{
1000 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1257;
1001 					result           = 1;
1002 				}
1003 				else if( system_string_compare(
1004 					  &( string[ 8 ] ),
1005 					  _SYSTEM_STRING( "1258" ),
1006 					  4 ) == 0 )
1007 				{
1008 					*header_codepage = LIBEWF_CODEPAGE_WINDOWS_1258;
1009 					result           = 1;
1010 				}
1011 			}
1012 		}
1013 	}
1014 	return( result );
1015 }
1016 
1017 /* Determines the yes or no value from a string
1018  * Returns 1 if successful, 0 if unsupported value or -1 on error
1019  */
ewfinput_determine_yes_no(const system_character_t * string,uint8_t * yes_no_value,libcerror_error_t ** error)1020 int ewfinput_determine_yes_no(
1021      const system_character_t *string,
1022      uint8_t *yes_no_value,
1023      libcerror_error_t **error )
1024 {
1025 	static char *function = "ewfinput_determine_yes_no";
1026 	size_t string_length  = 0;
1027 	int result            = 0;
1028 
1029 	if( string == NULL )
1030 	{
1031 		libcerror_error_set(
1032 		 error,
1033 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1034 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1035 		 "%s: invalid string.",
1036 		 function );
1037 
1038 		return( -1 );
1039 	}
1040 	if( yes_no_value == NULL )
1041 	{
1042 		libcerror_error_set(
1043 		 error,
1044 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1045 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1046 		 "%s: invalid yes no value.",
1047 		 function );
1048 
1049 		return( -1 );
1050 	}
1051 	string_length = system_string_length(
1052 	                 string );
1053 
1054 	if( string_length == 2 )
1055 	{
1056 		if( system_string_compare(
1057 		     string,
1058 		     _SYSTEM_STRING( "no" ),
1059 		     2 ) == 0 )
1060 		{
1061 			*yes_no_value = 0;
1062 			result        = 1;
1063 		}
1064 	}
1065 	else if( string_length == 3 )
1066 	{
1067 		if( system_string_compare(
1068 		     string,
1069 		     _SYSTEM_STRING( "yes" ),
1070 		     3 ) == 0 )
1071 		{
1072 			*yes_no_value = 1;
1073 			result        = 1;
1074 		}
1075 	}
1076 	return( result );
1077 }
1078 
1079 /* Retrieves a string variable
1080  * Returns 1 if successful, 0 if no input was provided or -1 on error
1081  */
ewfinput_get_string_variable(FILE * stream,const system_character_t * request_string,system_character_t * string_variable,size_t string_variable_size,libcerror_error_t ** error)1082 int ewfinput_get_string_variable(
1083      FILE *stream,
1084      const system_character_t *request_string,
1085      system_character_t *string_variable,
1086      size_t string_variable_size,
1087      libcerror_error_t **error )
1088 {
1089 	system_character_t *end_of_input  = NULL;
1090 	system_character_t *result_string = NULL;
1091 	static char *function                        = "ewfinput_get_string_variable";
1092 	ssize_t input_length                         = 0;
1093 
1094 	if( stream == NULL )
1095 	{
1096 		libcerror_error_set(
1097 		 error,
1098 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1099 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1100 		 "%s: invalid output stream.",
1101 		 function );
1102 
1103 		return( -1 );
1104 	}
1105 	if( request_string == NULL )
1106 	{
1107 		libcerror_error_set(
1108 		 error,
1109 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1110 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1111 		 "%s: invalid request string.",
1112 		 function );
1113 
1114 		return( -1 );
1115 	}
1116 	if( string_variable == NULL )
1117 	{
1118 		libcerror_error_set(
1119 		 error,
1120 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1121 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1122 		 "%s: invalid string variable.",
1123 		 function );
1124 
1125 		return( -1 );
1126 	}
1127 #if SIZEOF_SIZE_T > SIZEOF_INT
1128 	if( string_variable_size > (size_t) INT_MAX )
1129 #else
1130 	if( string_variable_size > (size_t) SSIZE_MAX )
1131 #endif
1132 	{
1133 		libcerror_error_set(
1134 		 error,
1135 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1136 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1137 		 "%s: invalid string variable size value exceeds maximum.",
1138 		 function );
1139 
1140 		return( -1 );
1141 	}
1142 	/* Safe guard the end of the input string
1143 	 */
1144 	string_variable[ string_variable_size - 1 ] = 0;
1145 
1146 	while( 1 )
1147 	{
1148 		fprintf(
1149 		 stream,
1150 		 "%" PRIs_SYSTEM ": ",
1151 		 request_string );
1152 
1153 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1154 		result_string = file_stream_get_string_wide(
1155 		                 stdin,
1156 		                 string_variable,
1157 		                 (int) ( string_variable_size - 1 ) );
1158 #else
1159 		result_string = file_stream_get_string(
1160 		                 stdin,
1161 		                 string_variable,
1162 		                 (int) ( string_variable_size - 1 ) );
1163 #endif
1164 		if( result_string != NULL )
1165 		{
1166 			end_of_input = system_string_search_character(
1167 			                string_variable,
1168 			                (system_character_t) '\n',
1169 			                string_variable_size );
1170 
1171 			/* Input was larger than size of buffer
1172 			 */
1173 			if( end_of_input == NULL )
1174 			{
1175 				/* Flush the stdin stream
1176 				 */
1177 				while( end_of_input == NULL )
1178 				{
1179 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1180 					result_string = file_stream_get_string_wide(
1181 					                 stdin,
1182 					                 string_variable,
1183 					                 (int) ( string_variable_size - 1 ) );
1184 #else
1185 					result_string = file_stream_get_string(
1186 					                 stdin,
1187 					                 string_variable,
1188 					                 (int) ( string_variable_size - 1 ) );
1189 #endif
1190 
1191 					end_of_input = system_string_search_character(
1192 					                string_variable,
1193 					                (system_character_t) '\n',
1194 					                string_variable_size );
1195 
1196 				}
1197 				return( -1 );
1198 			}
1199 			input_length = (ssize_t) ( end_of_input - string_variable );
1200 
1201 			if( input_length < 0 )
1202 			{
1203 				return( -1 );
1204 			}
1205 			/* Make sure the string is terminated with an end of string character
1206 			 */
1207 			string_variable[ input_length ] = 0;
1208 
1209 			break;
1210 		}
1211 		else
1212 		{
1213 			fprintf(
1214 			 stream,
1215 			 "Error reading input, please try again or terminate using Ctrl^C.\n" );
1216 		}
1217 	}
1218 	if( input_length == 0 )
1219 	{
1220 		return( 0 );
1221 	}
1222 	return( 1 );
1223 }
1224 
1225 /* Retrieves a size variable
1226  * Returns 1 if successful, 0 if no input was provided or -1 on error
1227  */
ewfinput_get_size_variable(FILE * stream,system_character_t * input_buffer,size_t input_buffer_size,const system_character_t * request_string,uint64_t minimum_size,uint64_t maximum_size,uint64_t default_size,uint64_t * size_variable,libcerror_error_t ** error)1228 int ewfinput_get_size_variable(
1229      FILE *stream,
1230      system_character_t *input_buffer,
1231      size_t input_buffer_size,
1232      const system_character_t *request_string,
1233      uint64_t minimum_size,
1234      uint64_t maximum_size,
1235      uint64_t default_size,
1236      uint64_t *size_variable,
1237      libcerror_error_t **error )
1238 {
1239 	system_character_t *end_of_input  = NULL;
1240 	system_character_t *result_string = NULL;
1241 	static char *function                        = "ewfinput_get_size_variable";
1242 	ssize_t input_length                         = 0;
1243 
1244 	if( stream == NULL )
1245 	{
1246 		libcerror_error_set(
1247 		 error,
1248 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1249 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1250 		 "%s: invalid output stream.",
1251 		 function );
1252 
1253 		return( -1 );
1254 	}
1255 	if( input_buffer == NULL )
1256 	{
1257 		libcerror_error_set(
1258 		 error,
1259 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1260 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1261 		 "%s: invalid input buffer.",
1262 		 function );
1263 
1264 		return( -1 );
1265 	}
1266 #if SIZEOF_SIZE_T > SIZEOF_INT
1267 	if( input_buffer_size > (size_t) INT_MAX )
1268 #else
1269 	if( input_buffer_size > (size_t) SSIZE_MAX )
1270 #endif
1271 	{
1272 		libcerror_error_set(
1273 		 error,
1274 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1275 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1276 		 "%s: invalid input buffer size value exceeds maximum.",
1277 		 function );
1278 
1279 		return( -1 );
1280 	}
1281 	if( request_string == NULL )
1282 	{
1283 		libcerror_error_set(
1284 		 error,
1285 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1286 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1287 		 "%s: invalid request string.",
1288 		 function );
1289 
1290 		return( -1 );
1291 	}
1292 	if( size_variable == NULL )
1293 	{
1294 		libcerror_error_set(
1295 		 error,
1296 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1297 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1298 		 "%s: invalid size variable.",
1299 		 function );
1300 
1301 		return( -1 );
1302 	}
1303 	/* Safe guard the end of the input buffer
1304 	 */
1305 	input_buffer[ input_buffer_size - 1 ] = 0;
1306 
1307 	while( 1 )
1308 	{
1309 		fprintf(
1310 		 stream,
1311 		 "%" PRIs_SYSTEM " (%" PRIu64 " <= value <= %" PRIu64 ") [%" PRIu64 "]: ",
1312 		 request_string,
1313 		 minimum_size,
1314 		 maximum_size,
1315 		 default_size );
1316 
1317 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1318 		result_string = file_stream_get_string_wide(
1319 		                 stdin,
1320 		                 input_buffer,
1321 		                 (int)( input_buffer_size - 1 ) );
1322 #else
1323 		result_string = file_stream_get_string(
1324 		                 stdin,
1325 		                 input_buffer,
1326 		                 (int)( input_buffer_size - 1 ) );
1327 #endif
1328 		if( result_string != NULL )
1329 		{
1330 			end_of_input = system_string_search_character(
1331 			                input_buffer,
1332 			                (system_character_t) '\n',
1333 			                input_buffer_size );
1334 
1335 			/* Input was larger than size of buffer
1336 			 */
1337 			if( end_of_input == NULL )
1338 			{
1339 				/* Flush the stdin stream
1340 				 */
1341 				while( end_of_input == NULL )
1342 				{
1343 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1344 					result_string = file_stream_get_string_wide(
1345 					                 stdin,
1346 					                 input_buffer,
1347 					                 (int) ( input_buffer_size - 1 ) );
1348 #else
1349 					result_string = file_stream_get_string(
1350 					                 stdin,
1351 					                 input_buffer,
1352 					                 (int) ( input_buffer_size - 1 ) );
1353 #endif
1354 
1355 					end_of_input = system_string_search_character(
1356 					                input_buffer,
1357 					                (system_character_t) '\n',
1358 					                input_buffer_size );
1359 
1360 				}
1361 				return( -1 );
1362 			}
1363 			input_length = (ssize_t) ( end_of_input - input_buffer );
1364 
1365 			if( input_length < 0 )
1366 			{
1367 				return( -1 );
1368 			}
1369 			else if( input_length == 0 )
1370 			{
1371 				*size_variable = default_size;
1372 
1373 				return( 0 );
1374 			}
1375 			if( ewftools_system_string_decimal_copy_to_64_bit(
1376 			     input_buffer,
1377 			     input_length,
1378 			     size_variable,
1379 			     NULL ) != 1 )
1380 			{
1381 				fprintf(
1382 				 stream,
1383 				 "Unable to convert value into number, please try again or terminate using Ctrl^C.\n" );
1384 			}
1385 			else if( ( *size_variable >= minimum_size )
1386 			      && ( *size_variable <= maximum_size ) )
1387 			{
1388 				break;
1389 			}
1390 			else
1391 			{
1392 				fprintf(
1393 				 stream,
1394 				 "Value not within specified range, please try again or terminate using Ctrl^C.\n" );
1395 			}
1396 		}
1397 		else
1398 		{
1399 			fprintf(
1400 			 stream,
1401 			 "Error reading input, please try again or terminate using Ctrl^C.\n" );
1402 		}
1403 	}
1404 	return( 1 );
1405 }
1406 
1407 /* Retrieves a byte size variable
1408  * Returns 1 if successful, 0 if no input was provided or -1 on error
1409  */
ewfinput_get_byte_size_variable(FILE * stream,system_character_t * input_buffer,size_t input_buffer_size,const system_character_t * request_string,uint64_t minimum_size,uint64_t maximum_size,uint64_t default_size,uint64_t * byte_size_variable,libcerror_error_t ** error)1410 int ewfinput_get_byte_size_variable(
1411      FILE *stream,
1412      system_character_t *input_buffer,
1413      size_t input_buffer_size,
1414      const system_character_t *request_string,
1415      uint64_t minimum_size,
1416      uint64_t maximum_size,
1417      uint64_t default_size,
1418      uint64_t *byte_size_variable,
1419      libcerror_error_t **error )
1420 {
1421 	system_character_t minimum_size_string[ 16 ];
1422 	system_character_t maximum_size_string[ 16 ];
1423 	system_character_t default_size_string[ 16 ];
1424 
1425 	system_character_t *end_of_input  = NULL;
1426 	system_character_t *result_string = NULL;
1427 	static char *function                        = "ewfinput_get_byte_size_variable";
1428 	ssize_t input_length                         = 0;
1429 
1430 	if( stream == NULL )
1431 	{
1432 		libcerror_error_set(
1433 		 error,
1434 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1435 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1436 		 "%s: invalid output stream.",
1437 		 function );
1438 
1439 		return( -1 );
1440 	}
1441 	if( input_buffer == NULL )
1442 	{
1443 		libcerror_error_set(
1444 		 error,
1445 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1446 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1447 		 "%s: invalid input buffer.",
1448 		 function );
1449 
1450 		return( -1 );
1451 	}
1452 #if SIZEOF_SIZE_T > SIZEOF_INT
1453 	if( input_buffer_size > (size_t) INT_MAX )
1454 #else
1455 	if( input_buffer_size > (size_t) SSIZE_MAX )
1456 #endif
1457 	{
1458 		libcerror_error_set(
1459 		 error,
1460 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1461 		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1462 		 "%s: invalid input buffer size value exceeds maximum.",
1463 		 function );
1464 
1465 		return( -1 );
1466 	}
1467 	if( request_string == NULL )
1468 	{
1469 		libcerror_error_set(
1470 		 error,
1471 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1472 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1473 		 "%s: invalid request string.",
1474 		 function );
1475 
1476 		return( -1 );
1477 	}
1478 	if( byte_size_variable == NULL )
1479 	{
1480 		libcerror_error_set(
1481 		 error,
1482 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1483 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1484 		 "%s: invalid byte size variable.",
1485 		 function );
1486 
1487 		return( -1 );
1488 	}
1489 	if( byte_size_string_create(
1490 	     minimum_size_string,
1491 	     16,
1492 	     minimum_size,
1493 	     BYTE_SIZE_STRING_UNIT_MEBIBYTE,
1494 	     error ) != 1 )
1495 	{
1496 		libcerror_error_set(
1497 		 error,
1498 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1499 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1500 		 "%s: unable to create minimum byte size string.",
1501 		 function );
1502 
1503 		return( -1 );
1504 	}
1505 	if( byte_size_string_create(
1506 	     default_size_string,
1507 	     16,
1508 	     default_size,
1509 	     BYTE_SIZE_STRING_UNIT_MEBIBYTE,
1510 	     error ) != 1 )
1511 	{
1512 		libcerror_error_set(
1513 		 error,
1514 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1515 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1516 		 "%s: unable to create default byte size string.",
1517 		 function );
1518 
1519 		return( -1 );
1520 	}
1521 	if( byte_size_string_create(
1522 	     maximum_size_string,
1523 	     16,
1524 	     maximum_size,
1525 	     BYTE_SIZE_STRING_UNIT_MEBIBYTE,
1526 	     error ) != 1 )
1527 	{
1528 		libcerror_error_set(
1529 		 error,
1530 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1531 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1532 		 "%s: unable to create maximum byte size string.",
1533 		 function );
1534 
1535 		return( -1 );
1536 	}
1537 	/* Safe guard the end of the input buffer
1538 	 */
1539 	input_buffer[ input_buffer_size - 1 ] = 0;
1540 
1541 	while( 1 )
1542 	{
1543 		fprintf(
1544 		 stream,
1545 		 "%" PRIs_SYSTEM " (%" PRIs_SYSTEM " <= value <= %" PRIs_SYSTEM ") [%" PRIs_SYSTEM "]: ",
1546 		 request_string,
1547 		 minimum_size_string,
1548 		 maximum_size_string,
1549 		 default_size_string );
1550 
1551 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1552 		result_string = file_stream_get_string_wide(
1553 		                 stdin,
1554 		                 input_buffer,
1555 		                 (int) ( input_buffer_size - 1 ) );
1556 #else
1557 		result_string = file_stream_get_string(
1558 		                 stdin,
1559 		                 input_buffer,
1560 		                 (int) ( input_buffer_size - 1 ) );
1561 #endif
1562 
1563 		if( result_string != NULL )
1564 		{
1565 			end_of_input = system_string_search_character(
1566 			                input_buffer,
1567 			                (system_character_t) '\n',
1568 			                input_buffer_size );
1569 
1570 			/* Input was larger than size of buffer
1571 			 */
1572 			if( end_of_input == NULL )
1573 			{
1574 				/* Flush the stdin stream
1575 				 */
1576 				while( end_of_input == NULL )
1577 				{
1578 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1579 					result_string = file_stream_get_string_wide(
1580 					                 stdin,
1581 					                 input_buffer,
1582 					                 (int) ( input_buffer_size - 1 ) );
1583 #else
1584 					result_string = file_stream_get_string(
1585 					                 stdin,
1586 					                 input_buffer,
1587 					                 (int) ( input_buffer_size - 1 ) );
1588 #endif
1589 
1590 					end_of_input = system_string_search_character(
1591 					                input_buffer,
1592 					                (system_character_t) '\n',
1593 					                input_buffer_size );
1594 
1595 				}
1596 				return( -1 );
1597 			}
1598 			input_length = (ssize_t) ( end_of_input - input_buffer );
1599 
1600 			if( input_length < 0 )
1601 			{
1602 				return( -1 );
1603 			}
1604 			else if( input_length == 0 )
1605 			{
1606 				*byte_size_variable = default_size;
1607 
1608 				return( 0 );
1609 			}
1610 			if( byte_size_string_convert(
1611 			     input_buffer,
1612 			     (size_t) input_length,
1613 			     byte_size_variable,
1614 			     NULL ) != 1 )
1615 			{
1616 				fprintf(
1617 				 stream,
1618 				 "Invalid value, please try again or terminate using Ctrl^C.\n" );
1619 			}
1620 			else if( ( *byte_size_variable >= minimum_size )
1621 			      && ( *byte_size_variable <= maximum_size ) )
1622 			{
1623 				break;
1624 			}
1625 			else
1626 			{
1627 				fprintf(
1628 				 stream,
1629 				 "Value not within specified range, please try again or terminate using Ctrl^C.\n" );
1630 			}
1631 		}
1632 		else
1633 		{
1634 			fprintf(
1635 			 stream,
1636 			 "Error reading input, please try again or terminate using Ctrl^C.\n" );
1637 		}
1638 	}
1639 	return( 1 );
1640 }
1641 
1642 /* Retrieves a fixed value string variable
1643  * Returns 1 if successful, 0 if no input was provided or -1 on error
1644  */
ewfinput_get_fixed_string_variable(FILE * stream,system_character_t * input_buffer,size_t input_buffer_size,const system_character_t * request_string,system_character_t ** values,uint8_t number_of_values,uint8_t default_value,system_character_t ** fixed_string_variable,libcerror_error_t ** error)1645 int ewfinput_get_fixed_string_variable(
1646      FILE *stream,
1647      system_character_t *input_buffer,
1648      size_t input_buffer_size,
1649      const system_character_t *request_string,
1650      system_character_t **values,
1651      uint8_t number_of_values,
1652      uint8_t default_value,
1653      system_character_t **fixed_string_variable,
1654      libcerror_error_t **error )
1655 {
1656 
1657 	system_character_t *end_of_input  = NULL;
1658 	system_character_t *result_string = NULL;
1659 	static char *function                        = "ewfinput_get_fixed_value";
1660 	size_t value_length                          = 0;
1661 	ssize_t input_length                         = 0;
1662 	uint8_t value_iterator                       = 0;
1663 
1664 	if( stream == NULL )
1665 	{
1666 		libcerror_error_set(
1667 		 error,
1668 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1669 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1670 		 "%s: invalid output stream.",
1671 		 function );
1672 
1673 		return( -1 );
1674 	}
1675 	if( input_buffer == NULL )
1676 	{
1677 		libcerror_error_set(
1678 		 error,
1679 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1680 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1681 		 "%s: invalid input buffer.",
1682 		 function );
1683 
1684 		return( -1 );
1685 	}
1686 #if SIZEOF_SIZE_T > SIZEOF_INT
1687 	if( input_buffer_size > (size_t) INT_MAX )
1688 #else
1689 	if( input_buffer_size > (size_t) SSIZE_MAX )
1690 #endif
1691 	{
1692 		libcerror_error_set(
1693 		 error,
1694 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1695 		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
1696 		 "%s: invalid input buffer size value exceeds maximum.",
1697 		 function );
1698 
1699 		return( -1 );
1700 	}
1701 	if( request_string == NULL )
1702 	{
1703 		libcerror_error_set(
1704 		 error,
1705 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1706 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1707 		 "%s: invalid request string.",
1708 		 function );
1709 
1710 		return( -1 );
1711 	}
1712 	if( default_value >= number_of_values )
1713 	{
1714 		libcerror_error_set(
1715 		 error,
1716 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1717 		 LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1718 		 "%s: default value exceeds number of values.",
1719 		 function );
1720 
1721 		return( -1 );
1722 	}
1723 	if( fixed_string_variable == NULL )
1724 	{
1725 		libcerror_error_set(
1726 		 error,
1727 		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1728 		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1729 		 "%s: invalid fixed string variable.",
1730 		 function );
1731 
1732 		return( -1 );
1733 	}
1734 	while( 1 )
1735 	{
1736 		fprintf(
1737 		 stream,
1738 		 "%" PRIs_SYSTEM " (",
1739 		 request_string );
1740 
1741 		for( value_iterator = 0;
1742 		     value_iterator < number_of_values;
1743 		     value_iterator++ )
1744 		{
1745 			if( value_iterator > 0 )
1746 			{
1747 				fprintf(
1748 				 stream,
1749 				 ", " );
1750 			}
1751 			fprintf(
1752 			 stream,
1753 			 "%" PRIs_SYSTEM "",
1754 			 values[ value_iterator ] );
1755 		}
1756 		fprintf(
1757 		 stream,
1758 		 ") [%" PRIs_SYSTEM "]: ",
1759 		 values[ default_value ] );
1760 
1761 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1762 		result_string = file_stream_get_string_wide(
1763 		                 stdin,
1764 		                 input_buffer,
1765 		                 (int) ( input_buffer_size - 1 ) );
1766 #else
1767 		result_string = file_stream_get_string(
1768 		                 stdin,
1769 		                 input_buffer,
1770 		                 (int) ( input_buffer_size - 1 ) );
1771 #endif
1772 
1773 		if( result_string != NULL )
1774 		{
1775 			end_of_input = system_string_search_character(
1776 			                input_buffer,
1777 			                (system_character_t) '\n',
1778 			                input_buffer_size );
1779 
1780 			/* Input was larger than size of buffer
1781 			 */
1782 			if( end_of_input == NULL )
1783 			{
1784 				/* Flush the stdin stream
1785 				 */
1786 				while( end_of_input == NULL )
1787 				{
1788 #if defined( HAVE_WIDE_SYSTEM_CHARACTER )
1789 					result_string = file_stream_get_string_wide(
1790 					                 stdin,
1791 					                 input_buffer,
1792 					                 (int) ( input_buffer_size - 1 ) );
1793 #else
1794 					result_string = file_stream_get_string(
1795 					                 stdin,
1796 					                 input_buffer,
1797 					                 (int) ( input_buffer_size - 1 ) );
1798 #endif
1799 
1800 					end_of_input = system_string_search_character(
1801 					                input_buffer,
1802 					                (system_character_t) '\n',
1803 					                input_buffer_size );
1804 
1805 				}
1806 				return( -1 );
1807 			}
1808 			input_length = (ssize_t) ( end_of_input - input_buffer );
1809 
1810 			if( input_length < 0 )
1811 			{
1812 				return( -1 );
1813 			}
1814 			else if( input_length == 0 )
1815 			{
1816 				*fixed_string_variable = values[ default_value ];
1817 
1818 				return( 0 );
1819 			}
1820 			for( value_iterator = 0;
1821 			     value_iterator < number_of_values;
1822 			     value_iterator++ )
1823 			{
1824 				value_length = system_string_length(
1825 						values[ value_iterator ] );
1826 
1827 				if( ( value_length == (size_t) input_length )
1828 				 && ( system_string_compare(
1829 				       input_buffer,
1830 				       values[ value_iterator ],
1831 				       value_length ) == 0 ) )
1832 				{
1833 					break;
1834 				}
1835 			}
1836 			if( value_iterator < number_of_values )
1837 			{
1838 				*fixed_string_variable = values[ value_iterator ];
1839 
1840 				break;
1841 			}
1842 			fprintf(
1843 			 stream,
1844 			 "Selected option not supported, please try again or terminate using Ctrl^C.\n" );
1845 		}
1846 		else
1847 		{
1848 			fprintf(
1849 			 stream,
1850 			 "Error reading input, please try again or terminate using Ctrl^C.\n" );
1851 		}
1852 	}
1853 	return( 1 );
1854 }
1855 
1856