Skip to content

Commit a77f771

Browse files
committed
move to clap 4
1 parent e1504ac commit a77f771

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

Diff for: fuzzers/jif/libjif/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ libafl_targets = { path = "../../../libafl_targets", features = ["sancov_pcguard
2424
libafl_cc = { path = "../../../libafl_cc"}
2525

2626
mimalloc = { version = "*", default-features = false }
27-
structopt = "0.3.25"
28-
serde_json = "1.0.83"
29-
serde = "1.0.143"
27+
clap = { version = "4.0", features = ["derive"] }
28+
serde_json = "1.0"
29+
serde = "1.0"
3030
atomic-counter = "1.0.1"
3131

3232
[lib]

Diff for: fuzzers/jif/libjif/src/lib.rs

+25-41
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ static GLOBAL: MiMalloc = MiMalloc;
88
use core::time::Duration;
99
use std::{env, fs, io::Read, net::SocketAddr, path::PathBuf};
1010

11+
use clap::{self, Parser};
1112
use libafl::{
1213
bolts::{
1314
current_nanos,
@@ -48,7 +49,6 @@ use libafl_targets::{
4849
libfuzzer_initialize, libfuzzer_test_one_input, CmpLogObserver, CMPLOG_MAP, EDGES_MAP,
4950
MAX_EDGES_NUM,
5051
};
51-
use structopt::StructOpt;
5252

5353
mod js;
5454
mod mutators;
@@ -68,60 +68,47 @@ fn timeout_from_millis_str(time: &str) -> Result<Duration, Error> {
6868
Ok(Duration::from_millis(time.parse()?))
6969
}
7070

71-
#[derive(Debug, StructOpt)]
72-
#[structopt(
71+
#[derive(Debug, Parser)]
72+
#[command(
7373
name = "jif",
7474
about = "JIF: Javascript Injection Fuzzer",
7575
author = "jhertz"
7676
)]
7777
struct Opt {
78-
#[structopt(
78+
#[arg(
7979
short,
8080
long,
81-
parse(try_from_str = Cores::from_cmdline),
81+
value_parser = Cores::from_cmdline,
8282
help = "Spawn a client in each of the provided cores. Broker runs in the 0th core. 'all' to select all available cores. 'none' to run a client without binding to any core. eg: '1,2-4,6' selects the cores 1,2,3,4,6.",
8383
name = "CORES"
8484
)]
8585
cores: Cores,
8686

87-
#[structopt(
88-
short = "p",
87+
#[arg(
88+
short = 'p',
8989
long,
9090
help = "Choose the broker TCP port, default is 1337",
9191
name = "PORT"
9292
)]
9393
broker_port: u16,
9494

95-
#[structopt(
96-
parse(try_from_str),
97-
short = "a",
98-
long,
99-
help = "Specify a remote broker",
100-
name = "REMOTE"
101-
)]
95+
#[arg(short = 'a', long, help = "Specify a remote broker", name = "REMOTE")]
10296
remote_broker_addr: Option<SocketAddr>,
10397

104-
#[structopt(
105-
parse(try_from_str),
106-
short,
107-
long,
108-
help = "Set an initial corpus directory",
109-
name = "INPUT"
110-
)]
98+
#[arg(short, long, help = "Set an initial corpus directory", name = "INPUT")]
11199
input: PathBuf,
112100

113-
#[structopt(
101+
#[arg(
114102
short,
115103
long,
116-
parse(try_from_str),
117104
help = "Set the output directory, default is ./out",
118105
name = "OUTPUT",
119106
default_value = "./out"
120107
)]
121108
output: PathBuf,
122109

123-
#[structopt(
124-
parse(try_from_str = timeout_from_millis_str),
110+
#[arg(
111+
value_parser = timeout_from_millis_str,
125112
short,
126113
long,
127114
help = "Set the exeucution timeout in milliseconds, default is 1000",
@@ -130,49 +117,46 @@ struct Opt {
130117
)]
131118
timeout: Duration,
132119

133-
#[structopt(
134-
parse(from_os_str),
135-
short = "x",
120+
#[arg(
121+
short = 'x',
136122
long,
137123
help = "Feed the fuzzer with an user-specified list of tokens (often called \"dictionary\"",
138-
name = "TOKENS",
139-
multiple = true
124+
name = "TOKENS"
140125
)]
141126
tokens: Vec<PathBuf>,
142127

143-
#[structopt(
128+
#[arg(
144129
help = "File to run instead of doing fuzzing loop",
145130
name = "REPRO",
146-
long = "repro",
147-
parse(from_os_str)
131+
long = "repro"
148132
)]
149133
repro_file: Option<PathBuf>,
150134

151135
// several new flags, -g for grimoire -b for bytes -t for tags
152-
#[structopt(
136+
#[arg(
153137
help = "Use grimoire mutator",
154138
name = "GRIMOIRE",
155139
long = "grimoire",
156-
short = "g"
140+
short = 'g'
157141
)]
158142
grimoire: bool,
159143

160-
#[structopt(
144+
#[arg(
161145
help = "Use bytes mutator",
162146
name = "BYTES",
163147
long = "bytes",
164-
short = "b"
148+
short = 'b'
165149
)]
166150
bytes: bool,
167151

168-
#[structopt(help = "Use tags mutator", name = "TAGS", long = "tags", short = "t")]
152+
#[arg(help = "Use tags mutator", name = "TAGS", long = "tags", short = 't')]
169153
tags: bool,
170154

171-
#[structopt(
155+
#[arg(
172156
help = "Use cmplog mutator",
173157
name = "CMPLOG",
174158
long = "cmplog",
175-
short = "c"
159+
short = 'c'
176160
)]
177161
cmplog: bool,
178162
}
@@ -183,7 +167,7 @@ struct Opt {
183167
pub extern "C" fn main() {
184168
let _args: Vec<String> = env::args().collect();
185169
let workdir = env::current_dir().unwrap();
186-
let opt = Opt::from_args();
170+
let opt = Opt::parse();
187171
let cores = opt.cores;
188172
let broker_port = opt.broker_port;
189173
let remote_broker_addr = opt.remote_broker_addr;

0 commit comments

Comments
 (0)