diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 300fdaf534..58ca7b6077 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -163,7 +163,7 @@ jobs: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 - name: Run a maturin build - run: cd ./bindings/pylibafl && python3 -m venv .env && . .env/bin/activate && pip install . && ./test.sh + run: cd ./bindings/pylibafl && python3 -m venv .env && . .env/bin/activate && pip install --upgrade --force-reinstall . && ./test.sh - name: Run python test run: . ./bindings/pylibafl/.env/bin/activate && cd ./fuzzers/baby_fuzzer && python3 baby_fuzzer.py 2>&1 | grep "Bye" diff --git a/.gitignore b/.gitignore index 51f20b02af..47c99960d0 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ __pycache__ libafl_nyx/QEMU-Nyx libafl_nyx/packer + +.z3-trace diff --git a/Cargo.toml b/Cargo.toml index a56246ffdc..82bda6dcfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,35 +2,37 @@ resolver = "2" members = [ "libafl", - "libafl_derive", + "libafl_bolts", "libafl_cc", - "libafl_targets", - "libafl_frida", - "libafl_qemu", - "libafl_tinyinst", - "libafl_sugar", - "libafl_nyx", "libafl_concolic/symcc_runtime", "libafl_concolic/symcc_libafl", "libafl_concolic/test/dump_constraints", "libafl_concolic/test/runtime_test", - "utils/deexit", - "utils/gramatron/construct_automata", - "utils/libafl_benches", + "libafl_derive", + "libafl_frida", + "libafl_nyx", + "libafl_qemu", + "libafl_sugar", + "libafl_targets", + "libafl_tinyinst", "utils/build_and_test_fuzzers", + "utils/deexit", + "utils/libafl_benches", + "utils/gramatron/construct_automata", ] default-members = [ "libafl", - "libafl_derive", + "libafl_bolts", "libafl_cc", + "libafl_derive", "libafl_targets", ] exclude = [ - "fuzzers", "bindings", - "scripts", + "fuzzers", "libafl_qemu/libafl_qemu_build", - "libafl_qemu/libafl_qemu_sys" + "libafl_qemu/libafl_qemu_sys", + "scripts", ] [workspace.package] diff --git a/Dockerfile b/Dockerfile index 398d3a5d29..c1e261a88e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,9 +29,12 @@ COPY libafl_derive/Cargo.toml libafl_derive/Cargo.toml COPY scripts/dummy.rs libafl_derive/src/lib.rs COPY libafl/Cargo.toml libafl/build.rs libafl/ -COPY libafl/examples libafl/examples COPY scripts/dummy.rs libafl/src/lib.rs +COPY libafl_bolts/Cargo.toml libafl_bolts/build.rs libafl_bolts/ +COPY libafl_bolts/examples libafl_bolts/examples +COPY scripts/dummy.rs libafl_bolts/src/lib.rs + COPY libafl_frida/Cargo.toml libafl_frida/build.rs libafl_frida/ COPY scripts/dummy.rs libafl_frida/src/lib.rs COPY libafl_frida/src/gettls.c libafl_frida/src/gettls.c @@ -95,6 +98,8 @@ COPY libafl_cc/src libafl_cc/src RUN touch libafl_cc/src/lib.rs COPY libafl_derive/src libafl_derive/src RUN touch libafl_derive/src/lib.rs +COPY libafl_bolts/src libafl_bolts/src +RUN touch libafl_bolts/src/lib.rs COPY libafl/src libafl/src RUN touch libafl/src/lib.rs COPY libafl_targets/src libafl_targets/src diff --git a/bindings/pylibafl/Cargo.toml b/bindings/pylibafl/Cargo.toml index 6ad50cf432..3abb219726 100644 --- a/bindings/pylibafl/Cargo.toml +++ b/bindings/pylibafl/Cargo.toml @@ -9,6 +9,7 @@ pyo3-log = "0.8.1" libafl_qemu = { path = "../../libafl_qemu", version = "0.10.1", features = ["python"] } libafl_sugar = { path = "../../libafl_sugar", version = "0.10.1", features = ["python"] } libafl = { path = "../../libafl", version = "0.10.1", features = ["python"] } +libafl_bolts = { path = "../../libafl_bolts", version = "0.10.1", features = ["python"] } [build-dependencies] pyo3-build-config = { version = "0.17" } diff --git a/bindings/pylibafl/src/lib.rs b/bindings/pylibafl/src/lib.rs index c0c7ccaa78..f5047ea544 100644 --- a/bindings/pylibafl/src/lib.rs +++ b/bindings/pylibafl/src/lib.rs @@ -1,4 +1,5 @@ use libafl; +use libafl_bolts; #[cfg(target_os = "linux")] use libafl_qemu; use libafl_sugar; @@ -91,18 +92,20 @@ pub fn python_module(py: Python, m: &PyModule) -> PyResult<()> { let sugar_module = PyModule::new(py, "sugar")?; libafl_sugar::python_module(py, sugar_module)?; m.add_submodule(sugar_module)?; - modules.set_item("pylibafl.sugar", sugar_module)?; #[cfg(target_os = "linux")] - let qemu_module = PyModule::new(py, "qemu")?; - #[cfg(target_os = "linux")] - libafl_qemu::python_module(py, qemu_module)?; - #[cfg(target_os = "linux")] - m.add_submodule(qemu_module)?; + { + let qemu_module = PyModule::new(py, "qemu")?; + libafl_qemu::python_module(py, qemu_module)?; + m.add_submodule(qemu_module)?; + modules.set_item("pylibafl.qemu", qemu_module)?; + } - #[cfg(target_os = "linux")] - modules.set_item("pylibafl.qemu", qemu_module)?; + let bolts_module = PyModule::new(py, "libafl_bolts")?; + libafl_bolts::pybind::python_module(py, bolts_module)?; + m.add_submodule(bolts_module)?; + modules.set_item("pylibafl.libafl_bolts", bolts_module)?; let libafl_module = PyModule::new(py, "libafl")?; libafl::pybind::python_module(py, libafl_module)?; @@ -116,7 +119,6 @@ pub fn python_module(py: Python, m: &PyModule) -> PyResult<()> { } m.add_submodule(libafl_module)?; - modules.set_item("pylibafl.libafl", libafl_module)?; Ok(()) diff --git a/docs/listings/baby_fuzzer/listing-02/Cargo.toml b/docs/listings/baby_fuzzer/listing-02/Cargo.toml index 91cb8efc71..cd43b8af18 100644 --- a/docs/listings/baby_fuzzer/listing-02/Cargo.toml +++ b/docs/listings/baby_fuzzer/listing-02/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] libafl = { path = "path/to/libafl/" } +libafl_bolts = { path = "path/to/libafl_bolts/" } [profile.dev] panic = "abort" diff --git a/docs/listings/baby_fuzzer/listing-03/Cargo.toml b/docs/listings/baby_fuzzer/listing-03/Cargo.toml index ff315365fc..cb12a810b0 100644 --- a/docs/listings/baby_fuzzer/listing-03/Cargo.toml +++ b/docs/listings/baby_fuzzer/listing-03/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] libafl = { path = "path/to/libafl/" } +libafl_bolts = { path = "path/to/libafl_bolts/" } [profile.dev] panic = "abort" diff --git a/docs/listings/baby_fuzzer/listing-03/src/main.rs b/docs/listings/baby_fuzzer/listing-03/src/main.rs index b6396a4987..d39118fa6e 100644 --- a/docs/listings/baby_fuzzer/listing-03/src/main.rs +++ b/docs/listings/baby_fuzzer/listing-03/src/main.rs @@ -1,9 +1,10 @@ extern crate libafl; +extern crate libafl_bolts; use libafl::{ - bolts::AsSlice, executors::ExitKind, inputs::{BytesInput, HasTargetBytes}, }; +use libafl_bolts::AsSlice; fn main() { let mut harness = |input: &BytesInput| { diff --git a/docs/listings/baby_fuzzer/listing-04/Cargo.toml b/docs/listings/baby_fuzzer/listing-04/Cargo.toml index 747be10704..a82804742a 100644 --- a/docs/listings/baby_fuzzer/listing-04/Cargo.toml +++ b/docs/listings/baby_fuzzer/listing-04/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] libafl = { path = "path/to/libafl/" } +libafl_bolts = { path = "path/to/libafl_bolts/" } [profile.dev] panic = "abort" diff --git a/docs/listings/baby_fuzzer/listing-04/src/main.rs b/docs/listings/baby_fuzzer/listing-04/src/main.rs index 62498db481..a070fec1b5 100644 --- a/docs/listings/baby_fuzzer/listing-04/src/main.rs +++ b/docs/listings/baby_fuzzer/listing-04/src/main.rs @@ -1,8 +1,8 @@ /* ANCHOR: use */ extern crate libafl; +extern crate libafl_bolts; use libafl::{ - bolts::{current_nanos, rands::StdRand, AsSlice}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -13,6 +13,7 @@ use libafl::{ schedulers::QueueScheduler, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, AsSlice}; use std::path::PathBuf; /* ANCHOR_END: use */ diff --git a/docs/listings/baby_fuzzer/listing-05/src/main.rs b/docs/listings/baby_fuzzer/listing-05/src/main.rs index 930cebd0be..f7fec1fb3b 100644 --- a/docs/listings/baby_fuzzer/listing-05/src/main.rs +++ b/docs/listings/baby_fuzzer/listing-05/src/main.rs @@ -1,8 +1,8 @@ /* ANCHOR: use */ extern crate libafl; +extern crate libafl_bolts; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -15,6 +15,7 @@ use libafl::{ schedulers::QueueScheduler, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use std::path::PathBuf; /* ANCHOR_END: use */ diff --git a/docs/listings/baby_fuzzer/listing-06/Cargo.toml b/docs/listings/baby_fuzzer/listing-06/Cargo.toml index d43d3bd2d5..a5de46326b 100644 --- a/docs/listings/baby_fuzzer/listing-06/Cargo.toml +++ b/docs/listings/baby_fuzzer/listing-06/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] libafl = { path = "path/to/libafl/" } +libafl_bolts = { path = "path/to/libafl_bolts/" } [profile.dev] panic = "abort" diff --git a/docs/listings/baby_fuzzer/listing-06/src/main.rs b/docs/listings/baby_fuzzer/listing-06/src/main.rs index 16819e24f4..02b27c7e92 100644 --- a/docs/listings/baby_fuzzer/listing-06/src/main.rs +++ b/docs/listings/baby_fuzzer/listing-06/src/main.rs @@ -1,8 +1,8 @@ /* ANCHOR: use */ extern crate libafl; +extern crate libafl_bolts; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -17,6 +17,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use std::path::PathBuf; /* ANCHOR_END: use */ diff --git a/docs/src/design/metadata.md b/docs/src/design/metadata.md index 00f17b75aa..0677e8c115 100644 --- a/docs/src/design/metadata.md +++ b/docs/src/design/metadata.md @@ -5,10 +5,10 @@ A metadata in LibAFL is a self-contained structure that holds associated data to In terms of code, a metadata can be defined as a Rust struct registered in the SerdeAny register. ```rust -extern crate libafl; -extern crate serde; +# extern crate libafl_bolts; +# extern crate serde; -use libafl::SerdeAny; +use libafl_bolts::SerdeAny; use serde::{Serialize, Deserialize}; #[derive(Debug, Serialize, Deserialize, SerdeAny)] @@ -19,7 +19,7 @@ pub struct MyMetadata { The struct must be static, so it cannot hold references to borrowed objects. -As an alternative to `derive(SerdeAny)` which is a proc-macro in `libafl_derive` the user can use `libafl::impl_serdeany!(MyMetadata);`. +As an alternative to `derive(SerdeAny)` which is a proc-macro in `libafl_derive` the user can use `libafl_bolts::impl_serdeany!(MyMetadata);`. ## Usage diff --git a/docs/src/getting_started/crates.md b/docs/src/getting_started/crates.md index 0e6cd6ac03..1e0bb1c8e9 100644 --- a/docs/src/getting_started/crates.md +++ b/docs/src/getting_started/crates.md @@ -31,6 +31,21 @@ You can choose the features by using `features = ["feature1", "feature2", ...]` Out of this list, by default, `std`, `derive`, and `rand_trait` are already set. You can choose to disable them by setting `default-features = false` in your `Cargo.toml`. +## [`libafl_bolts](https://github.com/AFLplusplus/LibAFL/tree/main/libafl) + +The `libafl_bolts` create is a minimal tool shed filled with useful low-level rust features, not necessarily related to fuzzers. +In it, you'll find highlights like: + +- `core_affinity` to bind the current process to cores +- `SerdeAnyMap` a map that can store typed values in a serializable fashion +- `minibsod` to dump the current process state +- `LLMP`, "low level message passing", a lock-free IPC mechanism +- `Rand`, different fast (non-cryptographically secure) RNG implementations like RomuRand +- `ShMem`, a platform independent shard memory implementation +- `Tuples`, a compiletime tuple implementation + +... and much more. + ### libafl_sugar The sugar crate abstracts away most of the complexity of LibAFL's API. diff --git a/fuzzers/baby_fuzzer_gramatron/Cargo.toml b/fuzzers/baby_fuzzer_gramatron/Cargo.toml index 4cab61214b..9cb567f2e6 100644 --- a/fuzzers/baby_fuzzer_gramatron/Cargo.toml +++ b/fuzzers/baby_fuzzer_gramatron/Cargo.toml @@ -20,4 +20,5 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } postcard = "0.7" diff --git a/fuzzers/baby_fuzzer_gramatron/src/main.rs b/fuzzers/baby_fuzzer_gramatron/src/main.rs index b718b11845..ada8c1dfb2 100644 --- a/fuzzers/baby_fuzzer_gramatron/src/main.rs +++ b/fuzzers/baby_fuzzer_gramatron/src/main.rs @@ -7,7 +7,6 @@ use std::{ }; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -25,6 +24,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list}; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; @@ -123,7 +123,7 @@ pub fn main() { } let mut set = HashSet::new(); - let st = libafl::bolts::current_milliseconds(); + let st = libafl_bolts::current_milliseconds(); let mut b = vec![]; let mut c = 0; for _ in 0..100000 { @@ -132,7 +132,7 @@ pub fn main() { set.insert(calculate_hash(&b)); c += b.len(); } - println!("{} / {}", c, libafl::bolts::current_milliseconds() - st); + println!("{} / {}", c, libafl_bolts::current_milliseconds() - st); println!("{} / 100000", set.len()); return; diff --git a/fuzzers/baby_fuzzer_grimoire/Cargo.toml b/fuzzers/baby_fuzzer_grimoire/Cargo.toml index 73017eff9d..56b513d83a 100644 --- a/fuzzers/baby_fuzzer_grimoire/Cargo.toml +++ b/fuzzers/baby_fuzzer_grimoire/Cargo.toml @@ -20,3 +20,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } diff --git a/fuzzers/baby_fuzzer_grimoire/src/main.rs b/fuzzers/baby_fuzzer_grimoire/src/main.rs index 59aa1b956e..b3be156e47 100644 --- a/fuzzers/baby_fuzzer_grimoire/src/main.rs +++ b/fuzzers/baby_fuzzer_grimoire/src/main.rs @@ -3,7 +3,6 @@ use std::ptr::write_volatile; use std::{fs, io::Read, path::PathBuf, ptr::write}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -21,6 +20,7 @@ use libafl::{ stages::{mutational::StdMutationalStage, GeneralizationStage}, state::{HasMetadata, StdState}, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; diff --git a/fuzzers/baby_fuzzer_minimizing/Cargo.toml b/fuzzers/baby_fuzzer_minimizing/Cargo.toml index 856ca271f2..d2d0d62575 100644 --- a/fuzzers/baby_fuzzer_minimizing/Cargo.toml +++ b/fuzzers/baby_fuzzer_minimizing/Cargo.toml @@ -21,3 +21,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/", features = ["prelude"] } +libafl_bolts = { path = "../../libafl_bolts/", features = ["prelude"] } diff --git a/fuzzers/baby_fuzzer_minimizing/src/main.rs b/fuzzers/baby_fuzzer_minimizing/src/main.rs index 1c716fd2b0..0eda481089 100644 --- a/fuzzers/baby_fuzzer_minimizing/src/main.rs +++ b/fuzzers/baby_fuzzer_minimizing/src/main.rs @@ -3,6 +3,7 @@ use std::ptr::write_volatile; use std::{path::PathBuf, ptr::write}; use libafl::prelude::*; +use libafl_bolts::prelude::*; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; diff --git a/fuzzers/baby_fuzzer_nautilus/Cargo.toml b/fuzzers/baby_fuzzer_nautilus/Cargo.toml index 70ffd7f29c..332bee1729 100644 --- a/fuzzers/baby_fuzzer_nautilus/Cargo.toml +++ b/fuzzers/baby_fuzzer_nautilus/Cargo.toml @@ -20,3 +20,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/", features = ["default", "nautilus"] } +libafl_bolts = { path = "../../libafl_bolts/" } diff --git a/fuzzers/baby_fuzzer_nautilus/src/main.rs b/fuzzers/baby_fuzzer_nautilus/src/main.rs index a9680f83e7..5c61c2bbc2 100644 --- a/fuzzers/baby_fuzzer_nautilus/src/main.rs +++ b/fuzzers/baby_fuzzer_nautilus/src/main.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use std::ptr::write_volatile; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -21,6 +20,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::{HasMetadata, StdState}, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list}; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; @@ -122,7 +122,7 @@ pub fn main() { } let mut set = HashSet::new(); - let st = libafl::bolts::current_milliseconds(); + let st = libafl_bolts::current_milliseconds(); let mut b = vec![]; let mut c = 0; for _ in 0..100000 { @@ -131,7 +131,7 @@ pub fn main() { set.insert(calculate_hash(&b)); c += b.len(); } - println!("{} / {}", c, libafl::bolts::current_milliseconds() - st); + println!("{} / {}", c, libafl_bolts::current_milliseconds() - st); println!("{} / 100000", set.len()); return; diff --git a/fuzzers/baby_fuzzer_swap_differential/Cargo.toml b/fuzzers/baby_fuzzer_swap_differential/Cargo.toml index cfa91fe2d2..7fc4d50114 100644 --- a/fuzzers/baby_fuzzer_swap_differential/Cargo.toml +++ b/fuzzers/baby_fuzzer_swap_differential/Cargo.toml @@ -26,6 +26,7 @@ cc = "1.0" [dependencies] libafl = { path = "../../libafl" } +libafl_bolts = { path = "../../libafl_bolts" } libafl_targets = { path = "../../libafl_targets", features = ["sancov_pcguard_hitcounts", "libfuzzer", "sancov_cmplog", "pointer_maps"] } mimalloc = { version = "*", default-features = false } diff --git a/fuzzers/baby_fuzzer_swap_differential/src/main.rs b/fuzzers/baby_fuzzer_swap_differential/src/main.rs index 1e8f39767d..ac4e5846ca 100644 --- a/fuzzers/baby_fuzzer_swap_differential/src/main.rs +++ b/fuzzers/baby_fuzzer_swap_differential/src/main.rs @@ -10,7 +10,6 @@ use libafl::monitors::tui::{ui::TuiUI, TuiMonitor}; #[cfg(not(feature = "tui"))] use libafl::monitors::SimpleMonitor; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{Corpus, InMemoryCorpus, InMemoryOnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, DiffExecutor, ExitKind}, @@ -24,6 +23,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::{HasSolutions, StdState}, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use libafl_targets::{edges_max_num, DifferentialAFLMapSwapObserver}; #[cfg(not(miri))] use mimalloc::MiMalloc; @@ -46,10 +46,8 @@ use bindings::{inspect_first, inspect_second}; #[cfg(feature = "multimap")] mod multimap { - pub use libafl::{ - bolts::ownedref::OwnedMutSlice, - observers::{HitcountsIterableMapObserver, MultiMapObserver}, - }; + pub use libafl::observers::{HitcountsIterableMapObserver, MultiMapObserver}; + pub use libafl_bolts::ownedref::OwnedMutSlice; } #[cfg(feature = "multimap")] use multimap::{HitcountsIterableMapObserver, MultiMapObserver, OwnedMutSlice}; diff --git a/fuzzers/baby_fuzzer_tokens/Cargo.toml b/fuzzers/baby_fuzzer_tokens/Cargo.toml index 4ce41691dc..d9faddef7c 100644 --- a/fuzzers/baby_fuzzer_tokens/Cargo.toml +++ b/fuzzers/baby_fuzzer_tokens/Cargo.toml @@ -20,3 +20,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } diff --git a/fuzzers/baby_fuzzer_tokens/src/main.rs b/fuzzers/baby_fuzzer_tokens/src/main.rs index b6ad7a9891..49cd737a60 100644 --- a/fuzzers/baby_fuzzer_tokens/src/main.rs +++ b/fuzzers/baby_fuzzer_tokens/src/main.rs @@ -3,7 +3,6 @@ use std::ptr::write_volatile; use std::{fs, io::Read, path::PathBuf, ptr::write}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -17,6 +16,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list}; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; diff --git a/fuzzers/baby_fuzzer_wasm/Cargo.toml b/fuzzers/baby_fuzzer_wasm/Cargo.toml index 157469cfd2..18548132ba 100644 --- a/fuzzers/baby_fuzzer_wasm/Cargo.toml +++ b/fuzzers/baby_fuzzer_wasm/Cargo.toml @@ -15,6 +15,7 @@ js-sys = "0.3" wasm-bindgen = "0.2.63" libafl = { path = "../../libafl", default-features = false } +libafl_bolts = { path = "../../libafl_bolts", default-features = false } # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/fuzzers/baby_fuzzer_wasm/README.md b/fuzzers/baby_fuzzer_wasm/README.md index 9dfc4db169..52080e68dd 100644 --- a/fuzzers/baby_fuzzer_wasm/README.md +++ b/fuzzers/baby_fuzzer_wasm/README.md @@ -9,4 +9,4 @@ write the fuzzer log to your console. In a real fuzzing campaign, you would likely need to also create a LibAFL Corpus implementation which was backed by JavaScript, and restart the fuzzing campaign by re-invoking the fuzzer and providing the associated corpora. This is -not demonstrated in this barebones example. \ No newline at end of file +not demonstrated in this barebones example. diff --git a/fuzzers/baby_fuzzer_wasm/src/lib.rs b/fuzzers/baby_fuzzer_wasm/src/lib.rs index 110abe8b74..5c4db77cd3 100644 --- a/fuzzers/baby_fuzzer_wasm/src/lib.rs +++ b/fuzzers/baby_fuzzer_wasm/src/lib.rs @@ -1,7 +1,6 @@ mod utils; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{Corpus, InMemoryCorpus}, events::SimpleEventManager, executors::{ExitKind, InProcessExecutor}, @@ -16,6 +15,7 @@ use libafl::{ state::{HasSolutions, StdState}, Fuzzer, StdFuzzer, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use wasm_bindgen::prelude::*; use web_sys::{Performance, Window}; diff --git a/fuzzers/baby_fuzzer_with_forkexecutor/Cargo.toml b/fuzzers/baby_fuzzer_with_forkexecutor/Cargo.toml index 3094280849..a4c65cbe27 100644 --- a/fuzzers/baby_fuzzer_with_forkexecutor/Cargo.toml +++ b/fuzzers/baby_fuzzer_with_forkexecutor/Cargo.toml @@ -20,3 +20,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } diff --git a/fuzzers/baby_fuzzer_with_forkexecutor/src/main.rs b/fuzzers/baby_fuzzer_with_forkexecutor/src/main.rs index 346ae7f249..a641a7abf0 100644 --- a/fuzzers/baby_fuzzer_with_forkexecutor/src/main.rs +++ b/fuzzers/baby_fuzzer_with_forkexecutor/src/main.rs @@ -3,13 +3,6 @@ use std::ptr::write_volatile; use std::{path::PathBuf, ptr::write}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{unix_shmem, ShMemProvider}, - tuples::tuple_list, - AsMutSlice, AsSlice, - }, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{ExitKind, InProcessForkExecutor}, @@ -24,6 +17,13 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{unix_shmem, ShMemProvider}, + tuples::tuple_list, + AsMutSlice, AsSlice, +}; #[allow(clippy::similar_names)] pub fn main() { diff --git a/fuzzers/baby_no_std/Cargo.toml b/fuzzers/baby_no_std/Cargo.toml index 5e685fca44..616b2868f7 100644 --- a/fuzzers/baby_no_std/Cargo.toml +++ b/fuzzers/baby_no_std/Cargo.toml @@ -16,6 +16,7 @@ debug = true [dependencies] libafl = { default-features = false, path = "../../libafl/" } +libafl_bolts = { default-features = false, path = "../../libafl_bolts/" } static-alloc = "0.2.3" [target.'cfg(unix)'.dependencies] diff --git a/fuzzers/baby_no_std/src/main.rs b/fuzzers/baby_no_std/src/main.rs index 852a70b490..12b445268e 100644 --- a/fuzzers/baby_no_std/src/main.rs +++ b/fuzzers/baby_no_std/src/main.rs @@ -11,7 +11,6 @@ use core::panic::PanicInfo; use core::ptr::write; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::InMemoryCorpus, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -26,6 +25,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; #[cfg(any(windows, unix))] use libc::{abort, printf}; use static_alloc::Bump; diff --git a/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/Cargo.toml b/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/Cargo.toml index 740eaaf31a..4c3981f802 100644 --- a/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/Cargo.toml +++ b/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/Cargo.toml @@ -16,6 +16,7 @@ debug = true [dependencies] libafl = { path = "../../../libafl/" } +libafl_bolts = { path = "../../../libafl_bolts/" } libc = "0.2" [build-dependencies] diff --git a/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/src/main.rs b/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/src/main.rs index 22b1216b7a..49323a435a 100644 --- a/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/src/main.rs +++ b/fuzzers/backtrace_baby_fuzzers/c_code_with_fork_executor/src/main.rs @@ -1,13 +1,6 @@ use std::path::PathBuf; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{ShMem, ShMemProvider, StdShMemProvider}, - tuples::tuple_list, - AsSlice, - }, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::InProcessForkExecutor, @@ -23,6 +16,13 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{ShMem, ShMemProvider, StdShMemProvider}, + tuples::tuple_list, + AsSlice, +}; use libc::{c_int, c_uchar}; extern crate libc; diff --git a/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/Cargo.toml b/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/Cargo.toml index dab9c0bbda..5eb3f1e931 100644 --- a/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/Cargo.toml +++ b/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/Cargo.toml @@ -16,6 +16,7 @@ debug = true [dependencies] libafl = { path = "../../../libafl/" } +libafl_bolts = { path = "../../../libafl_bolts/" } libc = "0.2" [build-dependencies] diff --git a/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/src/main.rs b/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/src/main.rs index 5521e6a19d..48d3a28d72 100644 --- a/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/src/main.rs +++ b/fuzzers/backtrace_baby_fuzzers/c_code_with_inprocess_executor/src/main.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::InProcessExecutor, @@ -17,6 +16,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use libc::c_uchar; extern crate libc; diff --git a/fuzzers/backtrace_baby_fuzzers/command_executor/Cargo.toml b/fuzzers/backtrace_baby_fuzzers/command_executor/Cargo.toml index 0e26e5c86e..90d7377d6a 100644 --- a/fuzzers/backtrace_baby_fuzzers/command_executor/Cargo.toml +++ b/fuzzers/backtrace_baby_fuzzers/command_executor/Cargo.toml @@ -18,4 +18,4 @@ cc = "*" [dependencies] libafl = { path = "../../../libafl/" } - +libafl_bolts = { path = "../../../libafl_bolts/" } diff --git a/fuzzers/backtrace_baby_fuzzers/command_executor/src/main.rs b/fuzzers/backtrace_baby_fuzzers/command_executor/src/main.rs index 78817c420e..f2a894ad1b 100644 --- a/fuzzers/backtrace_baby_fuzzers/command_executor/src/main.rs +++ b/fuzzers/backtrace_baby_fuzzers/command_executor/src/main.rs @@ -8,13 +8,6 @@ use std::{ }; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{unix_shmem, ShMem, ShMemId, ShMemProvider}, - tuples::tuple_list, - AsMutSlice, AsSlice, - }, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::command::CommandConfigurator, @@ -31,6 +24,13 @@ use libafl::{ state::StdState, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{unix_shmem, ShMem, ShMemId, ShMemProvider}, + tuples::tuple_list, + AsMutSlice, AsSlice, +}; #[allow(clippy::similar_names)] pub fn main() { diff --git a/fuzzers/backtrace_baby_fuzzers/forkserver_executor/Cargo.toml b/fuzzers/backtrace_baby_fuzzers/forkserver_executor/Cargo.toml index 7defc50f94..fa8933adb7 100644 --- a/fuzzers/backtrace_baby_fuzzers/forkserver_executor/Cargo.toml +++ b/fuzzers/backtrace_baby_fuzzers/forkserver_executor/Cargo.toml @@ -15,3 +15,4 @@ opt-level = 3 [dependencies] libafl = { path = "../../../libafl/" } +libafl_bolts = { path = "../../../libafl_bolts/" } diff --git a/fuzzers/backtrace_baby_fuzzers/forkserver_executor/src/main.rs b/fuzzers/backtrace_baby_fuzzers/forkserver_executor/src/main.rs index 8d8c87a5e8..6a65550ca1 100644 --- a/fuzzers/backtrace_baby_fuzzers/forkserver_executor/src/main.rs +++ b/fuzzers/backtrace_baby_fuzzers/forkserver_executor/src/main.rs @@ -1,17 +1,6 @@ use std::path::PathBuf; -#[cfg(not(target_vendor = "apple"))] -use libafl::bolts::shmem::StdShMemProvider; -#[cfg(target_vendor = "apple")] -use libafl::bolts::shmem::UnixShMemProvider; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{ShMem, ShMemProvider}, - tuples::tuple_list, - AsMutSlice, - }, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::forkserver::ForkserverExecutor, @@ -27,6 +16,17 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +#[cfg(not(target_vendor = "apple"))] +use libafl_bolts::shmem::StdShMemProvider; +#[cfg(target_vendor = "apple")] +use libafl_bolts::shmem::UnixShMemProvider; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{ShMem, ShMemProvider}, + tuples::tuple_list, + AsMutSlice, +}; #[allow(clippy::similar_names)] pub fn main() { diff --git a/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/Cargo.toml b/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/Cargo.toml index 9a02303a39..e41acff6a0 100644 --- a/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/Cargo.toml +++ b/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/Cargo.toml @@ -19,3 +19,4 @@ debug = true [dependencies] libafl = { path = "../../../libafl/" } +libafl_bolts = { path = "../../../libafl_bolts/" } diff --git a/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/src/main.rs b/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/src/main.rs index 9329645df9..1f5c34e2ed 100644 --- a/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/src/main.rs +++ b/fuzzers/backtrace_baby_fuzzers/rust_code_with_fork_executor/src/main.rs @@ -3,13 +3,6 @@ use std::ptr::write_volatile; use std::{path::PathBuf, ptr::write}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{unix_shmem, ShMem, ShMemProvider}, - tuples::tuple_list, - AsMutSlice, AsSlice, - }, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{ExitKind, InProcessForkExecutor}, @@ -25,6 +18,13 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{unix_shmem, ShMem, ShMemProvider}, + tuples::tuple_list, + AsMutSlice, AsSlice, +}; #[allow(clippy::similar_names)] pub fn main() { diff --git a/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/Cargo.toml b/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/Cargo.toml index bc9c6bad4e..5d09172a78 100644 --- a/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/Cargo.toml +++ b/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/Cargo.toml @@ -19,3 +19,4 @@ debug = true [dependencies] libafl = { path = "../../../libafl/" } +libafl_bolts = { path = "../../../libafl_bolts/" } diff --git a/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/src/main.rs b/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/src/main.rs index 2833f29ad4..5970b7104b 100644 --- a/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/src/main.rs +++ b/fuzzers/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/src/main.rs @@ -3,7 +3,6 @@ use std::ptr::write_volatile; use std::{path::PathBuf, ptr::write}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -19,6 +18,7 @@ use libafl::{ stages::mutational::StdMutationalStage, state::StdState, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; diff --git a/fuzzers/forkserver_libafl_cc/Cargo.toml b/fuzzers/forkserver_libafl_cc/Cargo.toml index 64fcff628f..c981ec8dd8 100644 --- a/fuzzers/forkserver_libafl_cc/Cargo.toml +++ b/fuzzers/forkserver_libafl_cc/Cargo.toml @@ -21,11 +21,12 @@ cc = { version = "1.0", features = ["parallel"] } which = { version = "4.0.2" } [dependencies] -libafl = { path = "../../libafl/", features = ["default"] } clap = { version = "4.0", features = ["derive"] } nix = "0.26" -libafl_targets = { path = "../../libafl_targets/" } +libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_cc = { path = "../../libafl_cc/" } +libafl_targets = { path = "../../libafl_targets/" } [lib] name = "libforkserver_libafl_cc" diff --git a/fuzzers/forkserver_libafl_cc/src/main.rs b/fuzzers/forkserver_libafl_cc/src/main.rs index 5bf6635ab2..b70dbe3878 100644 --- a/fuzzers/forkserver_libafl_cc/src/main.rs +++ b/fuzzers/forkserver_libafl_cc/src/main.rs @@ -3,13 +3,6 @@ use std::path::PathBuf; use clap::{self, Parser}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::{tuple_list, MatchName, Merge}, - AsMutSlice, Truncate, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{ @@ -27,6 +20,13 @@ use libafl::{ stages::mutational::StdMutationalStage, state::{HasCorpus, HasMetadata, StdState}, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::{tuple_list, MatchName, Merge}, + AsMutSlice, Truncate, +}; use nix::sys::signal::Signal; /// The commandline args this fuzzer accepts diff --git a/fuzzers/forkserver_simple/Cargo.toml b/fuzzers/forkserver_simple/Cargo.toml index c5e1486d8f..91773034ef 100644 --- a/fuzzers/forkserver_simple/Cargo.toml +++ b/fuzzers/forkserver_simple/Cargo.toml @@ -17,5 +17,6 @@ opt-level = 3 [dependencies] libafl = { path = "../../libafl/", features = ["std", "derive"] } +libafl_bolts = { path = "../../libafl_bolts/" } clap = { version = "4.0", features = ["derive"] } nix = "0.26" diff --git a/fuzzers/forkserver_simple/src/main.rs b/fuzzers/forkserver_simple/src/main.rs index 60faecf665..74f0f7be64 100644 --- a/fuzzers/forkserver_simple/src/main.rs +++ b/fuzzers/forkserver_simple/src/main.rs @@ -3,13 +3,6 @@ use std::path::PathBuf; use clap::{self, Parser}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::{tuple_list, MatchName, Merge}, - AsMutSlice, Truncate, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::{ @@ -27,6 +20,13 @@ use libafl::{ stages::mutational::StdMutationalStage, state::{HasCorpus, HasMetadata, StdState}, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::{tuple_list, MatchName, Merge}, + AsMutSlice, Truncate, +}; use nix::sys::signal::Signal; /// The commandline args this fuzzer accepts diff --git a/fuzzers/frida_executable_libpng/Cargo.toml b/fuzzers/frida_executable_libpng/Cargo.toml index 48556ffda0..5bef5fc35f 100644 --- a/fuzzers/frida_executable_libpng/Cargo.toml +++ b/fuzzers/frida_executable_libpng/Cargo.toml @@ -25,11 +25,9 @@ flate2 = "1.0.22" tar = "0.4.37" reqwest = { version = "0.11.4", features = ["blocking"] } - - - [dependencies] libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public", "frida_cli" ] } #, "llmp_small_maps", "llmp_debug"]} +libafl_bolts = { path = "../../libafl_bolts/" } capstone = "0.11.0" frida-gum = { version = "0.8.1", features = [ "auto-download", "event-sink", "invocation-listener"] } libafl_frida = { path = "../../libafl_frida", features = ["cmplog"] } diff --git a/fuzzers/frida_executable_libpng/src/fuzzer.rs b/fuzzers/frida_executable_libpng/src/fuzzer.rs index 9a71c883e8..f2361dbcda 100644 --- a/fuzzers/frida_executable_libpng/src/fuzzer.rs +++ b/fuzzers/frida_executable_libpng/src/fuzzer.rs @@ -8,17 +8,8 @@ use std::{path::PathBuf, ptr::null}; use frida_gum::Gum; use libafl::{ - bolts::{ - cli::{parse_args, FuzzerOptions}, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus}, - events::{llmp::LlmpRestartingEventManager, EventConfig}, + events::{launcher::Launcher, llmp::LlmpRestartingEventManager, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, ShadowExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -37,6 +28,14 @@ use libafl::{ }; #[cfg(unix)] use libafl::{feedback_and_fast, feedbacks::ConstFeedback}; +use libafl_bolts::{ + cli::{parse_args, FuzzerOptions}, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; #[cfg(unix)] use libafl_frida::asan::{ asan_rt::AsanRuntime, diff --git a/fuzzers/frida_gdiplus/Cargo.toml b/fuzzers/frida_gdiplus/Cargo.toml index 15471c27cd..471ca57a4a 100644 --- a/fuzzers/frida_gdiplus/Cargo.toml +++ b/fuzzers/frida_gdiplus/Cargo.toml @@ -25,6 +25,7 @@ reqwest = { version = "0.11.4", features = ["blocking"] } [dependencies] libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public", "frida_cli" ] } #, "llmp_small_maps", "llmp_debug"]} +libafl_bolts = { path = "../../libafl_bolts/" } frida-gum = { version = "0.8.1", features = [ "auto-download", "event-sink", "invocation-listener"] } libafl_frida = { path = "../../libafl_frida", features = ["cmplog"] } libafl_targets = { path = "../../libafl_targets", features = ["sancov_cmplog"] } diff --git a/fuzzers/frida_gdiplus/src/fuzzer.rs b/fuzzers/frida_gdiplus/src/fuzzer.rs index d8ab41cdb0..665ee5b5eb 100644 --- a/fuzzers/frida_gdiplus/src/fuzzer.rs +++ b/fuzzers/frida_gdiplus/src/fuzzer.rs @@ -14,17 +14,8 @@ use std::path::PathBuf; use frida_gum::Gum; use libafl::{ - bolts::{ - cli::{parse_args, FuzzerOptions}, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus}, - events::{llmp::LlmpRestartingEventManager, EventConfig}, + events::{launcher::Launcher, llmp::LlmpRestartingEventManager, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, ShadowExecutor}, feedback_and_fast, feedback_or, feedback_or_fast, feedbacks::{ConstFeedback, CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -41,6 +32,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + cli::{parse_args, FuzzerOptions}, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; #[cfg(unix)] use libafl_frida::asan::asan_rt::AsanRuntime; #[cfg(unix)] diff --git a/fuzzers/frida_libpng/Cargo.toml b/fuzzers/frida_libpng/Cargo.toml index 05e96dc1fb..a7669897b3 100644 --- a/fuzzers/frida_libpng/Cargo.toml +++ b/fuzzers/frida_libpng/Cargo.toml @@ -27,6 +27,7 @@ reqwest = { version = "0.11.4", features = ["blocking"] } [dependencies] libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public", "frida_cli" ] } #, "llmp_small_maps", "llmp_debug"]} +libafl_bolts = { path = "../../libafl_bolts/" } frida-gum = { version = "0.8.1", features = [ "auto-download", "event-sink", "invocation-listener"] } libafl_frida = { path = "../../libafl_frida", features = ["cmplog"] } libafl_targets = { path = "../../libafl_targets", features = ["sancov_cmplog"] } diff --git a/fuzzers/frida_libpng/src/fuzzer.rs b/fuzzers/frida_libpng/src/fuzzer.rs index b46b516b09..23ce1fcfd8 100644 --- a/fuzzers/frida_libpng/src/fuzzer.rs +++ b/fuzzers/frida_libpng/src/fuzzer.rs @@ -8,17 +8,8 @@ use std::path::PathBuf; use frida_gum::Gum; use libafl::{ - bolts::{ - cli::{parse_args, FuzzerOptions}, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus}, - events::{llmp::LlmpRestartingEventManager, EventConfig}, + events::{launcher::Launcher, llmp::LlmpRestartingEventManager, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, ShadowExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -37,6 +28,14 @@ use libafl::{ }; #[cfg(unix)] use libafl::{feedback_and_fast, feedbacks::ConstFeedback}; +use libafl_bolts::{ + cli::{parse_args, FuzzerOptions}, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; #[cfg(unix)] use libafl_frida::asan::{ asan_rt::AsanRuntime, diff --git a/fuzzers/fuzzbench/Cargo.toml b/fuzzers/fuzzbench/Cargo.toml index 13d208052b..82a9acee12 100644 --- a/fuzzers/fuzzbench/Cargo.toml +++ b/fuzzers/fuzzbench/Cargo.toml @@ -21,6 +21,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "sancov_cmplog", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/fuzzbench/src/lib.rs b/fuzzers/fuzzbench/src/lib.rs index 0542c75789..e92350ba6b 100644 --- a/fuzzers/fuzzbench/src/lib.rs +++ b/fuzzers/fuzzbench/src/lib.rs @@ -16,14 +16,6 @@ use std::{ use clap::{Arg, Command}; use libafl::{ - bolts::{ - current_nanos, current_time, - os::dup2, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, events::SimpleRestartingEventManager, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, @@ -47,6 +39,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, current_time, + os::dup2, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; #[cfg(any(target_os = "linux", target_vendor = "apple"))] use libafl_targets::autotokens; use libafl_targets::{ diff --git a/fuzzers/fuzzbench_fork_qemu/Cargo.toml b/fuzzers/fuzzbench_fork_qemu/Cargo.toml index e81d7cd88b..7b06e527c7 100644 --- a/fuzzers/fuzzbench_fork_qemu/Cargo.toml +++ b/fuzzers/fuzzbench_fork_qemu/Cargo.toml @@ -13,6 +13,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_qemu = { path = "../../libafl_qemu/", features = ["x86_64", "usermode"] } clap = { version = "4.0", features = ["default"] } diff --git a/fuzzers/fuzzbench_fork_qemu/src/fuzzer.rs b/fuzzers/fuzzbench_fork_qemu/src/fuzzer.rs index cc49c6e09e..dc771b9dac 100644 --- a/fuzzers/fuzzbench_fork_qemu/src/fuzzer.rs +++ b/fuzzers/fuzzbench_fork_qemu/src/fuzzer.rs @@ -13,14 +13,6 @@ use std::{ use clap::{Arg, Command}; use libafl::{ - bolts::{ - current_nanos, current_time, - os::dup2, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsMutSlice, AsSlice, - }, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, events::SimpleRestartingEventManager, executors::{ExitKind, ShadowExecutor}, @@ -44,6 +36,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, current_time, + os::dup2, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsMutSlice, AsSlice, +}; use libafl_qemu::{ cmplog::{CmpLogMap, CmpLogObserver, QemuCmpLogChildHelper}, edges::{QemuEdgeCoverageChildHelper, EDGES_MAP_PTR, EDGES_MAP_SIZE}, diff --git a/fuzzers/fuzzbench_forkserver/Cargo.toml b/fuzzers/fuzzbench_forkserver/Cargo.toml index a5fe37b362..1b2f24cda3 100644 --- a/fuzzers/fuzzbench_forkserver/Cargo.toml +++ b/fuzzers/fuzzbench_forkserver/Cargo.toml @@ -16,5 +16,6 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } clap = { version = "4.0", features = ["default"] } nix = "0.26" diff --git a/fuzzers/fuzzbench_forkserver/src/main.rs b/fuzzers/fuzzbench_forkserver/src/main.rs index fe3a4cb4e0..812bfbc083 100644 --- a/fuzzers/fuzzbench_forkserver/src/main.rs +++ b/fuzzers/fuzzbench_forkserver/src/main.rs @@ -9,13 +9,6 @@ use std::{ use clap::{Arg, ArgAction, Command}; use libafl::{ - bolts::{ - current_nanos, current_time, - rands::StdRand, - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::{tuple_list, Merge}, - AsMutSlice, - }, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::forkserver::{ForkserverExecutor, TimeoutForkserverExecutor}, @@ -41,6 +34,13 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, current_time, + rands::StdRand, + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::{tuple_list, Merge}, + AsMutSlice, +}; use nix::sys::signal::Signal; pub fn main() { diff --git a/fuzzers/fuzzbench_forkserver_cmplog/Cargo.toml b/fuzzers/fuzzbench_forkserver_cmplog/Cargo.toml index 5165b03ed6..398954a1c4 100644 --- a/fuzzers/fuzzbench_forkserver_cmplog/Cargo.toml +++ b/fuzzers/fuzzbench_forkserver_cmplog/Cargo.toml @@ -16,5 +16,6 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } clap = { version = "4.0", features = ["default"] } nix = "0.26" \ No newline at end of file diff --git a/fuzzers/fuzzbench_forkserver_cmplog/src/main.rs b/fuzzers/fuzzbench_forkserver_cmplog/src/main.rs index bb7ed78e0a..21bd751cba 100644 --- a/fuzzers/fuzzbench_forkserver_cmplog/src/main.rs +++ b/fuzzers/fuzzbench_forkserver_cmplog/src/main.rs @@ -9,13 +9,6 @@ use std::{ use clap::{Arg, ArgAction, Command}; use libafl::{ - bolts::{ - current_nanos, current_time, - rands::StdRand, - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::{tuple_list, Merge}, - AsMutSlice, - }, corpus::{Corpus, CorpusId, InMemoryOnDiskCorpus, OnDiskCorpus}, events::SimpleEventManager, executors::forkserver::{ForkserverExecutor, TimeoutForkserverExecutor}, @@ -42,6 +35,13 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, current_time, + rands::StdRand, + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::{tuple_list, Merge}, + AsMutSlice, +}; use nix::sys::signal::Signal; pub fn main() { @@ -245,7 +245,7 @@ fn fuzz( shmem.write_to_env("__AFL_SHM_ID").unwrap(); let shmem_buf = shmem.as_mut_slice(); // To let know the AFL++ binary that we have a big map - std::env::set_var("AFL_MAP_SIZE", format!("{}", MAP_SIZE)); + std::env::set_var("AFL_MAP_SIZE", format!("{MAP_SIZE}")); // Create an observation channel using the hitcounts map of AFL++ let edges_observer = diff --git a/fuzzers/fuzzbench_qemu/Cargo.toml b/fuzzers/fuzzbench_qemu/Cargo.toml index 5689a8faa2..e4422070b3 100644 --- a/fuzzers/fuzzbench_qemu/Cargo.toml +++ b/fuzzers/fuzzbench_qemu/Cargo.toml @@ -13,6 +13,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_qemu = { path = "../../libafl_qemu/", features = ["x86_64", "usermode"] } clap = { version = "4.0", features = ["default"] } diff --git a/fuzzers/fuzzbench_qemu/src/fuzzer.rs b/fuzzers/fuzzbench_qemu/src/fuzzer.rs index db1c4d45ed..0a8b9363cb 100644 --- a/fuzzers/fuzzbench_qemu/src/fuzzer.rs +++ b/fuzzers/fuzzbench_qemu/src/fuzzer.rs @@ -13,14 +13,6 @@ use std::{ use clap::{Arg, Command}; use libafl::{ - bolts::{ - current_nanos, current_time, - os::dup2, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, events::SimpleRestartingEventManager, executors::{ExitKind, ShadowExecutor, TimeoutExecutor}, @@ -44,6 +36,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, current_time, + os::dup2, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_qemu::{ cmplog::{CmpLogObserver, QemuCmpLogHelper}, //asan::{init_with_asan, QemuAsanHelper}, diff --git a/fuzzers/fuzzbench_text/Cargo.toml b/fuzzers/fuzzbench_text/Cargo.toml index fec6b673f7..5ff5240342 100644 --- a/fuzzers/fuzzbench_text/Cargo.toml +++ b/fuzzers/fuzzbench_text/Cargo.toml @@ -21,6 +21,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "sancov_cmplog", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/fuzzbench_text/src/lib.rs b/fuzzers/fuzzbench_text/src/lib.rs index 74004cefc6..fb04caa021 100644 --- a/fuzzers/fuzzbench_text/src/lib.rs +++ b/fuzzers/fuzzbench_text/src/lib.rs @@ -17,14 +17,6 @@ use std::{ use clap::{Arg, Command}; use content_inspector::inspect; use libafl::{ - bolts::{ - current_nanos, current_time, - os::dup2, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, events::SimpleRestartingEventManager, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, @@ -53,6 +45,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, current_time, + os::dup2, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; #[cfg(any(target_os = "linux", target_vendor = "apple"))] use libafl_targets::autotokens; use libafl_targets::{ diff --git a/fuzzers/libafl_atheris/Cargo.toml b/fuzzers/libafl_atheris/Cargo.toml index ed81bf1e0d..f0303f0d23 100644 --- a/fuzzers/libafl_atheris/Cargo.toml +++ b/fuzzers/libafl_atheris/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["pointer_maps", "sancov_cmplog", "libfuzzer"] } clap = { version = "4.0", features = ["default"] } diff --git a/fuzzers/libafl_atheris/src/lib.rs b/fuzzers/libafl_atheris/src/lib.rs index 98bac10a0f..b284d4fc9a 100644 --- a/fuzzers/libafl_atheris/src/lib.rs +++ b/fuzzers/libafl_atheris/src/lib.rs @@ -12,17 +12,8 @@ use std::{ use clap::{Arg, ArgAction, Command}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::EventConfig, + events::{launcher::Launcher, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, feedback_or, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -40,6 +31,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{ CmpLogObserver, __sanitizer_cov_trace_cmp1, __sanitizer_cov_trace_cmp2, __sanitizer_cov_trace_cmp4, __sanitizer_cov_trace_cmp8, std_edges_map_observer, EDGES_MAP_PTR, diff --git a/fuzzers/libfuzzer_libmozjpeg/Cargo.toml b/fuzzers/libfuzzer_libmozjpeg/Cargo.toml index 0311d429bc..9fe46445dd 100644 --- a/fuzzers/libfuzzer_libmozjpeg/Cargo.toml +++ b/fuzzers/libfuzzer_libmozjpeg/Cargo.toml @@ -16,6 +16,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_edges", "sancov_value_profile", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libmozjpeg/src/lib.rs b/fuzzers/libfuzzer_libmozjpeg/src/lib.rs index 95a91ce44c..24772b5e5a 100644 --- a/fuzzers/libfuzzer_libmozjpeg/src/lib.rs +++ b/fuzzers/libfuzzer_libmozjpeg/src/lib.rs @@ -7,12 +7,6 @@ static GLOBAL: MiMalloc = MiMalloc; use std::{env, path::PathBuf}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -31,6 +25,12 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{ libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer, CMP_MAP, }; diff --git a/fuzzers/libfuzzer_libpng/Cargo.toml b/fuzzers/libfuzzer_libpng/Cargo.toml index 08986b0367..a129bb9c2e 100644 --- a/fuzzers/libfuzzer_libpng/Cargo.toml +++ b/fuzzers/libfuzzer_libpng/Cargo.toml @@ -23,6 +23,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["default"] } # libafl = { path = "../../libafl/", features = ["default"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer", "sancov_cmplog"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng/src/lib.rs b/fuzzers/libfuzzer_libpng/src/lib.rs index fbf8f2a2ac..c229129b0a 100644 --- a/fuzzers/libfuzzer_libpng/src/lib.rs +++ b/fuzzers/libfuzzer_libpng/src/lib.rs @@ -10,12 +10,6 @@ use std::ptr; use std::{env, path::PathBuf}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig, EventRestarter}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, @@ -36,6 +30,12 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, EDGES_MAP, MAX_EDGES_NUM}; /// The main fn, `no_mangle` as it is a C main diff --git a/fuzzers/libfuzzer_libpng_accounting/Cargo.toml b/fuzzers/libfuzzer_libpng_accounting/Cargo.toml index dfd8e3d545..9f6457a0de 100644 --- a/fuzzers/libfuzzer_libpng_accounting/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_accounting/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["std", "derive", "llmp_compression", "introspection"] } +libafl_bolts = { path = "../../libafl_bolts/", features = ["std", "derive", "llmp_compression"] } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_accounting/src/lib.rs b/fuzzers/libfuzzer_libpng_accounting/src/lib.rs index 0f117f166f..58bdbd92ea 100644 --- a/fuzzers/libfuzzer_libpng_accounting/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_accounting/src/lib.rs @@ -11,17 +11,8 @@ use std::{env, net::SocketAddr, path::PathBuf}; use clap::Parser; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::EventConfig, + events::{EventConfig, Launcher}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -38,6 +29,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{ libfuzzer_initialize, libfuzzer_test_one_input, ACCOUNTING_MEMOP_MAP, EDGES_MAP, MAX_EDGES_NUM, }; diff --git a/fuzzers/libfuzzer_libpng_centralized/Cargo.toml b/fuzzers/libfuzzer_libpng_centralized/Cargo.toml index f7223f057b..ef2e6533da 100644 --- a/fuzzers/libfuzzer_libpng_centralized/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_centralized/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["std", "derive", "rand_trait", "fork", "prelude", "gzip", "regex"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_centralized/src/lib.rs b/fuzzers/libfuzzer_libpng_centralized/src/lib.rs index 8dc3b770f9..0338b7ad30 100644 --- a/fuzzers/libfuzzer_libpng_centralized/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_centralized/src/lib.rs @@ -11,18 +11,8 @@ use std::{env, net::SocketAddr, path::PathBuf}; use clap::{self, Parser}; use libafl::{ - bolts::{ - core_affinity::{CoreId, Cores}, - current_nanos, - launcher::Launcher, - llmp::{LlmpReceiver, LlmpSender}, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, ClientId, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::{CentralizedEventManager, EventConfig}, + events::{launcher::Launcher, CentralizedEventManager, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -39,6 +29,15 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::{CoreId, Cores}, + current_nanos, + llmp::{LlmpReceiver, LlmpSender}, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, ClientId, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; /// Parse a millis string to a [`Duration`]. Used for arg parsing. diff --git a/fuzzers/libfuzzer_libpng_cmin/Cargo.toml b/fuzzers/libfuzzer_libpng_cmin/Cargo.toml index d6b4ba45e2..daabd22c68 100644 --- a/fuzzers/libfuzzer_libpng_cmin/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_cmin/Cargo.toml @@ -23,6 +23,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["default", "cmin"] } # libafl = { path = "../../libafl/", features = ["default"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer", "sancov_cmplog"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_cmin/src/lib.rs b/fuzzers/libfuzzer_libpng_cmin/src/lib.rs index e177575338..6c58d8625a 100644 --- a/fuzzers/libfuzzer_libpng_cmin/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_cmin/src/lib.rs @@ -10,12 +10,6 @@ use std::ptr; use std::{env, path::PathBuf}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{ minimizer::{CorpusMinimizer, StdCorpusMinimizer}, Corpus, InMemoryCorpus, OnDiskCorpus, @@ -39,6 +33,12 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; /// The main fn, `no_mangle` as it is a C main diff --git a/fuzzers/libfuzzer_libpng_ctx/Cargo.toml b/fuzzers/libfuzzer_libpng_ctx/Cargo.toml index d4ddae3dab..f6e8d24b19 100644 --- a/fuzzers/libfuzzer_libpng_ctx/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_ctx/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["std", "derive", "llmp_compression", "introspection"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_ctx/src/lib.rs b/fuzzers/libfuzzer_libpng_ctx/src/lib.rs index d50f201db1..bdb22db1e8 100644 --- a/fuzzers/libfuzzer_libpng_ctx/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_ctx/src/lib.rs @@ -11,17 +11,8 @@ use std::{env, net::SocketAddr, path::PathBuf}; use clap::{self, Parser}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::EventConfig, + events::{launcher::Launcher, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -38,6 +29,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; fn timeout_from_millis_str(time: &str) -> Result { diff --git a/fuzzers/libfuzzer_libpng_launcher/Cargo.toml b/fuzzers/libfuzzer_libpng_launcher/Cargo.toml index 2062f51f03..3905eac90e 100644 --- a/fuzzers/libfuzzer_libpng_launcher/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_launcher/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["std", "derive", "llmp_compression", "introspection"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_launcher/src/lib.rs b/fuzzers/libfuzzer_libpng_launcher/src/lib.rs index 1c0c657c81..616341b9da 100644 --- a/fuzzers/libfuzzer_libpng_launcher/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_launcher/src/lib.rs @@ -11,17 +11,8 @@ use std::{env, net::SocketAddr, path::PathBuf}; use clap::{self, Parser}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::EventConfig, + events::{launcher::Launcher, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -38,6 +29,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; /// Parse a millis string to a [`Duration`]. Used for arg parsing. diff --git a/fuzzers/libfuzzer_libpng_norestart/Cargo.toml b/fuzzers/libfuzzer_libpng_norestart/Cargo.toml index 2e1d87883d..117a5751a8 100644 --- a/fuzzers/libfuzzer_libpng_norestart/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_norestart/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_norestart/src/lib.rs b/fuzzers/libfuzzer_libpng_norestart/src/lib.rs index 5c76afc983..1268009c9c 100644 --- a/fuzzers/libfuzzer_libpng_norestart/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_norestart/src/lib.rs @@ -11,17 +11,8 @@ use std::{env, net::SocketAddr, path::PathBuf}; use clap::{self, Parser}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus}, - events::{EventConfig, EventRestarter, LlmpRestartingEventManager}, + events::{launcher::Launcher, EventConfig, EventRestarter, LlmpRestartingEventManager}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -38,6 +29,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; /// Parse a millis string to a [`Duration`]. Used for arg parsing. diff --git a/fuzzers/libfuzzer_libpng_tcp_manager/Cargo.toml b/fuzzers/libfuzzer_libpng_tcp_manager/Cargo.toml index be33589158..90460254ef 100644 --- a/fuzzers/libfuzzer_libpng_tcp_manager/Cargo.toml +++ b/fuzzers/libfuzzer_libpng_tcp_manager/Cargo.toml @@ -23,6 +23,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["default", "tcp_manager"] } # libafl = { path = "../../libafl/", features = ["default"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer", "sancov_cmplog"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_libpng_tcp_manager/src/lib.rs b/fuzzers/libfuzzer_libpng_tcp_manager/src/lib.rs index 882dac2530..6c19c485b3 100644 --- a/fuzzers/libfuzzer_libpng_tcp_manager/src/lib.rs +++ b/fuzzers/libfuzzer_libpng_tcp_manager/src/lib.rs @@ -10,12 +10,6 @@ use std::ptr; use std::{env, path::PathBuf}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{tcp::setup_restarting_mgr_tcp, EventConfig, EventRestarter}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, @@ -36,6 +30,12 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, EDGES_MAP, MAX_EDGES_NUM}; /// The main fn, `no_mangle` as it is a C main diff --git a/fuzzers/libfuzzer_reachability/Cargo.toml b/fuzzers/libfuzzer_reachability/Cargo.toml index 0c2b4539a2..55f600f4ca 100644 --- a/fuzzers/libfuzzer_reachability/Cargo.toml +++ b/fuzzers/libfuzzer_reachability/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_reachability/src/lib.rs b/fuzzers/libfuzzer_reachability/src/lib.rs index 96f7320202..d1f4de5e41 100644 --- a/fuzzers/libfuzzer_reachability/src/lib.rs +++ b/fuzzers/libfuzzer_reachability/src/lib.rs @@ -7,7 +7,6 @@ static GLOBAL: MiMalloc = MiMalloc; use std::{env, path::PathBuf}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig, EventRestarter}, executors::{inprocess::InProcessExecutor, ExitKind}, @@ -22,6 +21,7 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; const TARGET_SIZE: usize = 4; diff --git a/fuzzers/libfuzzer_stb_image/Cargo.toml b/fuzzers/libfuzzer_stb_image/Cargo.toml index 7fd712e4b2..d29f617b69 100644 --- a/fuzzers/libfuzzer_stb_image/Cargo.toml +++ b/fuzzers/libfuzzer_stb_image/Cargo.toml @@ -17,6 +17,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_edges", "sancov_cmplog", "libfuzzer"] } mimalloc = { version = "*", default-features = false } diff --git a/fuzzers/libfuzzer_stb_image/src/main.rs b/fuzzers/libfuzzer_stb_image/src/main.rs index e80360a11b..cb395dfca4 100644 --- a/fuzzers/libfuzzer_stb_image/src/main.rs +++ b/fuzzers/libfuzzer_stb_image/src/main.rs @@ -7,7 +7,6 @@ static GLOBAL: MiMalloc = MiMalloc; use std::{env, path::PathBuf}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind, ShadowExecutor}, @@ -26,6 +25,7 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use libafl_targets::{ libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer, CmpLogObserver, }; diff --git a/fuzzers/libfuzzer_stb_image_concolic/fuzzer/Cargo.toml b/fuzzers/libfuzzer_stb_image_concolic/fuzzer/Cargo.toml index 0fbe5605ed..fc3cc3b9c3 100644 --- a/fuzzers/libfuzzer_stb_image_concolic/fuzzer/Cargo.toml +++ b/fuzzers/libfuzzer_stb_image_concolic/fuzzer/Cargo.toml @@ -17,6 +17,7 @@ debug = true [dependencies] libafl = { path = "../../../libafl/", features = ["concolic_mutation"] } +libafl_bolts = { path = "../../../libafl_bolts/" } libafl_targets = { path = "../../../libafl_targets/", features = ["sancov_pcguard_edges", "sancov_cmplog", "libfuzzer"] } clap = { version = "4.0", features = ["derive"]} mimalloc = { version = "*", default-features = false } diff --git a/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs b/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs index ac514f3c54..4894e806a3 100644 --- a/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs +++ b/fuzzers/libfuzzer_stb_image_concolic/fuzzer/src/main.rs @@ -13,13 +13,6 @@ use std::{ use clap::{self, Parser}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - shmem::{ShMem, ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Named}, - AsMutSlice, AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig}, executors::{ @@ -49,6 +42,13 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + shmem::{ShMem, ShMemProvider, StdShMemProvider}, + tuples::tuple_list, + AsMutSlice, AsSlice, Named, +}; use libafl_targets::{ libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer, CmpLogObserver, }; diff --git a/fuzzers/libfuzzer_stb_image_sugar/Cargo.toml b/fuzzers/libfuzzer_stb_image_sugar/Cargo.toml index 8aaa9985f2..76f9cf7428 100644 --- a/fuzzers/libfuzzer_stb_image_sugar/Cargo.toml +++ b/fuzzers/libfuzzer_stb_image_sugar/Cargo.toml @@ -18,6 +18,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_edges", "sancov_cmplog", "libfuzzer"] } libafl_sugar = { path = "../../libafl_sugar/" } mimalloc = { version = "*", default-features = false } diff --git a/fuzzers/libfuzzer_stb_image_sugar/src/main.rs b/fuzzers/libfuzzer_stb_image_sugar/src/main.rs index b0e0c90472..c9c1e65ab7 100644 --- a/fuzzers/libfuzzer_stb_image_sugar/src/main.rs +++ b/fuzzers/libfuzzer_stb_image_sugar/src/main.rs @@ -6,7 +6,7 @@ static GLOBAL: MiMalloc = MiMalloc; use std::{env, path::PathBuf}; -use libafl::bolts::core_affinity::Cores; +use libafl_bolts::core_affinity::Cores; use libafl_sugar::InMemoryBytesCoverageSugar; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input}; diff --git a/fuzzers/libfuzzer_windows_asan/Cargo.toml b/fuzzers/libfuzzer_windows_asan/Cargo.toml index 8a5810ae43..515cb3b7ac 100644 --- a/fuzzers/libfuzzer_windows_asan/Cargo.toml +++ b/fuzzers/libfuzzer_windows_asan/Cargo.toml @@ -15,6 +15,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["libfuzzer", "sancov_pcguard_edges"] } libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/libfuzzer_windows_asan/src/lib.rs b/fuzzers/libfuzzer_windows_asan/src/lib.rs index e2fb967c41..fbc735d484 100644 --- a/fuzzers/libfuzzer_windows_asan/src/lib.rs +++ b/fuzzers/libfuzzer_windows_asan/src/lib.rs @@ -2,12 +2,6 @@ use core::time::Duration; use std::{env, path::PathBuf}; use libafl::{ - bolts::{ - current_nanos, - rands::StdRand, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig, EventRestarter}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, @@ -25,6 +19,12 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{ + current_nanos, + rands::StdRand, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; #[no_mangle] pub extern "C" fn libafl_main() { diff --git a/fuzzers/nautilus_sync/Cargo.toml b/fuzzers/nautilus_sync/Cargo.toml index ad1becf102..f9b5c2b2da 100644 --- a/fuzzers/nautilus_sync/Cargo.toml +++ b/fuzzers/nautilus_sync/Cargo.toml @@ -21,6 +21,7 @@ debug = true [dependencies] libafl = { path = "../../libafl/", features = ["default", "nautilus"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] } # TODO Include it only when building cc libafl_cc = { path = "../../libafl_cc/" } diff --git a/fuzzers/nautilus_sync/src/lib.rs b/fuzzers/nautilus_sync/src/lib.rs index 91d285b2bd..54d7bb3ab1 100644 --- a/fuzzers/nautilus_sync/src/lib.rs +++ b/fuzzers/nautilus_sync/src/lib.rs @@ -8,16 +8,8 @@ use std::{env, net::SocketAddr, path::PathBuf, time::Duration}; use clap::{self, Parser}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::tuple_list, - }, corpus::{InMemoryCorpus, OnDiskCorpus}, - events::{llmp::LlmpEventConverter, EventConfig}, + events::{launcher::Launcher, llmp::LlmpEventConverter, EventConfig}, executors::{inprocess::InProcessExecutor, ExitKind}, feedback_or, feedbacks::{CrashFeedback, MaxMapFeedback, NautilusChunksMetadata, NautilusFeedback}, @@ -34,6 +26,13 @@ use libafl::{ state::{HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::tuple_list, +}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; /// Parse a millis string to a [`Duration`]. Used for arg parsing. diff --git a/fuzzers/nyx_libxml2_parallel/Cargo.toml b/fuzzers/nyx_libxml2_parallel/Cargo.toml index 49fdf104ac..ab50cbc1a6 100644 --- a/fuzzers/nyx_libxml2_parallel/Cargo.toml +++ b/fuzzers/nyx_libxml2_parallel/Cargo.toml @@ -6,6 +6,7 @@ default-run = "nyx_libxml2_parallel" [dependencies] libafl = { path = "../../libafl" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_cc = { path = "../../libafl_cc" } libafl_nyx = { path = "../../libafl_nyx" } diff --git a/fuzzers/nyx_libxml2_parallel/src/main.rs b/fuzzers/nyx_libxml2_parallel/src/main.rs index 14abb3e1e0..f4bd9b8a0f 100644 --- a/fuzzers/nyx_libxml2_parallel/src/main.rs +++ b/fuzzers/nyx_libxml2_parallel/src/main.rs @@ -1,15 +1,8 @@ use std::path::{Path, PathBuf}; use libafl::{ - bolts::{ - core_affinity::{CoreId, Cores}, - launcher::Launcher, - rands::{RandomSeed, StdRand}, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::tuple_list, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus, Testcase}, - events::EventConfig, + events::{launcher::Launcher, EventConfig}, feedbacks::{CrashFeedback, MaxMapFeedback}, inputs::BytesInput, monitors::MultiMonitor, @@ -20,6 +13,12 @@ use libafl::{ state::StdState, Error, Fuzzer, StdFuzzer, }; +use libafl_bolts::{ + core_affinity::{CoreId, Cores}, + rands::{RandomSeed, StdRand}, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::tuple_list, +}; use libafl_nyx::{executor::NyxExecutor, helper::NyxHelper}; fn main() { diff --git a/fuzzers/nyx_libxml2_standalone/Cargo.toml b/fuzzers/nyx_libxml2_standalone/Cargo.toml index 6ccfad1c3b..897546c0ce 100644 --- a/fuzzers/nyx_libxml2_standalone/Cargo.toml +++ b/fuzzers/nyx_libxml2_standalone/Cargo.toml @@ -6,6 +6,7 @@ default-run = "nyx_libxml2_standalone" [dependencies] libafl = { path = "../../libafl" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_cc = { path = "../../libafl_cc" } libafl_nyx = { path = "../../libafl_nyx" } diff --git a/fuzzers/nyx_libxml2_standalone/src/main.rs b/fuzzers/nyx_libxml2_standalone/src/main.rs index 05e8b70a32..3ce5ebc938 100644 --- a/fuzzers/nyx_libxml2_standalone/src/main.rs +++ b/fuzzers/nyx_libxml2_standalone/src/main.rs @@ -1,10 +1,6 @@ use std::path::{Path, PathBuf}; use libafl::{ - bolts::{ - rands::{RandomSeed, StdRand}, - tuples::tuple_list, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus, Testcase}, events::SimpleEventManager, feedbacks::{CrashFeedback, MaxMapFeedback}, @@ -17,6 +13,10 @@ use libafl::{ state::StdState, Fuzzer, StdFuzzer, }; +use libafl_bolts::{ + rands::{RandomSeed, StdRand}, + tuples::tuple_list, +}; use libafl_nyx::{executor::NyxExecutor, helper::NyxHelper}; fn main() { diff --git a/fuzzers/push_stage_harness/Cargo.toml b/fuzzers/push_stage_harness/Cargo.toml index bf9a9ed880..8fda3e74e7 100644 --- a/fuzzers/push_stage_harness/Cargo.toml +++ b/fuzzers/push_stage_harness/Cargo.toml @@ -20,3 +20,4 @@ debug = true [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } diff --git a/fuzzers/push_stage_harness/src/main.rs b/fuzzers/push_stage_harness/src/main.rs index 4dfc2be587..40b4886b65 100644 --- a/fuzzers/push_stage_harness/src/main.rs +++ b/fuzzers/push_stage_harness/src/main.rs @@ -8,7 +8,6 @@ use core::cell::{Cell, RefCell}; use std::{path::PathBuf, rc::Rc}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus, Testcase}, events::SimpleEventManager, executors::ExitKind, @@ -22,6 +21,7 @@ use libafl::{ stages::push::{PushStageSharedState, StdMutationalPushStage}, state::{HasCorpus, StdState}, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; diff --git a/fuzzers/qemu_coverage/Cargo.toml b/fuzzers/qemu_coverage/Cargo.toml index e7b8cd0442..318b0cefab 100644 --- a/fuzzers/qemu_coverage/Cargo.toml +++ b/fuzzers/qemu_coverage/Cargo.toml @@ -27,5 +27,6 @@ vergen = { version = "8.2.1", features = ["build", "cargo", "git", "gitcl", "rus [dependencies] clap = { version = "4.3.0", features = ["derive", "string"]} libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_qemu = { path = "../../libafl_qemu/", features = ["usermode"] } rangemap = { version = "1.0.3" } diff --git a/fuzzers/qemu_coverage/src/fuzzer.rs b/fuzzers/qemu_coverage/src/fuzzer.rs index 135de32e96..b54086a8eb 100644 --- a/fuzzers/qemu_coverage/src/fuzzer.rs +++ b/fuzzers/qemu_coverage/src/fuzzer.rs @@ -7,17 +7,8 @@ use std::{env, fs::DirEntry, io, path::PathBuf, process}; use clap::{builder::Str, Parser}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::tuple_list, - AsSlice, - }, corpus::{Corpus, NopCorpus}, - events::{EventConfig, EventRestarter}, + events::{launcher::Launcher, EventConfig, EventRestarter}, executors::{ExitKind, TimeoutExecutor}, fuzzer::StdFuzzer, inputs::{BytesInput, HasTargetBytes}, @@ -27,6 +18,14 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::tuple_list, + AsSlice, +}; use libafl_qemu::{ drcov::QemuDrCovHelper, elf::EasyElf, emu::Emulator, ArchExtras, CallingConvention, GuestAddr, GuestReg, MmapPerms, QemuExecutor, QemuHooks, QemuInstrumentationFilter, Regs, diff --git a/fuzzers/qemu_launcher/Cargo.toml b/fuzzers/qemu_launcher/Cargo.toml index 0d85aa7d77..b3e5561388 100644 --- a/fuzzers/qemu_launcher/Cargo.toml +++ b/fuzzers/qemu_launcher/Cargo.toml @@ -27,13 +27,6 @@ vergen = { version = "8.2.1", features = ["build", "cargo", "git", "gitcl", "rus [dependencies] clap = { version = "4.3.0", features = ["derive", "string"]} libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_qemu = { path = "../../libafl_qemu/", features = ["usermode"] } rangemap = { version = "1.0.3" } - - - - - - - - diff --git a/fuzzers/qemu_launcher/src/fuzzer.rs b/fuzzers/qemu_launcher/src/fuzzer.rs index 82cb6f4ba2..5465455855 100644 --- a/fuzzers/qemu_launcher/src/fuzzer.rs +++ b/fuzzers/qemu_launcher/src/fuzzer.rs @@ -5,17 +5,8 @@ use std::{env, path::PathBuf, process}; use clap::{builder::Str, Parser}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::tuple_list, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::{EventConfig, LlmpRestartingEventManager}, + events::{launcher::Launcher, EventConfig, LlmpRestartingEventManager}, executors::{ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -29,6 +20,14 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::tuple_list, + AsSlice, +}; use libafl_qemu::{ drcov::QemuDrCovHelper, edges::{edges_map_mut_slice, QemuEdgeCoverageHelper, MAX_EDGES_NUM}, diff --git a/fuzzers/qemu_systemmode/Cargo.toml b/fuzzers/qemu_systemmode/Cargo.toml index bfbd100d29..ab715c36d2 100644 --- a/fuzzers/qemu_systemmode/Cargo.toml +++ b/fuzzers/qemu_systemmode/Cargo.toml @@ -16,4 +16,5 @@ codegen-units = 1 [dependencies] libafl = { path = "../../libafl/" } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_qemu = { path = "../../libafl_qemu/", features = ["arm", "systemmode"] } diff --git a/fuzzers/qemu_systemmode/src/fuzzer.rs b/fuzzers/qemu_systemmode/src/fuzzer.rs index c662503375..3a9622b935 100644 --- a/fuzzers/qemu_systemmode/src/fuzzer.rs +++ b/fuzzers/qemu_systemmode/src/fuzzer.rs @@ -4,17 +4,8 @@ use core::{ptr::addr_of_mut, time::Duration}; use std::{env, path::PathBuf, process}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::tuple_list, - AsSlice, - }, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, - events::EventConfig, + events::{launcher::Launcher, EventConfig}, executors::{ExitKind, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -28,6 +19,14 @@ use libafl::{ state::{HasCorpus, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::tuple_list, + AsSlice, +}; use libafl_qemu::{ edges::{edges_map_mut_slice, QemuEdgeCoverageHelper, MAX_EDGES_NUM}, elf::EasyElf, diff --git a/fuzzers/tinyinst_simple/Cargo.toml b/fuzzers/tinyinst_simple/Cargo.toml index 874533d7fe..5f07ee0886 100644 --- a/fuzzers/tinyinst_simple/Cargo.toml +++ b/fuzzers/tinyinst_simple/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] libafl = { path = "../../libafl", features = ["introspection"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_tinyinst = { path = "../../libafl_tinyinst" } [profile.release] diff --git a/fuzzers/tinyinst_simple/src/main.rs b/fuzzers/tinyinst_simple/src/main.rs index d588b9ad01..60bf2307b5 100644 --- a/fuzzers/tinyinst_simple/src/main.rs +++ b/fuzzers/tinyinst_simple/src/main.rs @@ -1,15 +1,6 @@ use std::path::PathBuf; -#[cfg(target_vendor = "apple")] -use libafl::bolts::shmem::UnixShMemProvider; -#[cfg(windows)] -use libafl::bolts::shmem::Win32ShMemProvider; use libafl::{ - bolts::{ - rands::{RandomSeed, StdRand}, - shmem::ShMemProvider, - tuples::tuple_list, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus, Testcase}, events::SimpleEventManager, feedbacks::{CrashFeedback, ListFeedback}, @@ -22,6 +13,15 @@ use libafl::{ state::StdState, Fuzzer, StdFuzzer, }; +#[cfg(target_vendor = "apple")] +use libafl_bolts::shmem::UnixShMemProvider; +#[cfg(windows)] +use libafl_bolts::shmem::Win32ShMemProvider; +use libafl_bolts::{ + rands::{RandomSeed, StdRand}, + shmem::ShMemProvider, + tuples::tuple_list, +}; use libafl_tinyinst::executor::TinyInstExecutorBuilder; static mut COVERAGE: Vec = vec![]; diff --git a/fuzzers/tutorial/Cargo.toml b/fuzzers/tutorial/Cargo.toml index 29e9f303c2..6671c14fa1 100644 --- a/fuzzers/tutorial/Cargo.toml +++ b/fuzzers/tutorial/Cargo.toml @@ -20,6 +20,7 @@ which = { version = "4.0.2" } [dependencies] libafl = { path = "../../libafl/", features = ["default", "rand_trait"] } +libafl_bolts = { path = "../../libafl_bolts/" } libafl_targets = { path = "../../libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer", "sancov_cmplog"] } serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib lain = { version = "0.5", features = ["serde_support"], git = "https://github.com/Mrmaxmeier/lain.git", rev = "6c8a786" } # We're using a lain fork with updated rand crate diff --git a/fuzzers/tutorial/src/input.rs b/fuzzers/tutorial/src/input.rs index 2bb94f8d4f..0aec91454f 100644 --- a/fuzzers/tutorial/src/input.rs +++ b/fuzzers/tutorial/src/input.rs @@ -1,10 +1,8 @@ use std::hash::Hash; use lain::prelude::*; -use libafl::{ - bolts::{ownedref::OwnedSlice, HasLen}, - inputs::{HasTargetBytes, Input}, -}; +use libafl::inputs::{HasTargetBytes, Input}; +use libafl_bolts::{ownedref::OwnedSlice, HasLen}; use serde::{Deserialize, Serialize}; #[derive( diff --git a/fuzzers/tutorial/src/lib.rs b/fuzzers/tutorial/src/lib.rs index d0ca10980e..10c7ff9a76 100644 --- a/fuzzers/tutorial/src/lib.rs +++ b/fuzzers/tutorial/src/lib.rs @@ -7,7 +7,6 @@ use core::time::Duration; use std::{env, path::PathBuf}; use libafl::{ - bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::{setup_restarting_mgr_std, EventConfig, EventRestarter}, executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor}, @@ -22,16 +21,17 @@ use libafl::{ state::{HasCorpus, StdState}, Error, Fuzzer, }; +use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice}; use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer}; mod input; -use input::*; +use input::PacketData; mod mutator; -use mutator::*; +use mutator::LainMutator; mod metadata; -use metadata::*; +use metadata::{PacketLenFeedback, PacketLenMinimizerScheduler}; /// The main fn, `no_mangle` as it is a C main #[cfg(not(test))] diff --git a/fuzzers/tutorial/src/metadata.rs b/fuzzers/tutorial/src/metadata.rs index dac0806500..cc410cdbdd 100644 --- a/fuzzers/tutorial/src/metadata.rs +++ b/fuzzers/tutorial/src/metadata.rs @@ -1,5 +1,4 @@ use libafl::{ - bolts::tuples::Named, corpus::Testcase, events::EventFirer, executors::ExitKind, @@ -8,8 +7,9 @@ use libafl::{ observers::ObserversTuple, schedulers::{MinimizerScheduler, TestcaseScore}, state::{HasClientPerfMonitor, HasCorpus, HasMetadata}, - Error, SerdeAny, + Error, }; +use libafl_bolts::{Named, SerdeAny}; use serde::{Deserialize, Serialize}; use crate::input::PacketData; diff --git a/fuzzers/tutorial/src/mutator.rs b/fuzzers/tutorial/src/mutator.rs index 6ae72af90f..ce9d85ad51 100644 --- a/fuzzers/tutorial/src/mutator.rs +++ b/fuzzers/tutorial/src/mutator.rs @@ -1,13 +1,13 @@ use lain::traits::Mutatable; use libafl::{ - bolts::{ - rands::{Rand, StdRand}, - tuples::Named, - }, mutators::{MutationResult, Mutator}, state::HasRand, Error, }; +use libafl_bolts::{ + rands::{Rand, StdRand}, + Named, +}; use crate::input::PacketData; diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index 8c2c4b978e..fd03a1200a 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -13,24 +13,24 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s [features] default = ["std", "derive", "llmp_compression", "llmp_small_maps", "llmp_broker_timeouts", "rand_trait", "fork", "prelude", "gzip", "regex"] -std = ["serde_json", "serde_json/std", "hostname", "nix", "serde/std", "bincode", "wait-timeout", "byteorder", "once_cell", "uuid", "tui_monitor", "ctor", "backtrace", "uds", "serial_test"] # print, env, launcher ... support -derive = ["libafl_derive"] # provide derive(SerdeAny) macro. -fork = [] # uses the fork() syscall to spawn children, instead of launching a new command, if supported by the OS (has no effect on Windows, no_std). -rand_trait = ["rand_core"] # If set, libafl's rand implementations will implement `rand::Rng` +std = ["serde_json", "serde_json/std", "nix", "serde/std", "bincode", "wait-timeout", "uuid", "tui_monitor", "ctor", "backtrace", "serial_test", "libafl_bolts/std", "typed-builder"] # print, env, launcher ... support +derive = ["libafl_derive", "libafl_bolts/derive"] # provide derive(SerdeAny) macro. +fork = ["libafl_bolts/derive"] # uses the fork() syscall to spawn children, instead of launching a new command, if supported by the OS (has no effect on Windows, no_std). +rand_trait = ["libafl_bolts/rand_trait"] # If set, libafl's rand implementations will implement `rand::Rng` introspection = [] # Include performance statistics of the fuzzing pipeline concolic_mutation = ["z3"] # include a simple concolic mutator based on z3 -python = ["pyo3", "concat-idents"] -prelude = [] # Expose libafl::prelude for access without additional using directives +python = ["pyo3", "concat-idents", "libafl_bolts/python"] +prelude = ["libafl_bolts/prelude"] # Expose libafl::prelude for access without additional using directives tui_monitor = ["tui", "crossterm"] # enable TuiMonitor with crossterm prometheus_monitor = ["std", "async-std", "prometheus-client", "tide", "futures"] -cli = ["clap"] # expose bolts::cli for easy commandline parsing -qemu_cli = ["cli"] # Commandline flags for qemu-based fuzzers -frida_cli = ["cli"] # Commandline flags for frida-based fuzzers +cli = ["libafl_bolts/cli"] # expose libafl_bolts::cli for easy commandline parsing +qemu_cli = ["cli", "libafl_bolts/qemu_cli"] # Commandline flags for qemu-based fuzzers +frida_cli = ["cli", "libafl_bolts/frida_cli"] # Commandline flags for frida-based fuzzers afl_exec_sec = [] # calculate exec/sec like AFL -errors_backtrace = ["backtrace"] +errors_backtrace = ["libafl_bolts/errors_backtrace"] cmin = ["z3"] # corpus minimisation corpus_btreemap = [] # Switches from HashMap to BTreeMap for CorpusId -gzip = ["miniz_oxide"] # Enables gzip compression in certain parts of the lib +gzip = ["libafl_bolts/gzip"] # Enables gzip compression in certain parts of the lib regex = ["std", "dep:regex"] # enables the NaiveTokenizer and StacktraceObserver casr = ["libcasr", "std", "regex"] # enables deduplication based on libcasr for StacktraceObserver tcp_manager = ["tokio", "std"] # A simple EventManager proxying everything via TCP @@ -43,10 +43,10 @@ agpl = ["gpl", "nautilus"] nautilus = ["grammartec", "std", "serde_json/std"] # LLMP features -llmp_bind_public = [] # If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default. -llmp_compression = ["gzip"] # llmp compression using GZip -llmp_debug = [] # Enables debug output for LLMP -llmp_small_maps = [] # reduces initial map size for llmp +llmp_bind_public = ["libafl_bolts/llmp_bind_public"] # If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default. +llmp_compression = ["libafl_bolts/llmp_compression"] # llmp compression using GZip +llmp_debug = ["libafl_bolts/llmp_debug"] # Enables debug output for LLMP +llmp_small_maps = ["libafl_bolts/llmp_small_maps"] # reduces initial map size for llmp llmp_broker_timeouts = ["std"] # The broker loop will yield occasionally, even without status messages from client nodes [build-dependencies] @@ -58,38 +58,30 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] } bytecount = "0.6.3" [dependencies] -libafl_derive = { version = "0.10.1", optional = true, path = "../libafl_derive" } +libafl_bolts = { version = "0.10.1", path = "../libafl_bolts", default-features = false } +libafl_derive = { version = "0.10.1", path = "../libafl_derive", optional = true } rustversion = "1.0" tuple_list = { version = "0.1.3" } -hashbrown = { version = "0.13", features = ["serde", "ahash"], default-features=false } # A faster hashmap, nostd compatible +hashbrown = { version = "0.14", features = ["serde", "ahash"], default-features=false } # A faster hashmap, nostd compatible num-traits = { version = "0.2", default-features = false } -xxhash-rust = { version = "0.8.5", features = ["xxh3"] } # xxh3 hashing for rust serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } # serialization lib -erased-serde = { version = "0.3.21", default-features = false, features = ["alloc"] } # erased serde -postcard = { version = "1.0", features = ["alloc"] } # no_std compatible serde serialization fromat +postcard = { version = "1.0", features = ["alloc"] } # no_std compatible serde serialization format bincode = {version = "1.3", optional = true } c2rust-bitfields = { version = "0.17", features = ["no_std"] } -num_enum = { version = "0.6", default-features = false } -typed-builder = "0.15.1" # Implement the builder pattern at compiletime ahash = { version = "0.8", default-features=false } # The hash function already used in hashbrown intervaltree = { version = "0.2.7", default-features = false, features = ["serde"] } backtrace = {version = "0.3", optional = true} # Used to get the stacktrace in StacktraceObserver +typed-builder = { version = "0.15.1", optional = true } # Implement the builder pattern at compiletime ctor = { optional = true, version = "0.2" } serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } -miniz_oxide = { version = "0.7.1", optional = true} -hostname = { version = "^0.3", optional = true } # Is there really no gethostname in the stdlib? -rand_core = { version = "0.6", optional = true } nix = { version = "0.26", optional = true } regex = { version = "1", optional = true } uuid = { version = "1.1.2", optional = true, features = ["serde", "v4"] } -byteorder = { version = "1.4", optional = true } -once_cell = { version = "1.13", optional = true } libm = "0.2.2" tui = { version = "0.19", default-features = false, features = ['crossterm'], optional = true } # Commandline rendering, for TUI Monitor -crossterm = { version = "0.26", optional = true } -clap = {version = "4.0", features = ["derive", "wrap_help"], optional = true} # CLI parsing, for bolts::cli / the `cli` feature +crossterm = { version = "0.25", optional = true } prometheus-client = { version= "0.19", optional = true} # For the prometheus monitor tide = { version = "0.16.0", optional = true } @@ -116,8 +108,6 @@ grammartec = { version = "0.3", optional = true } [target.'cfg(unix)'.dependencies] libc = "0.2" # For (*nix) libc -uds = { version = "0.2.6", optional = true } -lock_api = "0.4.7" [target.'cfg(windows)'.dependencies] windows = { version = "0.44", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security", "Win32_System_SystemInformation"] } @@ -129,8 +119,3 @@ windows = "0.44" #lto = true #opt-level = 3 #debug = true - -[[example]] -name = "llmp_test" -path = "./examples/llmp_test/main.rs" -required-features = ["std"] diff --git a/libafl/src/bolts/mod.rs b/libafl/src/bolts/mod.rs deleted file mode 100644 index 6328edb89f..0000000000 --- a/libafl/src/bolts/mod.rs +++ /dev/null @@ -1,375 +0,0 @@ -//! Bolts are no conceptual fuzzing elements, but they keep libafl-based fuzzers together. - -pub mod anymap; -#[cfg(feature = "std")] -pub mod build_id; -#[cfg(all( - any(feature = "cli", feature = "frida_cli", feature = "qemu_cli"), - feature = "std" -))] -pub mod cli; -#[cfg(feature = "gzip")] -pub mod compress; -#[cfg(feature = "std")] -pub mod core_affinity; -pub mod cpu; -#[cfg(feature = "std")] -pub mod fs; -#[cfg(feature = "std")] -pub mod launcher; -pub mod llmp; -#[cfg(all(feature = "std", unix))] -pub mod minibsod; -pub mod os; -pub mod ownedref; -pub mod rands; -pub mod serdeany; -pub mod shmem; -#[cfg(feature = "std")] -pub mod staterestore; -pub mod tuples; - -use alloc::{string::String, vec::Vec}; -use core::{iter::Iterator, ops::AddAssign, time}; -#[cfg(feature = "std")] -use std::time::{SystemTime, UNIX_EPOCH}; - -use serde::{Deserialize, Serialize}; - -#[cfg(feature = "std")] -use crate::Error; - -/// The client ID == the sender id. -#[repr(transparent)] -#[derive( - Debug, Default, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, -)] -pub struct ClientId(pub u32); - -#[cfg(feature = "std")] -use log::{Metadata, Record}; - -/// Can be converted to a slice -pub trait AsSlice { - /// Type of the entries in this slice - type Entry; - /// Convert to a slice - fn as_slice(&self) -> &[Self::Entry]; -} - -/// Can be converted to a mutable slice -pub trait AsMutSlice { - /// Type of the entries in this mut slice - type Entry; - /// Convert to a slice - fn as_mut_slice(&mut self) -> &mut [Self::Entry]; -} - -impl AsSlice for Vec { - type Entry = T; - - fn as_slice(&self) -> &[Self::Entry] { - self - } -} - -impl AsMutSlice for Vec { - type Entry = T; - - fn as_mut_slice(&mut self) -> &mut [Self::Entry] { - self - } -} - -impl AsSlice for &[T] { - type Entry = T; - - fn as_slice(&self) -> &[Self::Entry] { - self - } -} - -impl AsSlice for [T] { - type Entry = T; - - fn as_slice(&self) -> &[Self::Entry] { - self - } -} - -impl AsMutSlice for &mut [T] { - type Entry = T; - - fn as_mut_slice(&mut self) -> &mut [Self::Entry] { - self - } -} - -impl AsMutSlice for [T] { - type Entry = T; - - fn as_mut_slice(&mut self) -> &mut [Self::Entry] { - self - } -} - -/// Create an `Iterator` from a reference -pub trait AsIter<'it> { - /// The item type - type Item: 'it; - /// The iterator type - type IntoIter: Iterator; - - /// Create an iterator from &self - fn as_iter(&'it self) -> Self::IntoIter; -} - -/// Create an `Iterator` from a mutable reference -pub trait AsIterMut<'it> { - /// The item type - type Item: 'it; - /// The iterator type - type IntoIter: Iterator; - - /// Create an iterator from &mut self - fn as_iter_mut(&'it mut self) -> Self::IntoIter; -} - -/// Has a length field -pub trait HasLen { - /// The length - fn len(&self) -> usize; - - /// Returns `true` if it has no elements. - fn is_empty(&self) -> bool { - self.len() == 0 - } -} - -/// Has a ref count -pub trait HasRefCnt { - /// The ref count - fn refcnt(&self) -> isize; - /// The ref count, mutable - fn refcnt_mut(&mut self) -> &mut isize; -} - -/// Trait to truncate slices and maps to a new size -pub trait Truncate { - /// Reduce the size of the slice - fn truncate(&mut self, len: usize); -} - -/// Current time -#[cfg(feature = "std")] -#[must_use] -#[inline] -pub fn current_time() -> time::Duration { - SystemTime::now().duration_since(UNIX_EPOCH).unwrap() -} - -// external defined function in case of `no_std` -// -// Define your own `external_current_millis()` function via `extern "C"` -// which is linked into the binary and called from here. -#[cfg(not(feature = "std"))] -extern "C" { - //#[no_mangle] - fn external_current_millis() -> u64; -} - -/// Current time (fixed fallback for `no_std`) -#[cfg(not(feature = "std"))] -#[inline] -#[must_use] -pub fn current_time() -> time::Duration { - let millis = unsafe { external_current_millis() }; - time::Duration::from_millis(millis) -} - -/// Given a u64 number, return a hashed number using this mixing function -/// This function is used to hash an address into a more random number (used in `libafl_frida`). -/// Mixing function: -#[inline] -#[must_use] -pub fn xxh3_rrmxmx_mixer(v: u64) -> u64 { - let tmp = (v >> 32) + ((v & 0xffffffff) << 32); - let bitflip = 0x1cad21f72c81017c ^ 0xdb979082e96dd4de; - let mut h64 = tmp ^ bitflip; - h64 = h64.rotate_left(49) & h64.rotate_left(24); - h64 = h64.wrapping_mul(0x9FB21C651E98DF25); - h64 ^= (h64 >> 35) + 8; - h64 = h64.wrapping_mul(0x9FB21C651E98DF25); - h64 ^= h64 >> 28; - h64 -} - -/// Gets current nanoseconds since [`UNIX_EPOCH`] -#[must_use] -#[inline] -pub fn current_nanos() -> u64 { - current_time().as_nanos() as u64 -} - -/// Gets current milliseconds since [`UNIX_EPOCH`] -#[must_use] -#[inline] -pub fn current_milliseconds() -> u64 { - current_time().as_millis() as u64 -} - -/// Format a `Duration` into a HMS string -#[must_use] -pub fn format_duration_hms(duration: &time::Duration) -> String { - let secs = duration.as_secs(); - format!("{}h-{}m-{}s", (secs / 60) / 60, (secs / 60) % 60, secs % 60) -} - -/// Calculates the cumulative sum for a slice, in-place. -/// The values are useful for example for cumulative probabilities. -/// -/// So, to give an example: -/// ```rust -/// use libafl::bolts::calculate_cumulative_sum_in_place; -/// -/// let mut value = [2, 4, 1, 3]; -/// calculate_cumulative_sum_in_place(&mut value); -/// assert_eq!(&[2, 6, 7, 10], &value); -/// ``` -pub fn calculate_cumulative_sum_in_place(mut_slice: &mut [T]) -where - T: Default + AddAssign + Copy, -{ - let mut acc = T::default(); - - for val in mut_slice { - acc += *val; - *val = acc; - } -} - -/// Stderr logger -#[cfg(feature = "std")] -pub static LIBAFL_STDERR_LOGGER: SimpleStderrLogger = SimpleStderrLogger::new(); - -/// Stdout logger -#[cfg(feature = "std")] -pub static LIBAFL_STDOUT_LOGGER: SimpleStdoutLogger = SimpleStdoutLogger::new(); - -/// A simple logger struct that logs to stderr when used with [`log::set_logger`]. -#[derive(Debug)] -#[cfg(feature = "std")] -pub struct SimpleStdoutLogger {} - -#[cfg(feature = "std")] -impl Default for SimpleStdoutLogger { - fn default() -> Self { - Self::new() - } -} - -#[cfg(feature = "std")] -impl SimpleStdoutLogger { - /// Create a new [`log::Log`] logger that will wrte log to stdout - #[must_use] - pub const fn new() -> Self { - Self {} - } - - /// register stdout logger - pub fn set_logger() -> Result<(), Error> { - log::set_logger(&LIBAFL_STDOUT_LOGGER) - .map_err(|_| Error::unknown("Failed to register logger")) - } -} - -#[cfg(feature = "std")] -impl log::Log for SimpleStdoutLogger { - #[inline] - fn enabled(&self, _metadata: &Metadata) -> bool { - true - } - - fn log(&self, record: &Record) { - println!( - "[{:?}] {}: {}", - current_time(), - record.level(), - record.args() - ); - } - - fn flush(&self) {} -} - -/// A simple logger struct that logs to stderr when used with [`log::set_logger`]. -#[derive(Debug)] -#[cfg(feature = "std")] -pub struct SimpleStderrLogger {} - -#[cfg(feature = "std")] -impl Default for SimpleStderrLogger { - fn default() -> Self { - Self::new() - } -} - -#[cfg(feature = "std")] -impl SimpleStderrLogger { - /// Create a new [`log::Log`] logger that will wrte log to stdout - #[must_use] - pub const fn new() -> Self { - Self {} - } - - /// register stderr logger - pub fn set_logger() -> Result<(), Error> { - log::set_logger(&LIBAFL_STDERR_LOGGER) - .map_err(|_| Error::unknown("Failed to register logger")) - } -} - -#[cfg(feature = "std")] -impl log::Log for SimpleStderrLogger { - #[inline] - fn enabled(&self, _metadata: &Metadata) -> bool { - true - } - - fn log(&self, record: &Record) { - eprintln!( - "[{:?}] {}: {}", - current_time(), - record.level(), - record.args() - ); - } - - fn flush(&self) {} -} -/// The purpose of this module is to alleviate imports of the bolts by adding a glob import. -#[cfg(feature = "prelude")] -pub mod bolts_prelude { - #[cfg(feature = "std")] - pub use super::build_id::*; - #[cfg(all( - any(feature = "cli", feature = "frida_cli", feature = "qemu_cli"), - feature = "std" - ))] - pub use super::cli::*; - #[cfg(feature = "llmp_compression")] - pub use super::compress::*; - #[cfg(feature = "std")] - pub use super::core_affinity::*; - #[cfg(feature = "std")] - pub use super::fs::*; - #[cfg(feature = "std")] - pub use super::launcher::*; - #[cfg(all(feature = "std", unix))] - pub use super::minibsod::*; - #[cfg(feature = "std")] - pub use super::staterestore::*; - pub use super::{ - anymap::*, cpu::*, llmp::*, os::*, ownedref::*, rands::*, serdeany::*, shmem::*, tuples::*, - }; -} diff --git a/libafl/src/corpus/inmemory_ondisk.rs b/libafl/src/corpus/inmemory_ondisk.rs index 281f8673e8..3fa7aecde8 100644 --- a/libafl/src/corpus/inmemory_ondisk.rs +++ b/libafl/src/corpus/inmemory_ondisk.rs @@ -12,16 +12,16 @@ use std::{ path::{Path, PathBuf}, }; +#[cfg(feature = "gzip")] +use libafl_bolts::compress::GzipCompressor; +use libafl_bolts::serdeany::SerdeAnyMap; use serde::{Deserialize, Serialize}; use super::{ ondisk::{OnDiskMetadata, OnDiskMetadataFormat}, HasTestcase, }; -#[cfg(feature = "gzip")] -use crate::bolts::compress::GzipCompressor; use crate::{ - bolts::serdeany::SerdeAnyMap, corpus::{Corpus, CorpusId, InMemoryCorpus, Testcase}, inputs::{Input, UsesInput}, state::HasMetadata, diff --git a/libafl/src/corpus/minimizer.rs b/libafl/src/corpus/minimizer.rs index 7ab506fa64..35dcb01ef4 100644 --- a/libafl/src/corpus/minimizer.rs +++ b/libafl/src/corpus/minimizer.rs @@ -8,14 +8,11 @@ use alloc::{ use core::{hash::Hash, marker::PhantomData}; use hashbrown::{HashMap, HashSet}; +use libafl_bolts::{tuples::MatchName, AsIter, Named}; use num_traits::ToPrimitive; use z3::{ast::Bool, Config, Context, Optimize}; use crate::{ - bolts::{ - tuples::{MatchName, Named}, - AsIter, - }, corpus::Corpus, executors::{Executor, HasObservers}, observers::{MapObserver, ObserversTuple}, diff --git a/libafl/src/corpus/mod.rs b/libafl/src/corpus/mod.rs index 7203795251..bdbc247b37 100644 --- a/libafl/src/corpus/mod.rs +++ b/libafl/src/corpus/mod.rs @@ -227,7 +227,7 @@ pub mod pybind { macro_rules! unwrap_me { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_body!( + libafl_bolts::unwrap_me_body!( $wrapper, $name, $body, @@ -244,7 +244,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!( + libafl_bolts::unwrap_me_mut_body!( $wrapper, $name, $body, diff --git a/libafl/src/corpus/nop.rs b/libafl/src/corpus/nop.rs index 07e9b3d1a4..091e2c29cb 100644 --- a/libafl/src/corpus/nop.rs +++ b/libafl/src/corpus/nop.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::{ corpus::{Corpus, CorpusId, Testcase}, inputs::{Input, UsesInput}, - Error, ErrorBacktrace, + Error, }; /// A corpus which does not store any [`Testcase`]s. @@ -37,37 +37,25 @@ where /// Add an entry to the corpus and return its index #[inline] fn add(&mut self, _testcase: Testcase) -> Result { - Err(Error::Unsupported( - "Unsupported".into(), - ErrorBacktrace::new(), - )) + Err(Error::unsupported("Unsupported by NopCorpus")) } /// Replaces the testcase at the given idx #[inline] fn replace(&mut self, _idx: CorpusId, _testcase: Testcase) -> Result, Error> { - Err(Error::Unsupported( - "Unsupported".into(), - ErrorBacktrace::new(), - )) + Err(Error::unsupported("Unsupported by NopCorpus")) } /// Removes an entry from the corpus, returning it if it was present. #[inline] fn remove(&mut self, _idx: CorpusId) -> Result, Error> { - Err(Error::Unsupported( - "Unsupported".into(), - ErrorBacktrace::new(), - )) + Err(Error::unsupported("Unsupported by NopCorpus")) } /// Get by id #[inline] fn get(&self, _idx: CorpusId) -> Result<&RefCell>, Error> { - Err(Error::Unsupported( - "Unsupported".into(), - ErrorBacktrace::new(), - )) + Err(Error::unsupported("Unsupported by NopCorpus")) } /// Current testcase scheduled @@ -109,18 +97,12 @@ where #[inline] fn load_input_into(&self, _testcase: &mut Testcase) -> Result<(), Error> { - Err(Error::Unsupported( - "Unsupported".into(), - ErrorBacktrace::new(), - )) + Err(Error::unsupported("Unsupported by NopCorpus")) } #[inline] fn store_input_from(&self, _testcase: &Testcase) -> Result<(), Error> { - Err(Error::Unsupported( - "Unsupported".into(), - ErrorBacktrace::new(), - )) + Err(Error::unsupported("Unsupported by NopCorpus")) } } diff --git a/libafl/src/corpus/ondisk.rs b/libafl/src/corpus/ondisk.rs index db1cda909e..95145830cb 100644 --- a/libafl/src/corpus/ondisk.rs +++ b/libafl/src/corpus/ondisk.rs @@ -7,11 +7,11 @@ use core::{cell::RefCell, time::Duration}; use std::path::{Path, PathBuf}; +use libafl_bolts::serdeany::SerdeAnyMap; use serde::{Deserialize, Serialize}; use super::{CachedOnDiskCorpus, HasTestcase}; use crate::{ - bolts::serdeany::SerdeAnyMap, corpus::{Corpus, CorpusId, Testcase}, inputs::{Input, UsesInput}, Error, diff --git a/libafl/src/corpus/testcase.rs b/libafl/src/corpus/testcase.rs index b3670fe574..bd3ed96739 100644 --- a/libafl/src/corpus/testcase.rs +++ b/libafl/src/corpus/testcase.rs @@ -11,11 +11,11 @@ use core::{ #[cfg(feature = "std")] use std::path::PathBuf; +use libafl_bolts::{serdeany::SerdeAnyMap, HasLen}; use serde::{Deserialize, Serialize}; use super::Corpus; use crate::{ - bolts::{serdeany::SerdeAnyMap, HasLen}, corpus::CorpusId, inputs::{Input, UsesInput}, state::HasMetadata, @@ -430,7 +430,7 @@ impl SchedulerTestcaseMetadata { } } -crate::impl_serdeany!(SchedulerTestcaseMetadata); +libafl_bolts::impl_serdeany!(SchedulerTestcaseMetadata); #[cfg(feature = "python")] #[allow(missing_docs)] @@ -438,10 +438,11 @@ crate::impl_serdeany!(SchedulerTestcaseMetadata); pub mod pybind { use alloc::{boxed::Box, vec::Vec}; + use libafl_bolts::ownedref::OwnedMutPtr; use pyo3::{prelude::*, types::PyDict}; use super::{HasMetadata, Testcase}; - use crate::{bolts::ownedref::OwnedMutPtr, inputs::BytesInput, pybind::PythonMetadata}; + use crate::{inputs::BytesInput, pybind::PythonMetadata}; /// `PythonTestcase` with fixed generics pub type PythonTestcase = Testcase; diff --git a/libafl/src/events/centralized.rs b/libafl/src/events/centralized.rs index b5e20b8d17..0e9249f704 100644 --- a/libafl/src/events/centralized.rs +++ b/libafl/src/events/centralized.rs @@ -4,17 +4,17 @@ use alloc::{boxed::Box, string::String, vec::Vec}; #[cfg(feature = "adaptive_serialization")] use core::time::Duration; +#[cfg(feature = "adaptive_serialization")] +use libafl_bolts::current_time; +use libafl_bolts::{ + llmp::{LlmpReceiver, LlmpSender, Tag}, + shmem::ShMemProvider, + ClientId, +}; use serde::{Deserialize, Serialize}; use super::{CustomBufEventResult, HasCustomBufHandlers, ProgressReporter}; -#[cfg(feature = "adaptive_serialization")] -use crate::bolts::current_time; use crate::{ - bolts::{ - llmp::{LlmpReceiver, LlmpSender, Tag}, - shmem::ShMemProvider, - ClientId, - }, events::{ llmp::EventStatsCollector, Event, EventConfig, EventFirer, EventManager, EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, LogSeverity, diff --git a/libafl/src/bolts/launcher.rs b/libafl/src/events/launcher.rs similarity index 98% rename from libafl/src/bolts/launcher.rs rename to libafl/src/events/launcher.rs index 147178d9d2..0414729b29 100644 --- a/libafl/src/bolts/launcher.rs +++ b/libafl/src/events/launcher.rs @@ -24,23 +24,25 @@ use std::process::Stdio; #[cfg(all(unix, feature = "std", feature = "fork"))] use std::{fs::File, os::unix::io::AsRawFd}; +#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] +use libafl_bolts::os::startable_self; +#[cfg(all(unix, feature = "std", feature = "fork"))] +use libafl_bolts::{ + core_affinity::get_core_ids, + os::{dup2, fork, ForkResult}, +}; +use libafl_bolts::{ + core_affinity::{CoreId, Cores}, + shmem::ShMemProvider, +}; #[cfg(feature = "std")] use serde::de::DeserializeOwned; #[cfg(feature = "std")] use typed_builder::TypedBuilder; -use super::core_affinity::CoreId; -#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] -use crate::bolts::os::startable_self; -#[cfg(all(unix, feature = "std", feature = "fork"))] -use crate::bolts::{ - core_affinity::get_core_ids, - os::{dup2, fork, ForkResult}, -}; use crate::inputs::UsesInput; #[cfg(feature = "std")] use crate::{ - bolts::{core_affinity::Cores, shmem::ShMemProvider}, events::{EventConfig, LlmpRestartingEventManager, ManagerKind, RestartingMgr}, monitors::Monitor, state::{HasClientPerfMonitor, HasExecutions}, @@ -254,7 +256,7 @@ where #[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] #[allow(unused_mut, clippy::match_wild_err_arm)] pub fn launch(&mut self) -> Result<(), Error> { - use crate::bolts::core_affinity; + use libafl_bolts::core_affinity; let is_client = std::env::var(_AFL_LAUNCHER_CLIENT); diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index cac6d63c3d..30a91e3ee7 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -11,6 +11,28 @@ use core::{marker::PhantomData, num::NonZeroUsize, time::Duration}; #[cfg(feature = "std")] use std::net::{SocketAddr, ToSocketAddrs}; +#[cfg(feature = "std")] +use libafl_bolts::core_affinity::CoreId; +#[cfg(feature = "adaptive_serialization")] +use libafl_bolts::current_time; +#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] +use libafl_bolts::os::startable_self; +#[cfg(all(unix, feature = "std", not(miri)))] +use libafl_bolts::os::unix_signals::setup_signal_handler; +#[cfg(all(feature = "std", feature = "fork", unix))] +use libafl_bolts::os::{fork, ForkResult}; +#[cfg(feature = "llmp_compression")] +use libafl_bolts::{ + compress::GzipCompressor, + llmp::{LLMP_FLAG_COMPRESSED, LLMP_FLAG_INITIALIZED}, +}; +#[cfg(feature = "std")] +use libafl_bolts::{llmp::LlmpConnection, shmem::StdShMemProvider, staterestore::StateRestorer}; +use libafl_bolts::{ + llmp::{self, LlmpClient, LlmpClientDescription, Tag}, + shmem::ShMemProvider, + ClientId, +}; #[cfg(feature = "std")] use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; @@ -18,31 +40,9 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use super::{CustomBufEventResult, CustomBufHandlerFn}; -#[cfg(feature = "std")] -use crate::bolts::core_affinity::CoreId; -#[cfg(feature = "adaptive_serialization")] -use crate::bolts::current_time; -#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] -use crate::bolts::os::startable_self; -#[cfg(all(unix, feature = "std", not(miri)))] -use crate::bolts::os::unix_signals::setup_signal_handler; -#[cfg(all(feature = "std", feature = "fork", unix))] -use crate::bolts::os::{fork, ForkResult}; -#[cfg(feature = "llmp_compression")] -use crate::bolts::{ - compress::GzipCompressor, - llmp::{LLMP_FLAG_COMPRESSED, LLMP_FLAG_INITIALIZED}, -}; -#[cfg(feature = "std")] -use crate::bolts::{llmp::LlmpConnection, shmem::StdShMemProvider, staterestore::StateRestorer}; #[cfg(all(unix, feature = "std"))] use crate::events::{shutdown_handler, SHUTDOWN_SIGHANDLER_DATA}; use crate::{ - bolts::{ - llmp::{self, LlmpClient, LlmpClientDescription, Tag}, - shmem::ShMemProvider, - ClientId, - }, events::{ BrokerEventResult, Event, EventConfig, EventFirer, EventManager, EventManagerId, EventProcessor, EventRestarter, HasCustomBufHandlers, HasEventManagerId, ProgressReporter, @@ -338,7 +338,7 @@ pub trait EventStatsCollector { pub trait EventStatsCollector {} /// An [`EventManager`] that forwards all events to other attached fuzzers on shared maps or via tcp, -/// using low-level message passing, [`crate::bolts::llmp`]. +/// using low-level message passing, [`libafl_bolts::llmp`]. pub struct LlmpEventManager where S: UsesInput, @@ -1715,17 +1715,17 @@ where mod tests { use core::sync::atomic::{compiler_fence, Ordering}; + use libafl_bolts::{ + llmp::{LlmpClient, LlmpSharedMap}, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + staterestore::StateRestorer, + tuples::tuple_list, + ClientId, + }; use serial_test::serial; use crate::{ - bolts::{ - llmp::{LlmpClient, LlmpSharedMap}, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - staterestore::StateRestorer, - tuples::tuple_list, - ClientId, - }, corpus::{Corpus, InMemoryCorpus, Testcase}, events::{llmp::_ENV_FUZZER_SENDER, LlmpEventManager}, executors::{ExitKind, InProcessExecutor}, diff --git a/libafl/src/events/mod.rs b/libafl/src/events/mod.rs index 65547aec24..07cb575c52 100644 --- a/libafl/src/events/mod.rs +++ b/libafl/src/events/mod.rs @@ -5,6 +5,8 @@ pub mod simple; pub use simple::*; pub mod centralized; pub use centralized::*; +#[cfg(feature = "std")] +pub mod launcher; pub mod llmp; #[cfg(feature = "tcp_manager")] pub mod tcp; @@ -19,17 +21,19 @@ use core::{ }; use ahash::RandomState; +#[cfg(feature = "std")] +pub use launcher::*; +#[cfg(all(unix, feature = "std"))] +use libafl_bolts::os::unix_signals::{siginfo_t, ucontext_t, Handler, Signal}; +use libafl_bolts::{current_time, ClientId}; +#[cfg(all(unix, feature = "std"))] +use libafl_bolts::{shmem::ShMemProvider, staterestore::StateRestorer}; pub use llmp::*; use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] use uuid::Uuid; -#[cfg(all(unix, feature = "std"))] -use crate::bolts::os::unix_signals::{siginfo_t, ucontext_t, Handler, Signal}; -#[cfg(all(unix, feature = "std"))] -use crate::bolts::{shmem::ShMemProvider, staterestore::StateRestorer}; use crate::{ - bolts::{current_time, ClientId}, executors::ExitKind, inputs::Input, monitors::UserStats, @@ -212,7 +216,7 @@ impl EventConfig { #[must_use] pub fn from_build_id() -> Self { EventConfig::BuildID { - id: crate::bolts::build_id::get(), + id: libafl_bolts::build_id::get(), } } @@ -497,7 +501,7 @@ where { state .introspection_monitor_mut() - .set_current_time(crate::bolts::cpu::read_time_counter()); + .set_current_time(libafl_bolts::cpu::read_time_counter()); // Send the current monitor over to the manager. This `.clone` shouldn't be // costly as `ClientPerfMonitor` impls `Copy` since it only contains `u64`s @@ -660,13 +664,10 @@ impl HasEventManagerId for NopEventManager { #[cfg(test)] mod tests { + use libafl_bolts::{current_time, tuples::tuple_list, Named}; use tuple_list::tuple_list_type; use crate::{ - bolts::{ - current_time, - tuples::{tuple_list, Named}, - }, events::{Event, EventConfig}, executors::ExitKind, inputs::bytes::BytesInput, @@ -748,7 +749,7 @@ pub mod pybind { macro_rules! unwrap_me { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_body!($wrapper, $name, $body, PythonEventManagerWrapper, { + libafl_bolts::unwrap_me_body!($wrapper, $name, $body, PythonEventManagerWrapper, { Simple }) }; @@ -756,7 +757,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonEventManagerWrapper, { + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonEventManagerWrapper, { Simple }) }; diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 07401c28d0..76f7eef05e 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -13,20 +13,28 @@ use core::ptr::write_volatile; use core::sync::atomic::{compiler_fence, Ordering}; use core::{fmt::Debug, marker::PhantomData}; +#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] +use libafl_bolts::os::startable_self; +#[cfg(all(unix, feature = "std", not(miri)))] +use libafl_bolts::os::unix_signals::setup_signal_handler; +#[cfg(all(feature = "std", feature = "fork", unix))] +use libafl_bolts::os::{fork, ForkResult}; +use libafl_bolts::ClientId; +#[cfg(feature = "std")] +use libafl_bolts::{shmem::ShMemProvider, staterestore::StateRestorer}; #[cfg(feature = "std")] use serde::{de::DeserializeOwned, Serialize}; use super::{CustomBufEventResult, CustomBufHandlerFn, HasCustomBufHandlers, ProgressReporter}; -#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] -use crate::bolts::os::startable_self; -#[cfg(all(unix, feature = "std", not(miri)))] -use crate::bolts::os::unix_signals::setup_signal_handler; -#[cfg(all(feature = "std", feature = "fork", unix))] -use crate::bolts::os::{fork, ForkResult}; #[cfg(all(unix, feature = "std"))] use crate::events::{shutdown_handler, SHUTDOWN_SIGHANDLER_DATA}; +#[cfg(feature = "std")] +use crate::{ + corpus::Corpus, + monitors::SimplePrintingMonitor, + state::{HasCorpus, HasSolutions}, +}; use crate::{ - bolts::ClientId, events::{ BrokerEventResult, Event, EventFirer, EventManager, EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, @@ -36,13 +44,6 @@ use crate::{ state::{HasClientPerfMonitor, HasExecutions, HasLastReportTime, HasMetadata, UsesState}, Error, }; -#[cfg(feature = "std")] -use crate::{ - bolts::{shmem::ShMemProvider, staterestore::StateRestorer}, - corpus::Corpus, - monitors::SimplePrintingMonitor, - state::{HasCorpus, HasSolutions}, -}; /// The llmp connection from the actual fuzzer to the process supervising it const _ENV_FUZZER_SENDER: &str = "_AFL_ENV_FUZZER_SENDER"; diff --git a/libafl/src/events/tcp.rs b/libafl/src/events/tcp.rs index 8c45cc8ab8..84e0e86a91 100644 --- a/libafl/src/events/tcp.rs +++ b/libafl/src/events/tcp.rs @@ -15,6 +15,17 @@ use std::{ net::{SocketAddr, TcpListener, TcpStream, ToSocketAddrs}, }; +#[cfg(feature = "std")] +use libafl_bolts::core_affinity::CoreId; +#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] +use libafl_bolts::os::startable_self; +#[cfg(all(unix, feature = "std", not(miri)))] +use libafl_bolts::os::unix_signals::setup_signal_handler; +#[cfg(all(feature = "std", feature = "fork", unix))] +use libafl_bolts::os::{fork, ForkResult}; +use libafl_bolts::{shmem::ShMemProvider, ClientId}; +#[cfg(feature = "std")] +use libafl_bolts::{shmem::StdShMemProvider, staterestore::StateRestorer}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, @@ -25,20 +36,9 @@ use tokio::{ use typed_builder::TypedBuilder; use super::{CustomBufEventResult, CustomBufHandlerFn}; -#[cfg(feature = "std")] -use crate::bolts::core_affinity::CoreId; -#[cfg(all(feature = "std", any(windows, not(feature = "fork"))))] -use crate::bolts::os::startable_self; -#[cfg(all(unix, feature = "std", not(miri)))] -use crate::bolts::os::unix_signals::setup_signal_handler; -#[cfg(all(feature = "std", feature = "fork", unix))] -use crate::bolts::os::{fork, ForkResult}; -#[cfg(feature = "std")] -use crate::bolts::{shmem::StdShMemProvider, staterestore::StateRestorer}; #[cfg(all(unix, feature = "std"))] use crate::events::{shutdown_handler, SHUTDOWN_SIGHANDLER_DATA}; use crate::{ - bolts::{shmem::ShMemProvider, ClientId}, events::{ BrokerEventResult, Event, EventConfig, EventFirer, EventManager, EventManagerId, EventProcessor, EventRestarter, HasCustomBufHandlers, HasEventManagerId, ProgressReporter, @@ -336,7 +336,7 @@ where } /// An [`EventManager`] that forwards all events to other attached fuzzers on shared maps or via tcp, -/// using low-level message passing, [`crate::bolts::tcp`]. +/// using low-level message passing, [`libafl_bolts::tcp`]. pub struct TcpEventManager where S: UsesInput, diff --git a/libafl/src/executors/command.rs b/libafl/src/executors/command.rs index 256ab875bf..fd8fa1e7f8 100644 --- a/libafl/src/executors/command.rs +++ b/libafl/src/executors/command.rs @@ -16,22 +16,23 @@ use std::{ time::Duration, }; +use libafl_bolts::{ + fs::{get_unique_std_input_file, InputFile}, + tuples::MatchName, + AsSlice, +}; + use super::HasObservers; #[cfg(all(feature = "std", unix))] use crate::executors::{Executor, ExitKind}; +#[cfg(feature = "std")] +use crate::{inputs::Input, Error}; use crate::{ - bolts::{ - fs::{get_unique_std_input_file, InputFile}, - tuples::MatchName, - AsSlice, - }, inputs::{HasTargetBytes, UsesInput}, observers::{ObserversTuple, UsesObservers}, state::UsesState, std::borrow::ToOwned, }; -#[cfg(feature = "std")] -use crate::{inputs::Input, Error}; /// How to deliver input to an external program /// `StdIn`: The target reads from stdin @@ -618,7 +619,8 @@ impl CommandExecutorBuilder { #[cfg_attr(all(feature = "std", unix), doc = " ```")] #[cfg_attr(not(all(feature = "std", unix)), doc = " ```ignore")] /// use std::{io::Write, process::{Stdio, Command, Child}, time::Duration}; -/// use libafl::{Error, bolts::AsSlice, inputs::{HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::UsesState}; +/// use libafl::{Error, inputs::{HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::UsesState}; +/// use libafl_bolts::AsSlice; /// #[derive(Debug)] /// struct MyExecutor; /// diff --git a/libafl/src/executors/differential.rs b/libafl/src/executors/differential.rs index 850a246115..a657c0eddc 100644 --- a/libafl/src/executors/differential.rs +++ b/libafl/src/executors/differential.rs @@ -4,10 +4,10 @@ //! use core::{cell::UnsafeCell, fmt::Debug}; +use libafl_bolts::{ownedref::OwnedMutPtr, tuples::MatchName}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{ownedref::OwnedMutPtr, tuples::MatchName}, executors::{Executor, ExitKind, HasObservers}, inputs::UsesInput, observers::{DifferentialObserversTuple, ObserversTuple, UsesObservers}, diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index 99545f9e3b..8e165d3af7 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -15,6 +15,13 @@ use std::{ process::{Command, Stdio}, }; +use libafl_bolts::{ + fs::{get_unique_std_input_file, InputFile}, + os::{dup2, pipes::Pipe}, + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::{MatchName, Prepend}, + AsMutSlice, AsSlice, Truncate, +}; use nix::{ sys::{ select::{pselect, FdSet}, @@ -27,13 +34,6 @@ use nix::{ #[cfg(feature = "regex")] use crate::observers::{get_asan_runtime_flags_with_log_path, AsanBacktraceObserver}; use crate::{ - bolts::{ - fs::{get_unique_std_input_file, InputFile}, - os::{dup2, pipes::Pipe}, - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::{MatchName, Prepend}, - AsMutSlice, AsSlice, Truncate, - }, executors::{Executor, ExitKind, HasObservers}, inputs::{HasTargetBytes, Input, UsesInput}, mutators::Tokens, @@ -1291,14 +1291,14 @@ where mod tests { use std::ffi::OsString; + use libafl_bolts::{ + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::tuple_list, + AsMutSlice, + }; use serial_test::serial; use crate::{ - bolts::{ - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::tuple_list, - AsMutSlice, - }, executors::forkserver::ForkserverExecutorBuilder, observers::{ConstMapObserver, HitcountsMapObserver}, Error, diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 6dba53d80b..0f4d8b82c9 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -25,6 +25,15 @@ use core::{ #[cfg(all(feature = "std", unix))] use std::intrinsics::transmute; +use libafl_bolts::current_time; +#[cfg(all(unix, not(miri)))] +use libafl_bolts::os::unix_signals::setup_signal_handler; +#[cfg(all(feature = "std", unix))] +use libafl_bolts::os::unix_signals::{ucontext_t, Handler, Signal}; +#[cfg(all(windows, feature = "std"))] +use libafl_bolts::os::windows_exceptions::setup_exception_handler; +#[cfg(all(feature = "std", unix))] +use libafl_bolts::shmem::ShMemProvider; #[cfg(all(feature = "std", unix))] use libc::siginfo_t; #[cfg(all(feature = "std", unix))] @@ -35,16 +44,7 @@ use nix::{ #[cfg(windows)] use windows::Win32::System::Threading::SetThreadStackGuarantee; -#[cfg(all(unix, not(miri)))] -use crate::bolts::os::unix_signals::setup_signal_handler; -#[cfg(all(feature = "std", unix))] -use crate::bolts::os::unix_signals::{ucontext_t, Handler, Signal}; -#[cfg(all(windows, feature = "std"))] -use crate::bolts::os::windows_exceptions::setup_exception_handler; -#[cfg(all(feature = "std", unix))] -use crate::bolts::shmem::ShMemProvider; use crate::{ - bolts::current_time, events::{EventFirer, EventRestarter}, executors::{Executor, ExitKind, HasObservers}, feedbacks::Feedback, @@ -692,12 +692,12 @@ mod unix_signal_handler { #[cfg(feature = "std")] use std::{io::Write, panic}; + use libafl_bolts::os::unix_signals::{ucontext_t, Handler, Signal}; use libc::siginfo_t; #[cfg(feature = "std")] use crate::inputs::Input; use crate::{ - bolts::os::unix_signals::{ucontext_t, Handler, Signal}, events::{EventFirer, EventRestarter}, executors::{ inprocess::{run_observers_and_save_state, InProcessExecutorHandlerData, GLOBAL_STATE}, @@ -893,7 +893,7 @@ mod unix_signal_handler { { let mut writer = std::io::BufWriter::new(&mut bsod); writeln!(writer, "input: {:?}", input.generate_name(0)).unwrap(); - crate::bolts::minibsod::generate_minibsod(&mut writer, signal, _info, _context) + libafl_bolts::minibsod::generate_minibsod(&mut writer, signal, _info, _context) .unwrap(); writer.flush().unwrap(); } @@ -925,7 +925,7 @@ mod unix_signal_handler { let mut bsod = Vec::new(); { let mut writer = std::io::BufWriter::new(&mut bsod); - crate::bolts::minibsod::generate_minibsod( + libafl_bolts::minibsod::generate_minibsod( &mut writer, signal, _info, @@ -1073,14 +1073,14 @@ mod windows_exception_handler { #[cfg(feature = "std")] use std::panic; + use libafl_bolts::os::windows_exceptions::{ + ExceptionCode, Handler, CRASH_EXCEPTIONS, EXCEPTION_HANDLERS_SIZE, EXCEPTION_POINTERS, + }; use windows::Win32::System::Threading::{ EnterCriticalSection, ExitProcess, LeaveCriticalSection, RTL_CRITICAL_SECTION, }; use crate::{ - bolts::os::windows_exceptions::{ - ExceptionCode, Handler, CRASH_EXCEPTIONS, EXCEPTION_HANDLERS_SIZE, EXCEPTION_POINTERS, - }, events::{EventFirer, EventRestarter}, executors::{ inprocess::{ @@ -2108,11 +2108,11 @@ pub mod child_signal_handlers { use alloc::boxed::Box; use std::panic; + use libafl_bolts::os::unix_signals::{ucontext_t, Signal}; use libc::siginfo_t; use super::{InProcessForkExecutorGlobalData, FORK_EXECUTOR_GLOBAL_DATA}; use crate::{ - bolts::os::unix_signals::{ucontext_t, Signal}, executors::{ExitKind, HasObservers}, inputs::UsesInput, observers::ObserversTuple, @@ -2196,11 +2196,11 @@ pub mod child_signal_handlers { mod tests { use core::marker::PhantomData; + use libafl_bolts::tuples::tuple_list; #[cfg(all(feature = "std", feature = "fork", unix))] use serial_test::serial; use crate::{ - bolts::tuples::tuple_list, events::NopEventManager, executors::{inprocess::InProcessHandlers, Executor, ExitKind, InProcessExecutor}, inputs::{NopInput, UsesInput}, @@ -2238,8 +2238,9 @@ mod tests { #[cfg_attr(miri, ignore)] #[cfg(all(feature = "std", feature = "fork", unix))] fn test_inprocessfork_exec() { + use libafl_bolts::shmem::{ShMemProvider, StdShMemProvider}; + use crate::{ - bolts::shmem::{ShMemProvider, StdShMemProvider}, events::SimpleEventManager, executors::{inprocess::InChildProcessHandlers, InProcessForkExecutor}, state::NopState, diff --git a/libafl/src/executors/mod.rs b/libafl/src/executors/mod.rs index bf4e5e44b4..709d1327c7 100644 --- a/libafl/src/executors/mod.rs +++ b/libafl/src/executors/mod.rs @@ -35,10 +35,10 @@ use core::{fmt::Debug, marker::PhantomData}; #[cfg(all(feature = "std", any(unix, doc)))] pub use command::CommandExecutor; +use libafl_bolts::AsSlice; use serde::{Deserialize, Serialize}; use crate::{ - bolts::AsSlice, inputs::{HasTargetBytes, UsesInput}, observers::{ObserversTuple, UsesObservers}, state::UsesState, @@ -84,7 +84,7 @@ pub enum DiffExitKind { // Custom(Box), } -crate::impl_serdeany!(ExitKind); +libafl_bolts::impl_serdeany!(ExitKind); impl From for DiffExitKind { fn from(exitkind: ExitKind) -> Self { @@ -98,7 +98,7 @@ impl From for DiffExitKind { } } -crate::impl_serdeany!(DiffExitKind); +libafl_bolts::impl_serdeany!(DiffExitKind); /// Holds a tuple of Observers pub trait HasObservers: UsesObservers { @@ -389,7 +389,7 @@ pub mod pybind { macro_rules! unwrap_me { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_body!($wrapper, $name, $body, PythonExecutorWrapper, + libafl_bolts::unwrap_me_body!($wrapper, $name, $body, PythonExecutorWrapper, { InProcess }, { Python(py_wrapper) => { @@ -403,7 +403,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonExecutorWrapper, + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonExecutorWrapper, { InProcess }, { Python(py_wrapper) => { diff --git a/libafl/src/executors/timeout.rs b/libafl/src/executors/timeout.rs index f9902e007f..b285eeb7b0 100644 --- a/libafl/src/executors/timeout.rs +++ b/libafl/src/executors/timeout.rs @@ -17,6 +17,8 @@ use core::{ sync::atomic::{compiler_fence, Ordering}, }; +#[cfg(target_os = "linux")] +use libafl_bolts::current_time; #[cfg(all(unix, not(target_os = "linux")))] use libc::c_int; #[cfg(all(windows, feature = "std"))] @@ -29,8 +31,6 @@ use windows::Win32::{ }, }; -#[cfg(target_os = "linux")] -use crate::bolts::current_time; #[cfg(all(windows, feature = "std"))] use crate::executors::inprocess::HasInProcessHandlers; #[cfg(any(windows, target_os = "linux"))] diff --git a/libafl/src/feedbacks/concolic.rs b/libafl/src/feedbacks/concolic.rs index 6a2b6aae53..946bae29a7 100644 --- a/libafl/src/feedbacks/concolic.rs +++ b/libafl/src/feedbacks/concolic.rs @@ -6,8 +6,9 @@ use alloc::{borrow::ToOwned, string::String}; use core::{fmt::Debug, marker::PhantomData}; +use libafl_bolts::Named; + use crate::{ - bolts::tuples::Named, corpus::Testcase, events::EventFirer, executors::ExitKind, diff --git a/libafl/src/feedbacks/differential.rs b/libafl/src/feedbacks/differential.rs index b8268a53a1..117e960dd0 100644 --- a/libafl/src/feedbacks/differential.rs +++ b/libafl/src/feedbacks/differential.rs @@ -7,10 +7,10 @@ use core::{ marker::PhantomData, }; +use libafl_bolts::{tuples::MatchName, Named}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::tuples::{MatchName, Named}, events::EventFirer, executors::ExitKind, feedbacks::Feedback, @@ -155,8 +155,9 @@ mod tests { use alloc::string::{String, ToString}; use core::marker::PhantomData; + use libafl_bolts::{tuples::tuple_list, Named}; + use crate::{ - bolts::tuples::{tuple_list, Named}, events::EventFirer, executors::ExitKind, feedbacks::{differential::DiffResult, DiffFeedback, Feedback}, diff --git a/libafl/src/feedbacks/map.rs b/libafl/src/feedbacks/map.rs index e838f16f2f..f7c8389aea 100644 --- a/libafl/src/feedbacks/map.rs +++ b/libafl/src/feedbacks/map.rs @@ -12,11 +12,11 @@ use core::{ ops::{BitAnd, BitOr}, }; +use libafl_bolts::{AsIter, AsMutSlice, AsSlice, HasRefCnt, Named}; use num_traits::PrimInt; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use crate::{ - bolts::{tuples::Named, AsIter, AsMutSlice, AsSlice, HasRefCnt}, corpus::Testcase, events::{Event, EventFirer}, executors::ExitKind, @@ -229,7 +229,7 @@ pub struct MapIndexesMetadata { pub tcref: isize, } -crate::impl_serdeany!(MapIndexesMetadata); +libafl_bolts::impl_serdeany!(MapIndexesMetadata); impl AsSlice for MapIndexesMetadata { type Entry = usize; @@ -271,7 +271,7 @@ pub struct MapNoveltiesMetadata { pub list: Vec, } -crate::impl_serdeany!(MapNoveltiesMetadata); +libafl_bolts::impl_serdeany!(MapNoveltiesMetadata); impl AsSlice for MapNoveltiesMetadata { type Entry = usize; @@ -308,7 +308,7 @@ where pub history_map: Vec, } -crate::impl_serdeany!( +libafl_bolts::impl_serdeany!( MapFeedbackMetadata, ,,,,,,,,,,, ); diff --git a/libafl/src/feedbacks/mod.rs b/libafl/src/feedbacks/mod.rs index 863c91b539..a32f815496 100644 --- a/libafl/src/feedbacks/mod.rs +++ b/libafl/src/feedbacks/mod.rs @@ -29,12 +29,12 @@ use core::{ marker::PhantomData, }; +use libafl_bolts::Named; #[cfg(feature = "nautilus")] pub use nautilus::*; use serde::{Deserialize, Serialize}; use crate::{ - bolts::tuples::Named, corpus::Testcase, events::EventFirer, executors::ExitKind, @@ -89,13 +89,13 @@ where OT: ObserversTuple, { // Start a timer for this feedback - let start_time = crate::bolts::cpu::read_time_counter(); + let start_time = libafl_bolts::cpu::read_time_counter(); // Execute this feedback let ret = self.is_interesting(state, manager, input, observers, exit_kind); // Get the elapsed time for checking this feedback - let elapsed = crate::bolts::cpu::read_time_counter() - start_time; + let elapsed = libafl_bolts::cpu::read_time_counter() - start_time; // Add this stat to the feedback metrics state @@ -777,13 +777,6 @@ where } } -impl Named for () { - #[inline] - fn name(&self) -> &str { - "Empty" - } -} - /// A [`CrashFeedback`] reports as interesting if the target crashed. #[derive(Serialize, Deserialize, Clone, Debug)] pub struct CrashFeedback {} @@ -1106,6 +1099,7 @@ impl From for ConstFeedback { pub mod pybind { use std::cell::UnsafeCell; + use libafl_bolts::Named; use pyo3::prelude::*; use super::{ @@ -1113,7 +1107,6 @@ pub mod pybind { FastOrFeedback, Feedback, NotFeedback, String, ToString, }; use crate::{ - bolts::tuples::Named, corpus::{testcase::pybind::PythonTestcaseWrapper, Testcase}, events::{pybind::PythonEventManager, EventFirer}, executors::{pybind::PythonExitKind, ExitKind}, @@ -1402,7 +1395,7 @@ pub mod pybind { macro_rules! unwrap_me { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_body!($wrapper, $name, $body, PythonFeedbackWrapper, + libafl_bolts::unwrap_me_body!($wrapper, $name, $body, PythonFeedbackWrapper, { MaxMapI8, MaxMapI16, @@ -1432,7 +1425,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonFeedbackWrapper, + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonFeedbackWrapper, { MaxMapI8, MaxMapI16, diff --git a/libafl/src/feedbacks/nautilus.rs b/libafl/src/feedbacks/nautilus.rs index e12216416d..aac145ae98 100644 --- a/libafl/src/feedbacks/nautilus.rs +++ b/libafl/src/feedbacks/nautilus.rs @@ -4,11 +4,11 @@ use core::{fmt::Debug, marker::PhantomData}; use std::fs::create_dir_all; use grammartec::{chunkstore::ChunkStore, context::Context}; +use libafl_bolts::Named; use serde::{Deserialize, Serialize}; use serde_json; use crate::{ - bolts::tuples::Named, corpus::{Corpus, Testcase}, events::EventFirer, executors::ExitKind, @@ -37,7 +37,7 @@ impl Debug for NautilusChunksMetadata { } } -crate::impl_serdeany!(NautilusChunksMetadata); +libafl_bolts::impl_serdeany!(NautilusChunksMetadata); impl NautilusChunksMetadata { /// Creates a new [`NautilusChunksMetadata`] diff --git a/libafl/src/feedbacks/new_hash_feedback.rs b/libafl/src/feedbacks/new_hash_feedback.rs index b0dffab72c..01833754ba 100644 --- a/libafl/src/feedbacks/new_hash_feedback.rs +++ b/libafl/src/feedbacks/new_hash_feedback.rs @@ -4,10 +4,10 @@ use alloc::string::{String, ToString}; use std::{fmt::Debug, marker::PhantomData}; use hashbrown::HashSet; +use libafl_bolts::Named; use serde::{Deserialize, Serialize}; use crate::{ - bolts::tuples::Named, events::EventFirer, executors::ExitKind, feedbacks::{Feedback, HasObserverName}, @@ -36,7 +36,7 @@ pub struct NewHashFeedbackMetadata { } #[rustfmt::skip] -crate::impl_serdeany!(NewHashFeedbackMetadata); +libafl_bolts::impl_serdeany!(NewHashFeedbackMetadata); impl NewHashFeedbackMetadata { /// Create a new [`NewHashFeedbackMetadata`] diff --git a/libafl/src/feedbacks/owned.rs b/libafl/src/feedbacks/owned.rs index 6549164940..c312e3771e 100644 --- a/libafl/src/feedbacks/owned.rs +++ b/libafl/src/feedbacks/owned.rs @@ -1,9 +1,9 @@ //! A dynamic collection of owned FeedbackStates use alloc::{boxed::Box, vec::Vec}; +use libafl_bolts::anymap::AsAny; use crate::{ - bolts::anymap::AsAny, feedbacks::{FeedbackState, FeedbackStateTuple}, Error, }; diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index 46f53cfc09..9717011593 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -3,6 +3,7 @@ use alloc::string::ToString; use core::{fmt::Debug, marker::PhantomData, time::Duration}; +use libafl_bolts::current_time; use serde::{de::DeserializeOwned, Serialize}; #[cfg(test)] @@ -12,7 +13,6 @@ use crate::monitors::PerfFeature; #[cfg(test)] use crate::state::NopState; use crate::{ - bolts::current_time, corpus::{Corpus, CorpusId, HasTestcase, Testcase}, events::{Event, EventConfig, EventFirer, EventProcessor, ProgressReporter}, executors::{Executor, ExitKind, HasObservers}, @@ -783,10 +783,10 @@ where pub mod pybind { use alloc::{boxed::Box, vec::Vec}; + use libafl_bolts::ownedref::OwnedMutPtr; use pyo3::prelude::*; use crate::{ - bolts::ownedref::OwnedMutPtr, events::pybind::PythonEventManager, executors::pybind::PythonExecutor, feedbacks::pybind::PythonFeedback, diff --git a/libafl/src/generators/gramatron.rs b/libafl/src/generators/gramatron.rs index 07ac077c8a..edf5b87d5e 100644 --- a/libafl/src/generators/gramatron.rs +++ b/libafl/src/generators/gramatron.rs @@ -2,10 +2,10 @@ use alloc::{string::String, vec::Vec}; use core::marker::PhantomData; +use libafl_bolts::rands::Rand; use serde::{Deserialize, Serialize}; use crate::{ - bolts::rands::Rand, generators::Generator, inputs::{GramatronInput, Terminal}, state::HasRand, diff --git a/libafl/src/generators/mod.rs b/libafl/src/generators/mod.rs index bbf4953e32..a2fbbca66f 100644 --- a/libafl/src/generators/mod.rs +++ b/libafl/src/generators/mod.rs @@ -1,13 +1,14 @@ //! Generators may generate bytes or, in general, data, for inputs. -use alloc::{string::String, vec::Vec}; +use alloc::vec::Vec; use core::marker::PhantomData; +use libafl_bolts::rands::Rand; + use crate::{ - bolts::rands::Rand, inputs::{bytes::BytesInput, Input}, state::HasRand, - Error, ErrorBacktrace, + Error, }; pub mod gramatron; @@ -39,9 +40,8 @@ where fn generate(&mut self, _state: &mut S) -> Result { match self.next() { Some(i) => Ok(i), - None => Err(Error::Empty( - String::from("No more items in iterator when generating inputs"), - ErrorBacktrace::new(), + None => Err(Error::empty( + "No more items in iterator when generating inputs", )), } } @@ -282,7 +282,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonGeneratorWrapper, + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonGeneratorWrapper, { RandBytes, RandPrintables }, { Python(py_wrapper) => { diff --git a/libafl/src/inputs/bytes.rs b/libafl/src/inputs/bytes.rs index 1981923b7e..20ff39e5c0 100644 --- a/libafl/src/inputs/bytes.rs +++ b/libafl/src/inputs/bytes.rs @@ -11,14 +11,12 @@ use core::{ use std::{fs::File, io::Read, path::Path}; use ahash::RandomState; +#[cfg(feature = "std")] +use libafl_bolts::{fs::write_file_atomic, Error}; +use libafl_bolts::{ownedref::OwnedSlice, HasLen}; use serde::{Deserialize, Serialize}; -#[cfg(feature = "std")] -use crate::{bolts::fs::write_file_atomic, Error}; -use crate::{ - bolts::{ownedref::OwnedSlice, HasLen}, - inputs::{HasBytesVec, HasTargetBytes, Input}, -}; +use crate::inputs::{HasBytesVec, HasTargetBytes, Input}; /// A bytes input is the basic input #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, Hash)] diff --git a/libafl/src/inputs/encoded.rs b/libafl/src/inputs/encoded.rs index 8cc679cf38..c86727ca93 100644 --- a/libafl/src/inputs/encoded.rs +++ b/libafl/src/inputs/encoded.rs @@ -15,11 +15,12 @@ use core::{ use ahash::RandomState; use hashbrown::HashMap; +use libafl_bolts::{Error, HasLen}; #[cfg(feature = "regex")] use regex::Regex; use serde::{Deserialize, Serialize}; -use crate::{bolts::HasLen, inputs::Input, Error}; +use crate::inputs::Input; /// Trait to encode bytes to an [`EncodedInput`] using the given [`Tokenizer`] pub trait InputEncoder diff --git a/libafl/src/inputs/generalized.rs b/libafl/src/inputs/generalized.rs index 445f86090b..27c117d79a 100644 --- a/libafl/src/inputs/generalized.rs +++ b/libafl/src/inputs/generalized.rs @@ -2,11 +2,11 @@ use alloc::vec::Vec; +use libafl_bolts::impl_serdeany; use serde::{Deserialize, Serialize}; use crate::{ corpus::{CorpusId, Testcase}, - impl_serdeany, inputs::BytesInput, stages::mutational::{MutatedTransform, MutatedTransformPost}, state::{HasCorpus, HasMetadata}, diff --git a/libafl/src/inputs/gramatron.rs b/libafl/src/inputs/gramatron.rs index 62f125ef2e..f11cf2287f 100644 --- a/libafl/src/inputs/gramatron.rs +++ b/libafl/src/inputs/gramatron.rs @@ -7,9 +7,10 @@ use core::{ }; use ahash::RandomState; +use libafl_bolts::{Error, HasLen}; use serde::{Deserialize, Serialize}; -use crate::{bolts::HasLen, inputs::Input, Error}; +use crate::inputs::Input; /// A terminal for gramatron grammar fuzzing #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, Hash)] diff --git a/libafl/src/inputs/mod.rs b/libafl/src/inputs/mod.rs index 80ba4c33ff..08fa39caea 100644 --- a/libafl/src/inputs/mod.rs +++ b/libafl/src/inputs/mod.rs @@ -23,14 +23,13 @@ use core::{clone::Clone, fmt::Debug, marker::PhantomData}; #[cfg(feature = "std")] use std::{fs::File, hash::Hash, io::Read, path::Path}; +#[cfg(feature = "std")] +use libafl_bolts::fs::write_file_atomic; +use libafl_bolts::{ownedref::OwnedSlice, Error}; #[cfg(feature = "nautilus")] pub use nautilus::*; use serde::{Deserialize, Serialize}; -#[cfg(feature = "std")] -use crate::bolts::fs::write_file_atomic; -use crate::{bolts::ownedref::OwnedSlice, Error}; - /// An input for the target #[cfg(not(feature = "std"))] pub trait Input: Clone + Serialize + serde::de::DeserializeOwned + Debug { diff --git a/libafl/src/inputs/nautilus.rs b/libafl/src/inputs/nautilus.rs index fb6468b338..a1a3ef46cc 100644 --- a/libafl/src/inputs/nautilus.rs +++ b/libafl/src/inputs/nautilus.rs @@ -13,10 +13,10 @@ use grammartec::{ rule::RuleIDOrCustom, tree::{Tree, TreeLike}, }; +use libafl_bolts::HasLen; use serde::{Deserialize, Serialize}; use crate::{ - bolts::HasLen, generators::nautilus::NautilusContext, inputs::{BytesInput, Input, InputConverter}, Error, diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index 2bb0915903..58ec83f096 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -84,19 +84,26 @@ pub extern crate alloc; pub use ctor::ctor; // Re-export derive(SerdeAny) -#[cfg(feature = "libafl_derive")] +#[cfg(feature = "derive")] #[allow(unused_imports)] #[macro_use] extern crate libafl_derive; -#[cfg(feature = "libafl_derive")] +/// Dummy export that will warn with a deprecation note on usage. +/// Use the `libafl_bolts` crate instead. +#[deprecated( + since = "0.11.0", + note = "All LibAFL bolts have moved to the libafl_bolts crate." +)] +pub mod bolts {} +#[cfg(feature = "derive")] #[doc(hidden)] pub use libafl_derive::*; -pub mod bolts; pub mod corpus; pub mod events; pub mod executors; pub mod feedbacks; +pub mod fuzzer; pub mod generators; pub mod inputs; pub mod monitors; @@ -106,356 +113,33 @@ pub mod schedulers; pub mod stages; pub mod state; -pub mod fuzzer; -use alloc::string::{FromUtf8Error, String}; -use core::{ - array::TryFromSliceError, - fmt, - num::{ParseIntError, TryFromIntError}, -}; -#[cfg(feature = "std")] -use std::{env::VarError, io}; - pub use fuzzer::*; - -#[cfg(feature = "errors_backtrace")] -/// Error Backtrace type when `errors_backtrace` feature is enabled (== [`backtrace::Backtrace`]) -pub type ErrorBacktrace = backtrace::Backtrace; - -#[cfg(not(feature = "errors_backtrace"))] -#[derive(Debug, Default)] -/// Empty struct to use when `errors_backtrace` is disabled -pub struct ErrorBacktrace {} -#[cfg(not(feature = "errors_backtrace"))] -impl ErrorBacktrace { - /// Nop - #[must_use] - pub fn new() -> Self { - Self {} - } -} - -#[cfg(feature = "errors_backtrace")] -fn display_error_backtrace(f: &mut fmt::Formatter, err: &ErrorBacktrace) -> fmt::Result { - write!(f, "\nBacktrace: {err:?}") -} -#[cfg(not(feature = "errors_backtrace"))] -#[allow(clippy::unnecessary_wraps)] -fn display_error_backtrace(_f: &mut fmt::Formatter, _err: &ErrorBacktrace) -> fmt::Result { - fmt::Result::Ok(()) -} - -/// Main error struct for `LibAFL` -#[derive(Debug)] -pub enum Error { - /// Serialization error - Serialize(String, ErrorBacktrace), - /// Compression error - #[cfg(feature = "gzip")] - Compression(ErrorBacktrace), - /// File related error - #[cfg(feature = "std")] - File(io::Error, ErrorBacktrace), - /// Optional val was supposed to be set, but isn't. - EmptyOptional(String, ErrorBacktrace), - /// Key not in Map - KeyNotFound(String, ErrorBacktrace), - /// No elements in the current item - Empty(String, ErrorBacktrace), - /// End of iteration - IteratorEnd(String, ErrorBacktrace), - /// This is not supported (yet) - NotImplemented(String, ErrorBacktrace), - /// You're holding it wrong - IllegalState(String, ErrorBacktrace), - /// The argument passed to this method or function is not valid - IllegalArgument(String, ErrorBacktrace), - /// The performed action is not supported on the current platform - Unsupported(String, ErrorBacktrace), - /// Shutting down, not really an error. - ShuttingDown, - /// Something else happened - Unknown(String, ErrorBacktrace), -} - -impl Error { - /// Serialization error - #[must_use] - pub fn serialize(arg: S) -> Self - where - S: Into, - { - Error::Serialize(arg.into(), ErrorBacktrace::new()) - } - #[cfg(feature = "gzip")] - /// Compression error - #[must_use] - pub fn compression() -> Self { - Error::Compression(ErrorBacktrace::new()) - } - #[cfg(feature = "std")] - /// File related error - #[must_use] - pub fn file(arg: io::Error) -> Self { - Error::File(arg, ErrorBacktrace::new()) - } - /// Optional val was supposed to be set, but isn't. - #[must_use] - pub fn empty_optional(arg: S) -> Self - where - S: Into, - { - Error::EmptyOptional(arg.into(), ErrorBacktrace::new()) - } - /// Key not in Map - #[must_use] - pub fn key_not_found(arg: S) -> Self - where - S: Into, - { - Error::KeyNotFound(arg.into(), ErrorBacktrace::new()) - } - /// No elements in the current item - #[must_use] - pub fn empty(arg: S) -> Self - where - S: Into, - { - Error::Empty(arg.into(), ErrorBacktrace::new()) - } - /// End of iteration - #[must_use] - pub fn iterator_end(arg: S) -> Self - where - S: Into, - { - Error::IteratorEnd(arg.into(), ErrorBacktrace::new()) - } - /// This is not supported (yet) - #[must_use] - pub fn not_implemented(arg: S) -> Self - where - S: Into, - { - Error::NotImplemented(arg.into(), ErrorBacktrace::new()) - } - /// You're holding it wrong - #[must_use] - pub fn illegal_state(arg: S) -> Self - where - S: Into, - { - Error::IllegalState(arg.into(), ErrorBacktrace::new()) - } - /// The argument passed to this method or function is not valid - #[must_use] - pub fn illegal_argument(arg: S) -> Self - where - S: Into, - { - Error::IllegalArgument(arg.into(), ErrorBacktrace::new()) - } - /// Shutting down, not really an error. - #[must_use] - pub fn shutting_down() -> Self { - Error::ShuttingDown - } - /// This operation is not supported on the current architecture or platform - #[must_use] - pub fn unsupported(arg: S) -> Self - where - S: Into, - { - Error::Unsupported(arg.into(), ErrorBacktrace::new()) - } - /// Something else happened - #[must_use] - pub fn unknown(arg: S) -> Self - where - S: Into, - { - Error::Unknown(arg.into(), ErrorBacktrace::new()) - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Self::Serialize(s, b) => { - write!(f, "Error in Serialization: `{0}`", &s)?; - display_error_backtrace(f, b) - } - #[cfg(feature = "gzip")] - Self::Compression(b) => { - write!(f, "Error in decompression")?; - display_error_backtrace(f, b) - } - #[cfg(feature = "std")] - Self::File(err, b) => { - write!(f, "File IO failed: {:?}", &err)?; - display_error_backtrace(f, b) - } - Self::EmptyOptional(s, b) => { - write!(f, "Optional value `{0}` was not set", &s)?; - display_error_backtrace(f, b) - } - Self::KeyNotFound(s, b) => { - write!(f, "Key `{0}` not in Corpus", &s)?; - display_error_backtrace(f, b) - } - Self::Empty(s, b) => { - write!(f, "No items in {0}", &s)?; - display_error_backtrace(f, b) - } - Self::IteratorEnd(s, b) => { - write!(f, "All elements have been processed in {0} iterator", &s)?; - display_error_backtrace(f, b) - } - Self::NotImplemented(s, b) => { - write!(f, "Not implemented: {0}", &s)?; - display_error_backtrace(f, b) - } - Self::IllegalState(s, b) => { - write!(f, "Illegal state: {0}", &s)?; - display_error_backtrace(f, b) - } - Self::IllegalArgument(s, b) => { - write!(f, "Illegal argument: {0}", &s)?; - display_error_backtrace(f, b) - } - Self::Unsupported(s, b) => { - write!( - f, - "The operation is not supported on the current platform: {0}", - &s - )?; - display_error_backtrace(f, b) - } - Self::ShuttingDown => write!(f, "Shutting down!"), - Self::Unknown(s, b) => { - write!(f, "Unknown error: {0}", &s)?; - display_error_backtrace(f, b) - } - } - } -} - -/// Stringify the postcard serializer error -impl From for Error { - fn from(err: postcard::Error) -> Self { - Self::serialize(format!("{err:?}")) - } -} - -/// Stringify the json serializer error -#[cfg(feature = "std")] -impl From for Error { - fn from(err: serde_json::Error) -> Self { - Self::serialize(format!("{err:?}")) - } -} - -#[cfg(all(unix, feature = "std"))] -impl From for Error { - fn from(err: nix::Error) -> Self { - Self::unknown(format!("Unix error: {err:?}")) - } -} - -/// Create an AFL Error from io Error -#[cfg(feature = "std")] -impl From for Error { - fn from(err: io::Error) -> Self { - Self::file(err) - } -} - -impl From for Error { - fn from(err: FromUtf8Error) -> Self { - Self::unknown(format!("Could not convert byte / utf-8: {err:?}")) - } -} - -#[cfg(feature = "std")] -impl From for Error { - fn from(err: VarError) -> Self { - Self::empty(format!("Could not get env var: {err:?}")) - } -} - -impl From for Error { - fn from(err: ParseIntError) -> Self { - Self::unknown(format!("Failed to parse Int: {err:?}")) - } -} - -impl From for Error { - fn from(err: TryFromIntError) -> Self { - Self::illegal_state(format!("Expected conversion failed: {err:?}")) - } -} - -impl From for Error { - fn from(err: TryFromSliceError) -> Self { - Self::illegal_argument(format!("Could not convert slice: {err:?}")) - } -} - -#[cfg(windows)] -impl From for Error { - fn from(err: windows::core::Error) -> Self { - Self::unknown(format!("Windows API error: {err:?}")) - } -} - -#[cfg(feature = "python")] -impl From for Error { - fn from(err: pyo3::PyErr) -> Self { - pyo3::Python::with_gil(|py| { - if err.matches( - py, - pyo3::types::PyType::new::(py), - ) { - Self::shutting_down() - } else { - Self::illegal_state(format!("Python exception: {err:?}")) - } - }) - } -} - -#[cfg(feature = "std")] -impl std::error::Error for Error {} +pub use libafl_bolts::Error; /// The purpose of this module is to alleviate imports of many components by adding a glob import. #[cfg(feature = "prelude")] pub mod prelude { pub use super::{ - bolts::{bolts_prelude::*, *}, - corpus::*, - events::*, - executors::*, - feedbacks::*, - fuzzer::*, - generators::*, - inputs::*, - monitors::*, - mutators::*, - observers::*, - schedulers::*, - stages::*, - state::*, - *, + corpus::*, events::*, executors::*, feedbacks::*, fuzzer::*, generators::*, inputs::*, + monitors::*, mutators::*, observers::*, schedulers::*, stages::*, state::*, *, }; } -// TODO: no_std test +#[cfg(all(any(doctest, test), not(feature = "std")))] +/// Provide custom time in `no_std` tests. +#[no_mangle] +pub unsafe extern "C" fn external_current_millis() -> u64 { + // TODO: use "real" time here + 1000 +} + #[cfg(feature = "std")] #[cfg(test)] mod tests { + use libafl_bolts::{rands::StdRand, tuples::tuple_list}; + use crate::{ - bolts::{rands::StdRand, tuples::tuple_list}, corpus::{Corpus, InMemoryCorpus, Testcase}, events::NopEventManager, executors::{ExitKind, InProcessExecutor}, @@ -540,22 +224,14 @@ mod tests { } } -#[cfg(all(any(doctest, test), not(feature = "std")))] -/// Provide custom time in `no_std` tests. -#[no_mangle] -pub extern "C" fn external_current_millis() -> u64 { - // TODO: use "real" time here - 1000 -} - #[cfg(feature = "python")] #[allow(missing_docs)] pub mod pybind { use pyo3::prelude::*; use super::{ - bolts, corpus, events, executors, feedbacks, fuzzer, generators, monitors, mutators, - observers, stages, state, + corpus, events, executors, feedbacks, fuzzer, generators, monitors, mutators, observers, + stages, state, }; #[derive(Debug, Clone)] @@ -563,8 +239,8 @@ pub mod pybind { pub map: PyObject, } - crate::impl_serde_pyobjectwrapper!(PythonMetadata, map); - crate::impl_serdeany!(PythonMetadata); + libafl_bolts::impl_serde_pyobjectwrapper!(PythonMetadata, map); + libafl_bolts::impl_serdeany!(PythonMetadata); impl PythonMetadata { #[must_use] @@ -573,137 +249,11 @@ pub mod pybind { } } - #[macro_export] - macro_rules! unwrap_me_body { - ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),* }) => { - match &$wrapper { - $( - $wrapper_type::$wrapper_option(py_wrapper) => { - Python::with_gil(|py| -> PyResult<_> { - let borrowed = py_wrapper.borrow(py); - let $name = &borrowed.inner; - Ok($body) - }) - .unwrap() - } - )* - } - }; - ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),* }, { $($wrapper_optional:tt($pw:ident) => $code_block:block)* }) => { - match &$wrapper { - $( - $wrapper_type::$wrapper_option(py_wrapper) => { - Python::with_gil(|py| -> PyResult<_> { - let borrowed = py_wrapper.borrow(py); - let $name = &borrowed.inner; - Ok($body) - }) - .unwrap() - } - )* - $($wrapper_type::$wrapper_optional($pw) => { $code_block })* - } - }; - } - - #[macro_export] - macro_rules! unwrap_me_mut_body { - ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),*}) => { - match &mut $wrapper { - $( - $wrapper_type::$wrapper_option(py_wrapper) => { - Python::with_gil(|py| -> PyResult<_> { - let mut borrowed = py_wrapper.borrow_mut(py); - let $name = &mut borrowed.inner; - Ok($body) - }) - .unwrap() - } - )* - } - }; - ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),*}, { $($wrapper_optional:tt($pw:ident) => $code_block:block)* }) => { - match &mut $wrapper { - $( - $wrapper_type::$wrapper_option(py_wrapper) => { - Python::with_gil(|py| -> PyResult<_> { - let mut borrowed = py_wrapper.borrow_mut(py); - let $name = &mut borrowed.inner; - Ok($body) - }) - .unwrap() - } - )* - $($wrapper_type::$wrapper_optional($pw) => { $code_block })* - } - }; - } - - #[macro_export] - macro_rules! impl_serde_pyobjectwrapper { - ($struct_name:ident, $inner:tt) => { - const _: () = { - use alloc::vec::Vec; - - use pyo3::prelude::*; - use serde::{Deserialize, Deserializer, Serialize, Serializer}; - - impl Serialize for $struct_name { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let buf = Python::with_gil(|py| -> PyResult> { - let pickle = PyModule::import(py, "pickle")?; - let buf: Vec = - pickle.getattr("dumps")?.call1((&self.$inner,))?.extract()?; - Ok(buf) - }) - .unwrap(); - serializer.serialize_bytes(&buf) - } - } - - struct PyObjectVisitor; - - impl<'de> serde::de::Visitor<'de> for PyObjectVisitor { - type Value = $struct_name; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter - .write_str("Expecting some bytes to deserialize from the Python side") - } - - fn visit_byte_buf(self, v: Vec) -> Result - where - E: serde::de::Error, - { - let obj = Python::with_gil(|py| -> PyResult { - let pickle = PyModule::import(py, "pickle")?; - let obj = pickle.getattr("loads")?.call1((v,))?.to_object(py); - Ok(obj) - }) - .unwrap(); - Ok($struct_name::new(obj)) - } - } - - impl<'de> Deserialize<'de> for $struct_name { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_byte_buf(PyObjectVisitor) - } - } - }; - }; - } - #[pymodule] #[pyo3(name = "libafl")] /// Register the classes to the python module pub fn python_module(py: Python, m: &PyModule) -> PyResult<()> { + libafl_bolts::rands::pybind::register(py, m)?; observers::map::pybind::register(py, m)?; observers::pybind::register(py, m)?; feedbacks::map::pybind::register(py, m)?; @@ -723,7 +273,6 @@ pub mod pybind { corpus::ondisk::pybind::register(py, m)?; corpus::inmemory::pybind::register(py, m)?; corpus::cached::pybind::register(py, m)?; - bolts::rands::pybind::register(py, m)?; stages::pybind::register(py, m)?; stages::mutational::pybind::register(py, m)?; Ok(()) diff --git a/libafl/src/monitors/disk.rs b/libafl/src/monitors/disk.rs index 766f94f13d..c4674b355c 100644 --- a/libafl/src/monitors/disk.rs +++ b/libafl/src/monitors/disk.rs @@ -8,12 +8,10 @@ use std::{ path::PathBuf, }; +use libafl_bolts::{current_time, format_duration_hms, ClientId}; use serde_json::json; -use crate::{ - bolts::{current_time, format_duration_hms, ClientId}, - monitors::{ClientStats, Monitor, NopMonitor}, -}; +use crate::monitors::{ClientStats, Monitor, NopMonitor}; /// Wrap a monitor and log the current state of the monitor into a TOML file. #[derive(Debug, Clone)] diff --git a/libafl/src/monitors/mod.rs b/libafl/src/monitors/mod.rs index 8730876537..de8268ed3f 100644 --- a/libafl/src/monitors/mod.rs +++ b/libafl/src/monitors/mod.rs @@ -21,10 +21,9 @@ use core::{fmt, fmt::Write, time::Duration}; #[cfg(feature = "std")] pub use disk::{OnDiskJSONMonitor, OnDiskTOMLMonitor}; use hashbrown::HashMap; +use libafl_bolts::{current_time, format_duration_hms, ClientId}; use serde::{Deserialize, Serialize}; -use crate::bolts::{current_time, format_duration_hms, ClientId}; - #[cfg(feature = "afl_exec_sec")] const CLIENT_STATS_TIME_WINDOW_SECS: u64 = 5; // 5 seconds @@ -670,7 +669,7 @@ impl ClientPerfMonitor { /// the current clock counter #[must_use] pub fn new() -> Self { - let start_time = crate::bolts::cpu::read_time_counter(); + let start_time = libafl_bolts::cpu::read_time_counter(); Self { start_time, @@ -694,7 +693,7 @@ impl ClientPerfMonitor { /// Start a timer with the current time counter #[inline] pub fn start_timer(&mut self) { - self.timer_start = Some(crate::bolts::cpu::read_time_counter()); + self.timer_start = Some(libafl_bolts::cpu::read_time_counter()); } /// Update the current [`ClientPerfMonitor`] with the given [`ClientPerfMonitor`] @@ -720,7 +719,7 @@ impl ClientPerfMonitor { } Some(timer_start) => { // Calculate the elapsed time - let elapsed = crate::bolts::cpu::read_time_counter() - timer_start; + let elapsed = libafl_bolts::cpu::read_time_counter() - timer_start; // Reset the timer self.timer_start = None; @@ -973,13 +972,11 @@ pub mod pybind { use alloc::{boxed::Box, string::String, vec::Vec}; use core::time::Duration; + use libafl_bolts::ClientId; use pyo3::{prelude::*, types::PyUnicode}; use super::ClientStats; - use crate::{ - bolts::ClientId, - monitors::{Monitor, SimpleMonitor}, - }; + use crate::monitors::{Monitor, SimpleMonitor}; // TODO create a PyObjectFnMut to pass, track stabilization of https://github.com/rust-lang/rust/issues/29625 @@ -1060,13 +1057,15 @@ pub mod pybind { macro_rules! unwrap_me { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_body!($wrapper, $name, $body, PythonMonitorWrapper, { Simple }) + libafl_bolts::unwrap_me_body!($wrapper, $name, $body, PythonMonitorWrapper, { Simple }) }; } macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonMonitorWrapper, { Simple }) + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonMonitorWrapper, { + Simple + }) }; } diff --git a/libafl/src/monitors/multi.rs b/libafl/src/monitors/multi.rs index 5eb6db8db8..30837b6363 100644 --- a/libafl/src/monitors/multi.rs +++ b/libafl/src/monitors/multi.rs @@ -5,10 +5,9 @@ use alloc::string::ToString; use alloc::{string::String, vec::Vec}; use core::{fmt::Write, time::Duration}; -use crate::{ - bolts::{current_time, format_duration_hms, ClientId}, - monitors::{ClientStats, Monitor}, -}; +use libafl_bolts::{current_time, format_duration_hms, ClientId}; + +use crate::monitors::{ClientStats, Monitor}; /// Tracking monitor during fuzzing and display both per-client and cumulative info. #[derive(Clone, Debug)] diff --git a/libafl/src/monitors/prometheus.rs b/libafl/src/monitors/prometheus.rs index f7b55b75ae..2ffc2e7411 100644 --- a/libafl/src/monitors/prometheus.rs +++ b/libafl/src/monitors/prometheus.rs @@ -31,6 +31,7 @@ use std::{ // using thread in order to start the HTTP server in a separate thread use futures::executor::block_on; +use libafl_bolts::{current_time, format_duration_hms, ClientId}; // using the official rust client library for Prometheus: https://github.com/prometheus/client_rust use prometheus_client::{ encoding::{text::encode, EncodeLabelSet}, @@ -40,10 +41,7 @@ use prometheus_client::{ // using tide for the HTTP server library (fast, async, simple) use tide::Request; -use crate::{ - bolts::{current_time, format_duration_hms, ClientId}, - monitors::{ClientStats, Monitor, UserStats}, -}; +use crate::monitors::{ClientStats, Monitor, UserStats}; /// Tracking monitor during fuzzing. #[derive(Clone)] diff --git a/libafl/src/monitors/tui/mod.rs b/libafl/src/monitors/tui/mod.rs index 2bf985f974..7b1e7b233f 100644 --- a/libafl/src/monitors/tui/mod.rs +++ b/libafl/src/monitors/tui/mod.rs @@ -20,14 +20,12 @@ use crossterm::{ terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; use hashbrown::HashMap; +use libafl_bolts::{current_time, format_duration_hms, ClientId}; use tui::{backend::CrosstermBackend, Terminal}; #[cfg(feature = "introspection")] use super::{ClientPerfMonitor, PerfFeature}; -use crate::{ - bolts::{current_time, format_duration_hms, ClientId}, - monitors::{ClientStats, Monitor, UserStats}, -}; +use crate::monitors::{ClientStats, Monitor, UserStats}; pub mod ui; use ui::TuiUI; diff --git a/libafl/src/mutators/encoded_mutations.rs b/libafl/src/mutators/encoded_mutations.rs index eb52925bef..3c5b9215f0 100644 --- a/libafl/src/mutators/encoded_mutations.rs +++ b/libafl/src/mutators/encoded_mutations.rs @@ -3,11 +3,12 @@ use alloc::vec::Vec; use core::cmp::{max, min}; +use libafl_bolts::{ + rands::Rand, + tuples::{tuple_list, tuple_list_type}, +}; + use crate::{ - bolts::{ - rands::Rand, - tuples::{tuple_list, tuple_list_type}, - }, corpus::Corpus, inputs::{EncodedInput, UsesInput}, mutators::{ diff --git a/libafl/src/mutators/gramatron.rs b/libafl/src/mutators/gramatron.rs index 6f707d21fa..59793a16c4 100644 --- a/libafl/src/mutators/gramatron.rs +++ b/libafl/src/mutators/gramatron.rs @@ -4,10 +4,10 @@ use alloc::vec::Vec; use core::cmp::max; use hashbrown::HashMap; +use libafl_bolts::{rands::Rand, Named}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{rands::Rand, tuples::Named}, corpus::{Corpus, HasTestcase}, generators::GramatronGenerator, inputs::{GramatronInput, Terminal}, @@ -77,7 +77,7 @@ pub struct GramatronIdxMapMetadata { pub map: HashMap>, } -crate::impl_serdeany!(GramatronIdxMapMetadata); +libafl_bolts::impl_serdeany!(GramatronIdxMapMetadata); impl GramatronIdxMapMetadata { /// Creates a new [`struct@GramatronIdxMapMetadata`]. diff --git a/libafl/src/mutators/grimoire.rs b/libafl/src/mutators/grimoire.rs index 154eb84ff7..c115b9db4d 100644 --- a/libafl/src/mutators/grimoire.rs +++ b/libafl/src/mutators/grimoire.rs @@ -4,8 +4,9 @@ use alloc::vec::Vec; use core::cmp::{max, min}; +use libafl_bolts::{rands::Rand, Named}; + use crate::{ - bolts::{rands::Rand, tuples::Named}, corpus::Corpus, inputs::{GeneralizedInputMetadata, GeneralizedItem}, mutators::{token_mutations::Tokens, MutationResult, Mutator}, diff --git a/libafl/src/mutators/mod.rs b/libafl/src/mutators/mod.rs index 70dd76eeb2..599e639963 100644 --- a/libafl/src/mutators/mod.rs +++ b/libafl/src/mutators/mod.rs @@ -24,14 +24,11 @@ pub use tuneable::*; pub mod nautilus; use alloc::vec::Vec; +use libafl_bolts::{tuples::HasConstLen, Named}; #[cfg(feature = "nautilus")] pub use nautilus::*; -use crate::{ - bolts::tuples::{HasConstLen, Named}, - corpus::CorpusId, - Error, -}; +use crate::{corpus::CorpusId, Error}; // TODO mutator stats method that produces something that can be sent with the NewTestcase event // We can use it to report which mutations generated the testcase in the broker logs @@ -287,11 +284,11 @@ where pub mod pybind { use core::ffi::CStr; + use libafl_bolts::Named; use pyo3::{prelude::*, AsPyPointer}; use super::{MutationResult, Mutator}; use crate::{ - bolts::tuples::Named, corpus::CorpusId, inputs::{BytesInput, HasBytesVec}, mutators::scheduled::pybind::PythonStdHavocMutator, @@ -379,7 +376,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonMutatorWrapper, { + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonMutatorWrapper, { StdHavoc }, { diff --git a/libafl/src/mutators/mopt_mutator.rs b/libafl/src/mutators/mopt_mutator.rs index d08c9350c2..7bad4050fc 100644 --- a/libafl/src/mutators/mopt_mutator.rs +++ b/libafl/src/mutators/mopt_mutator.rs @@ -8,14 +8,14 @@ use core::{ marker::PhantomData, }; +use libafl_bolts::{ + rands::{Rand, StdRand}, + Named, +}; use serde::{Deserialize, Serialize}; use super::MutationId; use crate::{ - bolts::{ - rands::{Rand, StdRand}, - tuples::Named, - }, corpus::{Corpus, CorpusId}, mutators::{ComposedByMutations, MutationResult, Mutator, MutatorsTuple, ScheduledMutator}, state::{HasCorpus, HasMetadata, HasRand, HasSolutions}, @@ -97,7 +97,7 @@ pub struct MOpt { pub core_operator_cycles_v3: Vec, } -crate::impl_serdeany!(MOpt); +libafl_bolts::impl_serdeany!(MOpt); impl Debug for MOpt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/libafl/src/mutators/mutations.rs b/libafl/src/mutators/mutations.rs index 55a8c51db3..bd279cc0c2 100644 --- a/libafl/src/mutators/mutations.rs +++ b/libafl/src/mutators/mutations.rs @@ -3,8 +3,9 @@ use alloc::{borrow::ToOwned, vec::Vec}; use core::{cmp::min, mem::size_of, ops::Range}; +use libafl_bolts::{rands::Rand, Named}; + use crate::{ - bolts::{rands::Rand, tuples::Named}, corpus::Corpus, inputs::HasBytesVec, mutators::{MutationResult, Mutator}, @@ -1246,9 +1247,9 @@ fn locate_diffs(this: &[u8], other: &[u8]) -> (i64, i64) { #[allow(clippy::cast_possible_wrap)] if this_el != other_el { if first_diff < 0 { - first_diff = i as i64; + first_diff = i64::try_from(i).unwrap(); } - last_diff = i as i64; + last_diff = i64::try_from(i).unwrap(); } } @@ -1369,12 +1370,13 @@ pub fn str_decode(item: &str) -> Result, Error> { #[cfg(test)] mod tests { + use libafl_bolts::{ + rands::StdRand, + tuples::{tuple_list, HasConstLen}, + }; + use super::*; use crate::{ - bolts::{ - rands::StdRand, - tuples::{tuple_list, HasConstLen}, - }, corpus::{Corpus, InMemoryCorpus}, feedbacks::ConstFeedback, inputs::BytesInput, diff --git a/libafl/src/mutators/nautilus.rs b/libafl/src/mutators/nautilus.rs index a9b259a092..d6b64808f9 100644 --- a/libafl/src/mutators/nautilus.rs +++ b/libafl/src/mutators/nautilus.rs @@ -7,9 +7,9 @@ use grammartec::{ mutator::Mutator as BackingMutator, tree::{Tree, TreeMutation}, }; +use libafl_bolts::Named; use crate::{ - bolts::tuples::Named, feedbacks::NautilusChunksMetadata, generators::nautilus::NautilusContext, inputs::nautilus::NautilusInput, diff --git a/libafl/src/mutators/scheduled.rs b/libafl/src/mutators/scheduled.rs index a2a739187c..cb43b3f104 100644 --- a/libafl/src/mutators/scheduled.rs +++ b/libafl/src/mutators/scheduled.rs @@ -6,16 +6,16 @@ use core::{ marker::PhantomData, }; +use libafl_bolts::{ + rands::Rand, + tuples::{tuple_list, tuple_list_type, NamedTuple}, + AsMutSlice, AsSlice, Named, +}; use serde::{Deserialize, Serialize}; use super::MutationId; pub use crate::mutators::{mutations::*, token_mutations::*}; use crate::{ - bolts::{ - rands::Rand, - tuples::{tuple_list, tuple_list_type, Named, NamedTuple}, - AsMutSlice, AsSlice, - }, corpus::{Corpus, CorpusId}, mutators::{MutationResult, Mutator, MutatorsTuple}, state::{HasCorpus, HasMetadata, HasRand}, @@ -29,7 +29,7 @@ pub struct LogMutationMetadata { pub list: Vec, } -crate::impl_serdeany!(LogMutationMetadata); +libafl_bolts::impl_serdeany!(LogMutationMetadata); impl AsSlice for LogMutationMetadata { type Entry = String; @@ -442,8 +442,9 @@ where #[cfg(test)] mod tests { + use libafl_bolts::rands::{Rand, StdRand, XkcdRand}; + use crate::{ - bolts::rands::{Rand, StdRand, XkcdRand}, corpus::{Corpus, InMemoryCorpus, Testcase}, feedbacks::ConstFeedback, inputs::{BytesInput, HasBytesVec}, diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index ce4c34ed18..3a2d4ba939 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -17,12 +17,12 @@ use std::{ }; use hashbrown::HashSet; +use libafl_bolts::{rands::Rand, AsSlice}; use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] use crate::mutators::str_decode; use crate::{ - bolts::{rands::Rand, AsSlice}, inputs::{HasBytesVec, UsesInput}, mutators::{ buffer_self_copy, mutations::buffer_copy, MultiMutator, MutationResult, Mutator, Named, @@ -42,7 +42,7 @@ pub struct Tokens { tokens_set: HashSet>, } -crate::impl_serdeany!(Tokens); +libafl_bolts::impl_serdeany!(Tokens); /// The metadata used for token mutators impl Tokens { diff --git a/libafl/src/mutators/tuneable.rs b/libafl/src/mutators/tuneable.rs index 67dbac46a1..b861441b47 100644 --- a/libafl/src/mutators/tuneable.rs +++ b/libafl/src/mutators/tuneable.rs @@ -8,12 +8,11 @@ use core::{ marker::PhantomData, }; +use libafl_bolts::{calculate_cumulative_sum_in_place, impl_serdeany, rands::Rand, Named}; use serde::{Deserialize, Serialize}; pub use crate::mutators::{mutations::*, token_mutations::*}; use crate::{ - bolts::{calculate_cumulative_sum_in_place, rands::Rand, tuples::Named}, - impl_serdeany, mutators::{ ComposedByMutations, MutationId, MutationResult, Mutator, MutatorsTuple, ScheduledMutator, }, @@ -336,11 +335,12 @@ where #[cfg(test)] mod test { + use libafl_bolts::tuples::tuple_list; + use super::{ BitFlipMutator, ByteDecMutator, TuneableScheduledMutator, TuneableScheduledMutatorMetadata, }; use crate::{ - bolts::tuples::tuple_list, inputs::BytesInput, mutators::{ByteRandMutator, ScheduledMutator}, state::NopState, diff --git a/libafl/src/observers/cmp.rs b/libafl/src/observers/cmp.rs index 29cc6f55c7..de885874d6 100644 --- a/libafl/src/observers/cmp.rs +++ b/libafl/src/observers/cmp.rs @@ -8,15 +8,11 @@ use core::{fmt::Debug, marker::PhantomData}; use c2rust_bitfields::BitfieldStruct; use hashbrown::HashMap; +use libafl_bolts::{ownedref::OwnedRefMut, AsMutSlice, AsSlice, Named}; use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize, Serializer}; use crate::{ - bolts::{ownedref::OwnedRefMut, tuples::Named, AsMutSlice, AsSlice}, - executors::ExitKind, - inputs::UsesInput, - observers::Observer, - state::HasMetadata, - Error, + executors::ExitKind, inputs::UsesInput, observers::Observer, state::HasMetadata, Error, }; /// Compare values collected during a run @@ -65,7 +61,7 @@ pub struct CmpValuesMetadata { pub list: Vec, } -crate::impl_serdeany!(CmpValuesMetadata); +libafl_bolts::impl_serdeany!(CmpValuesMetadata); impl AsSlice for CmpValuesMetadata { type Entry = CmpValues; @@ -578,7 +574,7 @@ pub struct AFLppCmpValuesMetadata { pub headers: Vec<(usize, AFLppCmpHeader)>, } -crate::impl_serdeany!(AFLppCmpValuesMetadata); +libafl_bolts::impl_serdeany!(AFLppCmpValuesMetadata); impl AFLppCmpValuesMetadata { /// Constructor for `AFLppCmpValuesMetadata` diff --git a/libafl/src/observers/concolic/metadata.rs b/libafl/src/observers/concolic/metadata.rs index b3d045a2af..ceb490bc11 100644 --- a/libafl/src/observers/concolic/metadata.rs +++ b/libafl/src/observers/concolic/metadata.rs @@ -23,4 +23,4 @@ impl ConcolicMetadata { } } -crate::impl_serdeany!(ConcolicMetadata); +libafl_bolts::impl_serdeany!(ConcolicMetadata); diff --git a/libafl/src/observers/concolic/observer.rs b/libafl/src/observers/concolic/observer.rs index 7f95cb227e..c84da0651f 100644 --- a/libafl/src/observers/concolic/observer.rs +++ b/libafl/src/observers/concolic/observer.rs @@ -1,9 +1,9 @@ use alloc::string::String; +use libafl_bolts::Named; use serde::{Deserialize, Serialize}; use crate::{ - bolts::tuples::Named, inputs::UsesInput, observers::{ concolic::{serialization_format::MessageFileReader, ConcolicMetadata}, diff --git a/libafl/src/observers/concolic/serialization_format.rs b/libafl/src/observers/concolic/serialization_format.rs index 9e1497128b..c6a6032b16 100644 --- a/libafl/src/observers/concolic/serialization_format.rs +++ b/libafl/src/observers/concolic/serialization_format.rs @@ -441,7 +441,7 @@ mod serialization_tests { } } -use crate::bolts::shmem::{ShMem, ShMemCursor, ShMemProvider, StdShMemProvider}; +use libafl_bolts::shmem::{ShMem, ShMemCursor, ShMemProvider, StdShMemProvider}; /// The default environment variable name to use for the shared memory used by the concolic tracing pub const DEFAULT_ENV_NAME: &str = "SHARED_MEMORY_MESSAGES"; diff --git a/libafl/src/observers/map.rs b/libafl/src/observers/map.rs index 5fd72eb187..0abb7bcfb1 100644 --- a/libafl/src/observers/map.rs +++ b/libafl/src/observers/map.rs @@ -14,15 +14,14 @@ use core::{ use ahash::RandomState; use intervaltree::IntervalTree; +use libafl_bolts::{ + ownedref::{OwnedMutPtr, OwnedMutSlice}, + AsIter, AsIterMut, AsMutSlice, AsSlice, HasLen, Named, Truncate, +}; use num_traits::Bounded; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{ - ownedref::{OwnedMutPtr, OwnedMutSlice}, - tuples::Named, - AsIter, AsIterMut, AsMutSlice, AsSlice, HasLen, Truncate, - }, executors::ExitKind, inputs::UsesInput, observers::{DifferentialObserver, Observer, ObserversTuple}, diff --git a/libafl/src/observers/mod.rs b/libafl/src/observers/mod.rs index d17c319d62..76801e4530 100644 --- a/libafl/src/observers/mod.rs +++ b/libafl/src/observers/mod.rs @@ -19,6 +19,7 @@ pub use stacktrace::*; pub mod concolic; pub mod value; + // Rust is breaking this with 'error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `type_id`' and so we disable this component for the moment //#[cfg(unstable_feature)] //pub mod owned; @@ -32,21 +33,13 @@ use core::{fmt::Debug, time::Duration}; #[cfg(feature = "std")] use std::time::Instant; +#[cfg(feature = "no_std")] +use libafl_bolts::current_time; +use libafl_bolts::{ownedref::OwnedMutPtr, tuples::MatchName, Named}; use serde::{Deserialize, Serialize}; pub use value::*; -#[cfg(feature = "no_std")] -use crate::bolts::current_time; -use crate::{ - bolts::{ - ownedref::OwnedMutPtr, - tuples::{MatchName, Named}, - }, - executors::ExitKind, - inputs::UsesInput, - state::UsesState, - Error, -}; +use crate::{executors::ExitKind, inputs::UsesInput, state::UsesState, Error}; /// Something that uses observer like mapfeedbacks pub trait UsesObserver @@ -607,12 +600,15 @@ where pub mod pybind { use std::cell::UnsafeCell; + use libafl_bolts::{ + tuples::{type_eq, MatchName}, + Named, + }; use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use super::{Debug, Observer, ObserversTuple, String, Vec}; use crate::{ - bolts::tuples::{type_eq, MatchName, Named}, executors::{pybind::PythonExitKind, ExitKind}, inputs::{BytesInput, HasBytesVec}, observers::map::pybind::{ @@ -651,7 +647,7 @@ pub mod pybind { } } - crate::impl_serde_pyobjectwrapper!(PyObjectObserver, inner); + libafl_bolts::impl_serde_pyobjectwrapper!(PyObjectObserver, inner); impl Named for PyObjectObserver { fn name(&self) -> &str { @@ -1393,11 +1389,13 @@ pub mod pybind { #[cfg(test)] mod tests { - use crate::{ - bolts::tuples::{tuple_list, tuple_list_type, Named}, - observers::{StdMapObserver, TimeObserver}, + use libafl_bolts::{ + tuples::{tuple_list, tuple_list_type}, + Named, }; + use crate::observers::{StdMapObserver, TimeObserver}; + static mut MAP: [u32; 4] = [0; 4]; #[test] diff --git a/libafl/src/observers/owned.rs b/libafl/src/observers/owned.rs index 7e336c86e2..d3d21f6169 100644 --- a/libafl/src/observers/owned.rs +++ b/libafl/src/observers/owned.rs @@ -3,12 +3,13 @@ use core::{any::Any, fmt::Debug}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - -use crate::{ - bolts::{ +use libafl_bolts::{ anymap::{pack_type_id, AsAny}, tuples::MatchName, - }, + }; + +use crate::{ + executors::ExitKind, observers::{Observer, ObserversTuple}, Error, diff --git a/libafl/src/observers/stacktrace.rs b/libafl/src/observers/stacktrace.rs index 86e27f60e5..ac14252f61 100644 --- a/libafl/src/observers/stacktrace.rs +++ b/libafl/src/observers/stacktrace.rs @@ -18,6 +18,7 @@ use std::{ }; use backtrace::Backtrace; +use libafl_bolts::{ownedref::OwnedRefMut, Named}; #[cfg(feature = "casr")] use libcasr::{ asan::AsanStacktrace, @@ -39,13 +40,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use super::ObserverWithHashField; -use crate::{ - bolts::{ownedref::OwnedRefMut, tuples::Named}, - executors::ExitKind, - inputs::UsesInput, - observers::Observer, - Error, -}; +use crate::{executors::ExitKind, inputs::UsesInput, observers::Observer, Error}; #[cfg(not(feature = "casr"))] /// Collects the backtrace via [`Backtrace`] and [`Debug`] diff --git a/libafl/src/observers/stdio.rs b/libafl/src/observers/stdio.rs index bcc893dddb..5e0ddc98ad 100644 --- a/libafl/src/observers/stdio.rs +++ b/libafl/src/observers/stdio.rs @@ -5,9 +5,10 @@ use alloc::string::String; use std::vec::Vec; +use libafl_bolts::Named; use serde::{Deserialize, Serialize}; -use crate::{bolts::tuples::Named, inputs::UsesInput, observers::Observer}; +use crate::{inputs::UsesInput, observers::Observer}; /// An observer that captures stdout of a target. /// Only works for supported executors. diff --git a/libafl/src/observers/value.rs b/libafl/src/observers/value.rs index 35c2a0da1c..4322bf806f 100644 --- a/libafl/src/observers/value.rs +++ b/libafl/src/observers/value.rs @@ -12,15 +12,11 @@ use core::{ }; use ahash::RandomState; +use libafl_bolts::{ownedref::OwnedRef, Named}; use serde::{Deserialize, Serialize}; use super::Observer; -use crate::{ - bolts::{ownedref::OwnedRef, tuples::Named}, - inputs::UsesInput, - observers::ObserverWithHashField, - Error, -}; +use crate::{inputs::UsesInput, observers::ObserverWithHashField, Error}; /// A simple observer with a single value. /// diff --git a/libafl/src/schedulers/accounting.rs b/libafl/src/schedulers/accounting.rs index 54d8dcf080..5ddffd7c3c 100644 --- a/libafl/src/schedulers/accounting.rs +++ b/libafl/src/schedulers/accounting.rs @@ -4,10 +4,10 @@ use alloc::vec::Vec; use core::fmt::Debug; use hashbrown::HashMap; +use libafl_bolts::{rands::Rand, AsMutSlice, AsSlice, HasLen, HasRefCnt}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{rands::Rand, AsMutSlice, AsSlice, HasLen, HasRefCnt}, corpus::{Corpus, CorpusId}, feedbacks::MapIndexesMetadata, inputs::UsesInput, @@ -29,7 +29,7 @@ pub struct AccountingIndexesMetadata { pub tcref: isize, } -crate::impl_serdeany!(AccountingIndexesMetadata); +libafl_bolts::impl_serdeany!(AccountingIndexesMetadata); impl AsSlice for AccountingIndexesMetadata { type Entry = usize; @@ -82,7 +82,7 @@ pub struct TopAccountingMetadata { pub max_accounting: Vec, } -crate::impl_serdeany!(TopAccountingMetadata); +libafl_bolts::impl_serdeany!(TopAccountingMetadata); impl TopAccountingMetadata { /// Creates a new [`struct@TopAccountingMetadata`] diff --git a/libafl/src/schedulers/ecofuzz.rs b/libafl/src/schedulers/ecofuzz.rs index cddfec41c2..9750fceafc 100644 --- a/libafl/src/schedulers/ecofuzz.rs +++ b/libafl/src/schedulers/ecofuzz.rs @@ -49,7 +49,7 @@ pub struct EcoTestcaseMetadata { computed_score: f64, } -crate::impl_serdeany!(EcoTestcaseMetadata); +libafl_bolts::impl_serdeany!(EcoTestcaseMetadata); /// The state Metadata for `EcoScheduler` #[derive(Serialize, Deserialize, Clone, Debug, Default)] @@ -64,7 +64,7 @@ pub struct EcoMetadata { regret: f64, } -crate::impl_serdeany!(EcoMetadata); +libafl_bolts::impl_serdeany!(EcoMetadata); /// A corpus scheduler implementing `EcoFuzz` (`https://www.usenix.org/conference/usenixsecurity20/presentation/yue`) #[derive(Clone, Debug)] diff --git a/libafl/src/schedulers/minimizer.rs b/libafl/src/schedulers/minimizer.rs index a1217e54e5..749bf5a128 100644 --- a/libafl/src/schedulers/minimizer.rs +++ b/libafl/src/schedulers/minimizer.rs @@ -5,10 +5,10 @@ use alloc::vec::Vec; use core::{any::type_name, cmp::Ordering, marker::PhantomData}; use hashbrown::{HashMap, HashSet}; +use libafl_bolts::{rands::Rand, serdeany::SerdeAny, AsSlice, HasRefCnt}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{rands::Rand, serdeany::SerdeAny, AsSlice, HasRefCnt}, corpus::{Corpus, CorpusId, Testcase}, feedbacks::MapIndexesMetadata, inputs::UsesInput, @@ -25,7 +25,7 @@ pub const DEFAULT_SKIP_NON_FAVORED_PROB: u64 = 95; #[derive(Debug, Serialize, Deserialize)] pub struct IsFavoredMetadata {} -crate::impl_serdeany!(IsFavoredMetadata); +libafl_bolts::impl_serdeany!(IsFavoredMetadata); /// A state metadata holding a map of favoreds testcases for each map entry #[derive(Debug, Serialize, Deserialize)] @@ -34,7 +34,7 @@ pub struct TopRatedsMetadata { pub map: HashMap, } -crate::impl_serdeany!(TopRatedsMetadata); +libafl_bolts::impl_serdeany!(TopRatedsMetadata); impl TopRatedsMetadata { /// Creates a new [`struct@TopRatedsMetadata`] @@ -105,7 +105,7 @@ where if let Some(meta) = state.metadata_map_mut().get_mut::() { let entries = meta .map - .drain_filter(|_, other_idx| *other_idx == idx) + .extract_if(|_, other_idx| *other_idx == idx) .map(|(entry, _)| entry) .collect::>(); entries diff --git a/libafl/src/schedulers/mod.rs b/libafl/src/schedulers/mod.rs index 63c6733f93..d62263de61 100644 --- a/libafl/src/schedulers/mod.rs +++ b/libafl/src/schedulers/mod.rs @@ -30,10 +30,10 @@ pub mod ecofuzz; pub use ecofuzz::{EcoMetadata, EcoScheduler, EcoState, EcoTestcaseMetadata, EcoTestcaseScore}; pub mod tuneable; +use libafl_bolts::rands::Rand; pub use tuneable::*; use crate::{ - bolts::rands::Rand, corpus::{Corpus, CorpusId, HasTestcase, Testcase}, inputs::UsesInput, observers::ObserversTuple, diff --git a/libafl/src/schedulers/powersched.rs b/libafl/src/schedulers/powersched.rs index 0dad9b3230..ece9679148 100644 --- a/libafl/src/schedulers/powersched.rs +++ b/libafl/src/schedulers/powersched.rs @@ -20,7 +20,7 @@ use crate::{ /// The n fuzz size pub const N_FUZZ_SIZE: usize = 1 << 21; -crate::impl_serdeany!(SchedulerMetadata); +libafl_bolts::impl_serdeany!(SchedulerMetadata); /// The metadata used for power schedules #[derive(Serialize, Deserialize, Clone, Debug)] diff --git a/libafl/src/schedulers/probabilistic_sampling.rs b/libafl/src/schedulers/probabilistic_sampling.rs index edc74cdf9f..44dd8335a4 100644 --- a/libafl/src/schedulers/probabilistic_sampling.rs +++ b/libafl/src/schedulers/probabilistic_sampling.rs @@ -5,10 +5,10 @@ use alloc::string::String; use core::marker::PhantomData; use hashbrown::HashMap; +use libafl_bolts::rands::Rand; use serde::{Deserialize, Serialize}; use crate::{ - bolts::rands::Rand, corpus::{Corpus, CorpusId, HasTestcase}, inputs::UsesInput, schedulers::{Scheduler, TestcaseScore}, @@ -34,7 +34,7 @@ pub struct ProbabilityMetadata { pub total_probability: f64, } -crate::impl_serdeany!(ProbabilityMetadata); +libafl_bolts::impl_serdeany!(ProbabilityMetadata); impl ProbabilityMetadata { /// Creates a new [`struct@ProbabilityMetadata`] @@ -152,8 +152,9 @@ where mod tests { use core::{borrow::BorrowMut, marker::PhantomData}; + use libafl_bolts::rands::StdRand; + use crate::{ - bolts::rands::StdRand, corpus::{Corpus, InMemoryCorpus, Testcase}, feedbacks::ConstFeedback, inputs::{bytes::BytesInput, Input, UsesInput}, diff --git a/libafl/src/schedulers/queue.rs b/libafl/src/schedulers/queue.rs index 62ae1e48f9..83754928fc 100644 --- a/libafl/src/schedulers/queue.rs +++ b/libafl/src/schedulers/queue.rs @@ -81,8 +81,9 @@ mod tests { use std::{fs, path::PathBuf}; + use libafl_bolts::rands::StdRand; + use crate::{ - bolts::rands::StdRand, corpus::{Corpus, OnDiskCorpus, Testcase}, feedbacks::ConstFeedback, inputs::bytes::BytesInput, diff --git a/libafl/src/schedulers/testcase_score.rs b/libafl/src/schedulers/testcase_score.rs index f2c6ce4ee8..8541fb1342 100644 --- a/libafl/src/schedulers/testcase_score.rs +++ b/libafl/src/schedulers/testcase_score.rs @@ -2,8 +2,9 @@ use alloc::string::{String, ToString}; use core::marker::PhantomData; +use libafl_bolts::{HasLen, HasRefCnt}; + use crate::{ - bolts::{HasLen, HasRefCnt}, corpus::{Corpus, SchedulerTestcaseMetadata, Testcase}, feedbacks::MapIndexesMetadata, schedulers::{ diff --git a/libafl/src/schedulers/tuneable.rs b/libafl/src/schedulers/tuneable.rs index 004b9c7b65..96aca13819 100644 --- a/libafl/src/schedulers/tuneable.rs +++ b/libafl/src/schedulers/tuneable.rs @@ -5,12 +5,12 @@ use alloc::borrow::ToOwned; use core::marker::PhantomData; +use libafl_bolts::impl_serdeany; use serde::{Deserialize, Serialize}; use super::RemovableScheduler; use crate::{ corpus::{Corpus, CorpusId, HasTestcase}, - impl_serdeany, inputs::UsesInput, schedulers::Scheduler, state::{HasCorpus, HasMetadata, UsesState}, diff --git a/libafl/src/schedulers/weighted.rs b/libafl/src/schedulers/weighted.rs index 48f3c0cde0..52e5c2e3f4 100644 --- a/libafl/src/schedulers/weighted.rs +++ b/libafl/src/schedulers/weighted.rs @@ -5,10 +5,10 @@ use alloc::string::{String, ToString}; use core::marker::PhantomData; use hashbrown::HashMap; +use libafl_bolts::rands::Rand; use serde::{Deserialize, Serialize}; use crate::{ - bolts::rands::Rand, corpus::{Corpus, CorpusId, HasTestcase, SchedulerTestcaseMetadata}, inputs::UsesInput, observers::{MapObserver, ObserversTuple}, @@ -85,7 +85,7 @@ impl WeightedScheduleMetadata { } } -crate::impl_serdeany!(WeightedScheduleMetadata); +libafl_bolts::impl_serdeany!(WeightedScheduleMetadata); /// A corpus scheduler using power schedules with weighted queue item selection algo. #[derive(Clone, Debug)] diff --git a/libafl/src/stages/calibrate.rs b/libafl/src/stages/calibrate.rs index 84b863fbba..95411f252f 100644 --- a/libafl/src/stages/calibrate.rs +++ b/libafl/src/stages/calibrate.rs @@ -7,11 +7,11 @@ use alloc::{ use core::{fmt::Debug, marker::PhantomData, time::Duration}; use hashbrown::HashSet; +use libafl_bolts::{current_time, AsIter, Named}; use num_traits::Bounded; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{current_time, tuples::Named, AsIter}, corpus::{Corpus, CorpusId, SchedulerTestcaseMetadata}, events::{Event, EventFirer, LogSeverity}, executors::{Executor, ExitKind, HasObservers}, @@ -26,7 +26,7 @@ use crate::{ Error, }; -crate::impl_serdeany!(UnstableEntriesMetadata); +libafl_bolts::impl_serdeany!(UnstableEntriesMetadata); /// The metadata to keep unstable entries /// In libafl, the stability is the number of the unstable entries divided by the size of the map /// This is different from AFL++, which shows the number of the unstable entries divided by the number of filled entries. diff --git a/libafl/src/stages/colorization.rs b/libafl/src/stages/colorization.rs index 206be61750..4a631d9fd9 100644 --- a/libafl/src/stages/colorization.rs +++ b/libafl/src/stages/colorization.rs @@ -6,10 +6,10 @@ use alloc::{ }; use core::{cmp::Ordering, fmt::Debug, marker::PhantomData, ops::Range}; +use libafl_bolts::{rands::Rand, tuples::MatchName}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{rands::Rand, tuples::MatchName}, corpus::{Corpus, CorpusId}, events::EventFirer, executors::{Executor, HasObservers}, @@ -134,7 +134,7 @@ impl TaintMetadata { } } -crate::impl_serdeany!(TaintMetadata); +libafl_bolts::impl_serdeany!(TaintMetadata); impl ColorizationStage where diff --git a/libafl/src/stages/concolic.rs b/libafl/src/stages/concolic.rs index a16b2d7777..3c810f95f2 100644 --- a/libafl/src/stages/concolic.rs +++ b/libafl/src/stages/concolic.rs @@ -78,9 +78,11 @@ impl ConcolicTracingStage { } } +use libafl_bolts::tuples::MatchName; + #[cfg(all(feature = "concolic_mutation", feature = "introspection"))] use crate::monitors::PerfFeature; -use crate::{bolts::tuples::MatchName, state::UsesState}; +use crate::state::UsesState; #[cfg(feature = "concolic_mutation")] use crate::{ inputs::HasBytesVec, diff --git a/libafl/src/stages/dump.rs b/libafl/src/stages/dump.rs index 210e08d55d..89f7b63d46 100644 --- a/libafl/src/stages/dump.rs +++ b/libafl/src/stages/dump.rs @@ -4,6 +4,7 @@ use alloc::{string::String, vec::Vec}; use core::{clone::Clone, marker::PhantomData}; use std::{fs, fs::File, io::Write, path::PathBuf}; +use libafl_bolts::impl_serdeany; use serde::{Deserialize, Serialize}; use crate::{ @@ -21,7 +22,7 @@ pub struct DumpToDiskMetadata { last_solution: Option, } -crate::impl_serdeany!(DumpToDiskMetadata); +impl_serdeany!(DumpToDiskMetadata); /// The [`DumpToDiskStage`] is a stage that dumps the corpus and the solutions to disk #[derive(Debug)] diff --git a/libafl/src/stages/generalization.rs b/libafl/src/stages/generalization.rs index 8ab9d53aea..1ef4d25509 100644 --- a/libafl/src/stages/generalization.rs +++ b/libafl/src/stages/generalization.rs @@ -6,10 +6,11 @@ use alloc::{ }; use core::{fmt::Debug, marker::PhantomData}; +use libafl_bolts::AsSlice; + #[cfg(feature = "introspection")] use crate::monitors::PerfFeature; use crate::{ - bolts::AsSlice, corpus::{Corpus, CorpusId}, executors::{Executor, HasObservers}, feedbacks::map::MapNoveltiesMetadata, diff --git a/libafl/src/stages/mod.rs b/libafl/src/stages/mod.rs index 14ecdb0b76..94dc54726c 100644 --- a/libafl/src/stages/mod.rs +++ b/libafl/src/stages/mod.rs @@ -388,7 +388,7 @@ pub mod pybind { macro_rules! unwrap_me_mut { ($wrapper:expr, $name:ident, $body:block) => { - crate::unwrap_me_mut_body!($wrapper, $name, $body, PythonStageWrapper, + libafl_bolts::unwrap_me_mut_body!($wrapper, $name, $body, PythonStageWrapper, { StdMutational }, { Python(py_wrapper) => { diff --git a/libafl/src/stages/mutational.rs b/libafl/src/stages/mutational.rs index fe28e99a39..d93b381065 100644 --- a/libafl/src/stages/mutational.rs +++ b/libafl/src/stages/mutational.rs @@ -3,10 +3,11 @@ use core::marker::PhantomData; +use libafl_bolts::rands::Rand; + #[cfg(feature = "introspection")] use crate::monitors::PerfFeature; use crate::{ - bolts::rands::Rand, corpus::{Corpus, CorpusId, Testcase}, fuzzer::Evaluator, inputs::Input, diff --git a/libafl/src/stages/owned.rs b/libafl/src/stages/owned.rs index 5983234b55..58896ad7c0 100644 --- a/libafl/src/stages/owned.rs +++ b/libafl/src/stages/owned.rs @@ -2,8 +2,9 @@ use alloc::{boxed::Box, vec::Vec}; +use libafl_bolts::anymap::AsAny; + use crate::{ - bolts::anymap::AsAny, corpus::CorpusId, stages::{Stage, StagesTuple}, state::UsesState, diff --git a/libafl/src/stages/push/mutational.rs b/libafl/src/stages/push/mutational.rs index d8a50603f3..2b1ae53bde 100644 --- a/libafl/src/stages/push/mutational.rs +++ b/libafl/src/stages/push/mutational.rs @@ -7,11 +7,12 @@ use core::{ fmt::Debug, }; +use libafl_bolts::rands::Rand; + use super::{PushStage, PushStageHelper, PushStageSharedState}; #[cfg(feature = "introspection")] use crate::monitors::PerfFeature; use crate::{ - bolts::rands::Rand, corpus::{Corpus, CorpusId}, events::{EventFirer, EventRestarter, HasEventManagerId, ProgressReporter}, executors::ExitKind, diff --git a/libafl/src/stages/sync.rs b/libafl/src/stages/sync.rs index 1a058759b1..cc413d7fe9 100644 --- a/libafl/src/stages/sync.rs +++ b/libafl/src/stages/sync.rs @@ -7,10 +7,10 @@ use std::{ time::SystemTime, }; +use libafl_bolts::{current_time, shmem::ShMemProvider}; use serde::{Deserialize, Serialize}; use crate::{ - bolts::{current_time, shmem::ShMemProvider}, corpus::{Corpus, CorpusId, HasTestcase}, events::{llmp::LlmpEventConverter, Event, EventConfig, EventFirer}, executors::{Executor, ExitKind, HasObservers}, @@ -28,7 +28,7 @@ pub struct SyncFromDiskMetadata { pub last_time: SystemTime, } -crate::impl_serdeany!(SyncFromDiskMetadata); +libafl_bolts::impl_serdeany!(SyncFromDiskMetadata); impl SyncFromDiskMetadata { /// Create a new [`struct@SyncFromDiskMetadata`] @@ -197,7 +197,7 @@ pub struct SyncFromBrokerMetadata { pub last_id: Option, } -crate::impl_serdeany!(SyncFromBrokerMetadata); +libafl_bolts::impl_serdeany!(SyncFromBrokerMetadata); impl SyncFromBrokerMetadata { /// Create a new [`struct@SyncFromBrokerMetadata`] diff --git a/libafl/src/stages/tmin.rs b/libafl/src/stages/tmin.rs index 52985cb136..5d872c8088 100644 --- a/libafl/src/stages/tmin.rs +++ b/libafl/src/stages/tmin.rs @@ -8,11 +8,11 @@ use core::{ }; use ahash::RandomState; +use libafl_bolts::{HasLen, Named}; #[cfg(feature = "introspection")] use crate::monitors::PerfFeature; use crate::{ - bolts::{tuples::Named, HasLen}, corpus::{Corpus, CorpusId, Testcase}, events::EventFirer, executors::{Executor, ExitKind, HasObservers}, diff --git a/libafl/src/stages/tracing.rs b/libafl/src/stages/tracing.rs index 8edcd7885f..158d8ae53f 100644 --- a/libafl/src/stages/tracing.rs +++ b/libafl/src/stages/tracing.rs @@ -3,10 +3,11 @@ use alloc::string::{String, ToString}; use core::{fmt::Debug, marker::PhantomData}; +use libafl_bolts::tuples::MatchName; + #[cfg(feature = "introspection")] use crate::monitors::PerfFeature; use crate::{ - bolts::tuples::MatchName, corpus::{Corpus, CorpusId}, executors::{Executor, HasObservers, ShadowExecutor}, inputs::{BytesInput, UsesInput}, diff --git a/libafl/src/stages/tuneable.rs b/libafl/src/stages/tuneable.rs index 07bd6b3908..30bd46a6a8 100644 --- a/libafl/src/stages/tuneable.rs +++ b/libafl/src/stages/tuneable.rs @@ -2,14 +2,14 @@ use core::{marker::PhantomData, time::Duration}; +use libafl_bolts::{current_time, impl_serdeany, rands::Rand}; use serde::{Deserialize, Serialize}; #[cfg(feature = "introspection")] use crate::monitors::PerfFeature; use crate::{ - bolts::{current_time, rands::Rand}, corpus::{Corpus, CorpusId}, - impl_serdeany, mark_feature_time, + mark_feature_time, mutators::{MutationResult, Mutator}, stages::{ mutational::{MutatedTransform, MutatedTransformPost, DEFAULT_MUTATIONAL_MAX_ITERATIONS}, diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index b94d5ddb7f..8d8fa5eed9 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -13,15 +13,15 @@ use std::{ vec::Vec, }; +#[cfg(test)] +use libafl_bolts::rands::StdRand; +use libafl_bolts::{ + rands::Rand, + serdeany::{NamedSerdeAnyMap, SerdeAny, SerdeAnyMap}, +}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -#[cfg(test)] -use crate::bolts::rands::StdRand; use crate::{ - bolts::{ - rands::Rand, - serdeany::{NamedSerdeAnyMap, SerdeAny, SerdeAnyMap}, - }, corpus::{Corpus, CorpusId, HasTestcase, Testcase}, events::{Event, EventFirer, LogSeverity}, feedbacks::Feedback, @@ -925,10 +925,10 @@ pub mod pybind { use alloc::{boxed::Box, vec::Vec}; use std::path::PathBuf; + use libafl_bolts::{ownedref::OwnedMutPtr, rands::pybind::PythonRand}; use pyo3::{prelude::*, types::PyDict}; use crate::{ - bolts::{ownedref::OwnedMutPtr, rands::pybind::PythonRand}, corpus::pybind::PythonCorpus, events::pybind::PythonEventManager, executors::pybind::PythonExecutor, diff --git a/libafl_bolts/Cargo.toml b/libafl_bolts/Cargo.toml new file mode 100644 index 0000000000..7701a9f9cf --- /dev/null +++ b/libafl_bolts/Cargo.toml @@ -0,0 +1,89 @@ +[package] +name = "libafl_bolts" +version.workspace = true +authors = ["Andrea Fioraldi ", "Dominik Maier "] +description = "Low-level bolts to create fuzzers and so much more" +documentation = "https://docs.rs/libafl" +repository = "https://github.com/AFLplusplus/LibAFL/" +readme = "../README.md" +license = "MIT OR Apache-2.0" +keywords = ["fuzzing", "testing", "security"] +edition = "2021" +categories = ["development-tools::testing", "emulators", "embedded", "os", "no-std"] + +[features] +default = ["std", "derive", "llmp_compression", "llmp_small_maps", "rand_trait", "prelude", "gzip"] +std = ["serde_json", "serde_json/std", "hostname", "nix", "serde/std", "once_cell", "uuid", "ctor", "byteorder", "backtrace", "uds", "serial_test"] # print, env, launcher ... support +derive = ["libafl_derive"] # provide derive(SerdeAny) macro. +rand_trait = ["rand_core"] # If set, libafl's rand implementations will implement `rand::Rng` +python = ["pyo3"] +prelude = [] # Expose libafl::prelude for access without additional using directives +cli = ["clap"] # expose libafl_bolts::cli for easy commandline parsing +qemu_cli = ["cli"] # Commandline flags for qemu-based fuzzers +frida_cli = ["cli"] # Commandline flags for frida-based fuzzers +errors_backtrace = ["backtrace"] +gzip = ["miniz_oxide"] # Enables gzip compression in certain parts of the lib + +# LLMP features +llmp_bind_public = [] # If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default. +llmp_compression = ["gzip"] # llmp compression using GZip +llmp_debug = [] # Enables debug output for LLMP +llmp_small_maps = [] # reduces initial map size for llmp + +[build-dependencies] +rustversion = "1.0" + +[dev-dependencies] +# clippy-suggested optimised byte counter +bytecount = "0.6.3" + +[dependencies] +libafl_derive = { version = "0.10.1", optional = true, path = "../libafl_derive" } + +rustversion = "1.0" +tuple_list = { version = "0.1.3" } +hashbrown = { version = "0.14", features = ["serde", "ahash"], default-features=false } # A faster hashmap, nostd compatible +xxhash-rust = { version = "0.8.5", features = ["xxh3"] } # xxh3 hashing for rust +serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } # serialization lib +erased-serde = { version = "0.3.21", default-features = false, features = ["alloc"] } # erased serde +postcard = { version = "1.0", features = ["alloc"] } # no_std compatible serde serialization format +num_enum = { version = "0.5.7", default-features = false } +ahash = { version = "0.8", default-features=false } # The hash function already used in hashbrown +backtrace = {version = "0.3", optional = true} # Used to get the stacktrace in StacktraceObserver + +ctor = { optional = true, version = "0.2" } +serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } +miniz_oxide = { version = "0.7.1", optional = true} +hostname = { version = "^0.3", optional = true } # Is there really no gethostname in the stdlib? +rand_core = { version = "0.6", optional = true } +nix = { version = "0.26", optional = true } +uuid = { version = "1.1.2", optional = true, features = ["serde", "v4"] } +byteorder = { version = "1.4", optional = true } +once_cell = { version = "1.13", optional = true } +clap = {version = "4.0", features = ["derive", "wrap_help"], optional = true} # CLI parsing, for libafl_bolts::cli / the `cli` feature +log = "0.4.18" + +pyo3 = { version = "0.18.3", optional = true, features = ["serde", "macros"] } + +# optional-dev deps (change when target.'cfg(accessible(::std))'.test-dependencies will be stable) +serial_test = { version = "2", optional = true } + +[target.'cfg(unix)'.dependencies] +libc = "0.2" # For (*nix) libc +uds = { version = "0.2.6", optional = true } + +[target.'cfg(windows)'.dependencies] +windows = { version = "0.44", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security", "Win32_System_SystemInformation"] } + +[target.'cfg(windows)'.build-dependencies] +windows = "0.44" + +#[profile.release] +#lto = true +#opt-level = 3 +#debug = true + +[[example]] +name = "llmp_test" +path = "./examples/llmp_test/main.rs" +required-features = ["std"] diff --git a/libafl_bolts/build.rs b/libafl_bolts/build.rs new file mode 100644 index 0000000000..19496e79a0 --- /dev/null +++ b/libafl_bolts/build.rs @@ -0,0 +1,10 @@ +#[rustversion::nightly] +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rustc-cfg=unstable_feature"); +} + +#[rustversion::not(nightly)] +fn main() { + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/libafl/examples/llmp_test/main.rs b/libafl_bolts/examples/llmp_test/main.rs similarity index 97% rename from libafl/examples/llmp_test/main.rs rename to libafl_bolts/examples/llmp_test/main.rs index 8df7a27119..2bbcc27af3 100644 --- a/libafl/examples/llmp_test/main.rs +++ b/libafl_bolts/examples/llmp_test/main.rs @@ -9,13 +9,10 @@ use core::time::Duration; use std::{num::NonZeroUsize, thread, time}; #[cfg(feature = "std")] -use libafl::{ - bolts::{ - llmp::{self, Tag}, - shmem::{ShMemProvider, StdShMemProvider}, - ClientId, SimpleStderrLogger, - }, - Error, +use libafl_bolts::{ + llmp::{self, Tag}, + shmem::{ShMemProvider, StdShMemProvider}, + ClientId, Error, SimpleStderrLogger, }; #[cfg(feature = "std")] diff --git a/libafl/src/bolts/anymap.rs b/libafl_bolts/src/anymap.rs similarity index 99% rename from libafl/src/bolts/anymap.rs rename to libafl_bolts/src/anymap.rs index 46bd7c65e9..3dc2572323 100644 --- a/libafl/src/bolts/anymap.rs +++ b/libafl_bolts/src/anymap.rs @@ -21,7 +21,7 @@ pub trait AsAny: Any { #[macro_export] macro_rules! impl_asany { ($struct_name:ident $(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)?) => { - impl $(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::bolts::anymap::AsAny for $struct_name $(< $( $lt ),+ >)? { + impl $(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $crate::anymap::AsAny for $struct_name $(< $( $lt ),+ >)? { fn as_any(&self) -> &dyn ::core::any::Any { self } @@ -47,6 +47,7 @@ macro_rules! impl_asany { /// The size changed in later rust versions, see #[inline] #[must_use] +#[allow(clippy::cast_ptr_alignment)] pub const fn pack_type_id(id: u128) -> TypeId { match size_of::() { 8 => { @@ -92,7 +93,7 @@ macro_rules! create_anymap_for_trait { use hashbrown::hash_map::{Keys, Values, ValuesMut}; use hashbrown::HashMap; - use $crate::bolts::anymap::{pack_type_id, unpack_type_id}; + use $crate::anymap::{pack_type_id, unpack_type_id}; use $crate::Error; use super::*; diff --git a/libafl/src/bolts/build_id.rs b/libafl_bolts/src/build_id.rs similarity index 96% rename from libafl/src/bolts/build_id.rs rename to libafl_bolts/src/build_id.rs index 7274c1e911..2a2ccc8693 100644 --- a/libafl/src/bolts/build_id.rs +++ b/libafl_bolts/src/build_id.rs @@ -31,8 +31,8 @@ static BUILD_ID: Lazy = Lazy::new(calculate); /// # Examples /// /// ``` -/// # let remote_build_id = libafl::bolts::build_id::get(); -/// let local_build_id = libafl::bolts::build_id::get(); +/// # let remote_build_id = libafl_bolts::build_id::get(); +/// let local_build_id = libafl_bolts::build_id::get(); /// if local_build_id == remote_build_id { /// println!("We're running the same binary as remote!"); /// } else { diff --git a/libafl/src/bolts/cli.rs b/libafl_bolts/src/cli.rs similarity index 98% rename from libafl/src/bolts/cli.rs rename to libafl_bolts/src/cli.rs index fe9275ba70..981654ee0a 100644 --- a/libafl/src/bolts/cli.rs +++ b/libafl_bolts/src/cli.rs @@ -7,7 +7,7 @@ //! The most common usage of the cli parser. Just call `parse_args` and use the results. //! //! ```ignore -//! use libafl::bolts::cli::{parse_args, FuzzerOptions}; +//! use libafl_bolts::cli::{parse_args, FuzzerOptions}; //! //! fn fuzz(options: FuzzerOptions) {} //! fn replay(options: FuzzerOptions) {} @@ -30,7 +30,7 @@ //! ## Example (`libafl_qemu`) //! //! ```ignore -//! use libafl::bolts::cli::{parse_args, FuzzerOptions}; +//! use libafl_bolts::cli::{parse_args, FuzzerOptions}; //! use std::env; //! //! // make sure to add `features = ["qemu_cli"]` to the `libafl` crate in `Cargo.toml` @@ -311,7 +311,7 @@ impl FuzzerOptions { /// /// ```ignore /// use clap::{App, IntoApp, Parser}; - /// use libafl::bolts::cli::FuzzerOptions; + /// use libafl_bolts::cli::FuzzerOptions; /// /// fn custom_func(_: &str) {} // not relevant; just for illustrative purposes /// diff --git a/libafl/src/bolts/compress.rs b/libafl_bolts/src/compress.rs similarity index 97% rename from libafl/src/bolts/compress.rs rename to libafl_bolts/src/compress.rs index 1a9ca4cc98..30a50b5a08 100644 --- a/libafl/src/bolts/compress.rs +++ b/libafl_bolts/src/compress.rs @@ -56,7 +56,7 @@ impl GzipCompressor { #[cfg(test)] mod tests { - use crate::bolts::compress::GzipCompressor; + use crate::compress::GzipCompressor; #[test] fn test_compression() { diff --git a/libafl/src/bolts/core_affinity.rs b/libafl_bolts/src/core_affinity.rs similarity index 99% rename from libafl/src/bolts/core_affinity.rs rename to libafl_bolts/src/core_affinity.rs index 46ef69b78a..e6f88a3865 100644 --- a/libafl/src/bolts/core_affinity.rs +++ b/libafl_bolts/src/core_affinity.rs @@ -6,7 +6,7 @@ //! //! ```rust //! # use std::thread; -//! use libafl::bolts::core_affinity; +//! use libafl_bolts::core_affinity; //! //! // Retrieve the IDs of all active CPU cores. //! # #[cfg(not(miri))] @@ -369,7 +369,7 @@ mod windows { Threading::{GetCurrentThread, SetThreadGroupAffinity}, }; - use crate::bolts::core_affinity::{CoreId, Error}; + use crate::core_affinity::{CoreId, Error}; pub fn get_core_ids() -> Result, Error> { let mut core_ids: Vec = Vec::new(); diff --git a/libafl/src/bolts/cpu.rs b/libafl_bolts/src/cpu.rs similarity index 98% rename from libafl/src/bolts/cpu.rs rename to libafl_bolts/src/cpu.rs index 950f16f959..c8be696d02 100644 --- a/libafl/src/bolts/cpu.rs +++ b/libafl_bolts/src/cpu.rs @@ -10,7 +10,7 @@ use core::arch::asm; target_arch = "riscv64", target_arsch = "riscv32" )))] -use crate::bolts::current_nanos; +use crate::current_nanos; // TODO: Add more architectures, using C code, see // https://github.com/google/benchmark/blob/master/src/cycleclock.h diff --git a/libafl/src/bolts/fs.rs b/libafl_bolts/src/fs.rs similarity index 98% rename from libafl/src/bolts/fs.rs rename to libafl_bolts/src/fs.rs index 181a2a02b9..0f6391f11c 100644 --- a/libafl/src/bolts/fs.rs +++ b/libafl_bolts/src/fs.rs @@ -157,7 +157,7 @@ impl Drop for InputFile { mod test { use std::fs; - use crate::bolts::fs::{write_file_atomic, InputFile}; + use crate::fs::{write_file_atomic, InputFile}; #[test] fn test_atomic_file_write() { diff --git a/libafl_bolts/src/lib.rs b/libafl_bolts/src/lib.rs new file mode 100644 index 0000000000..f33ffbf393 --- /dev/null +++ b/libafl_bolts/src/lib.rs @@ -0,0 +1,950 @@ +//! Bolts are no conceptual fuzzing elements, but they keep libafl-based fuzzers together. + +/*! +Welcome to `LibAFL` +*/ + +#![allow(incomplete_features)] +#![no_std] +// For `type_eq` +#![cfg_attr(unstable_feature, feature(specialization))] +// For `type_id` and owned things +#![cfg_attr(unstable_feature, feature(intrinsics))] +// For `std::simd` +#![cfg_attr(unstable_feature, feature(portable_simd))] +#![warn(clippy::cargo)] +#![allow(ambiguous_glob_reexports)] +#![deny(clippy::cargo_common_metadata)] +#![deny(rustdoc::broken_intra_doc_links)] +#![deny(clippy::all)] +#![deny(clippy::pedantic)] +#![allow( + clippy::unreadable_literal, + clippy::type_repetition_in_bounds, + clippy::missing_errors_doc, + clippy::cast_possible_truncation, + clippy::used_underscore_binding, + clippy::ptr_as_ptr, + clippy::missing_panics_doc, + clippy::missing_docs_in_private_items, + clippy::module_name_repetitions, + clippy::ptr_cast_constness +)] +#![cfg_attr(not(test), warn( + missing_debug_implementations, + missing_docs, + //trivial_casts, + trivial_numeric_casts, + unused_extern_crates, + unused_import_braces, + unused_qualifications, + //unused_results +))] +#![cfg_attr(test, deny( + missing_debug_implementations, + missing_docs, + //trivial_casts, + trivial_numeric_casts, + unused_extern_crates, + unused_import_braces, + unused_qualifications, + unused_must_use, + //unused_results +))] +#![cfg_attr( + test, + deny( + bad_style, + dead_code, + improper_ctypes, + non_shorthand_field_patterns, + no_mangle_generic_items, + overflowing_literals, + path_statements, + patterns_in_fns_without_body, + private_in_public, + unconditional_recursion, + unused, + unused_allocation, + unused_comparisons, + unused_parens, + while_true + ) +)] +// Till they fix this buggy lint in clippy +#![allow(clippy::borrow_as_ptr)] +#![allow(clippy::borrow_deref_ref)] + +#[cfg(feature = "std")] +#[macro_use] +extern crate std; +#[macro_use] +#[doc(hidden)] +pub extern crate alloc; +#[cfg(feature = "ctor")] +#[doc(hidden)] +pub use ctor::ctor; + +#[deprecated( + since = "0.11.0", + note = "The launcher module has moved out of `libafl_bolts` into `libafl::events::launcher`." +)] +/// Dummy module informing potential users that the launcher module has moved +/// out of `libafl_bolts` into `libafl::events::launcher`. +pub mod launcher {} + +// Re-export derive(SerdeAny) +#[cfg(feature = "libafl_derive")] +#[allow(unused_imports)] +#[macro_use] +extern crate libafl_derive; +use alloc::string::{FromUtf8Error, String}; +use core::{ + array::TryFromSliceError, + fmt, + num::{ParseIntError, TryFromIntError}, +}; +#[cfg(feature = "std")] +use std::{env::VarError, io}; + +#[cfg(feature = "libafl_derive")] +pub use libafl_derive::SerdeAny; + +/// We need fixed names for many parts of this lib. +pub trait Named { + /// Provide the name of this element. + fn name(&self) -> &str; +} + +#[cfg(feature = "errors_backtrace")] +/// Error Backtrace type when `errors_backtrace` feature is enabled (== [`backtrace::Backtrace`]) +pub type ErrorBacktrace = backtrace::Backtrace; + +#[cfg(not(feature = "errors_backtrace"))] +#[derive(Debug, Default)] +/// Empty struct to use when `errors_backtrace` is disabled +pub struct ErrorBacktrace {} +#[cfg(not(feature = "errors_backtrace"))] +impl ErrorBacktrace { + /// Nop + #[must_use] + pub fn new() -> Self { + Self {} + } +} + +#[cfg(feature = "errors_backtrace")] +fn display_error_backtrace(f: &mut fmt::Formatter, err: &ErrorBacktrace) -> fmt::Result { + write!(f, "\nBacktrace: {err:?}") +} +#[cfg(not(feature = "errors_backtrace"))] +#[allow(clippy::unnecessary_wraps)] +fn display_error_backtrace(_f: &mut fmt::Formatter, _err: &ErrorBacktrace) -> fmt::Result { + fmt::Result::Ok(()) +} + +/// Main error struct for `LibAFL` +#[derive(Debug)] +pub enum Error { + /// Serialization error + Serialize(String, ErrorBacktrace), + /// Compression error + #[cfg(feature = "llmp_compression")] + Compression(ErrorBacktrace), + /// File related error + #[cfg(feature = "std")] + File(io::Error, ErrorBacktrace), + /// Optional val was supposed to be set, but isn't. + EmptyOptional(String, ErrorBacktrace), + /// Key not in Map + KeyNotFound(String, ErrorBacktrace), + /// No elements in the current item + Empty(String, ErrorBacktrace), + /// End of iteration + IteratorEnd(String, ErrorBacktrace), + /// This is not supported (yet) + NotImplemented(String, ErrorBacktrace), + /// You're holding it wrong + IllegalState(String, ErrorBacktrace), + /// The argument passed to this method or function is not valid + IllegalArgument(String, ErrorBacktrace), + /// The performed action is not supported on the current platform + Unsupported(String, ErrorBacktrace), + /// Shutting down, not really an error. + ShuttingDown, + /// Something else happened + Unknown(String, ErrorBacktrace), +} + +impl Error { + /// Serialization error + #[must_use] + pub fn serialize(arg: S) -> Self + where + S: Into, + { + Error::Serialize(arg.into(), ErrorBacktrace::new()) + } + #[cfg(feature = "llmp_compression")] + /// Compression error + #[must_use] + pub fn compression() -> Self { + Error::Compression(ErrorBacktrace::new()) + } + #[cfg(feature = "std")] + /// File related error + #[must_use] + pub fn file(arg: io::Error) -> Self { + Error::File(arg, ErrorBacktrace::new()) + } + /// Optional val was supposed to be set, but isn't. + #[must_use] + pub fn empty_optional(arg: S) -> Self + where + S: Into, + { + Error::EmptyOptional(arg.into(), ErrorBacktrace::new()) + } + /// Key not in Map + #[must_use] + pub fn key_not_found(arg: S) -> Self + where + S: Into, + { + Error::KeyNotFound(arg.into(), ErrorBacktrace::new()) + } + /// No elements in the current item + #[must_use] + pub fn empty(arg: S) -> Self + where + S: Into, + { + Error::Empty(arg.into(), ErrorBacktrace::new()) + } + /// End of iteration + #[must_use] + pub fn iterator_end(arg: S) -> Self + where + S: Into, + { + Error::IteratorEnd(arg.into(), ErrorBacktrace::new()) + } + /// This is not supported (yet) + #[must_use] + pub fn not_implemented(arg: S) -> Self + where + S: Into, + { + Error::NotImplemented(arg.into(), ErrorBacktrace::new()) + } + /// You're holding it wrong + #[must_use] + pub fn illegal_state(arg: S) -> Self + where + S: Into, + { + Error::IllegalState(arg.into(), ErrorBacktrace::new()) + } + /// The argument passed to this method or function is not valid + #[must_use] + pub fn illegal_argument(arg: S) -> Self + where + S: Into, + { + Error::IllegalArgument(arg.into(), ErrorBacktrace::new()) + } + /// Shutting down, not really an error. + #[must_use] + pub fn shutting_down() -> Self { + Error::ShuttingDown + } + /// This operation is not supported on the current architecture or platform + #[must_use] + pub fn unsupported(arg: S) -> Self + where + S: Into, + { + Error::Unsupported(arg.into(), ErrorBacktrace::new()) + } + /// Something else happened + #[must_use] + pub fn unknown(arg: S) -> Self + where + S: Into, + { + Error::Unknown(arg.into(), ErrorBacktrace::new()) + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::Serialize(s, b) => { + write!(f, "Error in Serialization: `{0}`", &s)?; + display_error_backtrace(f, b) + } + #[cfg(feature = "llmp_compression")] + Self::Compression(b) => { + write!(f, "Error in decompression")?; + display_error_backtrace(f, b) + } + #[cfg(feature = "std")] + Self::File(err, b) => { + write!(f, "File IO failed: {:?}", &err)?; + display_error_backtrace(f, b) + } + Self::EmptyOptional(s, b) => { + write!(f, "Optional value `{0}` was not set", &s)?; + display_error_backtrace(f, b) + } + Self::KeyNotFound(s, b) => { + write!(f, "Key `{0}` not in Corpus", &s)?; + display_error_backtrace(f, b) + } + Self::Empty(s, b) => { + write!(f, "No items in {0}", &s)?; + display_error_backtrace(f, b) + } + Self::IteratorEnd(s, b) => { + write!(f, "All elements have been processed in {0} iterator", &s)?; + display_error_backtrace(f, b) + } + Self::NotImplemented(s, b) => { + write!(f, "Not implemented: {0}", &s)?; + display_error_backtrace(f, b) + } + Self::IllegalState(s, b) => { + write!(f, "Illegal state: {0}", &s)?; + display_error_backtrace(f, b) + } + Self::IllegalArgument(s, b) => { + write!(f, "Illegal argument: {0}", &s)?; + display_error_backtrace(f, b) + } + Self::Unsupported(s, b) => { + write!( + f, + "The operation is not supported on the current platform: {0}", + &s + )?; + display_error_backtrace(f, b) + } + Self::ShuttingDown => write!(f, "Shutting down!"), + Self::Unknown(s, b) => { + write!(f, "Unknown error: {0}", &s)?; + display_error_backtrace(f, b) + } + } + } +} + +/// Stringify the postcard serializer error +impl From for Error { + fn from(err: postcard::Error) -> Self { + Self::serialize(format!("{err:?}")) + } +} + +/// Stringify the json serializer error +#[cfg(feature = "std")] +impl From for Error { + fn from(err: serde_json::Error) -> Self { + Self::serialize(format!("{err:?}")) + } +} + +#[cfg(all(unix, feature = "std"))] +impl From for Error { + fn from(err: nix::Error) -> Self { + Self::unknown(format!("Unix error: {err:?}")) + } +} + +/// Create an AFL Error from io Error +#[cfg(feature = "std")] +impl From for Error { + fn from(err: io::Error) -> Self { + Self::file(err) + } +} + +impl From for Error { + fn from(err: FromUtf8Error) -> Self { + Self::unknown(format!("Could not convert byte / utf-8: {err:?}")) + } +} + +#[cfg(feature = "std")] +impl From for Error { + fn from(err: VarError) -> Self { + Self::empty(format!("Could not get env var: {err:?}")) + } +} + +impl From for Error { + fn from(err: ParseIntError) -> Self { + Self::unknown(format!("Failed to parse Int: {err:?}")) + } +} + +impl From for Error { + fn from(err: TryFromIntError) -> Self { + Self::illegal_state(format!("Expected conversion failed: {err:?}")) + } +} + +impl From for Error { + fn from(err: TryFromSliceError) -> Self { + Self::illegal_argument(format!("Could not convert slice: {err:?}")) + } +} + +#[cfg(windows)] +impl From for Error { + fn from(err: windows::core::Error) -> Self { + Self::unknown(format!("Windows API error: {err:?}")) + } +} + +#[cfg(feature = "python")] +impl From for Error { + fn from(err: pyo3::PyErr) -> Self { + pyo3::Python::with_gil(|py| { + if err.matches( + py, + pyo3::types::PyType::new::(py), + ) { + Self::shutting_down() + } else { + Self::illegal_state(format!("Python exception: {err:?}")) + } + }) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for Error {} + +/// The purpose of this module is to alleviate imports of many components by adding a glob import. +#[cfg(feature = "prelude")] +pub mod prelude { + pub use super::{bolts_prelude::*, *}; +} + +#[cfg(all(any(doctest, test), not(feature = "std")))] +/// Provide custom time in `no_std` tests. +#[no_mangle] +pub unsafe extern "C" fn external_current_millis() -> u64 { + // TODO: use "real" time here + 1000 +} + +pub mod anymap; +#[cfg(feature = "std")] +pub mod build_id; +#[cfg(all( + any(feature = "cli", feature = "frida_cli", feature = "qemu_cli"), + feature = "std" +))] +pub mod cli; +#[cfg(feature = "llmp_compression")] +pub mod compress; +#[cfg(feature = "std")] +pub mod core_affinity; +pub mod cpu; +#[cfg(feature = "std")] +pub mod fs; +pub mod llmp; +#[cfg(all(feature = "std", unix))] +pub mod minibsod; +pub mod os; +pub mod ownedref; +pub mod rands; +pub mod serdeany; +pub mod shmem; +#[cfg(feature = "std")] +pub mod staterestore; +pub mod tuples; + +use alloc::vec::Vec; +use core::{iter::Iterator, ops::AddAssign, time}; +#[cfg(feature = "std")] +use std::time::{SystemTime, UNIX_EPOCH}; + +use serde::{Deserialize, Serialize}; + +/// The client ID == the sender id. +#[repr(transparent)] +#[derive( + Debug, Default, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, +)] +pub struct ClientId(pub u32); + +#[cfg(feature = "std")] +use log::{Metadata, Record}; + +/// Can be converted to a slice +pub trait AsSlice { + /// Type of the entries in this slice + type Entry; + /// Convert to a slice + fn as_slice(&self) -> &[Self::Entry]; +} + +/// Can be converted to a mutable slice +pub trait AsMutSlice { + /// Type of the entries in this mut slice + type Entry; + /// Convert to a slice + fn as_mut_slice(&mut self) -> &mut [Self::Entry]; +} + +impl AsSlice for Vec { + type Entry = T; + + fn as_slice(&self) -> &[Self::Entry] { + self + } +} + +impl AsMutSlice for Vec { + type Entry = T; + + fn as_mut_slice(&mut self) -> &mut [Self::Entry] { + self + } +} + +impl AsSlice for &[T] { + type Entry = T; + + fn as_slice(&self) -> &[Self::Entry] { + self + } +} + +impl AsSlice for [T] { + type Entry = T; + + fn as_slice(&self) -> &[Self::Entry] { + self + } +} + +impl AsMutSlice for &mut [T] { + type Entry = T; + + fn as_mut_slice(&mut self) -> &mut [Self::Entry] { + self + } +} + +impl AsMutSlice for [T] { + type Entry = T; + + fn as_mut_slice(&mut self) -> &mut [Self::Entry] { + self + } +} + +/// Create an `Iterator` from a reference +pub trait AsIter<'it> { + /// The item type + type Item: 'it; + /// The iterator type + type IntoIter: Iterator; + + /// Create an iterator from &self + fn as_iter(&'it self) -> Self::IntoIter; +} + +/// Create an `Iterator` from a mutable reference +pub trait AsIterMut<'it> { + /// The item type + type Item: 'it; + /// The iterator type + type IntoIter: Iterator; + + /// Create an iterator from &mut self + fn as_iter_mut(&'it mut self) -> Self::IntoIter; +} + +/// Has a length field +pub trait HasLen { + /// The length + fn len(&self) -> usize; + + /// Returns `true` if it has no elements. + fn is_empty(&self) -> bool { + self.len() == 0 + } +} + +/// Has a ref count +pub trait HasRefCnt { + /// The ref count + fn refcnt(&self) -> isize; + /// The ref count, mutable + fn refcnt_mut(&mut self) -> &mut isize; +} + +/// Trait to truncate slices and maps to a new size +pub trait Truncate { + /// Reduce the size of the slice + fn truncate(&mut self, len: usize); +} + +/// Current time +#[cfg(feature = "std")] +#[must_use] +#[inline] +pub fn current_time() -> time::Duration { + SystemTime::now().duration_since(UNIX_EPOCH).unwrap() +} + +// external defined function in case of `no_std` +// +// Define your own `external_current_millis()` function via `extern "C"` +// which is linked into the binary and called from here. +#[cfg(all(not(any(doctest, test)), not(feature = "std")))] +extern "C" { + //#[no_mangle] + fn external_current_millis() -> u64; +} + +/// Current time (fixed fallback for `no_std`) +#[cfg(not(feature = "std"))] +#[inline] +#[must_use] +pub fn current_time() -> time::Duration { + let millis = unsafe { external_current_millis() }; + time::Duration::from_millis(millis) +} + +/// Given a u64 number, return a hashed number using this mixing function +/// This function is used to hash an address into a more random number (used in `libafl_frida`). +/// Mixing function: +#[inline] +#[must_use] +pub fn xxh3_rrmxmx_mixer(v: u64) -> u64 { + let tmp = (v >> 32) + ((v & 0xffffffff) << 32); + let bitflip = 0x1cad21f72c81017c ^ 0xdb979082e96dd4de; + let mut h64 = tmp ^ bitflip; + h64 = h64.rotate_left(49) & h64.rotate_left(24); + h64 = h64.wrapping_mul(0x9FB21C651E98DF25); + h64 ^= (h64 >> 35) + 8; + h64 = h64.wrapping_mul(0x9FB21C651E98DF25); + h64 ^= h64 >> 28; + h64 +} + +/// Gets current nanoseconds since [`UNIX_EPOCH`] +#[must_use] +#[inline] +pub fn current_nanos() -> u64 { + current_time().as_nanos() as u64 +} + +/// Gets current milliseconds since [`UNIX_EPOCH`] +#[must_use] +#[inline] +pub fn current_milliseconds() -> u64 { + current_time().as_millis() as u64 +} + +/// Format a `Duration` into a HMS string +#[must_use] +pub fn format_duration_hms(duration: &time::Duration) -> String { + let secs = duration.as_secs(); + format!("{}h-{}m-{}s", (secs / 60) / 60, (secs / 60) % 60, secs % 60) +} + +/// Calculates the cumulative sum for a slice, in-place. +/// The values are useful for example for cumulative probabilities. +/// +/// So, to give an example: +/// ```rust +/// # extern crate libafl_bolts; +/// use libafl_bolts::calculate_cumulative_sum_in_place; +/// +/// let mut value = [2, 4, 1, 3]; +/// calculate_cumulative_sum_in_place(&mut value); +/// assert_eq!(&[2, 6, 7, 10], &value); +/// ``` +pub fn calculate_cumulative_sum_in_place(mut_slice: &mut [T]) +where + T: Default + AddAssign + Copy, +{ + let mut acc = T::default(); + + for val in mut_slice { + acc += *val; + *val = acc; + } +} + +/// Stderr logger +#[cfg(feature = "std")] +pub static LIBAFL_STDERR_LOGGER: SimpleStderrLogger = SimpleStderrLogger::new(); + +/// Stdout logger +#[cfg(feature = "std")] +pub static LIBAFL_STDOUT_LOGGER: SimpleStdoutLogger = SimpleStdoutLogger::new(); + +/// A simple logger struct that logs to stderr when used with [`log::set_logger`]. +#[derive(Debug)] +#[cfg(feature = "std")] +pub struct SimpleStdoutLogger {} + +#[cfg(feature = "std")] +impl Default for SimpleStdoutLogger { + fn default() -> Self { + Self::new() + } +} + +#[cfg(feature = "std")] +impl SimpleStdoutLogger { + /// Create a new [`log::Log`] logger that will wrte log to stdout + #[must_use] + pub const fn new() -> Self { + Self {} + } + + /// register stdout logger + pub fn set_logger() -> Result<(), Error> { + log::set_logger(&LIBAFL_STDOUT_LOGGER) + .map_err(|_| Error::unknown("Failed to register logger")) + } +} + +#[cfg(feature = "std")] +impl log::Log for SimpleStdoutLogger { + #[inline] + fn enabled(&self, _metadata: &Metadata) -> bool { + true + } + + fn log(&self, record: &Record) { + println!( + "[{:?}] {}: {}", + current_time(), + record.level(), + record.args() + ); + } + + fn flush(&self) {} +} + +/// A simple logger struct that logs to stderr when used with [`log::set_logger`]. +#[derive(Debug)] +#[cfg(feature = "std")] +pub struct SimpleStderrLogger {} + +#[cfg(feature = "std")] +impl Default for SimpleStderrLogger { + fn default() -> Self { + Self::new() + } +} + +#[cfg(feature = "std")] +impl SimpleStderrLogger { + /// Create a new [`log::Log`] logger that will wrte log to stdout + #[must_use] + pub const fn new() -> Self { + Self {} + } + + /// register stderr logger + pub fn set_logger() -> Result<(), Error> { + log::set_logger(&LIBAFL_STDERR_LOGGER) + .map_err(|_| Error::unknown("Failed to register logger")) + } +} + +#[cfg(feature = "std")] +impl log::Log for SimpleStderrLogger { + #[inline] + fn enabled(&self, _metadata: &Metadata) -> bool { + true + } + + fn log(&self, record: &Record) { + eprintln!( + "[{:?}] {}: {}", + current_time(), + record.level(), + record.args() + ); + } + + fn flush(&self) {} +} +/// The purpose of this module is to alleviate imports of the bolts by adding a glob import. +#[cfg(feature = "prelude")] +pub mod bolts_prelude { + #[cfg(feature = "std")] + pub use super::build_id::*; + #[cfg(all( + any(feature = "cli", feature = "frida_cli", feature = "qemu_cli"), + feature = "std" + ))] + pub use super::cli::*; + #[cfg(feature = "llmp_compression")] + pub use super::compress::*; + #[cfg(feature = "std")] + pub use super::core_affinity::*; + #[cfg(feature = "std")] + pub use super::fs::*; + #[cfg(all(feature = "std", unix))] + pub use super::minibsod::*; + #[cfg(feature = "std")] + pub use super::staterestore::*; + pub use super::{ + anymap::*, cpu::*, llmp::*, os::*, ownedref::*, rands::*, serdeany::*, shmem::*, tuples::*, + }; +} + +#[cfg(feature = "python")] +#[allow(missing_docs)] +pub mod pybind { + + use pyo3::{pymodule, types::PyModule, PyResult, Python}; + + #[macro_export] + macro_rules! unwrap_me_body { + ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),* }) => { + match &$wrapper { + $( + $wrapper_type::$wrapper_option(py_wrapper) => { + Python::with_gil(|py| -> PyResult<_> { + let borrowed = py_wrapper.borrow(py); + let $name = &borrowed.inner; + Ok($body) + }) + .unwrap() + } + )* + } + }; + ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),* }, { $($wrapper_optional:tt($pw:ident) => $code_block:block)* }) => { + match &$wrapper { + $( + $wrapper_type::$wrapper_option(py_wrapper) => { + Python::with_gil(|py| -> PyResult<_> { + let borrowed = py_wrapper.borrow(py); + let $name = &borrowed.inner; + Ok($body) + }) + .unwrap() + } + )* + $($wrapper_type::$wrapper_optional($pw) => { $code_block })* + } + }; + } + + #[macro_export] + macro_rules! unwrap_me_mut_body { + ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),*}) => { + match &mut $wrapper { + $( + $wrapper_type::$wrapper_option(py_wrapper) => { + Python::with_gil(|py| -> PyResult<_> { + let mut borrowed = py_wrapper.borrow_mut(py); + let $name = &mut borrowed.inner; + Ok($body) + }) + .unwrap() + } + )* + } + }; + ($wrapper:expr, $name:ident, $body:block, $wrapper_type:ident, { $($wrapper_option:tt),*}, { $($wrapper_optional:tt($pw:ident) => $code_block:block)* }) => { + match &mut $wrapper { + $( + $wrapper_type::$wrapper_option(py_wrapper) => { + Python::with_gil(|py| -> PyResult<_> { + let mut borrowed = py_wrapper.borrow_mut(py); + let $name = &mut borrowed.inner; + Ok($body) + }) + .unwrap() + } + )* + $($wrapper_type::$wrapper_optional($pw) => { $code_block })* + } + }; + } + + #[macro_export] + macro_rules! impl_serde_pyobjectwrapper { + ($struct_name:ident, $inner:tt) => { + const _: () = { + use alloc::vec::Vec; + + use pyo3::prelude::*; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; + + impl Serialize for $struct_name { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let buf = Python::with_gil(|py| -> PyResult> { + let pickle = PyModule::import(py, "pickle")?; + let buf: Vec = + pickle.getattr("dumps")?.call1((&self.$inner,))?.extract()?; + Ok(buf) + }) + .unwrap(); + serializer.serialize_bytes(&buf) + } + } + + struct PyObjectVisitor; + + impl<'de> serde::de::Visitor<'de> for PyObjectVisitor { + type Value = $struct_name; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter + .write_str("Expecting some bytes to deserialize from the Python side") + } + + fn visit_byte_buf(self, v: Vec) -> Result + where + E: serde::de::Error, + { + let obj = Python::with_gil(|py| -> PyResult { + let pickle = PyModule::import(py, "pickle")?; + let obj = pickle.getattr("loads")?.call1((v,))?.to_object(py); + Ok(obj) + }) + .unwrap(); + Ok($struct_name::new(obj)) + } + } + + impl<'de> Deserialize<'de> for $struct_name { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_byte_buf(PyObjectVisitor) + } + } + }; + }; + } + + #[pymodule] + #[pyo3(name = "libafl_bolts")] + /// Register the classes to the python module + pub fn python_module(py: Python, m: &PyModule) -> PyResult<()> { + crate::rands::pybind::register(py, m)?; + Ok(()) + } +} diff --git a/libafl/src/bolts/llmp.rs b/libafl_bolts/src/llmp.rs similarity index 99% rename from libafl/src/bolts/llmp.rs rename to libafl_bolts/src/llmp.rs index 158a0b15c2..9d72b02478 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl_bolts/src/llmp.rs @@ -95,17 +95,14 @@ use nix::sys::socket::{self, sockopt::ReusePort}; use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] -use crate::bolts::current_time; +use crate::current_time; #[cfg(all(unix, not(miri)))] -use crate::bolts::os::unix_signals::setup_signal_handler; +use crate::os::unix_signals::setup_signal_handler; #[cfg(unix)] -use crate::bolts::os::unix_signals::{siginfo_t, ucontext_t, Handler, Signal}; +use crate::os::unix_signals::{siginfo_t, ucontext_t, Handler, Signal}; use crate::{ - bolts::{ - shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider}, - ClientId, - }, - Error, + shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider}, + ClientId, Error, }; /// The timeout after which a client will be considered stale, and removed. @@ -1752,7 +1749,7 @@ where // TODO: May be obsolete /// The page struct, placed on a shared mem instance. -/// A thin wrapper around a [`ShMem`] implementation, with special [`crate::bolts::llmp`] funcs +/// A thin wrapper around a [`ShMem`] implementation, with special [`crate::llmp`] funcs impl LlmpSharedMap where SHM: ShMem, @@ -3098,7 +3095,7 @@ mod tests { LlmpMsgHookResult::ForwardToClients, Tag, }; - use crate::bolts::shmem::{ShMemProvider, StdShMemProvider}; + use crate::shmem::{ShMemProvider, StdShMemProvider}; #[test] #[serial] diff --git a/libafl/src/bolts/minibsod.rs b/libafl_bolts/src/minibsod.rs similarity index 99% rename from libafl/src/bolts/minibsod.rs rename to libafl_bolts/src/minibsod.rs index f312ba39ae..d903d171ec 100644 --- a/libafl/src/bolts/minibsod.rs +++ b/libafl_bolts/src/minibsod.rs @@ -1,13 +1,13 @@ //! Implements a mini-bsod generator. //! It dumps all important registers and prints a stacktrace. -//! You may use the [`crate::bolts::os::unix_signals::ucontext`] +//! You may use the [`crate::os::unix_signals::ucontext`] //! function to get a [`ucontext_t`]. use std::io::{BufWriter, Write}; use libc::siginfo_t; -use crate::bolts::os::unix_signals::{ucontext_t, Signal}; +use crate::os::unix_signals::{ucontext_t, Signal}; /// Write the content of all important registers #[cfg(all(target_os = "linux", target_arch = "x86_64"))] @@ -700,7 +700,7 @@ mod tests { use std::io::{stdout, BufWriter}; - use crate::bolts::{minibsod::dump_registers, os::unix_signals::ucontext}; + use crate::{minibsod::dump_registers, os::unix_signals::ucontext}; #[test] #[cfg_attr(miri, ignore)] diff --git a/libafl/src/bolts/os/mod.rs b/libafl_bolts/src/os/mod.rs similarity index 100% rename from libafl/src/bolts/os/mod.rs rename to libafl_bolts/src/os/mod.rs diff --git a/libafl/src/bolts/os/pipes.rs b/libafl_bolts/src/os/pipes.rs similarity index 100% rename from libafl/src/bolts/os/pipes.rs rename to libafl_bolts/src/os/pipes.rs diff --git a/libafl/src/bolts/os/unix_shmem_server.rs b/libafl_bolts/src/os/unix_shmem_server.rs similarity index 99% rename from libafl/src/bolts/os/unix_shmem_server.rs rename to libafl_bolts/src/os/unix_shmem_server.rs index d69c1e3358..6842503608 100644 --- a/libafl/src/bolts/os/unix_shmem_server.rs +++ b/libafl_bolts/src/os/unix_shmem_server.rs @@ -39,11 +39,8 @@ use serde::{Deserialize, Serialize}; use uds::{UnixListenerExt, UnixSocketAddr, UnixStreamExt}; use crate::{ - bolts::{ - shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider}, - AsMutSlice, AsSlice, - }, - Error, + shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider}, + AsMutSlice, AsSlice, Error, }; /// The default server name for our abstract shmem server @@ -740,7 +737,7 @@ TODO: Fix test mod tests { use serial_test::serial; - use crate::bolts::{ + use crate::{ os::unix_shmem_server::ServedShMemProvider, shmem::{ShMem, ShMemProvider, UnixShMemProvider}, }; diff --git a/libafl/src/bolts/os/unix_signals.rs b/libafl_bolts/src/os/unix_signals.rs similarity index 99% rename from libafl/src/bolts/os/unix_signals.rs rename to libafl_bolts/src/os/unix_signals.rs index 3e9ecf3f9e..affcaaae9f 100644 --- a/libafl/src/bolts/os/unix_signals.rs +++ b/libafl_bolts/src/os/unix_signals.rs @@ -378,7 +378,7 @@ unsafe fn handle_signal(sig: c_int, info: siginfo_t, void: *mut c_void) { /// Setup signal handlers in a somewhat rusty way. /// This will allocate a signal stack and set the signal handlers accordingly. -/// It is, for example, used in the [`type@crate::executors::InProcessExecutor`] to restart the fuzzer in case of a crash, +/// It is, for example, used in `LibAFL's` `InProcessExecutor` to restart the fuzzer in case of a crash, /// or to handle `SIGINT` in the broker process. /// /// # Safety diff --git a/libafl/src/bolts/os/windows_exceptions.rs b/libafl_bolts/src/os/windows_exceptions.rs similarity index 100% rename from libafl/src/bolts/os/windows_exceptions.rs rename to libafl_bolts/src/os/windows_exceptions.rs diff --git a/libafl/src/bolts/ownedref.rs b/libafl_bolts/src/ownedref.rs similarity index 99% rename from libafl/src/bolts/ownedref.rs rename to libafl_bolts/src/ownedref.rs index e41464349a..6157608843 100644 --- a/libafl/src/bolts/ownedref.rs +++ b/libafl_bolts/src/ownedref.rs @@ -10,7 +10,7 @@ use core::{clone::Clone, fmt::Debug, slice}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use crate::bolts::{AsMutSlice, AsSlice, Truncate}; +use crate::{AsMutSlice, AsSlice, Truncate}; /// Trait to convert into an Owned type pub trait IntoOwned { diff --git a/libafl/src/bolts/rands.rs b/libafl_bolts/src/rands.rs similarity index 97% rename from libafl/src/bolts/rands.rs rename to libafl_bolts/src/rands.rs index 3ed45c92bf..f85e374ac3 100644 --- a/libafl/src/bolts/rands.rs +++ b/libafl_bolts/src/rands.rs @@ -7,7 +7,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize}; use xxhash_rust::xxh3::xxh3_64_with_seed; #[cfg(feature = "std")] -use crate::bolts::current_nanos; +use crate::current_nanos; const HASH_CONST: u64 = 0xa5b35705; @@ -340,14 +340,12 @@ impl Rand for RomuDuoJrRand { } /// fake rand, for testing purposes -#[cfg(test)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] #[allow(clippy::upper_case_acronyms)] pub struct XkcdRand { val: u64, } -#[cfg(test)] impl Rand for XkcdRand { fn set_seed(&mut self, val: u64) { self.val = val; @@ -359,9 +357,8 @@ impl Rand for XkcdRand { } /// A test rng that will return the same value (chose by fair dice roll) for testing. -#[cfg(test)] impl XkcdRand { - /// Creates a new [`XkCDRand`] with the rand of 4, [chosen by fair dice roll, guaranteed to be random](https://xkcd.com/221/). + /// Creates a new [`XkcdRand`] with the rand of 4, [chosen by fair dice roll, guaranteed to be random](https://xkcd.com/221/). /// Will always return this seed. #[must_use] pub fn new() -> Self { @@ -379,7 +376,7 @@ impl XkcdRand { mod tests { //use xxhash_rust::xxh3::xxh3_64_with_seed; - use crate::bolts::rands::{ + use crate::rands::{ Rand, RomuDuoJrRand, RomuTrioRand, StdRand, XorShift64Rand, Xoshiro256StarRand, }; @@ -404,7 +401,7 @@ mod tests { #[cfg(feature = "std")] #[test] fn test_random_seed() { - use crate::bolts::rands::RandomSeed; + use crate::rands::RandomSeed; let mut rand_fixed = StdRand::with_seed(0); let mut rand = StdRand::new(); @@ -419,7 +416,7 @@ mod tests { fn test_rgn_core_support() { use rand_core::RngCore; - use crate::bolts::rands::StdRand; + use crate::rands::StdRand; pub struct Mutator { rng: R, } @@ -440,7 +437,7 @@ pub mod pybind { use serde::{Deserialize, Serialize}; use super::Rand; - use crate::bolts::{current_nanos, rands::StdRand}; + use crate::{current_nanos, rands::StdRand}; #[pyclass(unsendable, name = "StdRand")] #[allow(clippy::unsafe_derive_deserialize)] diff --git a/libafl/src/bolts/serdeany.rs b/libafl_bolts/src/serdeany.rs similarity index 97% rename from libafl/src/bolts/serdeany.rs rename to libafl_bolts/src/serdeany.rs index b0980229be..d3d5b680f4 100644 --- a/libafl/src/bolts/serdeany.rs +++ b/libafl_bolts/src/serdeany.rs @@ -65,7 +65,7 @@ where #[macro_export] macro_rules! create_serde_registry_for_trait { ($mod_name:ident, $trait_name:path) => { - /// A [`crate::bolts::serdeany`] module. + /// A [`crate::serdeany`] module. pub mod $mod_name { use alloc::boxed::Box; @@ -78,10 +78,8 @@ macro_rules! create_serde_registry_for_trait { use postcard; use serde::{Deserialize, Serialize}; use $crate::{ - bolts::{ - anymap::{pack_type_id, unpack_type_id}, - serdeany::{DeserializeCallback, DeserializeCallbackSeed}, - }, + anymap::{pack_type_id, unpack_type_id}, + serdeany::{DeserializeCallback, DeserializeCallbackSeed}, Error, }; @@ -581,10 +579,10 @@ macro_rules! create_serde_registry_for_trait { { use serde::ser::SerializeSeq; - let id = $crate::bolts::anymap::unpack_type_id(self.type_id()); + let id = $crate::anymap::unpack_type_id(self.type_id()); let mut seq = se.serialize_seq(Some(2))?; seq.serialize_element(&id)?; - seq.serialize_element(&$crate::bolts::serdeany::Wrap(self))?; + seq.serialize_element(&$crate::serdeany::Wrap(self))?; seq.end() } } @@ -601,7 +599,7 @@ macro_rules! create_serde_registry_for_trait { }; } -create_serde_registry_for_trait!(serdeany_registry, crate::bolts::serdeany::SerdeAny); +create_serde_registry_for_trait!(serdeany_registry, crate::serdeany::SerdeAny); pub use serdeany_registry::*; /// Register a `SerdeAny` type in the [`RegistryBuilder`] @@ -612,7 +610,7 @@ macro_rules! register_at_startup { const _: () = { #[$crate::ctor] fn constructor() { - $crate::bolts::serdeany::RegistryBuilder::register::<$struct_type>(); + $crate::serdeany::RegistryBuilder::register::<$struct_type>(); } }; }; @@ -631,7 +629,7 @@ macro_rules! impl_serdeany { ($struct_name:ident < $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ > $(, < $( $opt:tt ),+ >)*) => { impl < $( $lt $( : $clt $(+ $dlt )* )? ),+ > - $crate::bolts::serdeany::SerdeAny + $crate::serdeany::SerdeAny for $struct_name < $( $lt ),+ > { fn as_any(&self) -> &dyn ::core::any::Any { @@ -656,7 +654,7 @@ macro_rules! impl_serdeany { ($struct_name:ident) => { impl - $crate::bolts::serdeany::SerdeAny + $crate::serdeany::SerdeAny for $struct_name { fn as_any(&self) -> &dyn ::core::any::Any { diff --git a/libafl/src/bolts/shmem.rs b/libafl_bolts/src/shmem.rs similarity index 97% rename from libafl/src/bolts/shmem.rs rename to libafl_bolts/src/shmem.rs index 530129dbd3..9cceaaee8a 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl_bolts/src/shmem.rs @@ -23,13 +23,10 @@ pub use unix_shmem::{UnixShMem, UnixShMemProvider}; pub use win32_shmem::{Win32ShMem, Win32ShMemProvider}; #[cfg(all(unix, feature = "std"))] -use crate::bolts::os::pipes::Pipe; +use crate::os::pipes::Pipe; #[cfg(all(feature = "std", unix))] -pub use crate::bolts::os::unix_shmem_server::{ServedShMemProvider, ShMemService}; -use crate::{ - bolts::{AsMutSlice, AsSlice}, - Error, -}; +pub use crate::os::unix_shmem_server::{ServedShMemProvider, ShMemService}; +use crate::{AsMutSlice, AsSlice, Error}; /// The standard sharedmem provider #[cfg(all(windows, feature = "std"))] @@ -168,7 +165,7 @@ impl Display for ShMemId { } /// A [`ShMem`] is an interface to shared maps. -/// They are the backbone of [`crate::bolts::llmp`] for inter-process communication. +/// They are the backbone of [`crate::llmp`] for inter-process communication. /// All you need for scaling on a new target is to implement this interface, as well as the respective [`ShMemProvider`]. pub trait ShMem: Sized + Debug + Clone + AsSlice + AsMutSlice { /// Get the id of this shared memory mapping @@ -228,7 +225,7 @@ pub trait ShMem: Sized + Debug + Clone + AsSlice + AsMutSlice Result { unsafe { let fd: i32 = id.to_string().parse().unwrap(); @@ -1196,11 +1187,8 @@ pub mod win32_shmem { use uuid::Uuid; use crate::{ - bolts::{ - shmem::{ShMem, ShMemId, ShMemProvider}, - AsMutSlice, AsSlice, - }, - Error, + shmem::{ShMem, ShMemId, ShMemProvider}, + AsMutSlice, AsSlice, Error, }; const INVALID_HANDLE_VALUE: isize = -1; @@ -1442,7 +1430,6 @@ impl std::io::Seek for ShMemCursor { std::io::SeekFrom::Start(s) => s, std::io::SeekFrom::End(offset) => { let map_len = self.inner.as_slice().len(); - i64::try_from(map_len).unwrap(); let signed_pos = i64::try_from(map_len).unwrap(); let effective = signed_pos.checked_add(offset).unwrap(); assert!(effective >= 0); @@ -1468,7 +1455,7 @@ impl std::io::Seek for ShMemCursor { mod tests { use serial_test::serial; - use crate::bolts::{ + use crate::{ shmem::{ShMemProvider, StdShMemProvider}, AsMutSlice, AsSlice, }; diff --git a/libafl/src/bolts/staterestore.rs b/libafl_bolts/src/staterestore.rs similarity index 99% rename from libafl/src/bolts/staterestore.rs rename to libafl_bolts/src/staterestore.rs index 8c485a12ab..25e34ab08a 100644 --- a/libafl/src/bolts/staterestore.rs +++ b/libafl_bolts/src/staterestore.rs @@ -19,11 +19,8 @@ use ahash::RandomState; use serde::{de::DeserializeOwned, Serialize}; use crate::{ - bolts::{ - shmem::{ShMem, ShMemProvider}, - AsSlice, - }, - Error, + shmem::{ShMem, ShMemProvider}, + AsSlice, Error, }; /// If the saved page content equals exactly this buf, the restarted child wants to exit cleanly. @@ -290,7 +287,7 @@ mod tests { use serial_test::serial; - use crate::bolts::{ + use crate::{ shmem::{ShMemProvider, StdShMemProvider}, staterestore::StateRestorer, }; diff --git a/libafl/src/bolts/tuples.rs b/libafl_bolts/src/tuples.rs similarity index 97% rename from libafl/src/bolts/tuples.rs rename to libafl_bolts/src/tuples.rs index 12b009912e..5d79c7a8ce 100644 --- a/libafl/src/bolts/tuples.rs +++ b/libafl_bolts/src/tuples.rs @@ -10,6 +10,8 @@ use core::{ pub use tuple_list::{tuple_list, tuple_list_type, TupleList}; use xxhash_rust::xxh3::xxh3_64; +use crate::Named; + /// Returns if the type `T` is equal to `U` /// From #[rustversion::nightly] @@ -206,12 +208,6 @@ where } } -/// We need fixed names for many parts of this lib. -pub trait Named { - /// Provide the name of this element. - fn name(&self) -> &str; -} - /// A named tuple pub trait NamedTuple: HasConstLen { /// Gets the name of this tuple @@ -224,6 +220,13 @@ impl NamedTuple for () { } } +impl Named for () { + #[inline] + fn name(&self) -> &str { + "Empty" + } +} + impl NamedTuple for (Head, Tail) where Head: Named, @@ -523,12 +526,15 @@ impl PlusOne for (Head, Tail) where #[cfg(test)] mod test { - use crate::bolts::{ownedref::OwnedMutSlice, tuples::type_eq}; + use crate::{ownedref::OwnedMutSlice, tuples::type_eq}; + + /// An alias for equality testing + type OwnedMutSliceAlias<'a> = OwnedMutSlice<'a, u8>; #[test] #[allow(unused_qualifications)] // for type name tests fn test_type_eq() { - #[allow(extra_unused_lifetimes)] + #[allow(clippy::extra_unused_lifetimes)] fn test_lifetimes<'a, 'b>() { assert!(type_eq::, OwnedMutSlice<'b, u8>>()); assert!(type_eq::, OwnedMutSlice<'a, u8>>()); @@ -536,7 +542,6 @@ mod test { assert!(type_eq::, OwnedMutSlice<'static, u8>>()); assert!(!type_eq::, OwnedMutSlice<'b, i8>>()); } - type OwnedMutSliceAlias<'a> = OwnedMutSlice<'a, u8>; assert!(type_eq::, OwnedMutSliceAlias>()); test_lifetimes(); @@ -552,11 +557,11 @@ mod test { assert!(type_eq::< OwnedMutSlice, - crate::bolts::ownedref::OwnedMutSlice, + crate::ownedref::OwnedMutSlice, >()); assert!(!type_eq::< OwnedMutSlice, - crate::bolts::ownedref::OwnedMutSlice, + crate::ownedref::OwnedMutSlice, >()); } } diff --git a/libafl_concolic/symcc_runtime/Cargo.toml b/libafl_concolic/symcc_runtime/Cargo.toml index 21e4c890c8..5b64c88452 100644 --- a/libafl_concolic/symcc_runtime/Cargo.toml +++ b/libafl_concolic/symcc_runtime/Cargo.toml @@ -23,6 +23,7 @@ unchecked_unwrap = "4" ctor = "0.2" libc = "0.2" libafl = { path = "../../libafl", version = "0.10.1", default-features=false, features=["std"] } +libafl_bolts = { path = "../../libafl_bolts", version = "0.10.1", default-features=false, features=["std"] } [build-dependencies] cmake = "0.1" diff --git a/libafl_concolic/symcc_runtime/src/filter/coverage.rs b/libafl_concolic/symcc_runtime/src/filter/coverage.rs index 6df854afbd..c20e0993f6 100644 --- a/libafl_concolic/symcc_runtime/src/filter/coverage.rs +++ b/libafl_concolic/symcc_runtime/src/filter/coverage.rs @@ -4,7 +4,7 @@ use std::{ marker::PhantomData, }; -use libafl::bolts::shmem::ShMem; +use libafl_bolts::shmem::ShMem; use super::Filter; diff --git a/libafl_concolic/test/dump_constraints/Cargo.toml b/libafl_concolic/test/dump_constraints/Cargo.toml index b24a232f3b..1621d33fe4 100644 --- a/libafl_concolic/test/dump_constraints/Cargo.toml +++ b/libafl_concolic/test/dump_constraints/Cargo.toml @@ -15,4 +15,5 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s [dependencies] libafl = {path = "../../../libafl"} +libafl_bolts = {path = "../../../libafl_bolts"} clap = { version = "4.0", features = ["derive"] } diff --git a/libafl_concolic/test/dump_constraints/src/main.rs b/libafl_concolic/test/dump_constraints/src/main.rs index efb7f89cc2..082a527870 100644 --- a/libafl_concolic/test/dump_constraints/src/main.rs +++ b/libafl_concolic/test/dump_constraints/src/main.rs @@ -12,15 +12,13 @@ use std::{ }; use clap::{self, Parser}; -use libafl::{ - bolts::{ - shmem::{ShMem, ShMemProvider, StdShMemProvider}, - AsSlice, - }, - observers::concolic::{ - serialization_format::{MessageFileReader, MessageFileWriter, DEFAULT_ENV_NAME}, - EXPRESSION_PRUNING, HITMAP_ENV_NAME, NO_FLOAT_ENV_NAME, SELECTIVE_SYMBOLICATION_ENV_NAME, - }, +use libafl::observers::concolic::{ + serialization_format::{MessageFileReader, MessageFileWriter, DEFAULT_ENV_NAME}, + EXPRESSION_PRUNING, HITMAP_ENV_NAME, NO_FLOAT_ENV_NAME, SELECTIVE_SYMBOLICATION_ENV_NAME, +}; +use libafl_bolts::{ + shmem::{ShMem, ShMemProvider, StdShMemProvider}, + AsSlice, }; #[derive(Debug, Parser)] diff --git a/libafl_derive/src/lib.rs b/libafl_derive/src/lib.rs index a7d8a9d93d..a6797d6d71 100644 --- a/libafl_derive/src/lib.rs +++ b/libafl_derive/src/lib.rs @@ -68,6 +68,6 @@ use syn::{parse_macro_input, DeriveInput}; pub fn libafl_serdeany_derive(input: TokenStream) -> TokenStream { let name = parse_macro_input!(input as DeriveInput).ident; TokenStream::from(quote! { - libafl::impl_serdeany!(#name); + libafl_bolts::impl_serdeany!(#name); }) } diff --git a/libafl_frida/Cargo.toml b/libafl_frida/Cargo.toml index 34818003d4..377cb0aef4 100644 --- a/libafl_frida/Cargo.toml +++ b/libafl_frida/Cargo.toml @@ -19,12 +19,13 @@ cmplog = [] cc = { version = "1.0", features = ["parallel"] } [dependencies] -libafl = { path = "../libafl", default-features = false, version = "0.10.1", features = ["std", "libafl_derive", "frida_cli"] } +libafl = { path = "../libafl", default-features = false, version = "0.10.1", features = ["std", "derive", "frida_cli"] } +libafl_bolts = { path = "../libafl_bolts", version = "0.10.1", default-features = false, features = ["std", "derive", "frida_cli"] } libafl_targets = { path = "../libafl_targets", version = "0.10.1", features = ["std", "sancov_cmplog"] } nix = "0.26" libc = "0.2" -hashbrown = "0.13" +hashbrown = "0.14" rangemap = "1.0" frida-gum-sys = { version = "0.4.1", features = [ "auto-download", "event-sink", "invocation-listener"] } frida-gum = { version = "0.8.1", features = [ "auto-download", "event-sink", "invocation-listener"] } diff --git a/libafl_frida/src/alloc.rs b/libafl_frida/src/alloc.rs index b6e35dbe88..b7ec8ef909 100644 --- a/libafl_frida/src/alloc.rs +++ b/libafl_frida/src/alloc.rs @@ -9,7 +9,7 @@ use std::{collections::BTreeMap, ffi::c_void, num::NonZeroUsize}; use backtrace::Backtrace; use frida_gum::{PageProtection, RangeDetails}; use hashbrown::HashMap; -use libafl::bolts::cli::FuzzerOptions; +use libafl_bolts::cli::FuzzerOptions; #[cfg(any( target_os = "linux", target_vendor = "apple", diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index 1df06264aa..7f356d71dd 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -37,7 +37,7 @@ use frida_gum::{ Module, ModuleDetails, ModuleMap, NativePointer, RangeDetails, }; use hashbrown::HashMap; -use libafl::bolts::{cli::FuzzerOptions, AsSlice}; +use libafl_bolts::{cli::FuzzerOptions, AsSlice}; #[cfg(unix)] use libc::RLIMIT_STACK; use libc::{c_char, wchar_t}; diff --git a/libafl_frida/src/asan/errors.rs b/libafl_frida/src/asan/errors.rs index 0bc0488823..6f85842f55 100644 --- a/libafl_frida/src/asan/errors.rs +++ b/libafl_frida/src/asan/errors.rs @@ -8,7 +8,6 @@ use color_backtrace::{default_output_stream, BacktracePrinter, Verbosity}; use frida_gum::interceptor::Interceptor; use frida_gum::ModuleDetails; use libafl::{ - bolts::{cli::FuzzerOptions, ownedref::OwnedPtr, tuples::Named}, corpus::Testcase, events::EventFirer, executors::ExitKind, @@ -16,8 +15,9 @@ use libafl::{ inputs::{HasTargetBytes, UsesInput}, observers::{Observer, ObserversTuple}, state::{HasClientPerfMonitor, HasMetadata}, - Error, SerdeAny, + Error, }; +use libafl_bolts::{cli::FuzzerOptions, ownedref::OwnedPtr, Named, SerdeAny}; use serde::{Deserialize, Serialize}; use termcolor::{Color, ColorSpec, WriteColor}; diff --git a/libafl_frida/src/coverage_rt.rs b/libafl_frida/src/coverage_rt.rs index 8d53680687..1312bda3f2 100644 --- a/libafl_frida/src/coverage_rt.rs +++ b/libafl_frida/src/coverage_rt.rs @@ -6,7 +6,7 @@ use std::{cell::RefCell, marker::PhantomPinned, pin::Pin, rc::Rc}; use dynasmrt::DynasmLabelApi; use dynasmrt::{dynasm, DynasmApi}; use frida_gum::{instruction_writer::InstructionWriter, stalker::StalkerOutput}; -use libafl::bolts::xxh3_rrmxmx_mixer; +use libafl_bolts::xxh3_rrmxmx_mixer; use rangemap::RangeMap; use crate::helper::FridaRuntime; diff --git a/libafl_frida/src/drcov_rt.rs b/libafl_frida/src/drcov_rt.rs index 8e44a18021..dc79b55ab3 100644 --- a/libafl_frida/src/drcov_rt.rs +++ b/libafl_frida/src/drcov_rt.rs @@ -6,10 +6,10 @@ use std::{ use ahash::RandomState; use libafl::{ - bolts::AsSlice, inputs::{HasTargetBytes, Input}, Error, }; +use libafl_bolts::AsSlice; use libafl_targets::drcov::{DrCovBasicBlock, DrCovWriter}; use rangemap::RangeMap; diff --git a/libafl_frida/src/helper.rs b/libafl_frida/src/helper.rs index d7b8532f7e..2c2a30c0a8 100644 --- a/libafl_frida/src/helper.rs +++ b/libafl_frida/src/helper.rs @@ -15,10 +15,10 @@ use frida_gum::instruction_writer::InstructionWriter; use frida_gum::CpuContext; use frida_gum::{stalker::Transformer, Gum, Module, ModuleDetails, ModuleMap, PageProtection}; use libafl::{ - bolts::{cli::FuzzerOptions, tuples::MatchFirstType}, inputs::{HasTargetBytes, Input}, Error, }; +use libafl_bolts::{cli::FuzzerOptions, tuples::MatchFirstType}; #[cfg(unix)] use libafl_targets::drcov::DrCovBasicBlock; #[cfg(unix)] diff --git a/libafl_frida/src/lib.rs b/libafl_frida/src/lib.rs index 9e3a3d0c24..c9819fc39f 100644 --- a/libafl_frida/src/lib.rs +++ b/libafl_frida/src/lib.rs @@ -99,7 +99,7 @@ pub mod executor; pub mod utils; // for parsing asan and cmplog cores -use libafl::bolts::core_affinity::{get_core_ids, CoreId, Cores}; +use libafl_bolts::core_affinity::{get_core_ids, CoreId, Cores}; /// A representation of the various Frida options #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] diff --git a/libafl_frida/src/windows_hooks.rs b/libafl_frida/src/windows_hooks.rs index 61bdfad230..f23ebb76dc 100644 --- a/libafl_frida/src/windows_hooks.rs +++ b/libafl_frida/src/windows_hooks.rs @@ -1,6 +1,6 @@ // Based on the example of setting hooks: Https://github.com/frida/frida-rust/blob/main/examples/gum/hook_open/src/lib.rs use frida_gum::{interceptor::Interceptor, Gum, Module, NativePointer}; -use libafl::bolts::os::windows_exceptions::{ +use libafl_bolts::os::windows_exceptions::{ handle_exception, IsProcessorFeaturePresent, UnhandledExceptionFilter, EXCEPTION_POINTERS, PROCESSOR_FEATURE_ID, }; diff --git a/libafl_nyx/Cargo.toml b/libafl_nyx/Cargo.toml index 9458151098..2245c5408b 100644 --- a/libafl_nyx/Cargo.toml +++ b/libafl_nyx/Cargo.toml @@ -16,4 +16,5 @@ categories = ["development-tools::testing", "emulators", "embedded", "os", "no-s [target.'cfg(target_os = "linux")'.dependencies] libnyx = {git = "https://github.com/nyx-fuzz/libnyx.git",rev = "acaf7f6"} libafl = { path = "../libafl", version = "0.10.1", features = ["std", "libafl_derive", "frida_cli" ]} +libafl_bolts = { path = "../libafl_bolts", version = "0.10.1", features = ["std", "libafl_derive", "frida_cli" ]} libafl_targets = { path = "../libafl_targets", version = "0.10.1", features = ["std", "sancov_cmplog"] } diff --git a/libafl_nyx/src/executor.rs b/libafl_nyx/src/executor.rs index 64347dd15e..324695dd53 100644 --- a/libafl_nyx/src/executor.rs +++ b/libafl_nyx/src/executor.rs @@ -1,13 +1,13 @@ use std::{fmt::Debug, marker::PhantomData}; use libafl::{ - bolts::AsSlice, executors::{Executor, ExitKind, HasObservers}, inputs::{HasTargetBytes, UsesInput}, observers::{ObserversTuple, UsesObservers}, state::{State, UsesState}, Error, }; +use libafl_bolts::AsSlice; use libnyx::NyxReturnValue; use crate::helper::NyxHelper; diff --git a/libafl_qemu/Cargo.toml b/libafl_qemu/Cargo.toml index 5a2c634bda..04f76e1592 100644 --- a/libafl_qemu/Cargo.toml +++ b/libafl_qemu/Cargo.toml @@ -37,11 +37,12 @@ clippy = [] # special feature for clippy, don't use in normal projects§ [dependencies] libafl = { path = "../libafl", version = "0.10.1", default-features = false, features = ["std", "derive", "regex"] } +libafl_bolts = { path = "../libafl_bolts", version = "0.10.1", default-features = false, features = ["std", "derive"] } libafl_targets = { path = "../libafl_targets", version = "0.10.1" } libafl_qemu_sys = { path = "./libafl_qemu_sys", version = "0.10.1" } serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib -hashbrown = { version = "0.13", features = ["serde"] } # A faster hashmap, nostd compatible +hashbrown = { version = "0.14", features = ["serde"] } # A faster hashmap, nostd compatible num-traits = "0.2" num_enum = "0.6" goblin = "0.6" diff --git a/libafl_qemu/src/calls.rs b/libafl_qemu/src/calls.rs index 2e7ba6337c..f22c9bc77a 100644 --- a/libafl_qemu/src/calls.rs +++ b/libafl_qemu/src/calls.rs @@ -2,11 +2,11 @@ use core::fmt::Debug; use capstone::prelude::*; use libafl::{ - bolts::tuples::{MatchFirstType, Named}, executors::ExitKind, inputs::{Input, UsesInput}, observers::{stacktrace::BacktraceObserver, ObserversTuple}, }; +use libafl_bolts::{tuples::MatchFirstType, Named}; use crate::{ capstone, diff --git a/libafl_qemu/src/cmplog.rs b/libafl_qemu/src/cmplog.rs index 687ed58c62..67e7d82e7f 100644 --- a/libafl_qemu/src/cmplog.rs +++ b/libafl_qemu/src/cmplog.rs @@ -28,7 +28,7 @@ impl QemuCmpsMapMetadata { } } -libafl::impl_serdeany!(QemuCmpsMapMetadata); +libafl_bolts::impl_serdeany!(QemuCmpsMapMetadata); #[derive(Debug)] pub struct QemuCmpLogHelper { diff --git a/libafl_qemu/src/drcov.rs b/libafl_qemu/src/drcov.rs index 4e8057aee4..6bcdf8831c 100644 --- a/libafl_qemu/src/drcov.rs +++ b/libafl_qemu/src/drcov.rs @@ -31,7 +31,7 @@ impl QemuDrCovMetadata { } } -libafl::impl_serdeany!(QemuDrCovMetadata); +libafl_bolts::impl_serdeany!(QemuDrCovMetadata); #[derive(Debug)] pub struct QemuDrCovHelper { diff --git a/libafl_qemu/src/edges.rs b/libafl_qemu/src/edges.rs index 927e2f3972..d9a735e64f 100644 --- a/libafl_qemu/src/edges.rs +++ b/libafl_qemu/src/edges.rs @@ -30,7 +30,7 @@ impl QemuEdgesMapMetadata { } } -libafl::impl_serdeany!(QemuEdgesMapMetadata); +libafl_bolts::impl_serdeany!(QemuEdgesMapMetadata); #[derive(Debug)] pub struct QemuEdgeCoverageHelper { diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index 84b0a1b01b..5f01ff384f 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -2,10 +2,7 @@ use core::fmt::{self, Debug, Formatter}; #[cfg(feature = "fork")] -use libafl::{ - bolts::shmem::ShMemProvider, events::EventManager, executors::InProcessForkExecutor, - state::HasMetadata, -}; +use libafl::{events::EventManager, executors::InProcessForkExecutor, state::HasMetadata}; use libafl::{ events::{EventFirer, EventRestarter}, executors::{Executor, ExitKind, HasObservers, InProcessExecutor}, @@ -19,6 +16,8 @@ use libafl::{ }, Error, }; +#[cfg(feature = "fork")] +use libafl_bolts::shmem::ShMemProvider; use crate::{emu::Emulator, helper::QemuHelperTuple, hooks::QemuHooks}; diff --git a/libafl_qemu/src/helper.rs b/libafl_qemu/src/helper.rs index d1ce2e3de0..5e110712b3 100644 --- a/libafl_qemu/src/helper.rs +++ b/libafl_qemu/src/helper.rs @@ -1,9 +1,7 @@ use core::{fmt::Debug, ops::Range}; -use libafl::{ - bolts::tuples::MatchFirstType, executors::ExitKind, inputs::UsesInput, - observers::ObserversTuple, -}; +use libafl::{executors::ExitKind, inputs::UsesInput, observers::ObserversTuple}; +use libafl_bolts::tuples::MatchFirstType; use crate::{ emu::{Emulator, GuestAddr}, diff --git a/libafl_sugar/Cargo.toml b/libafl_sugar/Cargo.toml index 3384c16cb4..c8e73a8b7a 100644 --- a/libafl_sugar/Cargo.toml +++ b/libafl_sugar/Cargo.toml @@ -28,6 +28,7 @@ pyo3-build-config = { version = "0.15", optional = true } [dependencies] libafl = { path = "../libafl", version = "0.10.1" } +libafl_bolts = { path = "../libafl_bolts", version = "0.10.1" } libafl_targets = { path = "../libafl_targets", version = "0.10.1" } libafl_qemu = { path = "../libafl_qemu", version = "0.10.1" } diff --git a/libafl_sugar/src/forkserver.rs b/libafl_sugar/src/forkserver.rs index 44701180e7..b3634d306a 100644 --- a/libafl_sugar/src/forkserver.rs +++ b/libafl_sugar/src/forkserver.rs @@ -3,17 +3,8 @@ use std::{fs, net::SocketAddr, path::PathBuf, time::Duration}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMem, ShMemProvider, UnixShMemProvider}, - tuples::{tuple_list, Merge}, - AsMutSlice, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus}, - events::{EventConfig, EventRestarter, LlmpRestartingEventManager}, + events::{launcher::Launcher, EventConfig, EventRestarter, LlmpRestartingEventManager}, executors::{forkserver::ForkserverExecutorBuilder, TimeoutForkserverExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -30,6 +21,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMem, ShMemProvider, UnixShMemProvider}, + tuples::{tuple_list, Merge}, + AsMutSlice, +}; use typed_builder::TypedBuilder; use crate::{CORPUS_CACHE_SIZE, DEFAULT_TIMEOUT_SECS}; @@ -313,7 +312,7 @@ impl<'a> ForkserverBytesCoverageSugar<'a> { pub mod pybind { use std::path::PathBuf; - use libafl::bolts::core_affinity::Cores; + use libafl_bolts::core_affinity::Cores; use pyo3::prelude::*; use crate::forkserver; diff --git a/libafl_sugar/src/inmemory.rs b/libafl_sugar/src/inmemory.rs index b86310756c..b73e1f8792 100644 --- a/libafl_sugar/src/inmemory.rs +++ b/libafl_sugar/src/inmemory.rs @@ -5,17 +5,8 @@ use core::fmt::{self, Debug, Formatter}; use std::{fs, net::SocketAddr, path::PathBuf, time::Duration}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus}, - events::{EventConfig, EventRestarter, LlmpRestartingEventManager}, + events::{launcher::Launcher, EventConfig, EventRestarter, LlmpRestartingEventManager}, executors::{inprocess::InProcessExecutor, ExitKind, ShadowExecutor, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -33,6 +24,14 @@ use libafl::{ state::{HasCorpus, HasMetadata, StdState}, Error, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; use libafl_targets::{std_edges_map_observer, CmpLogObserver}; use typed_builder::TypedBuilder; @@ -357,7 +356,7 @@ where pub mod pybind { use std::path::PathBuf; - use libafl::bolts::core_affinity::Cores; + use libafl_bolts::core_affinity::Cores; use pyo3::{prelude::*, types::PyBytes}; use crate::inmemory; diff --git a/libafl_sugar/src/qemu.rs b/libafl_sugar/src/qemu.rs index 7f32deefbf..1c86555669 100644 --- a/libafl_sugar/src/qemu.rs +++ b/libafl_sugar/src/qemu.rs @@ -7,17 +7,8 @@ use core::{ use std::{fs, net::SocketAddr, path::PathBuf, time::Duration}; use libafl::{ - bolts::{ - core_affinity::Cores, - current_nanos, - launcher::Launcher, - rands::StdRand, - shmem::{ShMemProvider, StdShMemProvider}, - tuples::{tuple_list, Merge}, - AsSlice, - }, corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus}, - events::{EventConfig, EventRestarter, LlmpRestartingEventManager}, + events::{launcher::Launcher, EventConfig, EventRestarter, LlmpRestartingEventManager}, executors::{ExitKind, ShadowExecutor, TimeoutExecutor}, feedback_or, feedback_or_fast, feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback, TimeoutFeedback}, @@ -35,6 +26,14 @@ use libafl::{ stages::{ShadowTracingStage, StdMutationalStage}, state::{HasCorpus, HasMetadata, StdState}, }; +use libafl_bolts::{ + core_affinity::Cores, + current_nanos, + rands::StdRand, + shmem::{ShMemProvider, StdShMemProvider}, + tuples::{tuple_list, Merge}, + AsSlice, +}; pub use libafl_qemu::emu::Emulator; use libafl_qemu::{edges, QemuCmpLogHelper, QemuEdgeCoverageHelper, QemuExecutor, QemuHooks}; use libafl_targets::{edges_map_mut_slice, CmpLogObserver}; @@ -438,7 +437,7 @@ where pub mod pybind { use std::path::PathBuf; - use libafl::bolts::core_affinity::Cores; + use libafl_bolts::core_affinity::Cores; use libafl_qemu::emu::pybind::Emulator; use pyo3::{prelude::*, types::PyBytes}; diff --git a/libafl_targets/Cargo.toml b/libafl_targets/Cargo.toml index 962a0143b4..f934dcae94 100644 --- a/libafl_targets/Cargo.toml +++ b/libafl_targets/Cargo.toml @@ -33,6 +33,7 @@ cc = { version = "1.0", features = ["parallel"] } [dependencies] libafl = { path = "../libafl", version = "0.10.1", default-features = false, features = [] } +libafl_bolts = { path = "../libafl_bolts", version = "0.10.1", default-features = false, features = [] } log = "0.4.17" rangemap = "1.0" diff --git a/libafl_targets/src/cmplog.rs b/libafl_targets/src/cmplog.rs index abe1c257f9..613c469d66 100644 --- a/libafl_targets/src/cmplog.rs +++ b/libafl_targets/src/cmplog.rs @@ -6,13 +6,13 @@ use alloc::string::{String, ToString}; use core::fmt::{self, Debug, Formatter}; use libafl::{ - bolts::{ownedref::OwnedMutPtr, tuples::Named}, executors::ExitKind, inputs::UsesInput, observers::{CmpMap, CmpObserver, CmpValues, Observer}, state::HasMetadata, Error, }; +use libafl_bolts::{ownedref::OwnedMutPtr, Named}; use crate::{CMPLOG_MAP_H, CMPLOG_MAP_W}; diff --git a/libafl_targets/src/coverage.rs b/libafl_targets/src/coverage.rs index 47c741d744..4d82ea7ea1 100644 --- a/libafl_targets/src/coverage.rs +++ b/libafl_targets/src/coverage.rs @@ -55,7 +55,8 @@ pub fn autotokens() -> Result { #[no_mangle] pub static mut __afl_map_size: usize = EDGES_MAP_SIZE; pub use __afl_map_size as EDGES_MAP_PTR_NUM; -use libafl::{bolts::ownedref::OwnedMutSlice, observers::StdMapObserver}; +use libafl::observers::StdMapObserver; +use libafl_bolts::ownedref::OwnedMutSlice; /// Gets the edges map from the `EDGES_MAP_PTR` raw pointer. /// Assumes a `len` of `EDGES_MAP_PTR_NUM`. @@ -146,11 +147,11 @@ mod swap { use core::fmt::Debug; use libafl::{ - bolts::{ownedref::OwnedMutSlice, tuples::Named, AsMutSlice}, inputs::UsesInput, observers::{DifferentialObserver, Observer, ObserversTuple, StdMapObserver}, Error, }; + use libafl_bolts::{ownedref::OwnedMutSlice, AsMutSlice, Named}; use serde::{Deserialize, Serialize}; use super::{EDGES_MAP_PTR, EDGES_MAP_PTR_NUM}; diff --git a/libafl_targets/src/sancov_8bit.rs b/libafl_targets/src/sancov_8bit.rs index 937879807b..41f0e3998f 100644 --- a/libafl_targets/src/sancov_8bit.rs +++ b/libafl_targets/src/sancov_8bit.rs @@ -1,7 +1,7 @@ //! [`LLVM` `8-bi-counters`](https://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs-with-guards) runtime for `LibAFL`. use alloc::vec::Vec; -use libafl::bolts::ownedref::OwnedMutSlice; +use libafl_bolts::ownedref::OwnedMutSlice; /// A [`Vec`] of `8-bit-counters` maps for multiple modules. /// They are initialized by calling [`__sanitizer_cov_8bit_counters_init`]( @@ -39,13 +39,13 @@ mod observers { use ahash::RandomState; use intervaltree::IntervalTree; use libafl::{ - bolts::{ - ownedref::OwnedMutSlice, tuples::Named, AsIter, AsIterMut, AsMutSlice, AsSlice, HasLen, - }, inputs::UsesInput, observers::{DifferentialObserver, MapObserver, Observer, ObserversTuple}, Error, }; + use libafl_bolts::{ + ownedref::OwnedMutSlice, AsIter, AsIterMut, AsMutSlice, AsSlice, HasLen, Named, + }; use serde::{Deserialize, Serialize}; use super::COUNTERS_MAPS; diff --git a/libafl_tinyinst/Cargo.toml b/libafl_tinyinst/Cargo.toml index dea5ba6458..86e9082ea4 100644 --- a/libafl_tinyinst/Cargo.toml +++ b/libafl_tinyinst/Cargo.toml @@ -16,6 +16,10 @@ libafl = { path = "../libafl", version = "0.10.1", features = [ "std", "libafl_derive", ] } +libafl_bolts = { path = "../libafl_bolts", version = "0.10.1", features = [ + "std", + "libafl_derive", +] } tinyinst = { git = "https://github.com/AFLplusplus/tinyinst-rs" } # tinyinst-rs = { path = "../../tinyinst-rs" } log = "0.4.17" diff --git a/libafl_tinyinst/src/executor.rs b/libafl_tinyinst/src/executor.rs index ca01384a58..fdafb5728e 100644 --- a/libafl_tinyinst/src/executor.rs +++ b/libafl_tinyinst/src/executor.rs @@ -2,17 +2,17 @@ use core::marker::PhantomData; use std::time::Duration; use libafl::{ - bolts::{ - fs::{InputFile, INPUTFILE_STD}, - shmem::{ShMem, ShMemProvider, StdShMemProvider}, - AsMutSlice, AsSlice, - }, executors::{Executor, ExitKind, HasObservers}, inputs::{HasTargetBytes, UsesInput}, observers::{ObserversTuple, UsesObservers}, state::{State, UsesState}, Error, }; +use libafl_bolts::{ + fs::{InputFile, INPUTFILE_STD}, + shmem::{ShMem, ShMemProvider, StdShMemProvider}, + AsMutSlice, AsSlice, +}; use tinyinst::tinyinst::{litecov::RunResult, TinyInst}; /// Tinyinst executor diff --git a/utils/gdb_qemu/gdb_qemu/Cargo.toml b/utils/gdb_qemu/gdb_qemu/Cargo.toml index 2f25e24b9e..6d35917d43 100644 --- a/utils/gdb_qemu/gdb_qemu/Cargo.toml +++ b/utils/gdb_qemu/gdb_qemu/Cargo.toml @@ -7,10 +7,10 @@ edition = "2021" vergen = { version = "8.1.1", features = ["build", "cargo", "git", "gitcl", "rustc", "si"] } [dependencies] -anyhow = { version = "1.0.71", default-features = false } -clap = { version = "4.2.0", default-features = false, features = ["derive", "string", "std", "help", "derive", "error-context", "usage"] } -libc = {version = "0.2.146", default-features = false } -log = { version = "0.4.19", default-features = false } -nix = { version = "0.26.2", default-features = false, features = ["signal", "fs"] } +anyhow = { version = "1.0", default-features = false } +clap = { version = "4.2", default-features = false, features = ["derive", "string", "std", "help", "derive", "error-context", "usage"] } +libc = {version = "0.2", default-features = false } +log = { version = "0.4", default-features = false } +nix = { version = "0.26", default-features = false, features = ["signal", "fs"] } readonly = { version = "0.2.8", default-features = false } simplelog = { version = "0.12.1", default-features = false } diff --git a/utils/libafl_benches/Cargo.toml b/utils/libafl_benches/Cargo.toml index 29dc77a011..6d7434e0d6 100644 --- a/utils/libafl_benches/Cargo.toml +++ b/utils/libafl_benches/Cargo.toml @@ -16,7 +16,7 @@ criterion = "0.4" # Benchmarking ahash = { version = "0.8", default-features=false } # The hash function already used in hashbrown rustc-hash = { version = "1.1", default-features=false } # yet another hash xxhash-rust = { version = "0.8.5", features = ["xxh3"] } # xxh3 hashing for rust -libafl = { path = "../../libafl", default-features=false } # libafl +libafl_bolts = { path = "../../libafl_bolts", default-features=false } # libafl_bolts [[bench]] name = "rand_speeds" diff --git a/utils/libafl_benches/benches/hash_speeds.rs b/utils/libafl_benches/benches/hash_speeds.rs index a707b1160f..35f61b3fcc 100644 --- a/utils/libafl_benches/benches/hash_speeds.rs +++ b/utils/libafl_benches/benches/hash_speeds.rs @@ -3,7 +3,7 @@ use std::hash::{BuildHasher, Hasher}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use libafl::bolts::rands::{Rand, StdRand}; +use libafl_bolts::rands::{Rand, StdRand}; //use xxhash_rust::const_xxh3; use xxhash_rust::xxh3; diff --git a/utils/libafl_benches/benches/rand_speeds.rs b/utils/libafl_benches/benches/rand_speeds.rs index 099420cfbb..53f30b855e 100644 --- a/utils/libafl_benches/benches/rand_speeds.rs +++ b/utils/libafl_benches/benches/rand_speeds.rs @@ -1,7 +1,7 @@ //! Compare the speed of rand implementations use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use libafl::bolts::rands::{ +use libafl_bolts::rands::{ Lehmer64Rand, Rand, RomuDuoJrRand, RomuTrioRand, XorShift64Rand, Xoshiro256StarRand, }; diff --git a/utils/noaslr/libnoaslr/Cargo.toml b/utils/noaslr/libnoaslr/Cargo.toml index 712c0d4a85..6b6c8db7e2 100644 --- a/utils/noaslr/libnoaslr/Cargo.toml +++ b/utils/noaslr/libnoaslr/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["dylib"] [dependencies] anyhow = { version = "1.0.71", default-features = false } -ctor = { version = "0.2.2", default-features = false } +ctor = { version = "0.2", default-features = false } nix = { version = "0.26.2", default-features = false, features = ["process", "personality"] } [target.'cfg(any(target_os = "freebsd", target_os = "netbsd"))'.dependencies]