diff --git a/afl/src/corpus/mod.rs b/afl/src/corpus/mod.rs index 8a000cfadd..95fc939cba 100644 --- a/afl/src/corpus/mod.rs +++ b/afl/src/corpus/mod.rs @@ -1,11 +1,12 @@ pub mod testcase; -pub use testcase::{Testcase, TestcaseMetadata}; +pub use testcase::{Testcase}; use alloc::borrow::ToOwned; use alloc::vec::Vec; use core::cell::RefCell; use core::marker::PhantomData; use core::ptr; +use serde::{Serialize, Deserialize}; #[cfg(feature = "std")] use std::path::PathBuf; @@ -27,7 +28,7 @@ where } /// Corpus with all current testcases -pub trait Corpus: HasTestcaseVec +pub trait Corpus: HasTestcaseVec + serde::Serialize + serde::de::DeserializeOwned where I: Input, R: Rand, @@ -118,6 +119,8 @@ where } /// A corpus handling all important fuzzing in memory. +#[derive(Serialize, Deserialize)] +#[serde(bound = "I: serde::de::DeserializeOwned")] pub struct InMemoryCorpus where I: Input, @@ -182,6 +185,8 @@ where /// A corpus able to store testcases to dis, and load them from disk, when they are being used. #[cfg(feature = "std")] +#[derive(Serialize, Deserialize)] +#[serde(bound = "I: serde::de::DeserializeOwned")] pub struct OnDiskCorpus where I: Input, @@ -268,6 +273,8 @@ where } /// A Queue-like corpus, wrapping an existing Corpus instance +#[derive(Serialize, Deserialize)] +#[serde(bound = "I: serde::de::DeserializeOwned")] pub struct QueueCorpus where C: Corpus, diff --git a/afl/src/corpus/testcase.rs b/afl/src/corpus/testcase.rs index 3d0730ac74..c529ad78cd 100644 --- a/afl/src/corpus/testcase.rs +++ b/afl/src/corpus/testcase.rs @@ -14,35 +14,6 @@ use crate::AflError; //#[cfg(feature = "std")] //use std::path::PathBuf; -// TODO: Give example -/// Metadata for a testcase -pub trait TestcaseMetadata: SerdeAny { - /// The name of this metadata - used to find it in the list of avaliable metadatas - fn name(&self) -> &'static str; -} - -/* -/// Just a wrapper of Boxed TestcaseMetadata trait object for Clone -#[derive(Serialize, Deserialize)] -pub struct TestcaseMetadataContainer { - meta: Box, -} -impl Clone for TestcaseMetadataContainer { - fn clone(&self) -> Self { - TestcaseMetadataContainer { - meta: self.meta.clone(), - } - } -} -impl TestcaseMetadataContainer { - pub fn meta(&self) -> &Box { - &self.meta - } - pub fn meta_mut(&mut self) -> &mut Box { - &mut self.meta - } -}*/ - /// An entry in the Testcase Corpus #[derive(Default, Serialize, Deserialize)] #[serde(bound = "I: serde::de::DeserializeOwned")] @@ -145,9 +116,9 @@ where /// Add a metadata #[inline] - pub fn add_metadata(&mut self, meta: TM) + pub fn add_metadata(&mut self, meta: M) where - TM: TestcaseMetadata + 'static, + M: SerdeAny, { self.metadatas.insert(meta); } diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index 7add828037..2a88d09407 100644 --- a/afl/src/engines/mod.rs +++ b/afl/src/engines/mod.rs @@ -1,9 +1,8 @@ //! The engine is the core piece of every good fuzzer -use alloc::boxed::Box; use core::fmt::Debug; use core::marker::PhantomData; -use hashbrown::HashMap; +use serde::{Serialize, Deserialize}; use crate::corpus::{Corpus, Testcase}; use crate::events::EventManager; @@ -13,6 +12,7 @@ use crate::generators::Generator; use crate::inputs::Input; use crate::observers::ObserversTuple; use crate::stages::StagesTuple; +use crate::serde_anymap::{SerdeAny, SerdeAnyMap}; use crate::tuples::{tuple_list, tuple_list_type}; use crate::utils::{current_milliseconds, Rand}; use crate::AflError; @@ -23,6 +23,8 @@ pub trait StateMetadata: Debug { } /// The state a fuzz run. +#[derive(Serialize, Deserialize)] +#[serde(bound = "FT: serde::de::DeserializeOwned")] pub struct State where I: Input, @@ -35,8 +37,9 @@ where /// At what time the fuzzing started start_time: u64, /// Metadata stored for this state by one of the components - metadatas: HashMap<&'static str, Box>, - // additional_corpuses: HashMap<&'static str, Box>, + metadatas: SerdeAnyMap, + // additional_corpuses, maybe another TupleList? + // Feedbacks used to evaluate an input feedbacks: FT, phantom: PhantomData<(I, R, OT)>, } @@ -86,20 +89,23 @@ where /// Get all the metadatas into an HashMap #[inline] - pub fn metadatas(&self) -> &HashMap<&'static str, Box> { + pub fn metadatas(&self) -> &SerdeAnyMap { &self.metadatas } /// Get all the metadatas into an HashMap (mutable) #[inline] - pub fn metadatas_mut(&mut self) -> &mut HashMap<&'static str, Box> { + pub fn metadatas_mut(&mut self) -> &mut SerdeAnyMap { &mut self.metadatas } /// Add a metadata #[inline] - pub fn add_metadata(&mut self, meta: Box) { - self.metadatas_mut().insert(meta.name(), meta); + pub fn add_metadata(&mut self, meta: M) + where + M: SerdeAny, + { + self.metadatas.insert(meta); } /// Returns vector of feebacks @@ -225,7 +231,7 @@ where Self { executions: 0, start_time: current_milliseconds(), - metadatas: HashMap::default(), + metadatas: SerdeAnyMap::default(), feedbacks: feedbacks, phantom: PhantomData, } @@ -405,9 +411,6 @@ where #[cfg(test)] mod tests { - #[cfg(feature = "std")] - use std::io::stderr; - use crate::corpus::{Corpus, InMemoryCorpus, Testcase}; use crate::engines::{Engine, Fuzzer, State, StdFuzzer}; #[cfg(feature = "std")] diff --git a/afl/src/events/shmem_translated.rs b/afl/src/events/shmem_translated.rs index 1a9a06e86b..3177b0d5b1 100644 --- a/afl/src/events/shmem_translated.rs +++ b/afl/src/events/shmem_translated.rs @@ -4,21 +4,13 @@ use std::{ffi::CStr, mem::size_of}; use crate::AflError; extern "C" { - #[no_mangle] fn snprintf(_: *mut c_char, _: c_ulong, _: *const c_char, _: ...) -> c_int; - #[no_mangle] fn strncpy(_: *mut c_char, _: *const c_char, _: c_ulong) -> *mut c_char; - #[no_mangle] - fn strlen(_: *const c_char) -> c_ulong; - #[no_mangle] + //fn strlen(_: *const c_char) -> c_ulong; fn shmctl(__shmid: c_int, __cmd: c_int, __buf: *mut shmid_ds) -> c_int; - #[no_mangle] fn shmget(__key: c_int, __size: c_ulong, __shmflg: c_int) -> c_int; - #[no_mangle] fn shmat(__shmid: c_int, __shmaddr: *const c_void, __shmflg: c_int) -> *mut c_void; - #[no_mangle] - fn strtol(_: *const c_char, _: *mut *mut c_char, _: c_int) -> c_long; - #[no_mangle] + //fn strtol(_: *const c_char, _: *mut *mut c_char, _: c_int) -> c_long; fn setenv(__name: *const c_char, __value: *const c_char, __replace: c_int) -> c_int; } #[derive(Copy, Clone)]