From c0e803baae16deca39ef472e2c47c06d03b4784e Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 27 Oct 2020 15:08:15 +0100 Subject: [PATCH] added initialstrages trait --- Cargo.toml | 5 ----- src/corpus/mod.rs | 18 +++++++++--------- src/inputs/bytes.rs | 6 +++--- src/inputs/mod.rs | 10 +++++----- src/lib.rs | 2 +- src/stages/mod.rs | 9 +++++++-- src/stages/mutational.rs | 15 +++++++++++++++ 7 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 src/stages/mutational.rs diff --git a/Cargo.toml b/Cargo.toml index 92d3d3f2f5..ee4bf652e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,7 @@ edition = "2018" [dev-dependencies] criterion = "0.3" # Benchmarking -[[bench]] -name = "rng_hash_benchmark" -harness = false - [dependencies] xxhash-rust = { version = "0.8.0-beta.4", features = ["xxh3"] } # xxh3 hashing for rust -ahash = "0.5.6" # Fast hashing algorithm thiserror = "1.0" # A nicer way to write Errors hashbrown = "0.9" # A faster hashmap, nostd compatible \ No newline at end of file diff --git a/src/corpus/mod.rs b/src/corpus/mod.rs index f2bfc182c0..bcf045d270 100644 --- a/src/corpus/mod.rs +++ b/src/corpus/mod.rs @@ -1,13 +1,13 @@ use crate::inputs::Input; use crate::utils::Rand; -use crate::Error; +use crate::AflError; use hashbrown::HashMap; use std::fmt::Debug; pub trait TestcaseMetadata: Debug {} pub trait Testcase: Debug { - fn load_input(&mut self) -> Result<&Box, Error>; + fn load_input(&mut self) -> Result<&Box, AflError>; fn is_on_disk(&self) -> bool; fn get_filename(&self) -> &str; fn get_metadatas(&mut self) -> &mut HashMap>; @@ -24,10 +24,10 @@ pub trait Corpus: Debug { fn remove(&mut self, entry: &dyn Testcase) -> Option>; /// Gets a random entry - fn random_entry(&mut self) -> Result<&Box, Error>; + fn random_entry(&mut self) -> Result<&Box, AflError>; /// Gets the next entry - fn get(&mut self) -> Result<&Box, Error>; + fn get(&mut self) -> Result<&Box, AflError>; } /// A queue-like corpus @@ -74,15 +74,15 @@ impl Corpus for DefaultQueue<'_> { } /// Gets a random entry - fn random_entry(&mut self) -> Result<&Box, Error> { + fn random_entry(&mut self) -> Result<&Box, AflError> { let id = self.rand.below(self.entries.len() as u64) as usize; Ok(self.entries.get_mut(id).unwrap()) } /// Gets the next entry - fn get(&mut self) -> Result<&Box, Error> { + fn get(&mut self) -> Result<&Box, AflError> { if self.entries.len() == 0 { - return Err(Error::Unknown); + return Err(AflError::Unknown); } self.pos = self.pos + 1; if self.pos >= self.entries.len() { @@ -123,9 +123,9 @@ struct SimpleTestcase { } impl Testcase for SimpleTestcase { - fn load_input(&mut self) -> Result<&Box, Error> { + fn load_input(&mut self) -> Result<&Box, AflError> { // TODO: Implement - Err(Error::Unknown) + Err(AflError::Unknown) } fn is_on_disk(&self) -> bool { diff --git a/src/inputs/bytes.rs b/src/inputs/bytes.rs index de89983ac6..e2ad2cbd90 100644 --- a/src/inputs/bytes.rs +++ b/src/inputs/bytes.rs @@ -1,5 +1,5 @@ use crate::inputs::Input; -use crate::Error; +use crate::AflError; #[derive(Clone, Debug, Default)] pub struct BytesInput { @@ -7,10 +7,10 @@ pub struct BytesInput { } impl Input for BytesInput { - fn serialize(&self) -> Result<&[u8], Error> { + fn serialize(&self) -> Result<&[u8], AflError> { Ok(&self.bytes) } - fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error> { + fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError> { self.bytes.truncate(0); self.bytes.extend_from_slice(buf); Ok(()) diff --git a/src/inputs/mod.rs b/src/inputs/mod.rs index 8ec6a18831..36c005d4bf 100644 --- a/src/inputs/mod.rs +++ b/src/inputs/mod.rs @@ -4,16 +4,16 @@ use std::fs::File; use std::io::Read; use std::io::Write; -use crate::Error; +use crate::AflError; pub trait Input { - fn to_file(&self, path: &str) -> Result<(), Error> { + fn to_file(&self, path: &str) -> Result<(), AflError> { let mut file = File::create(path)?; file.write_all(self.serialize()?)?; Ok(()) } - fn from_file(&mut self, path: &str) -> Result<(), Error> { + fn from_file(&mut self, path: &str) -> Result<(), AflError> { let mut file = File::create(path)?; let mut buf = vec![]; file.read_to_end(&mut buf)?; @@ -21,7 +21,7 @@ pub trait Input { Ok(()) } - fn serialize(&self) -> Result<&[u8], Error>; + fn serialize(&self) -> Result<&[u8], AflError>; - fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error>; + fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError>; } diff --git a/src/lib.rs b/src/lib.rs index db651e759b..9c6b412040 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ pub mod stages; pub mod utils; #[derive(Error, Debug)] -pub enum Error { +pub enum AflError { #[error("Error in Serialization: `{0}`")] Serialize(String), #[error("File IO failed")] diff --git a/src/stages/mod.rs b/src/stages/mod.rs index 5e219a7374..08e8c61c9e 100644 --- a/src/stages/mod.rs +++ b/src/stages/mod.rs @@ -1,2 +1,7 @@ -//! Stages -pub trait Stage {} +use crate::corpus::Testcase; +use crate::inputs::Input; +use crate::AflError; +/// Stages +pub trait Stage { + fn perform(&mut self, input: &dyn Input, entry: &mut dyn Testcase) -> Result<(), AflError>; +} diff --git a/src/stages/mutational.rs b/src/stages/mutational.rs new file mode 100644 index 0000000000..9e27a27a0d --- /dev/null +++ b/src/stages/mutational.rs @@ -0,0 +1,15 @@ +use std::Vec; +use crate::mutators::Mutator; +use crate::inputs::Input; +use c + +struct MutationalStage { + mutators: Vec>; +} + +impl Stage for MutationalStage { + + fn Perform(&mut self, input: &Input, entry: &mut Entry) -> Result<(), AflError> { + } + +} \ No newline at end of file