From 0d39314324d910a616aec2b245a9b08a5b810066 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Tue, 23 Feb 2021 20:36:23 +0100 Subject: [PATCH] remove old corpus mod --- libafl/src/corpus/mod old.rs | 103 ----------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 libafl/src/corpus/mod old.rs diff --git a/libafl/src/corpus/mod old.rs b/libafl/src/corpus/mod old.rs deleted file mode 100644 index 86eeaf961f..0000000000 --- a/libafl/src/corpus/mod old.rs +++ /dev/null @@ -1,103 +0,0 @@ -//! Corpuses contain the testcases, either in mem, on disk, or somewhere else. -//! They will hand out the next fuzz target, potentially doing basic scheduling. - -pub mod testcase; -pub use testcase::Testcase; - -pub mod inmemory; -pub use inmemory::InMemoryCorpus; - -#[cfg(feature = "std")] -pub mod ondisk; -#[cfg(feature = "std")] -pub use ondisk::OnDiskCorpus; - -pub mod queue; -pub use queue::QueueCorpus; - -use alloc::{borrow::ToOwned, vec::Vec}; -use core::{cell::RefCell, ptr}; - -use crate::{inputs::Input, utils::Rand, Error}; - -/// A way to obtain the containing testcase entries -pub trait HasTestcaseVec -where - I: Input, -{ - /// Get the entries vector field - fn entries(&self) -> &[RefCell>]; - - /// Get the entries vector field (mutable) - fn entries_mut(&mut self) -> &mut Vec>>; -} - -/// Corpus with all current testcases -pub trait Corpus: HasTestcaseVec + serde::Serialize + serde::de::DeserializeOwned -where - I: Input, - R: Rand, -{ - /// Returns the number of elements - #[inline] - fn count(&self) -> usize { - self.entries().len() - } - - // TODO implement a was_fuzzed counter - - /// Add an entry to the corpus and return its index - #[inline] - fn add(&mut self, testcase: Testcase) -> usize { - self.entries_mut().push(RefCell::new(testcase)); - self.entries().len() - 1 - } - - /// Replaces the testcase at the given idx - fn replace(&mut self, idx: usize, testcase: Testcase) -> Result<(), Error> { - if self.entries_mut().len() < idx { - return Err(Error::KeyNotFound(format!("Index {} out of bounds", idx))); - } - self.entries_mut()[idx] = RefCell::new(testcase); - Ok(()) - } - - /// Get by id - #[inline] - fn get(&self, idx: usize) -> &RefCell> { - &self.entries()[idx] - } - - /// Removes an entry from the corpus, returning it if it was present. - #[inline] - fn remove(&mut self, entry: &Testcase) -> Option> { - match self - .entries() - .iter() - .position(|x| ptr::eq(x.as_ptr(), entry)) - { - Some(i) => Some(self.entries_mut().remove(i).into_inner()), - None => None, - } - } - - /// Gets a random entry - #[inline] - fn random_entry(&self, rand: &mut R) -> Result<(&RefCell>, usize), Error> { - if self.count() == 0 { - Err(Error::Empty("No entries in corpus".to_owned())) - } else { - let len = { self.entries().len() }; - let id = rand.below(len as u64) as usize; - Ok((self.get(id), id)) - } - } - - // TODO: IntoIter - /// Gets the next entry - fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), Error>; - - /// Returns the testacase we currently use - fn current_testcase(&self) -> (&RefCell>, usize); -} -