add the version information of fuzzers in the UI (#1224)

Co-authored-by: toseven <Byone.heng@gmail.com>
This commit is contained in:
ToSeven 2023-04-26 22:52:21 +08:00 committed by GitHub
parent 037b9551ea
commit f248a061ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 26 deletions

View File

@ -3,7 +3,7 @@ use std::ptr::write_volatile;
use std::{path::PathBuf, ptr::write};
#[cfg(feature = "tui")]
use libafl::monitors::tui::TuiMonitor;
use libafl::monitors::tui::{ui::TuiUI, TuiMonitor};
#[cfg(not(feature = "tui"))]
use libafl::monitors::SimpleMonitor;
use libafl::{
@ -90,7 +90,9 @@ pub fn main() {
#[cfg(not(feature = "tui"))]
let mon = SimpleMonitor::new(|s| println!("{s}"));
#[cfg(feature = "tui")]
let mon = TuiMonitor::new(String::from("Baby Fuzzer"), false);
let ui = TuiUI::with_version(String::from("Baby Fuzzer"), String::from("0.0.1"), false);
#[cfg(feature = "tui")]
let mon = TuiMonitor::new(ui);
// The event manager handle the various events generated during the fuzzing loop
// such as the notification of the addition of a new item to the corpus

View File

@ -6,7 +6,7 @@ use std::{
};
#[cfg(feature = "tui")]
use libafl::monitors::tui::TuiMonitor;
use libafl::monitors::tui::{ui::TuiUI, TuiMonitor};
#[cfg(not(feature = "tui"))]
use libafl::monitors::SimpleMonitor;
use libafl::{
@ -206,7 +206,9 @@ pub fn main() {
#[cfg(not(feature = "tui"))]
let mon = SimpleMonitor::new(|s| println!("{s}"));
#[cfg(feature = "tui")]
let mon = TuiMonitor::new(String::from("Baby Fuzzer"), false);
let ui = TuiUI::new(String::from("Baby Fuzzer"), false);
#[cfg(feature = "tui")]
let mon = TuiMonitor::new(ui);
// The event manager handle the various events generated during the fuzzing loop
// such as the notification of the addition of a new item to the corpus

View File

@ -9,7 +9,7 @@ use libafl::{
events::SimpleEventManager,
feedbacks::{CrashFeedback, MaxMapFeedback},
inputs::BytesInput,
monitors::tui::TuiMonitor,
monitors::tui::{ui::TuiUI, TuiMonitor},
mutators::{havoc_mutations, StdScheduledMutator},
observers::StdMapObserver,
schedulers::RandScheduler,
@ -46,7 +46,8 @@ fn main() {
// switch monitor if you want
// let monitor = SimpleMonitor::new(|x|-> () {println!("{}",x)});
let monitor = TuiMonitor::new("test_fuzz".to_string(), true);
let ui = TuiUI::new(String::from("test_fuzz"), true);
let monitor = TuiMonitor::new(ui);
let mut mgr = SimpleEventManager::new(monitor);
let mut executor = NyxExecutor::new(&mut helper, tuple_list!(observer)).unwrap();

View File

@ -29,7 +29,7 @@ use crate::{
monitors::{ClientStats, Monitor, UserStats},
};
mod ui;
pub mod ui;
use ui::TuiUI;
const DEFAULT_TIME_WINDOW: u64 = 60 * 10; // 10 min
@ -326,20 +326,15 @@ impl Monitor for TuiMonitor {
impl TuiMonitor {
/// Creates the monitor
#[must_use]
pub fn new(title: String, enhanced_graphics: bool) -> Self {
Self::with_time(title, enhanced_graphics, current_time())
pub fn new(tui_ui: TuiUI) -> Self {
Self::with_time(tui_ui, current_time())
}
/// Creates the monitor with a given `start_time`.
#[must_use]
pub fn with_time(title: String, enhanced_graphics: bool, start_time: Duration) -> Self {
pub fn with_time(tui_ui: TuiUI, start_time: Duration) -> Self {
let context = Arc::new(RwLock::new(TuiContext::new(start_time)));
run_tui_thread(
context.clone(),
Duration::from_millis(250),
title,
enhanced_graphics,
);
run_tui_thread(context.clone(), Duration::from_millis(250), tui_ui);
Self {
context,
start_time,
@ -348,12 +343,7 @@ impl TuiMonitor {
}
}
fn run_tui_thread(
context: Arc<RwLock<TuiContext>>,
tick_rate: Duration,
title: String,
enhanced_graphics: bool,
) {
fn run_tui_thread(context: Arc<RwLock<TuiContext>>, tick_rate: Duration, tui_ui: TuiUI) {
thread::spawn(move || -> io::Result<()> {
// setup terminal
let mut stdout = io::stdout();
@ -362,7 +352,8 @@ fn run_tui_thread(
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let mut ui = TuiUI::new(title, enhanced_graphics);
let mut ui = tui_ui;
let mut last_tick = Instant::now();
let mut cnt = 0;

View File

@ -18,9 +18,10 @@ use tui::{
use super::{current_time, format_duration_hms, Duration, String, TimedStats, TuiContext};
#[derive(Default)]
#[derive(Default, Debug)]
pub struct TuiUI {
title: String,
version: String,
enhanced_graphics: bool,
show_logs: bool,
clients_idx: usize,
@ -32,16 +33,23 @@ pub struct TuiUI {
}
impl TuiUI {
#[must_use]
pub fn new(title: String, enhanced_graphics: bool) -> Self {
Self::with_version(title, String::from("default"), enhanced_graphics)
}
// create the TuiUI with a given `version`.
#[must_use]
pub fn with_version(title: String, version: String, enhanced_graphics: bool) -> Self {
Self {
title,
version,
enhanced_graphics,
show_logs: true,
clients_idx: 1,
..TuiUI::default()
}
}
pub fn on_key(&mut self, c: char) {
match c {
'q' => {
@ -106,8 +114,11 @@ impl TuiUI {
.constraints([Constraint::Length(3), Constraint::Min(0)].as_ref())
.split(top_layout[0]);
let mut status_bar: String = self.title.clone();
status_bar = status_bar + " (" + self.version.as_str() + ")";
let text = vec![Spans::from(Span::styled(
&self.title,
&status_bar,
Style::default()
.fg(Color::LightMagenta)
.add_modifier(Modifier::BOLD),