finish DefaultMutationalStage

This commit is contained in:
Andrea Fioraldi 2020-11-04 15:29:46 +01:00
parent 2e711360c1
commit b2a6ddb0dd
2 changed files with 32 additions and 1 deletions

View File

@ -5,6 +5,9 @@ use crate::inputs::Input;
use crate::engines::Engine;
use crate::AflError;
use std::cell::RefCell;
use std::rc::Rc;
pub trait HasEngine<'a, I> where I: Input {
type E : Engine<'a, I>;
@ -15,5 +18,5 @@ pub trait HasEngine<'a, I> where I: Input {
pub trait Stage<'a, I> : HasEngine<'a, I> where I: Input {
/// Run the stage
fn perform(&mut self, entry: &mut Testcase<I>) -> Result<(), AflError>;
fn perform(&mut self, entry: Rc<RefCell<Testcase<I>>>) -> Result<(), AflError>;
}

View File

@ -9,6 +9,8 @@ use crate::engines::Engine;
use std::cell::RefCell;
use std::rc::Rc;
// TODO create HasMutatorsVec trait
pub trait MutationalStage<'a, I> : Stage<'a, I> + HasRand where I: Input {
fn mutators(&self) -> &Vec<Box<dyn Mutator<I, R = Self::R>>>;
@ -72,3 +74,29 @@ impl<'a, I, R, E> HasEngine<'a, I> for DefaultMutationalStage<'a, I, R, E> where
self.engine
}
}
impl<'a, I, R, E> MutationalStage<'a, I> for DefaultMutationalStage<'a, I, R, E> where I: Input, R: Rand, E: Engine<'a, I> {
fn mutators(&self) -> &Vec<Box<dyn Mutator<I, R = Self::R>>> {
&self.mutators
}
fn mutators_mut(&mut self) -> &mut Vec<Box<dyn Mutator<I, R = Self::R>>> {
&mut self.mutators
}
}
impl<'a, I, R, E> Stage<'a, I> for DefaultMutationalStage<'a, I, R, E> where I: Input, R: Rand, E: Engine<'a, I> {
fn perform(&mut self, entry: Rc<RefCell<Testcase<I>>>) -> Result<(), AflError> {
self.perform_mutational(entry)
}
}
impl<'a, I, R, E> DefaultMutationalStage<'a, I, R, E> where I: Input, R: Rand, E: Engine<'a, I> {
pub fn new(rand: &'a mut R, engine: &'a mut E) -> Self {
DefaultMutationalStage {
rand: rand,
engine: engine,
mutators: vec![]
}
}
}