diff --git a/fuzzers/libfuzzer_libpng/src/mod.rs b/fuzzers/libfuzzer_libpng/src/mod.rs index 0912d8a462..50a02df796 100644 --- a/fuzzers/libfuzzer_libpng/src/mod.rs +++ b/fuzzers/libfuzzer_libpng/src/mod.rs @@ -4,7 +4,7 @@ use std::{env, path::PathBuf}; use libafl::{ - bolts::{serdeany::RegistryBuilder, shmem::UnixShMem, tuples::tuple_list}, + bolts::{shmem::UnixShMem, tuples::tuple_list}, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::setup_restarting_mgr, executors::{inprocess::InProcessExecutor, Executor, ExitKind}, @@ -52,8 +52,8 @@ where /// The main fn, parsing parameters, and starting the fuzzer pub fn main() { // Registry the metadata types used in this fuzzer - RegistryBuilder::register::(); - RegistryBuilder::finalize(); + // Needed only on no_std + //RegistryBuilder::register::(); println!( "Workdir: {:?}", diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index 90e9ed0a61..75488b6c61 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -50,6 +50,7 @@ erased-serde = "0.3.12" postcard = { version = "0.5.1", features = ["alloc"] } # no_std compatible serde serialization fromat static_assertions = "1.1.0" serde_json = { version = "1.0", default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap +ctor = "0.1.3" #TODO: for llmp brotli = { version = "3.3.0", default-features = false } # brotli compression [target.'cfg(unix)'.dependencies] diff --git a/libafl/src/bolts/serdeany.rs b/libafl/src/bolts/serdeany.rs index 70b1937e5a..d7cf5dc7e9 100644 --- a/libafl/src/bolts/serdeany.rs +++ b/libafl/src/bolts/serdeany.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use alloc::boxed::Box; use core::any::{Any, TypeId}; -#[cfg(fature = "anymap_debug")] +#[cfg(feature = "anymap_debug")] use serde_json; // yolo @@ -499,3 +499,25 @@ macro_rules! create_serde_registry_for_trait { create_serde_registry_for_trait!(serdeany_registry, crate::bolts::serdeany::SerdeAny); pub use serdeany_registry::*; + +#[macro_export] +macro_rules! impl_serdeany { + ($struct_name:ident) => { + impl crate::bolts::serdeany::SerdeAny for $struct_name { + fn as_any(&self) -> &dyn Any { + self + } + + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + } + + #[allow(non_snake_case)] + #[cfg(feature = "std")] + #[ctor] + fn $struct_name() { + crate::bolts::serdeany::RegistryBuilder::register::<$struct_name>(); + } + }; +} diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index bbaa547864..9f3b523719 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -239,7 +239,7 @@ pub mod unix_signals { static mut EVENT_MGR_PTR: *mut c_void = ptr::null_mut(); static mut OBSERVERS_PTR: *const c_void = ptr::null(); /// The (unsafe) pointer to the current inmem input, for the current run. - /// This is neede for certain non-rust side effects, as well as unix signal handling. + /// This is needed for certain non-rust side effects, as well as unix signal handling. static mut CURRENT_INPUT_PTR: *const c_void = ptr::null(); pub unsafe extern "C" fn libaflrs_executor_inmem_handle_crash( @@ -267,6 +267,15 @@ pub mod unix_signals { Ok(maps) => println!("maps:\n{}", maps), Err(e) => println!("Couldn't load mappings: {:?}", e), }; + + #[cfg(feature = "std")] + { + println!("Type QUIT to restart the child"); + let mut line = String::new(); + while line.trim() != "QUIT" { + std::io::stdin().read_line(&mut line).unwrap(); + } + } // TODO tell the parent to not restart std::process::exit(1); diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index 0ab68a8c77..2906185e91 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -8,6 +8,8 @@ Welcome to libAFL extern crate alloc; #[macro_use] extern crate static_assertions; +#[macro_use] +extern crate ctor; pub mod bolts; pub mod corpus; diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index 417a6f7dae..a075fdaa4e 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -2,7 +2,6 @@ //! They may be inserted as part of mutations during fuzzing. use crate::{ - bolts::serdeany::SerdeAny, inputs::{HasBytesVec, Input}, mutators::*, utils::Rand, @@ -21,15 +20,7 @@ pub struct TokensMetadata { tokens: Vec>, } -impl SerdeAny for TokensMetadata { - fn as_any(&self) -> &dyn Any { - self - } - - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } -} +crate::impl_serdeany!(TokensMetadata); impl TokensMetadata { pub fn new(tokens: Vec>) -> Self {