added initialstrages trait
This commit is contained in:
parent
ca1be853e1
commit
c0e803baae
@ -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
|
@ -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>;
|
||||
}
|
||||
|
||||
/// A queue-like corpus
|
||||
@ -74,15 +74,15 @@ impl Corpus for DefaultQueue<'_> {
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
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<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 {
|
||||
|
@ -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(())
|
||||
|
@ -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>;
|
||||
}
|
||||
|
@ -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")]
|
||||
|
@ -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>;
|
||||
}
|
||||
|
15
src/stages/mutational.rs
Normal file
15
src/stages/mutational.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use std::Vec;
|
||||
use crate::mutators::Mutator;
|
||||
use crate::inputs::Input;
|
||||
use c
|
||||
|
||||
struct MutationalStage {
|
||||
mutators: Vec<Box<dyn Mutator>>;
|
||||
}
|
||||
|
||||
impl Stage for MutationalStage {
|
||||
|
||||
fn Perform(&mut self, input: &Input, entry: &mut Entry) -> Result<(), AflError> {
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user