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