1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
use crate::input::ByteCounter;
use clap::arg_enum;
use lazy_static::lazy_static;
use std::path::PathBuf;
use structopt::StructOpt;
pub const ASCII_ENC_LABEL: &str = "ascii";
pub const ENCODING_DEFAULT: &str = "UTF-8";
pub const CHARS_MIN_DEFAULT: u8 = 4;
pub const COUNTER_OFFSET_DEFAULT: ByteCounter = 0;
pub const OUTPUT_LINE_CHAR_NB_MAX_DEFAULT: usize = 64;
pub const OUTPUT_LINE_CHAR_NB_MIN: usize = 6;
#[derive(Debug, PartialEq, StructOpt)]
#[structopt(
name = "stringsext",
about = "Find multi-byte encoded strings in binary data."
)]
pub struct Args {
#[structopt(long, short = "a")]
pub ascii_filter: Option<String>,
#[structopt(long, short = "c")]
pub no_metadata: bool,
#[structopt(long, short = "d")]
pub debug_option: bool,
#[structopt(name = "FILE", parse(from_os_str))]
pub inputs: Vec<PathBuf>,
#[structopt(long, short = "e")]
pub encoding: Vec<String>,
#[structopt(long, short = "g")]
pub grep_char: Option<String>,
#[structopt(long, short = "l")]
pub list_encodings: bool,
#[structopt(long, short = "n")]
pub chars_min: Option<String>,
#[structopt(long, short = "r")]
pub same_unicode_block: bool,
#[structopt(long, short = "p", parse(from_os_str))]
pub output: Option<PathBuf>,
#[structopt(long, short = "q")]
pub output_line_len: Option<String>,
#[structopt(long, short = "s")]
pub counter_offset: Option<String>,
#[structopt(long, short = "t", possible_values = &Radix::variants(), case_insensitive = true)]
pub radix: Option<Radix>,
#[structopt(long, short = "u")]
pub unicode_block_filter: Option<String>,
#[structopt(long, short = "V")]
pub version: bool,
}
arg_enum! {
#[derive(Debug, PartialEq)]
pub enum Radix {
O,
X,
D,
}
}
lazy_static! {
pub static ref ARGS : Args = Args::from_args();
}
#[cfg(test)]
mod tests {
#[test]
fn test_arg_parser() {
use super::{Args, Radix};
use std::path::PathBuf;
use structopt::StructOpt;
let argv = vec![
"stringsext",
"-d",
"-n",
"10",
"-g",
"64",
"-e",
"ascii",
"-e",
"utf-8",
"-V",
"-l",
"-s",
"1500",
"-p",
"outfile",
"-q",
"40",
"-t",
"o",
"-r",
"infile1",
"infile2",
];
let args = Args::from_iter(argv);
assert_eq!(args.inputs[0], PathBuf::from("infile1"));
assert_eq!(args.inputs[1], PathBuf::from("infile2"));
assert_eq!(args.debug_option, true);
assert_eq!(
args.encoding,
vec!["ascii".to_string(), "utf-8".to_string()]
);
assert_eq!(args.version, true);
assert_eq!(args.list_encodings, true);
assert_eq!(args.chars_min, Some("10".to_string()));
assert_eq!(args.same_unicode_block, true);
assert_eq!(args.grep_char, Some("64".to_string()));
assert_eq!(args.radix, Some(Radix::O));
assert_eq!(args.counter_offset, Some("1500".to_string()));
assert_eq!(args.output, Some(PathBuf::from("outfile")));
assert_eq!(args.output_line_len, Some("40".to_string()));
assert_eq!(args.no_metadata, false);
}
}