Fix docs (follow-up to #2385) (#2388)

* Fix docs (follow-up to #2385)

* More fix

* fix fuzzer

* More docs
This commit is contained in:
Dominik Maier 2024-07-12 16:13:43 +02:00 committed by GitHub
parent 3c93b96b70
commit 7feeb00546
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 30 additions and 17 deletions

View File

@ -6,6 +6,6 @@ Mutators can be composed, and they are generally linked to a specific Input type
There can be, for instance, a Mutator that applies more than a single type of mutation to the input. Consider a generic Mutator for a byte stream, bit flip is just one of the possible mutations but not the only one, there is also, for instance, the random replacement of a byte of the copy of a chunk. There can be, for instance, a Mutator that applies more than a single type of mutation to the input. Consider a generic Mutator for a byte stream, bit flip is just one of the possible mutations but not the only one, there is also, for instance, the random replacement of a byte of the copy of a chunk.
There are also mutators that always produce valid inputs, say a mutator that generates valid Json or code, but these grammar based mutators need a grammar to work. There are also mutators that always produce valid inputs, say a mutator that generates valid JSON or code, but these grammar based mutators need a grammar to work.
In LibAFL, [`Mutator`](https://docs.rs/libafl/latest/libafl/mutators/trait.Mutator.html) is a trait. In LibAFL, [`Mutator`](https://docs.rs/libafl/latest/libafl/mutators/trait.Mutator.html) is a trait.

View File

@ -25,7 +25,7 @@ def concatenate_json_files(input_dir):
with open(output_file, 'w') as file: with open(output_file, 'w') as file:
json.dump([data], file) json.dump([data], file)
print(f"Json files concatenated successfully! Output file: {output_file}") print(f"JSON files concatenated successfully! Output file: {output_file}")
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 2: if len(sys.argv) != 2:

View File

@ -69,8 +69,7 @@ fn fuzz(
// 'While the stats are state, they are usually used in the broker - which is likely never restarted // 'While the stats are state, they are usually used in the broker - which is likely never restarted
// let monitor = MultiMonitor::new(|s| println!("{s}")); // let monitor = MultiMonitor::new(|s| println!("{s}"));
//Setup an Monitor with AFL-Style UI to display the stats // Setup an Monitor with AFL-Style UI to display the stats
#[cfg(feature = "tui")]
let monitor = TuiMonitor::builder() let monitor = TuiMonitor::builder()
.title("Libfuzzer in LibAFL") .title("Libfuzzer in LibAFL")
.version("0.0.1") .version("0.0.1")

View File

@ -24,9 +24,9 @@ use crate::{
pub enum OnDiskMetadataFormat { pub enum OnDiskMetadataFormat {
/// A binary-encoded postcard /// A binary-encoded postcard
Postcard, Postcard,
/// Json /// JSON
Json, Json,
/// Json formatted for readability /// JSON formatted for readability
#[default] #[default]
JsonPretty, JsonPretty,
/// The same as [`OnDiskMetadataFormat::JsonPretty`], but compressed /// The same as [`OnDiskMetadataFormat::JsonPretty`], but compressed

View File

@ -1,4 +1,4 @@
//! Monitors that wrap a base monitor and also log to disk using different formats. //! Monitors that wrap a base monitor and also log to disk using different formats like `JSON` and `TOML`.
use alloc::{string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use core::time::Duration; use core::time::Duration;

View File

@ -7,7 +7,6 @@ pub use multi::MultiMonitor;
pub mod tui; pub mod tui;
#[cfg(all(feature = "prometheus_monitor", feature = "std"))] #[cfg(all(feature = "prometheus_monitor", feature = "std"))]
#[allow(missing_docs)]
pub mod prometheus; pub mod prometheus;
use alloc::string::ToString; use alloc::string::ToString;

View File

@ -1,4 +1,4 @@
//! Monitor to display both cumulative and per-client monitor //! The [`MultiMonitor`] displays both cumulative and per-client stats.
use alloc::{string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use core::{ use core::{

View File

@ -1,16 +1,16 @@
//! Prometheus Monitor to log to a prometheus endpoint. //! The [`PrometheusMonitor`] logs fuzzer progress to a prometheus endpoint.
//! //!
//! ## Overview //! ## Overview
//! //!
//! The client (i.e., the fuzzer) sets up an HTTP endpoint (/metrics). //! The client (i.e., the fuzzer) sets up an HTTP endpoint (/metrics).
//! The endpoint contains metrics such as execution rate. //! The endpoint contains metrics such as execution rate.
//! //!
//! A prometheus server (can use a precompiled binary or docker) then scrapes \ //! A prometheus server (can use a precompiled binary or docker) then scrapes
//! the endpoint at regular intervals (configurable via prometheus.yml file). //! the endpoint at regular intervals (configurable via prometheus.yml file).
//! //!
//! ## How to use it //! ## How to use it
//! //!
//! This monitor should plug into any fuzzer similar to other monitors. //! Create a [`PrometheusMonitor`] and plug it into any fuzzer similar to other monitors.
//! In your fuzzer: //! In your fuzzer:
//! //!
//! ```rust //! ```rust
@ -199,6 +199,9 @@ impl<F> PrometheusMonitor<F>
where where
F: FnMut(&str), F: FnMut(&str),
{ {
/// Create a new [`PrometheusMonitor`].
/// The `listener` is the address to send logs to.
/// The `print_fn` is the printing function that can output the logs otherwise.
pub fn new(listener: String, print_fn: F) -> Self { pub fn new(listener: String, print_fn: F) -> Self {
// Gauge's implementation of clone uses Arc // Gauge's implementation of clone uses Arc
let corpus_count = Family::<Labels, Gauge>::default(); let corpus_count = Family::<Labels, Gauge>::default();
@ -290,9 +293,9 @@ where
} }
} }
// set up an HTTP endpoint /metrics /// Set up an HTTP endpoint /metrics
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn serve_metrics( pub(crate) async fn serve_metrics(
listener: String, listener: String,
corpus: Family<Labels, Gauge>, corpus: Family<Labels, Gauge>,
objectives: Family<Labels, Gauge>, objectives: Family<Labels, Gauge>,
@ -354,12 +357,16 @@ pub async fn serve_metrics(
Ok(()) Ok(())
} }
/// Struct used to define the labels in `prometheus`.
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)] #[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
pub struct Labels { pub struct Labels {
client: u32, // sender_id: u32, to differentiate between clients when multiple are spawned. /// The `sender_id` helps to differentiate between clients when multiple are spawned.
stat: Cow<'static, str>, // for custom_stat filtering. client: u32,
/// Used for `custom_stat` filtering.
stat: Cow<'static, str>,
} }
/// The state for this monitor.
#[derive(Clone)] #[derive(Clone)]
struct State { struct State {
registry: Arc<Registry>, registry: Arc<Registry>,

View File

@ -1,4 +1,6 @@
//! Fancy-looking terminal UI monitor, similar to AFL, based on [ratatui](https://ratatui.rs/) //! [`TuiMonitor`] is a fancy-looking TUI monitor similar to `AFL`.
//!
//! It's based on [ratatui](https://ratatui.rs/)
use alloc::{borrow::Cow, boxed::Box, string::ToString}; use alloc::{borrow::Cow, boxed::Box, string::ToString};
use core::cmp; use core::cmp;
@ -126,10 +128,15 @@ impl TimedStats {
#[cfg(feature = "introspection")] #[cfg(feature = "introspection")]
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct PerfTuiContext { pub struct PerfTuiContext {
/// Time spent in the scheduler
pub scheduler: f64, pub scheduler: f64,
/// Time spent in the event manager
pub manager: f64, pub manager: f64,
/// Additional time
pub unmeasured: f64, pub unmeasured: f64,
/// Time spent in each individual stage
pub stages: Vec<Vec<(String, f64)>>, pub stages: Vec<Vec<(String, f64)>>,
/// Time spent in each individual feedback
pub feedbacks: Vec<(String, f64)>, pub feedbacks: Vec<(String, f64)>,
} }
@ -234,6 +241,7 @@ pub struct ItemGeometry {
} }
impl ItemGeometry { impl ItemGeometry {
/// Create a new [`ItemGeometry`]
fn new() -> Self { fn new() -> Self {
Self { Self {
stability: "0%".to_string(), stability: "0%".to_string(),