Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display AFL++ version and whether plugins are in use #500

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cargo-afl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tempfile = "3.10"
xdg = "2.5"

[dependencies]
clap = { version = "4.5", features = ["cargo", "derive"] }
clap = { version = "4.5", features = ["cargo", "derive", "string"] }
fs_extra = "1.3"
home = "0.5"
libc = "0.2"
Expand Down
45 changes: 41 additions & 4 deletions cargo-afl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{crate_version, Parser};
use clap::{crate_version, CommandFactory, FromArgMatches, Parser};
use std::collections::HashMap;
use std::env;
use std::ffi::{OsStr, OsString};
Expand Down Expand Up @@ -115,7 +115,9 @@ declare_afl_subcommand_enum! {
}

fn main() {
let afl_args = match Args::parse() {
let command = command_with_afl_version();

let afl_args = match Args::from_arg_matches(&command.get_matches()).unwrap() {
Args {
subcmd: CargoSubcommand::Afl(afl_args),
} => afl_args,
Expand Down Expand Up @@ -175,6 +177,42 @@ fn main() {
}
}

fn command_with_afl_version() -> clap::Command {
let mut command = Args::command();

(|| -> Option<()> {
let afl_version = afl_version()?;
let with_plugins = common::plugins_available().ok()?;

let subcmd = command.find_subcommand_mut("afl").unwrap();
let ver = format!(
"{} (AFL++ version {}{})",
subcmd.get_version().unwrap(),
afl_version,
if with_plugins { " with plugins" } else { "" }
);
*subcmd = subcmd.clone().version(ver);
Some(())
})()
.unwrap_or_default();

command
}

fn afl_version() -> Option<String> {
const PREFIX: &str = "afl-fuzz++";
let afl_fuzz_path = common::afl_dir().unwrap().join("bin/afl-fuzz");
let output = Command::new(afl_fuzz_path).output().ok()?;
let stdout = String::from_utf8(output.stdout).ok()?;
let index = stdout.find(PREFIX)?;
Some(
stdout[index + PREFIX.len()..]
.chars()
.take_while(|c| !c.is_ascii_whitespace())
.collect(),
)
}

fn run_afl<I, S>(tool: &str, args: I)
where
I: IntoIterator<Item = S>,
Expand Down Expand Up @@ -334,13 +372,12 @@ fn is_nightly() -> bool {
mod tests {
use super::*;
use assert_cmd::Command;
use clap::CommandFactory;
use std::os::unix::ffi::OsStringExt;
use std::process::Output;

#[test]
fn test_app() {
Args::command().debug_assert();
command_with_afl_version().debug_assert();
}

#[test]
Expand Down
Loading