solve conflict

This commit is contained in:
Andrea Fioraldi 2020-10-27 15:26:20 +01:00
commit c5e38d6961
7 changed files with 43 additions and 27 deletions

View File

@ -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

View File

@ -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<dyn Input>, Error>;
fn load_input(&mut self) -> Result<&Box<dyn Input>, AflError>;
fn is_on_disk(&self) -> bool;
fn get_filename(&self) -> &str;
fn get_metadatas(&mut self) -> &mut HashMap<String, Box<dyn TestcaseMetadata>>;
@ -24,10 +24,10 @@ pub trait Corpus: Debug {
fn remove(&mut self, entry: &dyn Testcase) -> Option<Box<dyn Testcase>>;
/// Gets a random entry
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, Error>;
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, AflError>;
/// Gets the next entry
fn get(&mut self) -> Result<&Box<dyn Testcase>, Error>;
fn get(&mut self) -> Result<&Box<dyn Testcase>, AflError>;
}
#[derive(Debug)]
@ -65,13 +65,13 @@ impl Corpus for RandomCorpus<'_> {
}
/// Gets a random entry
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, Error> {
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, 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<dyn Testcase>, Error> {
fn get(&mut self) -> Result<&Box<dyn Testcase>, AflError> {
self.random_entry()
}
}
@ -110,14 +110,14 @@ impl Corpus for QueueCorpus<'_> {
}
/// Gets a random entry
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, Error> {
fn random_entry(&mut self) -> Result<&Box<dyn Testcase>, AflError> {
self.random_corpus.random_entry()
}
/// Gets the next entry
fn get(&mut self) -> Result<&Box<dyn Testcase>, Error> {
fn get(&mut self) -> Result<&Box<dyn Testcase>, AflError> {
if self.count() == 0 {
return Err(Error::Unknown); // TODO(andrea) why unknown? use EmptyContainerError or similar
return Err(AflError::Unknown); // TODO(andrea) why unknown? use EmptyContainerError or similar
}
self.pos = self.pos + 1;
if self.pos >= self.count() {
@ -154,9 +154,9 @@ struct SimpleTestcase {
}
impl Testcase for SimpleTestcase {
fn load_input(&mut self) -> Result<&Box<dyn Input>, Error> {
fn load_input(&mut self) -> Result<&Box<dyn Input>, AflError> {
// TODO: Implement
Err(Error::Unknown)
Err(AflError::Unknown)
}
fn is_on_disk(&self) -> bool {

View File

@ -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(())

View File

@ -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>;
}

View File

@ -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")]

View File

@ -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>;
}

16
src/stages/mutational.rs Normal file
View File

@ -0,0 +1,16 @@
use std::Vec;
use crate::mutators::Mutator;
use crate::inputs::Input;
pub struct MutationalStage {
mutators: Vec<Box<dyn Mutator>>;
}
impl Stage for MutationalStage {
fn Perform(&mut self, input: &Input, entry: &mut Entry) -> Result<(), AflError> {
// TODO: Implement me
Err(AflError::Unknown);
}
}