Skip to content

Commit

Permalink
Merge pull request #70 from srlabs/colorize
Browse files Browse the repository at this point in the history
Yet another TUI redesign
  • Loading branch information
louismerlin committed Oct 16, 2023
2 parents 540d890 + ec4d8fe commit 21d1daf
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl Fuzz {
);
}

eprintln!("\nSee live information by running:");
eprintln!("\nSee more live information by running:");
if afl_jobs > 0 {
eprintln!(
" {}",
Expand All @@ -485,11 +485,6 @@ impl Fuzz {
.bold()
);
}
eprintln!("\n\n\n\n\n");
eprintln!(" Waiting for fuzzers to");
eprintln!(" finish executing the");
eprintln!(" existing corpus once");
eprintln!("\n\n");

Ok(fuzzer_handles)
}
Expand Down Expand Up @@ -580,18 +575,29 @@ impl Fuzz {
}

pub fn print_stats(&self) {
let fuzzer_name = format!(" {} ", self.target);

let reset = "\x1b[0m";
let gray = "\x1b[1;90m";
let red = "\x1b[1;91m";
let green = "\x1b[1;92m";
let yellow = "\x1b[1;93m";
let purple = "\x1b[1;95m";
let blue = "\x1b[1;96m";

// First step: execute afl-whatsup
let mut afl_status = String::from("running ─");
let mut afl_status = format!("{green}running{reset} ─");
let mut afl_total_execs = String::new();
let mut afl_instances = String::new();
let mut afl_speed = String::new();
let mut afl_coverage = String::new();
let mut afl_crashes = String::new();
let mut afl_timeouts = String::new();
let mut afl_new_finds = String::new();
let mut afl_faves = String::new();

if !self.afl() {
afl_status = String::from("disabled ")
afl_status = format!("{yellow}disabled{reset} ")
} else {
let cargo = env::var("CARGO").unwrap_or_else(|_| String::from("cargo"));
let afl_stats_process = process::Command::new(cargo)
Expand Down Expand Up @@ -619,6 +625,8 @@ impl Fuzz {
afl_coverage = String::from(coverage);
} else if let Some(crashes) = line.strip_prefix("Crashes saved : ") {
afl_crashes = String::from(crashes);
} else if let Some(timeouts) = line.strip_prefix("Hangs saved : ") {
afl_timeouts = String::from(timeouts.split(' ').next().unwrap_or_default());
} else if let Some(new_finds) = line.strip_prefix("Time without finds : ") {
afl_new_finds =
String::from(new_finds.split(',').next().unwrap_or_default());
Expand All @@ -637,16 +645,17 @@ impl Fuzz {
}

// Second step: Get stats from honggfuzz logs
let mut hf_status = String::from("running ─");
let mut hf_status = format!("{green}running{reset} ─");
let mut hf_total_execs = String::new();
let mut hf_threads = String::new();
let mut hf_speed = String::new();
let mut hf_coverage = String::new();
let mut hf_crashes = String::new();
let mut hf_timeouts = String::new();
let mut hf_new_finds = String::new();

if !self.honggfuzz() {
hf_status = String::from("disabled ");
hf_status = format!("{yellow}disabled{reset} ");
} else {
let hf_stats_process = process::Command::new("tail")
.args([
Expand Down Expand Up @@ -685,6 +694,8 @@ impl Fuzz {
);
} else if let Some(crashes) = line.strip_prefix("Crashes : ") {
hf_crashes = String::from(crashes.split(' ').next().unwrap_or_default());
} else if let Some(timeouts) = line.strip_prefix("Timeouts : ") {
hf_timeouts = String::from(timeouts.split(' ').next().unwrap_or_default());
} else if let Some(new_finds) = line.strip_prefix("Cov Update : ") {
hf_new_finds = String::from(new_finds.trim());
hf_new_finds = String::from(
Expand Down Expand Up @@ -721,35 +732,39 @@ impl Fuzz {
}

// Fourth step: Print stats
// TODO Colors, of course!
// Move 11 lines up and clear line
eprint!("\x1B[11A\x1B[K");
eprint!("\x1B[K");
eprintln!("β”Œβ”€β”€ ziggy rocking ──────────────────────────────────────────────────────────┐");
eprint!("\x1B[K");
// We start by clearing the screen
eprint!("\x1B[1;1H\x1B[2J");
eprintln!("β”Œβ”€ {blue}ziggy{reset} {purple}rocking{reset} ─────────{fuzzer_name:─^25.25}──────────────────{blue}/{red}///{reset}───┐");
eprintln!(
"β”‚ run time : {total_run_time:17} β”‚"
"β”‚{gray}run time :{reset} {total_run_time:17.17} {blue}/{red}//////{reset} β”‚"
);
eprint!("\x1B[K");
eprintln!("β”œβ”€β”€ afl++ {afl_status:0}───────────────────┬── honggfuzz {hf_status:0}────────────────");
eprint!("\x1B[K");
eprintln!("β”œβ”€ {blue}afl++{reset} {afl_status:0}────────────────────┬────────────────────────────────{blue}/{red}//{reset}───");
if !afl_status.contains("disabled") {
eprintln!("β”‚ {gray}instances :{reset} {afl_instances:17.17} β”‚ {gray}best coverage :{reset} {afl_coverage:11.11} {blue}/{red}//{reset} β”‚");
if afl_crashes == "0" {
eprintln!("β”‚{gray}cumulative speed :{reset} {afl_speed:17.17} β”‚ {gray}crashes saved :{reset} {afl_crashes:11.11} {blue}/{red}//{reset} β”‚");
} else {
eprintln!("β”‚{gray}cumulative speed :{reset} {afl_speed:17.17} β”‚ {gray}crashes saved :{reset} {red}{afl_crashes:11.11}{reset} {blue}/{red}//{reset} β”‚");
}
eprintln!(
"β”‚ {gray}total execs :{reset} {afl_total_execs:17.17} β”‚{gray}timeouts saved :{reset} {afl_timeouts:17.17} β”‚"
);
eprintln!("β”‚ {gray}top inputs todo :{reset} {afl_faves:17.17} β”‚ {gray}no find for :{reset} {afl_new_finds:17.17} β”‚");
}
eprintln!(
"β”‚ total execs : {afl_total_execs:17} β”‚ total execs : {hf_total_execs:17} β”‚"
"β”œβ”€ {blue}honggfuzz{reset} {hf_status:0}β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜"
);
eprint!("\x1B[K");
eprintln!("β”‚ instances : {afl_instances:17} β”‚ threads : {hf_threads:17} β”‚");
eprint!("\x1B[K");
eprintln!("β”‚cumulative speed : {afl_speed:17} β”‚ average Speed : {hf_speed:17} β”‚");
eprint!("\x1B[K");
eprintln!("β”‚ best coverage : {afl_coverage:17} β”‚ coverage : {hf_coverage:17} β”‚");
eprint!("\x1B[K");
eprintln!("β”‚ crashes saved : {afl_crashes:17} β”‚ crashes saved : {hf_crashes:17} β”‚");
eprint!("\x1B[K");
eprintln!("β”‚ no find for : {afl_new_finds:17} β”‚ no find for : {hf_new_finds:17} β”‚");
eprint!("\x1B[K");
eprintln!("β”‚ top inputs todo : {afl_faves:17} β”‚ β”‚");
eprint!("\x1B[K");
eprintln!("β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜");
if !hf_status.contains("disabled") {
eprintln!("β”‚ {gray}threads :{reset} {hf_threads:17.17} β”‚ {gray}coverage :{reset} {hf_coverage:17.17} β”‚");
if hf_crashes == "0" {
eprintln!("β”‚{gray}average Speed :{reset} {hf_speed:17.17} β”‚ {gray}crashes saved :{reset} {hf_crashes:17.17} β”‚");
} else {
eprintln!("β”‚{gray}average Speed :{reset} {hf_speed:17.17} β”‚ {gray}crashes saved :{reset} {red}{hf_crashes:17.17}{reset} β”‚");
}
eprintln!("β”‚ {gray}total execs :{reset} {hf_total_execs:17.17} β”‚{gray}timeouts saved :{reset} {hf_timeouts:17.17} β”‚");
eprintln!("β”‚ β”‚ {gray}no find for :{reset} {hf_new_finds:17.17} β”‚");
}
eprintln!("β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜");
}
}

Expand Down

0 comments on commit 21d1daf

Please sign in to comment.