diff --git a/afl/Cargo.toml b/afl/Cargo.toml index 71775a583b..407ec699d9 100644 --- a/afl/Cargo.toml +++ b/afl/Cargo.toml @@ -19,5 +19,5 @@ libc = "0.2" # For (*nix) libc num = "*" xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib -serde_traitobject = { version = "0.2.7" } # trait obj serialization lib +typetag = "0.1" postcard = "0.5.1" # no_std compatible serde serialization fromat \ No newline at end of file diff --git a/afl/src/corpus/testcase.rs b/afl/src/corpus/testcase.rs index 05f91c0bde..d351d50cd1 100644 --- a/afl/src/corpus/testcase.rs +++ b/afl/src/corpus/testcase.rs @@ -1,13 +1,13 @@ use alloc::boxed::Box; use alloc::rc::Rc; use alloc::string::String; -use core::any::Any; +use core::any::{Any, TypeId}; use core::cell::RefCell; use core::convert::Into; use core::default::Default; use core::option::Option; use hashbrown::HashMap; -use serde_traitobject::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use crate::inputs::Input; use crate::AflError; @@ -18,7 +18,8 @@ use crate::AflError; // TODO: Give example /// Metadata for a testcase -pub trait TestcaseMetadata: Any + Serialize + Deserialize<'static> { +#[typetag::serde(tag = "type")] +pub trait TestcaseMetadata: Any { /// The name of this metadata - used to find it in the list of avaliable metadatas fn name(&self) -> &'static str; } @@ -36,7 +37,7 @@ where /// Accumulated fitness from all the feedbacks fitness: u32, /// Map of metadatas associated with this testcase - metadatas: HashMap<&'static str, Box>, + metadatas: HashMap>, } impl Into>> for Testcase @@ -99,12 +100,12 @@ where } /// Get all the metadatas into an HashMap (mutable) - pub fn metadatas(&mut self) -> &mut HashMap<&'static str, Box> { + pub fn metadatas(&mut self) -> &mut HashMap> { &mut self.metadatas } /// Add a metadata pub fn add_metadata(&mut self, meta: Box) { - self.metadatas.insert(meta.name(), meta); + self.metadatas.insert(meta.name().to_string(), meta); } /// Create a new Testcase instace given an input diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index 8912470ccc..9b1f1e12af 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -106,6 +106,9 @@ where message: String, phantom: PhantomData<(S, C, E, I, R)>, }, + None { + phantom: PhantomData<(S, C, E, I, R)>, + }, //Custom {sender_id: u64, custom_event: CE}, } @@ -122,34 +125,35 @@ where match self { Event::LoadInitial { sender_id: _, - phantom, + phantom: _, } => "Initial", Event::NewTestcase { sender_id: _, testcase: _, - phantom, + phantom: _, } => "New Testcase", Event::UpdateStats { sender_id: _, new_execs: _, - phantom, + phantom: _, } => "Stats", Event::Crash { sender_id: _, input: _, - phantom, + phantom: _, } => "Crash", Event::Timeout { sender_id: _, input: _, - phantom, + phantom: _, } => "Timeout", Event::Log { sender_id: _, severity_level: _, message: _, - phantom, + phantom: _, } => "Log", + Event::None { phantom: _ } => "None", //Event::Custom {sender_id, custom_event} => custom_event.name(), } } @@ -160,16 +164,19 @@ where _corpus: &mut C, ) -> Result { match self { - Event::LoadInitial { sender_id: _, phantom } => Ok(BrokerEventResult::Handled), + Event::LoadInitial { + sender_id: _, + phantom: _, + } => Ok(BrokerEventResult::Handled), Event::NewTestcase { sender_id: _, testcase: _, - phantom, + phantom: _, } => Ok(BrokerEventResult::Forward), Event::UpdateStats { sender_id: _, new_execs: _, - phantom, + phantom: _, } => { // TODO Ok(BrokerEventResult::Handled) @@ -177,12 +184,12 @@ where Event::Crash { sender_id: _, input: _, - phantom, + phantom: _, } => Ok(BrokerEventResult::Handled), Event::Timeout { sender_id: _, input: _, - phantom, + phantom: _, } => { // TODO Ok(BrokerEventResult::Handled) @@ -191,30 +198,38 @@ where sender_id, severity_level, message, - phantom, + phantom: _, } => { //TODO: broker.log() #[cfg(feature = "std")] println!("{}[{}]: {}", sender_id, severity_level, message); Ok(BrokerEventResult::Handled) - } + }, + Event::None { + phantom: _, + } => Ok(BrokerEventResult::Handled) //Event::Custom {sender_id, custom_event} => custom_event.handle_in_broker(state, corpus), //_ => Ok(BrokerEventResult::Forward), } } fn handle_in_client( - &self, + &mut self, /*client: &dyn EventManager,*/ _state: &mut S, corpus: &mut C, ) -> Result<(), AflError> { - match self { + match std::mem::replace( + self, + Event::None { + phantom: PhantomData, + }, + ) { Event::NewTestcase { sender_id: _, testcase, - phantom, + phantom: _, } => { - corpus.add(*testcase); + corpus.add(testcase); Ok(()) } _ => Err(AflError::Unknown( @@ -307,7 +322,7 @@ where } handled .iter() - .zip(self.events.iter()) + .zip(self.events.iter_mut()) .map(|(x, event)| match x { BrokerEventResult::Forward => event.handle_in_client(state, corpus), // Ignore broker-only events diff --git a/afl/src/feedbacks/mod.rs b/afl/src/feedbacks/mod.rs index 91c94f897a..271088cf9c 100644 --- a/afl/src/feedbacks/mod.rs +++ b/afl/src/feedbacks/mod.rs @@ -170,6 +170,8 @@ where pub struct MapNoveltiesMetadata { novelties: Vec, } + +#[typetag::serde] impl TestcaseMetadata for MapNoveltiesMetadata { fn name(&self) -> &'static str { "MapNoveltiesMetadata"