diff --git a/TODO.md b/TODO.md index 834bca8a3f..663f85b96a 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ - [ ] Objective-Specific Corpuses (named per objective) - [ ] Good documentation -- [ ] More informative outpus, deeper introspection (stats, what mutation did x, etc.) +- [ ] More informative outpus, deeper introspection (monitor, what mutation did x, etc.) - [ ] Timeout handling for llmp clients (no ping for n seconds -> treat as disconnected) - [ ] Heap for signal handling (bumpallo or llmp directly?) - [x] Frida support for Windows diff --git a/docs/src/baby_fuzzer.md b/docs/src/baby_fuzzer.md index 98f1c6abee..89bab33c99 100644 --- a/docs/src/baby_fuzzer.md +++ b/docs/src/baby_fuzzer.md @@ -121,15 +121,15 @@ As the second parameter, it takes an instance of something implementing the Corp We will discuss the last parameter later. The third parameter is another corpus, in this case, to store the testcases that are considered as "solutions" for the fuzzer. For our purpose, the solution is the input that triggers the panic. In this case, we want to store it to disk under the `crashes` directory, so we can inspect it. -Another required component is the EventManager. It handles some events such as the addition of a testcase to the corpus during the fuzzing process. For our purpose, we use the simplest one that just displays the information about these events to the user using a Stats instance. +Another required component is the EventManager. It handles some events such as the addition of a testcase to the corpus during the fuzzing process. For our purpose, we use the simplest one that just displays the information about these events to the user using a `Monitor` instance. ```rust,ignore -// The Stats trait define how the fuzzer stats are reported to the user -let stats = SimpleStats::new(|s| println!("{}", s)); +// The Monitor trait defines how the fuzzer stats are displayed to the user +let mon = SimpleMonitor::new(|s| println!("{}", s)); // 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 -let mut mgr = SimpleEventManager::new(stats); +let mut mgr = SimpleEventManager::new(mon); ``` In addition, we have the Fuzzer, an entity that contains some actions that alter the State. One of these actions is the scheduling of the testcases to the fuzzer using a CorpusScheduler. @@ -190,8 +190,8 @@ use libafl::{ fuzzer::StdFuzzer, generators::RandPrintablesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, state::StdState, - stats::SimpleStats, }; ``` diff --git a/docs/src/message_passing/spawn_instances.md b/docs/src/message_passing/spawn_instances.md index babb3bc7bb..dd5a7bc00a 100644 --- a/docs/src/message_passing/spawn_instances.md +++ b/docs/src/message_passing/spawn_instances.md @@ -27,7 +27,7 @@ An example may look like this: Launcher::builder() .configuration(EventConfig::from_name(&configuration)) .shmem_provider(shmem_provider) - .stats(stats) + .monitor(mon) .run_client(&mut run_client) .cores(cores) .broker_port(broker_port) diff --git a/fuzzers/baby_fuzzer/src/main.rs b/fuzzers/baby_fuzzer/src/main.rs index 3b9c8f70ba..45b664d93a 100644 --- a/fuzzers/baby_fuzzer/src/main.rs +++ b/fuzzers/baby_fuzzer/src/main.rs @@ -12,11 +12,11 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::RandPrintablesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, observers::StdMapObserver, stages::mutational::StdMutationalStage, state::StdState, - stats::SimpleStats, }; /// Coverage map with explicit assignments due to the lack of instrumentation @@ -82,12 +82,12 @@ pub fn main() { tuple_list!(feedback_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are displayed to the user + let mon = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(mon); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/baby_fuzzer_gramatron/src/main.rs b/fuzzers/baby_fuzzer_gramatron/src/main.rs index b48b6e8da0..fe914d8bda 100644 --- a/fuzzers/baby_fuzzer_gramatron/src/main.rs +++ b/fuzzers/baby_fuzzer_gramatron/src/main.rs @@ -17,6 +17,7 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::{Automaton, GramatronGenerator}, inputs::GramatronInput, + monitors::SimpleMonitor, mutators::{ GramatronRandomMutator, GramatronRecursionMutator, GramatronSpliceMutator, StdScheduledMutator, @@ -24,7 +25,6 @@ use libafl::{ observers::StdMapObserver, stages::mutational::StdMutationalStage, state::StdState, - stats::SimpleStats, }; /// Coverage map with explicit assignments due to the lack of instrumentation @@ -83,12 +83,12 @@ pub fn main() { tuple_list!(feedback_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(monitor); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/baby_fuzzer_nautilus/src/main.rs b/fuzzers/baby_fuzzer_nautilus/src/main.rs index bfdb1ef031..776cd7435d 100644 --- a/fuzzers/baby_fuzzer_nautilus/src/main.rs +++ b/fuzzers/baby_fuzzer_nautilus/src/main.rs @@ -15,13 +15,13 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::{NautilusContext, NautilusGenerator}, inputs::NautilusInput, + monitors::SimpleMonitor, mutators::{ NautilusRandomMutator, NautilusRecursionMutator, NautilusSpliceMutator, StdScheduledMutator, }, observers::StdMapObserver, stages::mutational::StdMutationalStage, state::{HasMetadata, StdState}, - stats::SimpleStats, }; /// Coverage map with explicit assignments due to the lack of instrumentation @@ -80,12 +80,12 @@ pub fn main() { state.add_metadata(NautilusChunksMetadata::new("/tmp/".into())); } - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(monitor); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/baby_fuzzer_tokens/src/main.rs b/fuzzers/baby_fuzzer_tokens/src/main.rs index f619148f90..6e8ada2013 100644 --- a/fuzzers/baby_fuzzer_tokens/src/main.rs +++ b/fuzzers/baby_fuzzer_tokens/src/main.rs @@ -12,11 +12,11 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback}, fuzzer::{Evaluator, Fuzzer, StdFuzzer}, inputs::{EncodedInput, InputDecoder, InputEncoder, NaiveTokenizer, TokenInputEncoderDecoder}, + monitors::SimpleMonitor, mutators::{encoded_mutations::encoded_mutations, scheduled::StdScheduledMutator}, observers::StdMapObserver, stages::mutational::StdMutationalStage, state::StdState, - stats::SimpleStats, }; /// Coverage map with explicit assignments due to the lack of instrumentation @@ -91,12 +91,12 @@ pub fn main() { tuple_list!(feedback_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(monitor); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/baby_no_std/src/main.rs b/fuzzers/baby_no_std/src/main.rs index 80ffebc092..450bc57040 100644 --- a/fuzzers/baby_no_std/src/main.rs +++ b/fuzzers/baby_no_std/src/main.rs @@ -13,11 +13,11 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::RandPrintablesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, observers::StdMapObserver, stages::mutational::StdMutationalStage, state::StdState, - stats::SimpleStats, }; #[cfg(any(windows, unix))] @@ -99,8 +99,8 @@ pub fn main() { tuple_list!(feedback_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| { + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| { // TODO: Print `s` here, if your target permits it. #[cfg(any(windows, unix))] unsafe { @@ -113,7 +113,7 @@ pub fn main() { // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(monitor); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/forkserver_simple/src/main.rs b/fuzzers/forkserver_simple/src/main.rs index 65b51ab10d..b6b35241a9 100644 --- a/fuzzers/forkserver_simple/src/main.rs +++ b/fuzzers/forkserver_simple/src/main.rs @@ -16,11 +16,11 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::BytesInput, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, observers::{ConstMapObserver, HitcountsMapObserver, TimeObserver}, stages::mutational::StdMutationalStage, state::{HasCorpus, StdState}, - stats::SimpleStats, }; use std::path::PathBuf; @@ -83,12 +83,12 @@ pub fn main() { tuple_list!(feedback_state, objective_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(monitor); // A minimization+queue policy to get testcasess from the corpus let scheduler = IndexesLenTimeMinimizerCorpusScheduler::new(QueueCorpusScheduler::new()); diff --git a/fuzzers/frida_libpng/src/fuzzer.rs b/fuzzers/frida_libpng/src/fuzzer.rs index d4e984878a..90b00b554e 100644 --- a/fuzzers/frida_libpng/src/fuzzer.rs +++ b/fuzzers/frida_libpng/src/fuzzer.rs @@ -25,6 +25,7 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes, Input}, + monitors::MultiMonitor, mutators::{ scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, token_mutations::I2SRandReplace, @@ -33,7 +34,6 @@ use libafl::{ observers::{HitcountsMapObserver, ObserversTuple, StdMapObserver, TimeObserver}, stages::{ShadowTracingStage, StdMutationalStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; @@ -277,7 +277,7 @@ unsafe fn fuzz( configuration: String, ) -> Result<(), Error> { // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); let shmem_provider = StdShMemProvider::new()?; @@ -458,7 +458,7 @@ unsafe fn fuzz( Launcher::builder() .configuration(EventConfig::from_name(&configuration)) .shmem_provider(shmem_provider) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(cores) .broker_port(broker_port) diff --git a/fuzzers/fuzzbench/src/lib.rs b/fuzzers/fuzzbench/src/lib.rs index d4c7d5c955..146ccc3e81 100644 --- a/fuzzers/fuzzbench/src/lib.rs +++ b/fuzzers/fuzzbench/src/lib.rs @@ -29,6 +29,7 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::{ scheduled::{havoc_mutations, StdScheduledMutator}, token_mutations::I2SRandReplace, @@ -37,7 +38,6 @@ use libafl::{ observers::{StdMapObserver, TimeObserver}, stages::{StdMutationalStage, TracingStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::SimpleStats, Error, }; use libafl_targets::{ @@ -171,7 +171,7 @@ fn fuzz( let file_null = File::open("/dev/null")?; // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = SimpleStats::new(|s| { + let monitor = SimpleMonitor::new(|s| { #[cfg(unix)] writeln!(&mut stdout_cpy, "{}", s).unwrap(); #[cfg(windows)] @@ -183,7 +183,8 @@ fn fuzz( // This way, we are able to continue fuzzing afterwards. let mut shmem_provider = StdShMemProvider::new()?; - let (state, mut mgr) = match SimpleRestartingEventManager::launch(stats, &mut shmem_provider) { + let (state, mut mgr) = match SimpleRestartingEventManager::launch(monitor, &mut shmem_provider) + { // The restarting state will spawn the same process again as child, then restarted it each time it crashes. Ok(res) => res, Err(err) => match err { diff --git a/fuzzers/fuzzbench_gsoc/src/lib.rs b/fuzzers/fuzzbench_gsoc/src/lib.rs index 8fa8e8f958..81f4f1516d 100644 --- a/fuzzers/fuzzbench_gsoc/src/lib.rs +++ b/fuzzers/fuzzbench_gsoc/src/lib.rs @@ -31,6 +31,7 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::{ scheduled::havoc_mutations, token_mutations::I2SRandReplace, tokens_mutations, StdMOptMutator, Tokens, @@ -42,7 +43,6 @@ use libafl::{ TracingStage, }, state::{HasCorpus, HasMetadata, StdState}, - stats::SimpleStats, Error, }; use libafl_targets::{ @@ -175,8 +175,8 @@ fn fuzz( #[cfg(unix)] let file_null = File::open("/dev/null")?; - // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = SimpleStats::new(|s| { + // 'While the monitor are state, they are usually used in the broker - which is likely never restarted + let monitor = SimpleMonitor::new(|s| { #[cfg(unix)] writeln!(&mut stdout_cpy, "{}", s).unwrap(); #[cfg(windows)] @@ -188,7 +188,8 @@ fn fuzz( // This way, we are able to continue fuzzing afterwards. let mut shmem_provider = StdShMemProvider::new()?; - let (state, mut mgr) = match SimpleRestartingEventManager::launch(stats, &mut shmem_provider) { + let (state, mut mgr) = match SimpleRestartingEventManager::launch(monitor, &mut shmem_provider) + { // The restarting state will spawn the same process again as child, then restarted it each time it crashes. Ok(res) => res, Err(err) => match err { diff --git a/fuzzers/fuzzbench_qemu/src/fuzzer.rs b/fuzzers/fuzzbench_qemu/src/fuzzer.rs index e47eb4b0ea..586c1644dd 100644 --- a/fuzzers/fuzzbench_qemu/src/fuzzer.rs +++ b/fuzzers/fuzzbench_qemu/src/fuzzer.rs @@ -29,6 +29,7 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::{ scheduled::{havoc_mutations, StdScheduledMutator}, tokens_mutations, I2SRandReplace, Tokens, @@ -36,7 +37,6 @@ use libafl::{ observers::{HitcountsMapObserver, TimeObserver, VariableMapObserver}, stages::{ShadowTracingStage, StdMutationalStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::SimpleStats, Error, }; use libafl_qemu::{ @@ -205,7 +205,7 @@ fn fuzz( let file_null = File::open("/dev/null")?; // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = SimpleStats::new(|s| { + let monitor = SimpleMonitor::new(|s| { #[cfg(unix)] writeln!(&mut stdout_cpy, "{}", s).unwrap(); #[cfg(windows)] @@ -215,7 +215,8 @@ fn fuzz( let mut shmem_provider = StdShMemProvider::new()?; - let (state, mut mgr) = match SimpleRestartingEventManager::launch(stats, &mut shmem_provider) { + let (state, mut mgr) = match SimpleRestartingEventManager::launch(monitor, &mut shmem_provider) + { // The restarting state will spawn the same process again as child, then restarted it each time it crashes. Ok(res) => res, Err(err) => match err { diff --git a/fuzzers/generic_inmemory/src/lib.rs b/fuzzers/generic_inmemory/src/lib.rs index bbae8e6a83..1000d9d5e0 100644 --- a/fuzzers/generic_inmemory/src/lib.rs +++ b/fuzzers/generic_inmemory/src/lib.rs @@ -25,12 +25,12 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::RandBytesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::{I2SRandReplace, Tokens}, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, stages::{StdMutationalStage, TracingStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; @@ -82,7 +82,7 @@ pub fn libafl_main() { let shmem_provider = StdShMemProvider::new().expect("Failed to init shared memory"); - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); let mut run_client = |state: Option>, mut mgr, _core_id| { // Create an observation channel using the coverage map @@ -234,7 +234,7 @@ pub fn libafl_main() { match Launcher::builder() .shmem_provider(shmem_provider) .configuration(EventConfig::from_name("default")) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(&cores) .broker_port(broker_port) diff --git a/fuzzers/libafl_atheris/src/lib.rs b/fuzzers/libafl_atheris/src/lib.rs index 96d7d3bb1e..c80f006fe3 100644 --- a/fuzzers/libafl_atheris/src/lib.rs +++ b/fuzzers/libafl_atheris/src/lib.rs @@ -31,12 +31,12 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::RandBytesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::{I2SRandReplace, Tokens}, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, stages::{StdMutationalStage, TracingStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; use libafl_targets::{ @@ -210,7 +210,7 @@ pub fn LLVMFuzzerRunDriver( let shmem_provider = StdShMemProvider::new().expect("Failed to init shared memory"); - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); // TODO: we need to handle Atheris calls to `exit` on errors somhow. @@ -359,7 +359,7 @@ pub fn LLVMFuzzerRunDriver( match Launcher::builder() .shmem_provider(shmem_provider) .configuration(EventConfig::from_name("default")) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(&cores) .broker_port(broker_port) diff --git a/fuzzers/libfuzzer_libmozjpeg/src/lib.rs b/fuzzers/libfuzzer_libmozjpeg/src/lib.rs index 5a6231e6ef..9c7e0dfe96 100644 --- a/fuzzers/libfuzzer_libmozjpeg/src/lib.rs +++ b/fuzzers/libfuzzer_libmozjpeg/src/lib.rs @@ -16,12 +16,12 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::Tokens, observers::StdMapObserver, stages::mutational::StdMutationalStage, state::{HasCorpus, HasMetadata, StdState}, - stats::SimpleStats, Error, }; @@ -56,11 +56,11 @@ pub fn libafl_main() { /// The actual fuzzer fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Result<(), Error> { // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = SimpleStats::new(|s| println!("{}", s)); + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - match setup_restarting_mgr_std(stats, broker_port, EventConfig::from_name("default")) { + match setup_restarting_mgr_std(monitor, broker_port, EventConfig::from_name("default")) { Ok(tuple) => tuple, Err(Error::ShuttingDown) => { println!("\nFinished fuzzing. Good bye."); diff --git a/fuzzers/libfuzzer_libpng/src/lib.rs b/fuzzers/libfuzzer_libpng/src/lib.rs index 563bae9174..093bbf3fb2 100644 --- a/fuzzers/libfuzzer_libpng/src/lib.rs +++ b/fuzzers/libfuzzer_libpng/src/lib.rs @@ -20,6 +20,7 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::Tokens, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, @@ -28,7 +29,6 @@ use libafl::{ power::{PowerMutationalStage, PowerSchedule}, }, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; @@ -57,11 +57,11 @@ pub fn libafl_main() { /// The actual fuzzer fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Result<(), Error> { // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - match setup_restarting_mgr_std(stats, broker_port, EventConfig::AlwaysUnique) { + match setup_restarting_mgr_std(monitor, broker_port, EventConfig::AlwaysUnique) { Ok(res) => res, Err(err) => match err { Error::ShuttingDown => { diff --git a/fuzzers/libfuzzer_libpng_launcher/src/lib.rs b/fuzzers/libfuzzer_libpng_launcher/src/lib.rs index 8bc07bd71c..4ea130b517 100644 --- a/fuzzers/libfuzzer_libpng_launcher/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_launcher/src/lib.rs @@ -26,12 +26,12 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::Tokens, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, stages::mutational::StdMutationalStage, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; @@ -58,7 +58,7 @@ pub fn libafl_main() { let shmem_provider = StdShMemProvider::new().expect("Failed to init shared memory"); - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); let mut run_client = |state: Option>, mut restarting_mgr, _core_id| { let corpus_dirs = &[PathBuf::from("./corpus")]; @@ -168,7 +168,7 @@ pub fn libafl_main() { match Launcher::builder() .shmem_provider(shmem_provider) .configuration(EventConfig::from_name("default")) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(&cores) .broker_port(broker_port) diff --git a/fuzzers/libfuzzer_reachability/src/lib.rs b/fuzzers/libfuzzer_reachability/src/lib.rs index 9dcc102063..f52f6bffb6 100644 --- a/fuzzers/libfuzzer_reachability/src/lib.rs +++ b/fuzzers/libfuzzer_reachability/src/lib.rs @@ -11,11 +11,11 @@ use libafl::{ feedbacks::{MapFeedbackState, MaxMapFeedback, ReachabilityFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, observers::{HitcountsMapObserver, StdMapObserver}, stages::mutational::StdMutationalStage, state::{HasCorpus, StdState}, - stats::SimpleStats, Error, }; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, EDGES_MAP, MAX_EDGES_NUM}; @@ -48,11 +48,11 @@ pub fn libafl_main() { /// The actual fuzzer fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Result<(), Error> { // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = SimpleStats::new(|s| println!("{}", s)); + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - match setup_restarting_mgr_std(stats, broker_port, EventConfig::AlwaysUnique) { + match setup_restarting_mgr_std(monitor, broker_port, EventConfig::AlwaysUnique) { Ok(res) => res, Err(err) => match err { Error::ShuttingDown => { diff --git a/fuzzers/libfuzzer_stb_image/src/main.rs b/fuzzers/libfuzzer_stb_image/src/main.rs index 79f34c2bcc..c89e26f21e 100644 --- a/fuzzers/libfuzzer_stb_image/src/main.rs +++ b/fuzzers/libfuzzer_stb_image/src/main.rs @@ -15,12 +15,12 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, mutators::token_mutations::I2SRandReplace, observers::{StdMapObserver, TimeObserver}, stages::{ShadowTracingStage, StdMutationalStage}, state::{HasCorpus, StdState}, - stats::MultiStats, Error, }; @@ -49,11 +49,11 @@ pub fn main() { /// The actual fuzzer fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Result<(), Error> { // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - match setup_restarting_mgr_std(stats, broker_port, EventConfig::from_name("default")) { + match setup_restarting_mgr_std(monitor, broker_port, EventConfig::from_name("default")) { Ok(res) => res, Err(err) => match err { Error::ShuttingDown => { diff --git a/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs b/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs index a707c61da0..2cb9cdb8c5 100644 --- a/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs +++ b/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs @@ -38,7 +38,7 @@ use libafl::{ StdMutationalStage, TracingStage, }, state::{HasCorpus, StdState}, - stats::MultiStats, + monitors::MultiMonitor, Error, }; @@ -84,11 +84,11 @@ fn fuzz( concolic: bool, ) -> Result<(), Error> { // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - match setup_restarting_mgr_std(stats, broker_port, EventConfig::from_name("default")) { + match setup_restarting_mgr_std(monitor, broker_port, EventConfig::from_name("default")) { Ok(res) => res, Err(err) => match err { Error::ShuttingDown => { diff --git a/fuzzers/push_harness/src/main.rs b/fuzzers/push_harness/src/main.rs index 01298b1391..8ea8c02d71 100644 --- a/fuzzers/push_harness/src/main.rs +++ b/fuzzers/push_harness/src/main.rs @@ -10,11 +10,11 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback}, fuzzer::{Fuzzer, StdFuzzer}, generators::RandPrintablesGenerator, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, observers::StdMapObserver, stages::mutational::StdMutationalStage, state::StdState, - stats::SimpleStats, }; use std::path::PathBuf; @@ -63,12 +63,12 @@ fn input_generator() { tuple_list!(feedback_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mut mgr = SimpleEventManager::new(stats); + let mut mgr = SimpleEventManager::new(monitor); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/push_stage_harness/src/main.rs b/fuzzers/push_stage_harness/src/main.rs index ede15267d8..30da620adb 100644 --- a/fuzzers/push_stage_harness/src/main.rs +++ b/fuzzers/push_stage_harness/src/main.rs @@ -17,11 +17,11 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback}, fuzzer::StdFuzzer, inputs::{BytesInput, HasTargetBytes}, + monitors::SimpleMonitor, mutators::scheduled::{havoc_mutations, StdScheduledMutator}, observers::StdMapObserver, stages::push::StdMutationalPushStage, state::{HasCorpus, StdState}, - stats::SimpleStats, }; /// Coverage map with explicit assignments due to the lack of instrumentation @@ -60,12 +60,12 @@ pub fn main() { tuple_list!(feedback_state), ); - // The Stats trait define how the fuzzer stats are reported to the user - let stats = SimpleStats::new(|s| println!("{}", s)); + // The Monitor trait define how the fuzzer stats are reported to the user + let monitor = SimpleMonitor::new(|s| println!("{}", s)); // 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 - let mgr = SimpleEventManager::new(stats); + let mgr = SimpleEventManager::new(monitor); // A queue policy to get testcasess from the corpus let scheduler = QueueCorpusScheduler::new(); diff --git a/fuzzers/tutorial/src/lib.rs b/fuzzers/tutorial/src/lib.rs index 9787bed9c1..c6c61e6835 100644 --- a/fuzzers/tutorial/src/lib.rs +++ b/fuzzers/tutorial/src/lib.rs @@ -15,13 +15,13 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, fuzzer::{Fuzzer, StdFuzzer}, inputs::HasTargetBytes, + monitors::MultiMonitor, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, stages::{ calibrate::CalibrationStage, power::{PowerMutationalStage, PowerSchedule}, }, state::{HasCorpus, StdState}, - stats::MultiStats, Error, }; @@ -67,11 +67,11 @@ fn fuzz(corpus_dirs: &[PathBuf], objective_dir: PathBuf, broker_port: u16) -> Re }; // 'While the stats are state, they are usually used in the broker - which is likely never restarted - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - match setup_restarting_mgr_std(stats, broker_port, EventConfig::AlwaysUnique) { + match setup_restarting_mgr_std(monitor, broker_port, EventConfig::AlwaysUnique) { Ok(res) => res, Err(err) => match err { Error::ShuttingDown => { diff --git a/fuzzers/tutorial/src/metadata.rs b/fuzzers/tutorial/src/metadata.rs index a2188bfb6e..d53b9d4608 100644 --- a/fuzzers/tutorial/src/metadata.rs +++ b/fuzzers/tutorial/src/metadata.rs @@ -5,7 +5,7 @@ use libafl::{ executors::ExitKind, feedbacks::{Feedback, MapIndexesMetadata}, observers::ObserversTuple, - state::{HasClientPerfStats, HasMetadata}, + state::{HasClientPerfMonitor, HasMetadata}, Error, SerdeAny, }; @@ -39,7 +39,7 @@ pub struct PacketLenFeedback { impl Feedback for PacketLenFeedback where - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl/src/bolts/launcher.rs b/libafl/src/bolts/launcher.rs index 1d6caf9273..c634803f63 100644 --- a/libafl/src/bolts/launcher.rs +++ b/libafl/src/bolts/launcher.rs @@ -19,8 +19,8 @@ use crate::{ bolts::shmem::ShMemProvider, events::{EventConfig, LlmpRestartingEventManager, ManagerKind, RestartingMgr}, inputs::Input, + monitors::Monitor, observers::ObserversTuple, - stats::Stats, Error, }; @@ -45,19 +45,19 @@ const _AFL_LAUNCHER_CLIENT: &str = "AFL_LAUNCHER_CLIENT"; #[cfg(feature = "std")] #[derive(TypedBuilder)] #[allow(clippy::type_complexity)] -pub struct Launcher<'a, CF, I, OT, S, SP, ST> +pub struct Launcher<'a, CF, I, MT, OT, S, SP> where CF: FnOnce(Option, LlmpRestartingEventManager, usize) -> Result<(), Error>, I: Input + 'a, - ST: Stats, + MT: Monitor, SP: ShMemProvider + 'static, OT: ObserversTuple + 'a, S: DeserializeOwned + 'a, { /// The ShmemProvider to use shmem_provider: SP, - /// The stats instance to use - stats: ST, + /// The monitor instance to use + monitor: MT, /// The configuration configuration: EventConfig, /// The 'main' function to run for each client forked. This probably shouldn't return @@ -86,12 +86,12 @@ where } #[cfg(feature = "std")] -impl<'a, CF, I, OT, S, SP, ST> Launcher<'a, CF, I, OT, S, SP, ST> +impl<'a, CF, I, MT, OT, S, SP> Launcher<'a, CF, I, MT, OT, S, SP> where CF: FnOnce(Option, LlmpRestartingEventManager, usize) -> Result<(), Error>, I: Input, OT: ObserversTuple + serde::de::DeserializeOwned, - ST: Stats + Clone, + MT: Monitor + Clone, SP: ShMemProvider + 'static, S: DeserializeOwned, { @@ -138,7 +138,7 @@ where dup2(file.as_raw_fd(), libc::STDERR_FILENO)?; } // Fuzzer client. keeps retrying the connection to broker till the broker starts - let (state, mgr) = RestartingMgr::::builder() + let (state, mgr) = RestartingMgr::::builder() .shmem_provider(self.shmem_provider.clone()) .broker_port(self.broker_port) .kind(ManagerKind::Client { @@ -161,9 +161,9 @@ where println!("I am broker!!."); // TODO we don't want always a broker here, think about using different laucher process to spawn different configurations - RestartingMgr::::builder() + RestartingMgr::::builder() .shmem_provider(self.shmem_provider.clone()) - .stats(Some(self.stats.clone())) + .monitor(Some(self.monitor.clone())) .broker_port(self.broker_port) .kind(ManagerKind::Broker) .remote_broker_addr(self.remote_broker_addr) @@ -206,7 +206,7 @@ where //todo: silence stdout and stderr for clients // the actual client. do the fuzzing - let (state, mgr) = RestartingMgr::::builder() + let (state, mgr) = RestartingMgr::::builder() .shmem_provider(self.shmem_provider.clone()) .broker_port(self.broker_port) .kind(ManagerKind::Client { @@ -259,9 +259,9 @@ where #[cfg(feature = "std")] println!("I am broker!!."); - RestartingMgr::::builder() + RestartingMgr::::builder() .shmem_provider(self.shmem_provider.clone()) - .stats(Some(self.stats.clone())) + .monitor(Some(self.monitor.clone())) .broker_port(self.broker_port) .kind(ManagerKind::Broker) .remote_broker_addr(self.remote_broker_addr) diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 78e557c2df..b8a1d70922 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -31,8 +31,8 @@ use crate::{ executors::{Executor, HasObservers}, fuzzer::{EvaluatorObservers, ExecutionProcessor}, inputs::Input, + monitors::Monitor, observers::ObserversTuple, - stats::Stats, Error, }; @@ -66,30 +66,30 @@ const _LLMP_TAG_NO_RESTART: llmp::Tag = 0x57A7EE71; const COMPRESS_THRESHOLD: usize = 1024; #[derive(Debug)] -pub struct LlmpEventBroker +pub struct LlmpEventBroker where I: Input, SP: ShMemProvider + 'static, - ST: Stats, + MT: Monitor, //CE: CustomEvent, { - stats: ST, + monitor: MT, llmp: llmp::LlmpBroker, #[cfg(feature = "llmp_compression")] compressor: GzipCompressor, phantom: PhantomData, } -impl LlmpEventBroker +impl LlmpEventBroker where I: Input, SP: ShMemProvider + 'static, - ST: Stats, + MT: Monitor, { /// Create an even broker from a raw broker. - pub fn new(llmp: llmp::LlmpBroker, stats: ST) -> Result { + pub fn new(llmp: llmp::LlmpBroker, monitor: MT) -> Result { Ok(Self { - stats, + monitor, llmp, #[cfg(feature = "llmp_compression")] compressor: GzipCompressor::new(COMPRESS_THRESHOLD), @@ -100,9 +100,9 @@ where /// Create llmp on a port /// The port must not be bound yet to have a broker. #[cfg(feature = "std")] - pub fn new_on_port(shmem_provider: SP, stats: ST, port: u16) -> Result { + pub fn new_on_port(shmem_provider: SP, monitor: MT, port: u16) -> Result { Ok(Self { - stats, + monitor, llmp: llmp::LlmpBroker::create_attach_to_tcp(shmem_provider, port)?, #[cfg(feature = "llmp_compression")] compressor: GzipCompressor::new(COMPRESS_THRESHOLD), @@ -120,7 +120,7 @@ where /// Run forever in the broker pub fn broker_loop(&mut self) -> Result<(), Error> { - let stats = &mut self.stats; + let monitor = &mut self.monitor; #[cfg(feature = "llmp_compression")] let compressor = &self.compressor; self.llmp.loop_forever( @@ -138,7 +138,7 @@ where msg }; let event: Event = postcard::from_bytes(event_bytes)?; - match Self::handle_in_broker(stats, client_id, &event)? { + match Self::handle_in_broker(monitor, client_id, &event)? { BrokerEventResult::Forward => Ok(llmp::LlmpMsgHookResult::ForwardToClients), BrokerEventResult::Handled => Ok(llmp::LlmpMsgHookResult::Handled), } @@ -155,7 +155,7 @@ where /// Handle arriving events in the broker #[allow(clippy::unnecessary_wraps)] fn handle_in_broker( - stats: &mut ST, + monitor: &mut MT, client_id: u32, event: &Event, ) -> Result { @@ -169,21 +169,21 @@ where time, executions, } => { - let client = stats.client_stats_mut_for(client_id); + let client = monitor.client_stats_mut_for(client_id); client.update_corpus_size(*corpus_size as u64); client.update_executions(*executions as u64, *time); - stats.display(event.name().to_string(), client_id); + monitor.display(event.name().to_string(), client_id); Ok(BrokerEventResult::Forward) } - Event::UpdateStats { + Event::UpdateExecutions { time, executions, phantom: _, } => { - // TODO: The stats buffer should be added on client add. - let client = stats.client_stats_mut_for(client_id); + // TODO: The monitor buffer should be added on client add. + let client = monitor.client_stats_mut_for(client_id); client.update_executions(*executions as u64, *time); - stats.display(event.name().to_string(), client_id); + monitor.display(event.name().to_string(), client_id); Ok(BrokerEventResult::Handled) } Event::UpdateUserStats { @@ -191,39 +191,39 @@ where value, phantom: _, } => { - let client = stats.client_stats_mut_for(client_id); + let client = monitor.client_stats_mut_for(client_id); client.update_user_stats(name.clone(), value.clone()); - stats.display(event.name().to_string(), client_id); + monitor.display(event.name().to_string(), client_id); Ok(BrokerEventResult::Handled) } #[cfg(feature = "introspection")] - Event::UpdatePerfStats { + Event::UpdatePerfMonitor { time, executions, - introspection_stats, + introspection_monitor, phantom: _, } => { - // TODO: The stats buffer should be added on client add. + // TODO: The monitor buffer should be added on client add. // Get the client for the staterestorer ID - let client = stats.client_stats_mut_for(client_id); + let client = monitor.client_stats_mut_for(client_id); - // Update the normal stats for this client + // Update the normal monitor for this client client.update_executions(*executions as u64, *time); - // Update the performance stats for this client - client.update_introspection_stats((**introspection_stats).clone()); + // Update the performance monitor for this client + client.update_introspection_monitor((**introspection_monitor).clone()); - // Display the stats via `.display` only on core #1 - stats.display(event.name().to_string(), client_id); + // Display the monitor via `.display` only on core #1 + monitor.display(event.name().to_string(), client_id); // Correctly handled the event Ok(BrokerEventResult::Handled) } Event::Objective { objective_size } => { - let client = stats.client_stats_mut_for(client_id); + let client = monitor.client_stats_mut_for(client_id); client.update_objective_size(*objective_size as u64); - stats.display(event.name().to_string(), client_id); + monitor.display(event.name().to_string(), client_id); Ok(BrokerEventResult::Handled) } Event::Log { @@ -232,7 +232,7 @@ where phantom: _, } => { let (_, _) = (severity_level, message); - // TODO rely on Stats + // TODO rely on Monitor #[cfg(feature = "std")] println!("[LOG {}]: {}", severity_level, message); Ok(BrokerEventResult::Handled) @@ -672,8 +672,8 @@ pub enum ManagerKind { /// The restarter will spawn a new process each time the child crashes or timeouts. #[cfg(feature = "std")] #[allow(clippy::type_complexity)] -pub fn setup_restarting_mgr_std( - stats: ST, +pub fn setup_restarting_mgr_std( + monitor: MT, broker_port: u16, configuration: EventConfig, ) -> Result< @@ -686,13 +686,13 @@ pub fn setup_restarting_mgr_std( where I: Input, S: DeserializeOwned, - ST: Stats + Clone, + MT: Monitor + Clone, OT: ObserversTuple + serde::de::DeserializeOwned, S: DeserializeOwned, { RestartingMgr::builder() .shmem_provider(StdShMemProvider::new()?) - .stats(Some(stats)) + .monitor(Some(monitor)) .broker_port(broker_port) .configuration(configuration) .build() @@ -705,13 +705,13 @@ where #[cfg(feature = "std")] #[allow(clippy::default_trait_access)] #[derive(TypedBuilder, Debug)] -pub struct RestartingMgr +pub struct RestartingMgr where I: Input, OT: ObserversTuple + serde::de::DeserializeOwned, S: DeserializeOwned, SP: ShMemProvider + 'static, - ST: Stats, + MT: Monitor, //CE: CustomEvent, { /// The shared memory provider to use for the broker or client spawned by the restarting @@ -719,9 +719,9 @@ where shmem_provider: SP, /// The configuration configuration: EventConfig, - /// The stats to use + /// The monitor to use #[builder(default = None)] - stats: Option, + monitor: Option, /// The broker port to use #[builder(default = 1337_u16)] broker_port: u16, @@ -737,13 +737,13 @@ where #[cfg(feature = "std")] #[allow(clippy::type_complexity, clippy::too_many_lines)] -impl RestartingMgr +impl RestartingMgr where I: Input, OT: ObserversTuple + serde::de::DeserializeOwned, S: DeserializeOwned, SP: ShMemProvider, - ST: Stats + Clone, + MT: Monitor + Clone, { /// Launch the restarting manager pub fn launch( @@ -753,7 +753,7 @@ where let (staterestorer, new_shmem_provider, core_id) = if std::env::var(_ENV_FUZZER_SENDER) .is_err() { - let broker_things = |mut broker: LlmpEventBroker, remote_broker_addr| { + let broker_things = |mut broker: LlmpEventBroker, remote_broker_addr| { if let Some(remote_broker_addr) = remote_broker_addr { println!("B2b: Connecting to {:?}", &remote_broker_addr); broker.connect_b2b(remote_broker_addr)?; @@ -769,9 +769,9 @@ where LlmpConnection::on_port(self.shmem_provider.clone(), self.broker_port)?; match connection { LlmpConnection::IsBroker { broker } => { - let event_broker = LlmpEventBroker::::new( + let event_broker = LlmpEventBroker::::new( broker, - self.stats.take().unwrap(), + self.monitor.take().unwrap(), )?; // Yep, broker. Just loop here. @@ -791,9 +791,9 @@ where } } ManagerKind::Broker => { - let event_broker = LlmpEventBroker::::new_on_port( + let event_broker = LlmpEventBroker::::new_on_port( self.shmem_provider.clone(), - self.stats.take().unwrap(), + self.monitor.take().unwrap(), self.broker_port, )?; diff --git a/libafl/src/events/mod.rs b/libafl/src/events/mod.rs index a2e0937de7..b7b36d1488 100644 --- a/libafl/src/events/mod.rs +++ b/libafl/src/events/mod.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::{ - executors::ExitKind, inputs::Input, observers::ObserversTuple, stats::UserStats, Error, + executors::ExitKind, inputs::Input, monitors::UserStats, observers::ObserversTuple, Error, }; /// A per-fuzzer unique `ID`, usually starting with `0` and increasing @@ -26,7 +26,7 @@ pub struct EventManagerId { } #[cfg(feature = "introspection")] -use crate::stats::ClientPerfStats; +use crate::monitors::ClientPerfMonitor; #[cfg(feature = "introspection")] use alloc::boxed::Box; @@ -169,8 +169,8 @@ where /// The executions of this client executions: usize, }, - /// New stats. - UpdateStats { + /// New stats event to monitor. + UpdateExecutions { /// The time of generation of the [`Event`] time: Duration, /// The executions of this client @@ -178,18 +178,18 @@ where /// [`PhantomData`] phantom: PhantomData, }, - /// New stats. + /// New user stats event to monitor. UpdateUserStats { - /// Custom user stats name + /// Custom user monitor name name: String, - /// Custom user stats value + /// Custom user monitor value value: UserStats, /// [`PhantomData`] phantom: PhantomData, }, - /// New stats with performance stats. + /// New monitor with performance monitor. #[cfg(feature = "introspection")] - UpdatePerfStats { + UpdatePerfMonitor { /// The time of generation of the event time: Duration, @@ -197,7 +197,7 @@ where executions: usize, /// Current performance statistics - introspection_stats: Box, + introspection_monitor: Box, phantom: PhantomData, }, @@ -237,7 +237,7 @@ where time: _, executions: _, } => "Testcase", - Event::UpdateStats { + Event::UpdateExecutions { time: _, executions: _, phantom: _, @@ -248,12 +248,12 @@ where phantom: _, } => "Stats", #[cfg(feature = "introspection")] - Event::UpdatePerfStats { + Event::UpdatePerfMonitor { time: _, executions: _, - introspection_stats: _, + introspection_monitor: _, phantom: _, - } => "PerfStats", + } => "PerfMonitor", Event::Objective { objective_size: _ } => "Objective", Event::Log { severity_level: _, diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 6959983067..55bbd76a15 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -6,7 +6,7 @@ use crate::{ EventRestarter, HasEventManagerId, }, inputs::Input, - stats::Stats, + monitors::Monitor, Error, }; use alloc::{string::ToString, vec::Vec}; @@ -37,24 +37,24 @@ const _ENV_FUZZER_BROKER_CLIENT_INITIAL: &str = "_AFL_ENV_FUZZER_BROKER_CLIENT"; /// A simple, single-threaded event manager that just logs #[derive(Clone, Debug)] -pub struct SimpleEventManager +pub struct SimpleEventManager where I: Input, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { - /// The stats - stats: ST, + /// The monitor + monitor: MT, /// The events that happened since the last handle_in_broker events: Vec>, } -impl EventFirer for SimpleEventManager +impl EventFirer for SimpleEventManager where I: Input, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { fn fire(&mut self, _state: &mut S, event: Event) -> Result<(), Error> { - match Self::handle_in_broker(&mut self.stats, &event)? { + match Self::handle_in_broker(&mut self.monitor, &event)? { BrokerEventResult::Forward => self.events.push(event), BrokerEventResult::Handled => (), }; @@ -62,17 +62,17 @@ where } } -impl EventRestarter for SimpleEventManager +impl EventRestarter for SimpleEventManager where I: Input, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { } -impl EventProcessor for SimpleEventManager +impl EventProcessor for SimpleEventManager where I: Input, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { fn process( &mut self, @@ -89,39 +89,39 @@ where } } -impl EventManager for SimpleEventManager +impl EventManager for SimpleEventManager where I: Input, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { } -impl HasEventManagerId for SimpleEventManager +impl HasEventManagerId for SimpleEventManager where I: Input, - ST: Stats, + MT: Monitor, { fn mgr_id(&self) -> EventManagerId { EventManagerId { id: 0 } } } -impl SimpleEventManager +impl SimpleEventManager where I: Input, - ST: Stats, //TODO CE: CustomEvent, + MT: Monitor, //TODO CE: CustomEvent, { /// Creates a new [`SimpleEventManager`]. - pub fn new(stats: ST) -> Self { + pub fn new(monitor: MT) -> Self { Self { - stats, + monitor, events: vec![], } } // Handle arriving events in the broker #[allow(clippy::unnecessary_wraps)] - fn handle_in_broker(stats: &mut ST, event: &Event) -> Result { + fn handle_in_broker(monitor: &mut MT, event: &Event) -> Result { match event { Event::NewTestcase { input: _, @@ -132,25 +132,25 @@ where time, executions, } => { - stats + monitor .client_stats_mut_for(0) .update_corpus_size(*corpus_size as u64); - stats + monitor .client_stats_mut_for(0) .update_executions(*executions as u64, *time); - stats.display(event.name().to_string(), 0); + monitor.display(event.name().to_string(), 0); Ok(BrokerEventResult::Handled) } - Event::UpdateStats { + Event::UpdateExecutions { time, executions, phantom: _, } => { - // TODO: The stats buffer should be added on client add. - stats + // TODO: The monitor buffer should be added on client add. + monitor .client_stats_mut_for(0) .update_executions(*executions as u64, *time); - stats.display(event.name().to_string(), 0); + monitor.display(event.name().to_string(), 0); Ok(BrokerEventResult::Handled) } Event::UpdateUserStats { @@ -158,31 +158,31 @@ where value, phantom: _, } => { - stats + monitor .client_stats_mut_for(0) .update_user_stats(name.clone(), value.clone()); - stats.display(event.name().to_string(), 0); + monitor.display(event.name().to_string(), 0); Ok(BrokerEventResult::Handled) } #[cfg(feature = "introspection")] - Event::UpdatePerfStats { + Event::UpdatePerfMonitor { time, executions, - introspection_stats, + introspection_monitor, phantom: _, } => { - // TODO: The stats buffer should be added on client add. - stats.client_stats_mut()[0].update_executions(*executions as u64, *time); - stats.client_stats_mut()[0] - .update_introspection_stats((**introspection_stats).clone()); - stats.display(event.name().to_string(), 0); + // TODO: The monitor buffer should be added on client add. + monitor.client_stats_mut()[0].update_executions(*executions as u64, *time); + monitor.client_stats_mut()[0] + .update_introspection_monitor((**introspection_monitor).clone()); + monitor.display(event.name().to_string(), 0); Ok(BrokerEventResult::Handled) } Event::Objective { objective_size } => { - stats + monitor .client_stats_mut_for(0) .update_objective_size(*objective_size as u64); - stats.display(event.name().to_string(), 0); + monitor.display(event.name().to_string(), 0); Ok(BrokerEventResult::Handled) } Event::Log { @@ -213,16 +213,16 @@ where /// `restarter` will start a new process each time the child crashes or times out. #[cfg(feature = "std")] #[allow(clippy::default_trait_access)] -pub struct SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +pub struct SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { /// The actual simple event mgr - simple_event_mgr: SimpleEventManager, + simple_event_mgr: SimpleEventManager, /// [`StateRestorer`] for restarts staterestorer: StateRestorer, /// Phantom data @@ -230,14 +230,14 @@ where } #[cfg(feature = "std")] -impl<'a, C, I, S, SC, SP, ST> EventFirer - for SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +impl<'a, C, I, MT, S, SC, SP> EventFirer + for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { fn fire(&mut self, _state: &mut S, event: Event) -> Result<(), Error> { self.simple_event_mgr.fire(_state, event) @@ -245,14 +245,14 @@ where } #[cfg(feature = "std")] -impl<'a, C, I, S, SC, SP, ST> EventRestarter - for SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +impl<'a, C, I, MT, S, SC, SP> EventRestarter + for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { /// Reset the single page (we reuse it over and over from pos 0), then send the current state to the next runner. fn on_restart(&mut self, state: &mut S) -> Result<(), Error> { @@ -263,14 +263,14 @@ where } #[cfg(feature = "std")] -impl<'a, C, E, I, S, SC, SP, ST, Z> EventProcessor - for SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +impl<'a, C, E, I, S, SC, SP, MT, Z> EventProcessor + for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { fn process(&mut self, fuzzer: &mut Z, state: &mut S, executor: &mut E) -> Result { self.simple_event_mgr.process(fuzzer, state, executor) @@ -278,26 +278,26 @@ where } #[cfg(feature = "std")] -impl<'a, C, E, I, S, SC, SP, ST, Z> EventManager - for SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +impl<'a, C, E, I, S, SC, SP, MT, Z> EventManager + for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, - ST: Stats, //CE: CustomEvent, + MT: Monitor, //CE: CustomEvent, { } #[cfg(feature = "std")] -impl<'a, C, I, S, SC, SP, ST> HasEventManagerId - for SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +impl<'a, C, I, MT, S, SC, SP> HasEventManagerId + for SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: Serialize, SP: ShMemProvider, - ST: Stats, + MT: Monitor, { fn mgr_id(&self) -> EventManagerId { self.simple_event_mgr.mgr_id() @@ -306,20 +306,20 @@ where #[cfg(feature = "std")] #[allow(clippy::type_complexity, clippy::too_many_lines)] -impl<'a, C, I, S, SC, SP, ST> SimpleRestartingEventManager<'a, C, I, S, SC, SP, ST> +impl<'a, C, I, MT, S, SC, SP> SimpleRestartingEventManager<'a, C, I, MT, S, SC, SP> where C: Corpus, I: Input, S: DeserializeOwned + Serialize + HasCorpus + HasSolutions, SC: Corpus, SP: ShMemProvider, - ST: Stats, //TODO CE: CustomEvent, + MT: Monitor, //TODO CE: CustomEvent, { /// Creates a new [`SimpleEventManager`]. - fn new_launched(stats: ST, staterestorer: StateRestorer) -> Self { + fn new_launched(monitor: MT, staterestorer: StateRestorer) -> Self { Self { staterestorer, - simple_event_mgr: SimpleEventManager::new(stats), + simple_event_mgr: SimpleEventManager::new(monitor), _phantom: PhantomData {}, } } @@ -328,7 +328,7 @@ where /// This [`EventManager`] is simple and single threaded, /// but can still used shared maps to recover from crashes and timeouts. #[allow(clippy::similar_names)] - pub fn launch(mut stats: ST, shmem_provider: &mut SP) -> Result<(Option, Self), Error> { + pub fn launch(mut monitor: MT, shmem_provider: &mut SP) -> Result<(Option, Self), Error> { // We start ourself as child process to actually fuzz let mut staterestorer = if std::env::var(_ENV_FUZZER_SENDER).is_err() { // First, create a place to store state in, for restarts. @@ -397,7 +397,7 @@ where // Mgr to send and receive msgs from/to all other fuzzer instances ( None, - SimpleRestartingEventManager::new_launched(stats, staterestorer), + SimpleRestartingEventManager::new_launched(monitor, staterestorer), ) } // Restoring from a previous run, deserialize state and corpus. @@ -406,14 +406,14 @@ where // We reset the staterestorer, the next staterestorer and receiver (after crash) will reuse the page from the initial message. staterestorer.reset(); - // load the corpus size into stats to still display the correct numbers after restart. - let client_stats = stats.client_stats_mut_for(0); + // load the corpus size into monitor to still display the correct numbers after restart. + let client_stats = monitor.client_stats_mut_for(0); client_stats.update_corpus_size(state.corpus().count().try_into()?); client_stats.update_objective_size(state.solutions().count().try_into()?); ( Some(state), - SimpleRestartingEventManager::new_launched(stats, staterestorer), + SimpleRestartingEventManager::new_launched(monitor, staterestorer), ) } }; diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 89018517aa..199b3f5f52 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -33,7 +33,7 @@ use crate::{ fuzzer::HasObjective, inputs::Input, observers::ObserversTuple, - state::{HasClientPerfStats, HasSolutions}, + state::{HasClientPerfMonitor, HasSolutions}, Error, }; @@ -166,7 +166,7 @@ where EM: EventFirer + EventRestarter, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { #[cfg(unix)] @@ -333,7 +333,7 @@ mod unix_signal_handler { fuzzer::HasObjective, inputs::Input, observers::ObserversTuple, - state::{HasClientPerfStats, HasMetadata, HasSolutions}, + state::{HasClientPerfMonitor, HasMetadata, HasSolutions}, }; pub type HandlerFuncPtr = @@ -397,7 +397,7 @@ mod unix_signal_handler { OT: ObserversTuple, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -475,7 +475,7 @@ mod unix_signal_handler { OT: ObserversTuple, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -608,7 +608,7 @@ mod windows_exception_handler { fuzzer::HasObjective, inputs::Input, observers::ObserversTuple, - state::{HasClientPerfStats, HasMetadata, HasSolutions}, + state::{HasClientPerfMonitor, HasMetadata, HasSolutions}, }; pub type HandlerFuncPtr = @@ -647,7 +647,7 @@ mod windows_exception_handler { OT: ObserversTuple, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -723,7 +723,7 @@ mod windows_exception_handler { OT: ObserversTuple, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, I: Input, Z: HasObjective, { @@ -920,7 +920,7 @@ where EM: EventFirer + EventRestarter, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { Ok(Self { diff --git a/libafl/src/feedbacks/concolic.rs b/libafl/src/feedbacks/concolic.rs index a8d708f908..9efa963fdf 100644 --- a/libafl/src/feedbacks/concolic.rs +++ b/libafl/src/feedbacks/concolic.rs @@ -9,7 +9,7 @@ use crate::{ concolic::{ConcolicMetadata, ConcolicObserver}, ObserversTuple, }, - state::{HasClientPerfStats, HasMetadata}, + state::{HasClientPerfMonitor, HasMetadata}, Error, }; @@ -42,7 +42,7 @@ impl Named for ConcolicFeedback { impl Feedback for ConcolicFeedback where I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl/src/feedbacks/map.rs b/libafl/src/feedbacks/map.rs index 338a2f8858..72f9c94924 100644 --- a/libafl/src/feedbacks/map.rs +++ b/libafl/src/feedbacks/map.rs @@ -15,9 +15,9 @@ use crate::{ executors::ExitKind, feedbacks::{Feedback, FeedbackState, FeedbackStatesTuple}, inputs::Input, + monitors::UserStats, observers::{MapObserver, ObserversTuple}, - state::{HasClientPerfStats, HasFeedbackStates, HasMetadata}, - stats::UserStats, + state::{HasClientPerfMonitor, HasFeedbackStates, HasMetadata}, Error, }; @@ -324,7 +324,7 @@ where O: MapObserver, MF: MapFindFilter, I: Input, - S: HasFeedbackStates + HasClientPerfStats, + S: HasFeedbackStates + HasClientPerfMonitor, FT: FeedbackStatesTuple, { fn is_interesting( @@ -552,7 +552,7 @@ impl Feedback for ReachabilityFeedback where I: Input, O: MapObserver, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl/src/feedbacks/mod.rs b/libafl/src/feedbacks/mod.rs index 024542a34b..4c689ac1da 100644 --- a/libafl/src/feedbacks/mod.rs +++ b/libafl/src/feedbacks/mod.rs @@ -24,7 +24,7 @@ use crate::{ executors::ExitKind, inputs::Input, observers::{ObserversTuple, TimeObserver}, - state::HasClientPerfStats, + state::HasClientPerfMonitor, Error, }; @@ -36,7 +36,7 @@ use core::{marker::PhantomData, time::Duration}; pub trait Feedback: Named where I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { /// `is_interesting ` return if an input is worth the addition to the corpus fn is_interesting( @@ -76,7 +76,7 @@ where // Add this stat to the feedback metrics state - .introspection_stats_mut() + .introspection_monitor_mut() .update_feedback(self.name(), elapsed); ret @@ -136,7 +136,7 @@ where B: Feedback, FL: FeedbackLogic, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { pub first: A, pub second: B, @@ -150,7 +150,7 @@ where B: Feedback, FL: FeedbackLogic, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn name(&self) -> &str { self.name.as_ref() @@ -163,7 +163,7 @@ where B: Feedback, FL: FeedbackLogic, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { pub fn new(first: A, second: B) -> Self { let name = format!("{} ({},{})", FL::name(), first.name(), second.name()); @@ -182,7 +182,7 @@ where B: Feedback, FL: FeedbackLogic, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, @@ -249,7 +249,7 @@ where A: Feedback, B: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn name() -> &'static str; @@ -292,7 +292,7 @@ where A: Feedback, B: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn name() -> &'static str { "Eager OR" @@ -343,7 +343,7 @@ where A: Feedback, B: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn name() -> &'static str { "Fast OR" @@ -400,7 +400,7 @@ where A: Feedback, B: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn name() -> &'static str { "Eager AND" @@ -451,7 +451,7 @@ where A: Feedback, B: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn name() -> &'static str { "Fast AND" @@ -526,7 +526,7 @@ pub struct NotFeedback where A: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { /// The feedback to invert pub first: A, @@ -539,7 +539,7 @@ impl Feedback for NotFeedback where A: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, @@ -573,7 +573,7 @@ impl Named for NotFeedback where A: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { #[inline] fn name(&self) -> &str { @@ -585,7 +585,7 @@ impl NotFeedback where A: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { /// Creates a new [`NotFeedback`]. pub fn new(first: A) -> Self { @@ -653,7 +653,7 @@ macro_rules! feedback_not { impl Feedback for () where I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, @@ -685,7 +685,7 @@ pub struct CrashFeedback {} impl Feedback for CrashFeedback where I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, @@ -735,7 +735,7 @@ pub struct TimeoutFeedback {} impl Feedback for TimeoutFeedback where I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, @@ -790,7 +790,7 @@ pub struct TimeFeedback { impl Feedback for TimeFeedback where I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl/src/feedbacks/nautilus.rs b/libafl/src/feedbacks/nautilus.rs index 6e49a7526e..b7125f016f 100644 --- a/libafl/src/feedbacks/nautilus.rs +++ b/libafl/src/feedbacks/nautilus.rs @@ -11,7 +11,7 @@ use crate::{ generators::NautilusContext, inputs::NautilusInput, observers::ObserversTuple, - state::{HasClientPerfStats, HasMetadata}, + state::{HasClientPerfMonitor, HasMetadata}, Error, }; @@ -52,7 +52,7 @@ impl<'a> Named for NautilusFeedback<'a> { impl<'a, S> Feedback for NautilusFeedback<'a> where - S: HasMetadata + HasClientPerfStats, + S: HasMetadata + HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index 403400f164..be8c44b6aa 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -11,19 +11,19 @@ use crate::{ observers::ObserversTuple, stages::StagesTuple, start_timer, - state::{HasClientPerfStats, HasCorpus, HasExecutions, HasSolutions}, + state::{HasClientPerfMonitor, HasCorpus, HasExecutions, HasSolutions}, Error, }; #[cfg(feature = "introspection")] -use crate::stats::PerfFeature; +use crate::monitors::PerfFeature; #[cfg(feature = "introspection")] use alloc::boxed::Box; use alloc::string::ToString; use core::{marker::PhantomData, time::Duration}; -/// Send a stats update all 15 (or more) seconds +/// Send a monitor update all 15 (or more) seconds const STATS_TIMEOUT_DEFAULT: Duration = Duration::from_secs(15); /// Holds a scheduler @@ -44,7 +44,7 @@ pub trait HasFeedback where F: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { /// The feedback fn feedback(&self) -> &F; @@ -58,7 +58,7 @@ pub trait HasObjective where OF: Feedback, I: Input, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { /// The objective feedback fn objective(&self) -> &OF; @@ -172,10 +172,10 @@ pub trait Fuzzer { manager: &mut EM, ) -> Result { let mut last = current_time(); - let stats_timeout = STATS_TIMEOUT_DEFAULT; + let monitor_timeout = STATS_TIMEOUT_DEFAULT; loop { self.fuzz_one(stages, executor, state, manager)?; - last = Self::maybe_report_stats(state, manager, last, stats_timeout)?; + last = Self::maybe_report_monitor(state, manager, last, monitor_timeout)?; } } @@ -201,11 +201,11 @@ pub trait Fuzzer { let mut ret = 0; let mut last = current_time(); - let stats_timeout = STATS_TIMEOUT_DEFAULT; + let monitor_timeout = STATS_TIMEOUT_DEFAULT; for _ in 0..iters { ret = self.fuzz_one(stages, executor, state, manager)?; - last = Self::maybe_report_stats(state, manager, last, stats_timeout)?; + last = Self::maybe_report_monitor(state, manager, last, monitor_timeout)?; } // If we would assume the fuzzer loop will always exit after this, we could do this here: @@ -216,14 +216,14 @@ pub trait Fuzzer { Ok(ret) } - /// Given the last time, if `stats_timeout` seconds passed, send off an info/stats/heartbeat message to the broker. - /// Returns the new `last` time (so the old one, unless `stats_timeout` time has passed and stats have been sent) - /// Will return an [`crate::Error`], if the stats could not be sent. - fn maybe_report_stats( + /// Given the last time, if `monitor_timeout` seconds passed, send off an info/monitor/heartbeat message to the broker. + /// Returns the new `last` time (so the old one, unless `monitor_timeout` time has passed and monitor have been sent) + /// Will return an [`crate::Error`], if the monitor could not be sent. + fn maybe_report_monitor( state: &mut S, manager: &mut EM, last: Duration, - stats_timeout: Duration, + monitor_timeout: Duration, ) -> Result; } @@ -242,7 +242,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { scheduler: CS, feedback: F, @@ -257,7 +257,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn scheduler(&self) -> &CS { &self.scheduler @@ -274,7 +274,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn feedback(&self) -> &F { &self.feedback @@ -291,7 +291,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn objective(&self) -> &OF { &self.objective @@ -312,7 +312,7 @@ where I: Input, OF: Feedback, OT: ObserversTuple + serde::Serialize + serde::de::DeserializeOwned, - S: HasCorpus + HasSolutions + HasClientPerfStats + HasExecutions, + S: HasCorpus + HasSolutions + HasClientPerfMonitor + HasExecutions, { /// Evaluate if a set of observation channels has an interesting state fn process_execution( @@ -428,7 +428,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasExecutions + HasCorpus + HasSolutions + HasClientPerfStats, + S: HasExecutions + HasCorpus + HasSolutions + HasClientPerfMonitor, SC: Corpus, { /// Process one input, adding to the respective corpuses if needed and firing the right events @@ -462,7 +462,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasExecutions + HasCorpus + HasSolutions + HasClientPerfStats, + S: HasExecutions + HasCorpus + HasSolutions + HasClientPerfMonitor, SC: Corpus, { /// Process one input, adding to the respective corpuses if needed and firing the right events @@ -527,46 +527,46 @@ where EM: EventManager, F: Feedback, I: Input, - S: HasExecutions + HasClientPerfStats, + S: HasExecutions + HasClientPerfMonitor, OF: Feedback, ST: StagesTuple, { #[inline] - fn maybe_report_stats( + fn maybe_report_monitor( state: &mut S, manager: &mut EM, last: Duration, - stats_timeout: Duration, + monitor_timeout: Duration, ) -> Result { let cur = current_time(); // default to 0 here to avoid crashes on clock skew - if cur.checked_sub(last).unwrap_or_default() > stats_timeout { + if cur.checked_sub(last).unwrap_or_default() > monitor_timeout { // Default no introspection implmentation #[cfg(not(feature = "introspection"))] manager.fire( state, - Event::UpdateStats { + Event::UpdateExecutions { executions: *state.executions(), time: cur, phantom: PhantomData, }, )?; - // If performance stats are requested, fire the `UpdatePerfStats` event + // If performance monitor are requested, fire the `UpdatePerfMonitor` event #[cfg(feature = "introspection")] { state - .introspection_stats_mut() + .introspection_monitor_mut() .set_current_time(crate::bolts::cpu::read_time_counter()); - // Send the current stats over to the manager. This `.clone` shouldn't be - // costly as `ClientPerfStats` impls `Copy` since it only contains `u64`s + // Send the current monitor over to the manager. This `.clone` shouldn't be + // costly as `ClientPerfMonitor` impls `Copy` since it only contains `u64`s manager.fire( state, - Event::UpdatePerfStats { + Event::UpdatePerfMonitor { executions: *state.executions(), time: cur, - introspection_stats: Box::new(state.introspection_stats().clone()), + introspection_monitor: Box::new(state.introspection_monitor().clone()), phantom: PhantomData, }, )?; @@ -588,32 +588,32 @@ where ) -> Result { // Init timer for scheduler #[cfg(feature = "introspection")] - state.introspection_stats_mut().start_timer(); + state.introspection_monitor_mut().start_timer(); // Get the next index from the scheduler let idx = self.scheduler.next(state)?; // Mark the elapsed time for the scheduler #[cfg(feature = "introspection")] - state.introspection_stats_mut().mark_scheduler_time(); + state.introspection_monitor_mut().mark_scheduler_time(); // Mark the elapsed time for the scheduler #[cfg(feature = "introspection")] - state.introspection_stats_mut().reset_stage_index(); + state.introspection_monitor_mut().reset_stage_index(); // Execute all stages stages.perform_all(self, executor, state, manager, idx)?; // Init timer for manager #[cfg(feature = "introspection")] - state.introspection_stats_mut().start_timer(); + state.introspection_monitor_mut().start_timer(); // Execute the manager manager.process(self, state, executor)?; // Mark the elapsed time for the manager #[cfg(feature = "introspection")] - state.introspection_stats_mut().mark_manager_time(); + state.introspection_monitor_mut().mark_manager_time(); Ok(idx) } @@ -625,7 +625,7 @@ where F: Feedback, I: Input, OF: Feedback, - S: HasExecutions + HasClientPerfStats, + S: HasExecutions + HasClientPerfMonitor, { /// Create a new `StdFuzzer` with standard behavior. pub fn new(scheduler: CS, feedback: F, objective: OF) -> Self { diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index 56196d3073..6df1af87ff 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -31,15 +31,36 @@ pub mod executors; pub mod feedbacks; pub mod generators; pub mod inputs; +pub mod monitors; pub mod mutators; pub mod observers; pub mod stages; pub mod state; -pub mod stats; pub mod fuzzer; pub use fuzzer::*; +/// The `stats` module got renamed to [`monitors`]. +/// It monitors and displays the statistics of the fuzzing process. +#[deprecated(since = "0.6.0", note = "The `stats` module got renamed to `monitors`")] +pub mod stats { + #[deprecated( + since = "0.6.0", + note = "Use monitors::MultiMonitor instead of stats::MultiStats!" + )] + pub use crate::monitors::MultiMonitor as MultiStats; + #[deprecated( + since = "0.6.0", + note = "Use monitors::SimpleMonitor instead of stats::SimpleStats!" + )] + pub use crate::monitors::SimpleMonitor as SimpleStats; + #[deprecated( + since = "0.6.0", + note = "Use monitors::UserMonitor instead of stats::SimpleStats!" + )] + pub use crate::monitors::UserStats; +} + use alloc::string::String; use core::fmt; @@ -173,10 +194,10 @@ mod tests { corpus::{Corpus, InMemoryCorpus, RandCorpusScheduler, Testcase}, executors::{ExitKind, InProcessExecutor}, inputs::BytesInput, + monitors::SimpleMonitor, mutators::{mutations::BitFlipMutator, StdScheduledMutator}, stages::StdMutationalStage, state::{HasCorpus, StdState}, - stats::SimpleStats, Fuzzer, StdFuzzer, }; @@ -199,10 +220,10 @@ mod tests { tuple_list!(), ); - let stats = SimpleStats::new(|s| { + let monitor = SimpleMonitor::new(|s| { println!("{}", s); }); - let mut event_manager = SimpleEventManager::new(stats); + let mut event_manager = SimpleEventManager::new(monitor); let scheduler = RandCorpusScheduler::new(); let mut fuzzer = StdFuzzer::new(scheduler, (), ()); diff --git a/libafl/src/stats/mod.rs b/libafl/src/monitors/mod.rs similarity index 88% rename from libafl/src/stats/mod.rs rename to libafl/src/monitors/mod.rs index 8ab9c389f8..476a4cb22a 100644 --- a/libafl/src/stats/mod.rs +++ b/libafl/src/monitors/mod.rs @@ -1,7 +1,7 @@ //! Keep stats, and dispaly them to the user. Usually used in a broker, or main node, of some sort. pub mod multi; -pub use multi::MultiStats; +pub use multi::MultiMonitor; use serde::{Deserialize, Serialize}; @@ -17,7 +17,7 @@ use crate::bolts::current_time; const CLIENT_STATS_TIME_WINDOW_SECS: u64 = 5; // 5 seconds -/// User-defined stats types +/// User-defined stat types #[derive(Serialize, Deserialize, Debug, Clone)] pub enum UserStats { Number(u64), @@ -41,10 +41,10 @@ impl fmt::Display for UserStats { } } -/// A simple struct to keep track of client stats +/// A simple struct to keep track of client monitor #[derive(Debug, Clone, Default)] pub struct ClientStats { - // stats (maybe we need a separated struct?) + // monitor (maybe we need a separated struct?) /// The corpus size for this client pub corpus_size: u64, /// The total executions for this client @@ -57,12 +57,12 @@ pub struct ClientStats { pub last_window_time: time::Duration, /// The last executions per sec pub last_execs_per_sec: f32, - /// User-defined stats - pub user_stats: HashMap, + /// User-defined monitor + pub user_monitor: HashMap, /// Client performance statistics #[cfg(feature = "introspection")] - pub introspection_stats: ClientPerfStats, + pub introspection_monitor: ClientPerfMonitor, } impl ClientStats { @@ -121,33 +121,33 @@ impl ClientStats { /// Update the user-defined stat with name and value pub fn update_user_stats(&mut self, name: String, value: UserStats) { - self.user_stats.insert(name, value); + self.user_monitor.insert(name, value); } /// Get a user-defined stat using the name pub fn get_user_stats(&mut self, name: &str) -> Option<&UserStats> { - self.user_stats.get(name) + self.user_monitor.get(name) } - /// Update the current [`ClientPerfStats`] with the given [`ClientPerfStats`] + /// Update the current [`ClientPerfMonitor`] with the given [`ClientPerfMonitor`] #[cfg(feature = "introspection")] - pub fn update_introspection_stats(&mut self, introspection_stats: ClientPerfStats) { - self.introspection_stats = introspection_stats; + pub fn update_introspection_monitor(&mut self, introspection_monitor: ClientPerfMonitor) { + self.introspection_monitor = introspection_monitor; } } -/// The stats trait keeps track of all the client's stats, and offers methods to dispaly them. -pub trait Stats { - /// the client stats (mut) +/// The monitor trait keeps track of all the client's monitor, and offers methods to dispaly them. +pub trait Monitor { + /// the client monitor (mut) fn client_stats_mut(&mut self) -> &mut Vec; - /// the client stats + /// the client monitor fn client_stats(&self) -> &[ClientStats]; /// creation time fn start_time(&mut self) -> time::Duration; - /// show the stats to the user + /// show the monitor to the user fn display(&mut self, event_msg: String, sender_id: u32); /// Amount of elements in the corpus (combined for all children) @@ -181,7 +181,7 @@ pub trait Stats { .fold(0_u64, |acc, x| acc + x.execs_per_sec(cur_time)) } - /// The client stats for a specific id, creating new if it doesn't exist + /// The client monitor for a specific id, creating new if it doesn't exist fn client_stats_mut_for(&mut self, client_id: u32) -> &mut ClientStats { let client_stat_count = self.client_stats().len(); for _ in client_stat_count..(client_id + 1) as usize { @@ -194,20 +194,20 @@ pub trait Stats { } } -/// Stats that print exactly nothing. +/// Monitor that print exactly nothing. /// Not good for debuging, very good for speed. -pub struct NopStats { +pub struct NopMonitor { start_time: Duration, client_stats: Vec, } -impl Stats for NopStats { - /// the client stats, mutable +impl Monitor for NopMonitor { + /// the client monitor, mutable fn client_stats_mut(&mut self) -> &mut Vec { &mut self.client_stats } - /// the client stats + /// the client monitor fn client_stats(&self) -> &[ClientStats] { &self.client_stats } @@ -220,8 +220,8 @@ impl Stats for NopStats { fn display(&mut self, _event_msg: String, _sender_id: u32) {} } -impl NopStats { - /// Create new [`NopStats`] +impl NopMonitor { + /// Create new [`NopMonitor`] #[must_use] pub fn new() -> Self { Self { @@ -231,15 +231,15 @@ impl NopStats { } } -impl Default for NopStats { +impl Default for NopMonitor { fn default() -> Self { Self::new() } } -/// Tracking stats during fuzzing. +/// Tracking monitor during fuzzing. #[derive(Clone, Debug)] -pub struct SimpleStats +pub struct SimpleMonitor where F: FnMut(String), { @@ -248,16 +248,16 @@ where client_stats: Vec, } -impl Stats for SimpleStats +impl Monitor for SimpleMonitor where F: FnMut(String), { - /// the client stats, mutable + /// the client monitor, mutable fn client_stats_mut(&mut self) -> &mut Vec { &mut self.client_stats } - /// the client stats + /// the client monitor fn client_stats(&self) -> &[ClientStats] { &self.client_stats } @@ -269,7 +269,8 @@ where fn display(&mut self, event_msg: String, sender_id: u32) { let fmt = format!( - "[{} #{}] clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", + "{}: [{} #{}] clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", + (current_time() - self.start_time).as_millis(), event_msg, sender_id, self.client_stats().len(), @@ -280,13 +281,13 @@ where ); (self.print_fn)(fmt); - // Only print perf stats if the feature is enabled + // Only print perf monitor if the feature is enabled #[cfg(feature = "introspection")] { - // Print the client performance stats. + // Print the client performance monitor. let fmt = format!( "Client {:03}:\n{}", - sender_id, self.client_stats[sender_id as usize].introspection_stats + sender_id, self.client_stats[sender_id as usize].introspection_monitor ); (self.print_fn)(fmt); @@ -296,11 +297,11 @@ where } } -impl SimpleStats +impl SimpleMonitor where F: FnMut(String), { - /// Creates the stats, using the `current_time` as `start_time`. + /// Creates the monitor, using the `current_time` as `start_time`. pub fn new(print_fn: F) -> Self { Self { print_fn, @@ -309,7 +310,7 @@ where } } - /// Creates the stats with a given `start_time`. + /// Creates the monitor with a given `start_time`. pub fn with_time(print_fn: F, start_time: time::Duration) -> Self { Self { print_fn, @@ -324,7 +325,7 @@ macro_rules! start_timer { ($state:expr) => {{ // Start the timer #[cfg(feature = "introspection")] - $state.introspection_stats_mut().start_timer(); + $state.introspection_monitor_mut().start_timer(); }}; } @@ -333,7 +334,9 @@ macro_rules! mark_feature_time { ($state:expr, $feature:expr) => {{ // Mark the elapsed time for the given feature #[cfg(feature = "introspection")] - $state.introspection_stats_mut().mark_feature_time($feature); + $state + .introspection_monitor_mut() + .mark_feature_time($feature); }}; } @@ -342,13 +345,13 @@ macro_rules! mark_feedback_time { ($state:expr) => {{ // Mark the elapsed time for the given feature #[cfg(feature = "introspection")] - $state.introspection_stats_mut().mark_feedback_time(); + $state.introspection_monitor_mut().mark_feedback_time(); }}; } /// Client performance statistics #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct ClientPerfStats { +pub struct ClientPerfMonitor { /// Starting counter (in clock cycles from `read_time_counter`) start_time: u64, @@ -465,8 +468,8 @@ impl From for PerfFeature { pub const NUM_PERF_FEATURES: usize = PerfFeature::Count as usize; #[cfg(feature = "introspection")] -impl ClientPerfStats { - /// Create a blank [`ClientPerfStats`] with the `start_time` and `current_time` with +impl ClientPerfMonitor { + /// Create a blank [`ClientPerfMonitor`] with the `start_time` and `current_time` with /// the current clock counter #[must_use] pub fn new() -> Self { @@ -497,13 +500,13 @@ impl ClientPerfStats { self.timer_start = Some(crate::bolts::cpu::read_time_counter()); } - /// Update the current [`ClientPerfStats`] with the given [`ClientPerfStats`] - pub fn update(&mut self, stats: &ClientPerfStats) { - self.set_current_time(stats.current_time); - self.update_scheduler(stats.scheduler); - self.update_manager(stats.manager); - self.update_stages(&stats.stages); - self.update_feedbacks(&stats.feedbacks); + /// Update the current [`ClientPerfMonitor`] with the given [`ClientPerfMonitor`] + pub fn update(&mut self, monitor: &ClientPerfMonitor) { + self.set_current_time(monitor.current_time); + self.update_scheduler(monitor.scheduler); + self.update_manager(monitor.manager); + self.update_stages(&monitor.stages); + self.update_feedbacks(&monitor.feedbacks); } /// Gets the elapsed time since the internal timer started. Resets the timer when @@ -562,7 +565,7 @@ impl ClientPerfStats { self.update_feature(feature, elapsed); } - /// Add the given `time` to the `scheduler` stats + /// Add the given `time` to the `scheduler` monitor #[inline] pub fn update_scheduler(&mut self, time: u64) { self.scheduler = self @@ -571,7 +574,7 @@ impl ClientPerfStats { .expect("update_scheduler overflow"); } - /// Add the given `time` to the `manager` stats + /// Add the given `time` to the `manager` monitor #[inline] pub fn update_manager(&mut self, time: u64) { self.manager = self @@ -689,10 +692,10 @@ impl ClientPerfStats { } #[cfg(feature = "introspection")] -impl core::fmt::Display for ClientPerfStats { +impl core::fmt::Display for ClientPerfMonitor { #[allow(clippy::cast_precision_loss)] fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { - // Calculate the elapsed time from the stats + // Calculate the elapsed time from the monitor let elapsed: f64 = self.elapsed_cycles() as f64; // Calculate the percentages for each benchmark @@ -762,7 +765,7 @@ impl core::fmt::Display for ClientPerfStats { } #[cfg(feature = "introspection")] -impl Default for ClientPerfStats { +impl Default for ClientPerfMonitor { #[must_use] fn default() -> Self { Self::new() diff --git a/libafl/src/stats/multi.rs b/libafl/src/monitors/multi.rs similarity index 79% rename from libafl/src/stats/multi.rs rename to libafl/src/monitors/multi.rs index 615b5d47f2..c767800b4f 100644 --- a/libafl/src/stats/multi.rs +++ b/libafl/src/monitors/multi.rs @@ -1,4 +1,4 @@ -//! Stats to disply both cumulative and per-client stats +//! Monitor to disply both cumulative and per-client monitor use alloc::{string::String, vec::Vec}; use core::{time, time::Duration}; @@ -8,12 +8,12 @@ use alloc::string::ToString; use crate::{ bolts::current_time, - stats::{ClientStats, Stats}, + monitors::{ClientStats, Monitor}, }; -/// Tracking stats during fuzzing and display both per-client and cumulative info. +/// Tracking monitor during fuzzing and display both per-client and cumulative info. #[derive(Clone, Debug)] -pub struct MultiStats +pub struct MultiMonitor where F: FnMut(String), { @@ -22,16 +22,16 @@ where client_stats: Vec, } -impl Stats for MultiStats +impl Monitor for MultiMonitor where F: FnMut(String), { - /// the client stats, mutable + /// the client monitor, mutable fn client_stats_mut(&mut self) -> &mut Vec { &mut self.client_stats } - /// the client stats + /// the client monitor fn client_stats(&self) -> &[ClientStats] { &self.client_stats } @@ -69,17 +69,17 @@ where " {} (CLIENT) corpus: {}, objectives: {}, executions: {}, exec/sec: {}", pad, client.corpus_size, client.objective_size, client.executions, exec_sec ); - for (key, val) in &client.user_stats { + for (key, val) in &client.user_monitor { fmt += &format!(", {}: {}", key, val); } (self.print_fn)(fmt); - // Only print perf stats if the feature is enabled + // Only print perf monitor if the feature is enabled #[cfg(feature = "introspection")] { - // Print the client performance stats. Skip the Client 0 which is the broker + // Print the client performance monitor. Skip the Client 0 which is the broker for (i, client) in self.client_stats.iter().skip(1).enumerate() { - let fmt = format!("Client {:03}:\n{}", i + 1, client.introspection_stats); + let fmt = format!("Client {:03}:\n{}", i + 1, client.introspection_monitor); (self.print_fn)(fmt); } @@ -89,11 +89,11 @@ where } } -impl MultiStats +impl MultiMonitor where F: FnMut(String), { - /// Creates the stats, using the `current_time` as `start_time`. + /// Creates the monitor, using the `current_time` as `start_time`. pub fn new(print_fn: F) -> Self { Self { print_fn, @@ -102,7 +102,7 @@ where } } - /// Creates the stats with a given `start_time`. + /// Creates the monitor with a given `start_time`. pub fn with_time(print_fn: F, start_time: time::Duration) -> Self { Self { print_fn, diff --git a/libafl/src/stages/concolic.rs b/libafl/src/stages/concolic.rs index 909768b67c..2d41fb650d 100644 --- a/libafl/src/stages/concolic.rs +++ b/libafl/src/stages/concolic.rs @@ -9,7 +9,7 @@ use crate::{ executors::{Executor, HasObservers}, inputs::Input, observers::{concolic::ConcolicObserver, ObserversTuple}, - state::{HasClientPerfStats, HasCorpus, HasExecutions, HasMetadata}, + state::{HasClientPerfMonitor, HasCorpus, HasExecutions, HasMetadata}, Error, }; @@ -23,7 +23,7 @@ where C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { inner: TracingStage, observer_name: String, @@ -35,7 +35,7 @@ where C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { #[inline] fn perform( @@ -73,7 +73,7 @@ where C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { /// Creates a new default tracing stage using the given [`Executor`], observing traces from a [`ConcolicObserver`] with the given name. pub fn new(inner: TracingStage, observer_name: String) -> Self { @@ -93,7 +93,7 @@ use crate::{ }; #[cfg(all(feature = "concolic_mutation", feature = "introspection"))] -use crate::stats::PerfFeature; +use crate::monitors::PerfFeature; #[cfg(feature = "concolic_mutation")] #[allow(clippy::too_many_lines)] @@ -348,7 +348,7 @@ pub struct SimpleConcolicMutationalStage where I: Input, C: Corpus, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { _phantom: PhantomData<(C, EM, I, S, Z)>, } @@ -358,7 +358,7 @@ impl Stage for SimpleConcolicMutationalStage, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, Z: Evaluator, { #[inline] @@ -402,7 +402,7 @@ impl Default for SimpleConcolicMutationalStage where I: Input, C: Corpus, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { fn default() -> Self { Self { diff --git a/libafl/src/stages/mutational.rs b/libafl/src/stages/mutational.rs index f81dfe28a1..317557d700 100644 --- a/libafl/src/stages/mutational.rs +++ b/libafl/src/stages/mutational.rs @@ -12,12 +12,12 @@ use crate::{ mutators::Mutator, stages::Stage, start_timer, - state::{HasClientPerfStats, HasCorpus, HasRand}, + state::{HasClientPerfMonitor, HasCorpus, HasRand}, Error, }; #[cfg(feature = "introspection")] -use crate::stats::PerfFeature; +use crate::monitors::PerfFeature; // TODO multi mutators stage @@ -29,7 +29,7 @@ where C: Corpus, M: Mutator, I: Input, - S: HasClientPerfStats + HasCorpus, + S: HasClientPerfMonitor + HasCorpus, Z: Evaluator, { /// The mutator registered for this stage @@ -90,7 +90,7 @@ where M: Mutator, I: Input, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { mutator: M, @@ -105,7 +105,7 @@ where M: Mutator, I: Input, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { /// The mutator, added to this stage @@ -132,7 +132,7 @@ where M: Mutator, I: Input, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { #[inline] @@ -148,7 +148,7 @@ where let ret = self.perform_mutational(fuzzer, executor, state, manager, corpus_idx); #[cfg(feature = "introspection")] - state.introspection_stats_mut().finish_stage(); + state.introspection_monitor_mut().finish_stage(); ret } @@ -160,7 +160,7 @@ where M: Mutator, I: Input, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: Evaluator, { /// Creates a new default mutational stage diff --git a/libafl/src/stages/power.rs b/libafl/src/stages/power.rs index ac4e6854d1..ef37673409 100644 --- a/libafl/src/stages/power.rs +++ b/libafl/src/stages/power.rs @@ -12,7 +12,7 @@ use crate::{ mutators::Mutator, observers::{MapObserver, ObserversTuple}, stages::{MutationalStage, PowerScheduleMetadata, Stage}, - state::{HasClientPerfStats, HasCorpus, HasMetadata}, + state::{HasClientPerfMonitor, HasCorpus, HasMetadata}, Error, }; @@ -41,7 +41,7 @@ where M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfStats + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { map_observer_name: String, @@ -62,7 +62,7 @@ where M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfStats + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { /// The mutator, added to this stage @@ -163,7 +163,7 @@ where M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfStats + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { #[inline] @@ -190,7 +190,7 @@ where M: Mutator, O: MapObserver, OT: ObserversTuple, - S: HasClientPerfStats + HasCorpus + HasMetadata, + S: HasClientPerfMonitor + HasCorpus + HasMetadata, Z: Evaluator, { pub fn new(mutator: M, strat: PowerSchedule, map_observer_name: &O) -> Self { diff --git a/libafl/src/stages/push/mutational.rs b/libafl/src/stages/push/mutational.rs index d657935d4a..ffb50c7a84 100644 --- a/libafl/src/stages/push/mutational.rs +++ b/libafl/src/stages/push/mutational.rs @@ -19,14 +19,14 @@ use crate::{ mutators::Mutator, observers::ObserversTuple, start_timer, - state::{HasClientPerfStats, HasCorpus, HasRand}, + state::{HasClientPerfMonitor, HasCorpus, HasRand}, Error, EvaluatorObservers, ExecutionProcessor, Fuzzer, HasCorpusScheduler, }; #[cfg(feature = "introspection")] -use crate::stats::PerfFeature; +use crate::monitors::PerfFeature; -/// Send a stats update all 15 (or more) seconds +/// Send a monitor update all 15 (or more) seconds const STATS_TIMEOUT_DEFAULT: Duration = Duration::from_secs(15); pub static DEFAULT_MUTATIONAL_MAX_ITERATIONS: u64 = 128; @@ -50,7 +50,7 @@ where M: Mutator, OT: ObserversTuple, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + Fuzzer<(), EM, I, S, ()> @@ -73,7 +73,7 @@ where mutator: M, #[allow(clippy::type_complexity)] phantom: PhantomData<(C, CS, (), EM, I, R, OT, S, Z)>, - last_stats_time: Duration, + last_monitor_time: Duration, observers: Rc>, exit_kind: Rc>>, } @@ -87,7 +87,7 @@ where M: Mutator, OT: ObserversTuple, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + Fuzzer<(), EM, I, S, ()> @@ -188,7 +188,7 @@ where M: Mutator, OT: ObserversTuple, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + Fuzzer<(), EM, I, S, ()> @@ -219,14 +219,14 @@ where //let fuzzer: &mut Z = &mut (*self.fuzzer).borrow_mut(); let event_mgr: &mut EM = &mut (*self.event_mgr).borrow_mut(); - self.last_stats_time = Z::maybe_report_stats( + self.last_monitor_time = Z::maybe_report_monitor( state, event_mgr, - self.last_stats_time, + self.last_monitor_time, STATS_TIMEOUT_DEFAULT, ) .unwrap(); - //self.fuzzer.maybe_report_stats(); + //self.fuzzer.maybe_report_monitor(); } else { self.exit_kind.replace(None); } @@ -243,7 +243,7 @@ where M: Mutator, OT: ObserversTuple, R: Rand, - S: HasClientPerfStats + HasCorpus + HasRand, + S: HasClientPerfMonitor + HasCorpus + HasRand, Z: ExecutionProcessor + EvaluatorObservers + Fuzzer<(), EM, I, S, ()> @@ -274,7 +274,7 @@ where event_mgr, observers, exit_kind, - last_stats_time: current_time(), + last_monitor_time: current_time(), } } } diff --git a/libafl/src/stages/tracing.rs b/libafl/src/stages/tracing.rs index d0c004eac7..41198ef1bd 100644 --- a/libafl/src/stages/tracing.rs +++ b/libafl/src/stages/tracing.rs @@ -10,12 +10,12 @@ use crate::{ observers::ObserversTuple, stages::Stage, start_timer, - state::{HasClientPerfStats, HasCorpus, HasExecutions}, + state::{HasClientPerfMonitor, HasCorpus, HasExecutions}, Error, }; #[cfg(feature = "introspection")] -use crate::stats::PerfFeature; +use crate::monitors::PerfFeature; /// A stage that runs a tracer executor #[derive(Clone, Debug)] @@ -25,7 +25,7 @@ where C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { tracer_executor: TE, #[allow(clippy::type_complexity)] @@ -38,7 +38,7 @@ where C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { #[inline] fn perform( @@ -88,7 +88,7 @@ where C: Corpus, TE: Executor + HasObservers, OT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { /// Creates a new default stage pub fn new(tracer_executor: TE) -> Self { @@ -118,7 +118,7 @@ where E: Executor + HasObservers, OT: ObserversTuple, SOT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { #[inline] fn perform( @@ -169,7 +169,7 @@ where E: Executor + HasObservers, OT: ObserversTuple, SOT: ObserversTuple, - S: HasClientPerfStats + HasExecutions + HasCorpus, + S: HasClientPerfMonitor + HasExecutions + HasCorpus, { /// Creates a new default stage pub fn new(_executor: &mut ShadowExecutor) -> Self { diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index 7a16c65fce..ecae009a96 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -19,7 +19,7 @@ use crate::{ fuzzer::{Evaluator, ExecuteInputResult}, generators::Generator, inputs::Input, - stats::ClientPerfStats, + monitors::ClientPerfMonitor, Error, }; @@ -71,13 +71,13 @@ where fn rand_mut(&mut self) -> &mut R; } -/// Trait for offering a [`ClientPerfStats`] -pub trait HasClientPerfStats { - /// [`ClientPerfStats`] itself - fn introspection_stats(&self) -> &ClientPerfStats; +/// Trait for offering a [`ClientPerfMonitor`] +pub trait HasClientPerfMonitor { + /// [`ClientPerfMonitor`] itself + fn introspection_monitor(&self) -> &ClientPerfMonitor; - /// Mutatable ref to [`ClientPerfStats`] - fn introspection_stats_mut(&mut self) -> &mut ClientPerfStats; + /// Mutatable ref to [`ClientPerfMonitor`] + fn introspection_monitor_mut(&mut self) -> &mut ClientPerfMonitor; } /// Trait for elements offering metadata @@ -166,7 +166,7 @@ where /// Performance statistics for this fuzzer #[cfg(feature = "introspection")] - introspection_stats: ClientPerfStats, + introspection_monitor: ClientPerfMonitor, phantom: PhantomData, } @@ -559,14 +559,14 @@ where solutions, max_size: DEFAULT_MAX_SIZE, #[cfg(feature = "introspection")] - introspection_stats: ClientPerfStats::new(), + introspection_monitor: ClientPerfMonitor::new(), phantom: PhantomData, } } } #[cfg(feature = "introspection")] -impl HasClientPerfStats for StdState +impl HasClientPerfMonitor for StdState where C: Corpus, I: Input, @@ -574,17 +574,17 @@ where FT: FeedbackStatesTuple, SC: Corpus, { - fn introspection_stats(&self) -> &ClientPerfStats { - &self.introspection_stats + fn introspection_monitor(&self) -> &ClientPerfMonitor { + &self.introspection_monitor } - fn introspection_stats_mut(&mut self) -> &mut ClientPerfStats { - &mut self.introspection_stats + fn introspection_monitor_mut(&mut self) -> &mut ClientPerfMonitor { + &mut self.introspection_monitor } } #[cfg(not(feature = "introspection"))] -impl HasClientPerfStats for StdState +impl HasClientPerfMonitor for StdState where C: Corpus, I: Input, @@ -592,11 +592,11 @@ where FT: FeedbackStatesTuple, SC: Corpus, { - fn introspection_stats(&self) -> &ClientPerfStats { + fn introspection_monitor(&self) -> &ClientPerfMonitor { unimplemented!() } - fn introspection_stats_mut(&mut self) -> &mut ClientPerfStats { + fn introspection_monitor_mut(&mut self) -> &mut ClientPerfMonitor { unimplemented!() } } diff --git a/libafl_frida/src/asan_errors.rs b/libafl_frida/src/asan_errors.rs index c9416872af..0fc2374e0f 100644 --- a/libafl_frida/src/asan_errors.rs +++ b/libafl_frida/src/asan_errors.rs @@ -13,7 +13,7 @@ use libafl::{ feedbacks::Feedback, inputs::{HasTargetBytes, Input}, observers::{Observer, ObserversTuple}, - state::{HasClientPerfStats, HasMetadata}, + state::{HasClientPerfMonitor, HasMetadata}, Error, SerdeAny, }; use serde::{Deserialize, Serialize}; @@ -614,7 +614,7 @@ pub struct AsanErrorsFeedback { impl Feedback for AsanErrorsFeedback where I: Input + HasTargetBytes, - S: HasClientPerfStats, + S: HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index 7bdcdf9b0a..8a751841b9 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -10,7 +10,7 @@ use libafl::{ fuzzer::HasObjective, inputs::Input, observers::ObserversTuple, - state::{HasClientPerfStats, HasSolutions}, + state::{HasClientPerfMonitor, HasSolutions}, Error, }; @@ -386,7 +386,7 @@ where EM: EventFirer + EventRestarter, OC: Corpus, OF: Feedback, - S: HasSolutions + HasClientPerfStats, + S: HasSolutions + HasClientPerfMonitor, Z: HasObjective, { let slf = Self { diff --git a/libafl_sugar/src/forkserver.rs b/libafl_sugar/src/forkserver.rs index 10601b423e..2b863c2fc2 100644 --- a/libafl_sugar/src/forkserver.rs +++ b/libafl_sugar/src/forkserver.rs @@ -20,12 +20,12 @@ use libafl::{ feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, fuzzer::{Fuzzer, StdFuzzer}, generators::RandBytesGenerator, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::Tokens, observers::{ConstMapObserver, HitcountsMapObserver, TimeObserver}, stages::StdMutationalStage, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; @@ -97,7 +97,7 @@ impl<'a> ForkserverBytesCoverageSugar<'a> { let shmem_provider = StdShMemProvider::new().expect("Failed to init shared memory"); - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); let mut run_client = |state: Option>, mut mgr, _core_id| { // Coverage map shared between target and fuzzer @@ -233,7 +233,7 @@ impl<'a> ForkserverBytesCoverageSugar<'a> { let launcher = Launcher::builder() .shmem_provider(shmem_provider) .configuration(conf) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(self.cores) .broker_port(self.broker_port) diff --git a/libafl_sugar/src/inmemory.rs b/libafl_sugar/src/inmemory.rs index 1bfd5b2a36..986f5dea83 100644 --- a/libafl_sugar/src/inmemory.rs +++ b/libafl_sugar/src/inmemory.rs @@ -21,12 +21,12 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::RandBytesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::{I2SRandReplace, Tokens}, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, stages::{ShadowTracingStage, StdMutationalStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, Error, }; @@ -99,7 +99,7 @@ where let shmem_provider = StdShMemProvider::new().expect("Failed to init shared memory"); - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); let mut run_client = |state: Option>, mut mgr, _core_id| { // Create an observation channel using the coverage map @@ -254,7 +254,7 @@ where let launcher = Launcher::builder() .shmem_provider(shmem_provider) .configuration(conf) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(self.cores) .broker_port(self.broker_port) diff --git a/libafl_sugar/src/qemu.rs b/libafl_sugar/src/qemu.rs index 9a20bba107..bd07cf4a51 100644 --- a/libafl_sugar/src/qemu.rs +++ b/libafl_sugar/src/qemu.rs @@ -21,12 +21,12 @@ use libafl::{ fuzzer::{Fuzzer, StdFuzzer}, generators::RandBytesGenerator, inputs::{BytesInput, HasTargetBytes}, + monitors::MultiMonitor, mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::{token_mutations::Tokens, I2SRandReplace}, observers::{HitcountsMapObserver, TimeObserver, VariableMapObserver}, stages::{ShadowTracingStage, StdMutationalStage}, state::{HasCorpus, HasMetadata, StdState}, - stats::MultiStats, }; pub use libafl_qemu::emu; @@ -99,7 +99,7 @@ where let shmem_provider = StdShMemProvider::new().expect("Failed to init shared memory"); - let stats = MultiStats::new(|s| println!("{}", s)); + let monitor = MultiMonitor::new(|s| println!("{}", s)); let mut run_client = |state: Option>, mut mgr, _core_id| { // Create an observation channel using the coverage map @@ -316,7 +316,7 @@ where let launcher = Launcher::builder() .shmem_provider(shmem_provider) .configuration(conf) - .stats(stats) + .monitor(monitor) .run_client(&mut run_client) .cores(self.cores) .broker_port(self.broker_port) diff --git a/scripts/fmt_all.sh b/scripts/fmt_all.sh new file mode 100755 index 0000000000..3d993fa953 --- /dev/null +++ b/scripts/fmt_all.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +cd "$SCRIPT_DIR/.." + +# TODO: This should be rewritten in rust, a Makefile, or some platform-independent language + +echo "Welcome to the happy fmt script. :)" +echo "[*] Running fmt for the main crates" +cargo fmt + +cd fuzzers + +for fuzzer in *; +do + cd $fuzzer + echo "[*] Running fmt for $fuzzer" + cargo fmt --all + cd .. +done