working refactoring with observers
This commit is contained in:
parent
de4fb23f31
commit
9111fdcf22
@ -24,10 +24,8 @@ pub trait StateMetadata: Debug {
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
pub struct State<C, E, I, R>
|
||||
pub struct State<I, R>
|
||||
where
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
@ -35,16 +33,12 @@ where
|
||||
start_time: u64,
|
||||
metadatas: HashMap<&'static str, Box<dyn StateMetadata>>,
|
||||
// additional_corpuses: HashMap<&'static str, Box<dyn Corpus>>,
|
||||
observers: Vec<Rc<RefCell<dyn Observer>>>,
|
||||
feedbacks: Vec<Box<dyn Feedback<I>>>,
|
||||
executor: E,
|
||||
phantom: PhantomData<(C, R)>,
|
||||
phantom: PhantomData<R>,
|
||||
}
|
||||
|
||||
impl<C, E, I, R> State<C, E, I, R>
|
||||
impl<I, R> State<I, R>
|
||||
where
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
@ -108,10 +102,13 @@ where
|
||||
self.feedbacks_mut().push(feedback);
|
||||
}
|
||||
|
||||
// TODO move some of these, like evaluate_input, to FuzzingEngine
|
||||
|
||||
/// Runs the input and triggers observers and feedback
|
||||
pub fn evaluate_input<FE, EM>(&mut self, input: &I, engine: &FE) -> Result<u32, AflError>
|
||||
pub fn evaluate_input<C, E, EM>(&mut self, input: &I, engine: &mut Engine<EM, E, C, I, R>) -> Result<u32, AflError>
|
||||
where
|
||||
FE: FuzzingEngine<EM, E, C, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
{
|
||||
engine.executor_mut().reset_observers()?;
|
||||
@ -120,7 +117,7 @@ where
|
||||
engine.executor_mut().post_exec_observers()?;
|
||||
|
||||
let mut fitness = 0;
|
||||
let observers = self.executor().observers();
|
||||
let observers = engine.executor().observers();
|
||||
for feedback in self.feedbacks_mut() {
|
||||
fitness += feedback.is_interesting(&input, observers)?;
|
||||
}
|
||||
@ -162,12 +159,15 @@ where
|
||||
}
|
||||
|
||||
/// Adds this input to the corpus, if it's intersting
|
||||
pub fn add_if_interesting(
|
||||
pub fn add_if_interesting<C>(
|
||||
&mut self,
|
||||
corpus: &mut C,
|
||||
input: I,
|
||||
fitness: u32,
|
||||
) -> Result<Option<usize>, AflError> {
|
||||
) -> Result<Option<usize>, AflError>
|
||||
where
|
||||
C: Corpus<I, R>
|
||||
{
|
||||
if fitness > 0 {
|
||||
let testcase = self.input_to_testcase(input, fitness)?;
|
||||
Ok(Some(corpus.add(testcase)))
|
||||
@ -177,45 +177,95 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_initial_inputs<G, EM>(
|
||||
pub fn generate_initial_inputs<G, C, E, FE, EM>(
|
||||
&mut self,
|
||||
rand: &mut R,
|
||||
corpus: &mut C,
|
||||
generator: &mut G,
|
||||
events: &mut EM,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
num: usize,
|
||||
) -> Result<(), AflError>
|
||||
where
|
||||
G: Generator<I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
{
|
||||
for _ in 0..num {
|
||||
let input = generator.generate(rand)?;
|
||||
let fitness = self.evaluate_input(&input)?;
|
||||
let fitness = self.evaluate_input(&input, engine)?;
|
||||
self.add_if_interesting(corpus, input, fitness)?;
|
||||
events.fire(Event::LoadInitial {
|
||||
engine.events_manager_mut().fire(Event::LoadInitial {
|
||||
sender_id: 0,
|
||||
phantom: PhantomData,
|
||||
})?;
|
||||
}
|
||||
events.process(self, corpus)?;
|
||||
engine.events_manager_mut().process(self, corpus)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new(executor: E) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
executions: 0,
|
||||
start_time: current_milliseconds(),
|
||||
metadatas: HashMap::default(),
|
||||
observers: vec![],
|
||||
feedbacks: vec![],
|
||||
executor: executor,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FuzzingEngine<EM, E, C, I, R>
|
||||
pub struct Engine<EM, E, C, I, R>
|
||||
where
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
manager: EM,
|
||||
executor: E,
|
||||
phantom: PhantomData<(C, I, R)>
|
||||
}
|
||||
|
||||
impl<EM, E, C, I, R> Engine<EM, E, C, I, R>
|
||||
where
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
pub fn events_manager(&self) -> &EM {
|
||||
&self.manager
|
||||
}
|
||||
|
||||
pub fn events_manager_mut(&mut self) -> &mut EM {
|
||||
&mut self.manager
|
||||
}
|
||||
|
||||
/// Return the executor
|
||||
pub fn executor(&self) -> &E {
|
||||
&self.executor
|
||||
}
|
||||
|
||||
/// Return the executor (mutable)
|
||||
pub fn executor_mut(&mut self) -> &mut E {
|
||||
&mut self.executor
|
||||
}
|
||||
|
||||
// TODO additional executors, Vec<Box<dyn Executor<I>>>
|
||||
|
||||
pub fn new(executor: E, events_manager: EM) -> Self {
|
||||
Self {
|
||||
executor: executor,
|
||||
manager: events_manager,
|
||||
phantom: PhantomData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Fuzzer<EM, E, C, I, R>
|
||||
where
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
@ -231,24 +281,12 @@ where
|
||||
self.stages_mut().push(stage);
|
||||
}
|
||||
|
||||
fn events_manager(&self) -> &EM;
|
||||
|
||||
fn events_manager_mut(&mut self) -> &mut EM;
|
||||
|
||||
/// Return the executor
|
||||
fn executor(&self) -> &E;
|
||||
|
||||
/// Return the executor (mutable)
|
||||
fn executor_mut(&mut self) -> &mut E;
|
||||
|
||||
// TODO additional executors, Vec<Box<dyn Executor<I>>>
|
||||
|
||||
fn fuzz_one(
|
||||
&mut self,
|
||||
rand: &mut R,
|
||||
state: &mut State<C, E, I, R>,
|
||||
state: &mut State<I, R>,
|
||||
corpus: &mut C,
|
||||
events: &mut EM,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
) -> Result<usize, AflError> {
|
||||
let (testcase, idx) = corpus.next(rand)?;
|
||||
match testcase.input() {
|
||||
@ -262,27 +300,27 @@ where
|
||||
let input = corpus.get(idx).input().as_ref().unwrap();
|
||||
|
||||
for stage in self.stages_mut() {
|
||||
stage.perform(rand, state, corpus, events, &input)?;
|
||||
stage.perform(rand, state, corpus, engine, &input)?;
|
||||
}
|
||||
|
||||
events.process(state, corpus)?;
|
||||
engine.events_manager_mut().process(state, corpus)?;
|
||||
Ok(idx)
|
||||
}
|
||||
|
||||
fn fuzz_loop(
|
||||
&mut self,
|
||||
rand: &mut R,
|
||||
state: &mut State<C, E, I, R>,
|
||||
state: &mut State<I, R>,
|
||||
corpus: &mut C,
|
||||
events: &mut EM,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
) -> Result<(), AflError> {
|
||||
let mut last = current_milliseconds();
|
||||
loop {
|
||||
self.fuzz_one(rand, state, corpus, events)?;
|
||||
self.fuzz_one(rand, state, corpus, engine)?;
|
||||
let cur = current_milliseconds();
|
||||
if cur - last > 60 * 100 {
|
||||
last = cur;
|
||||
events.fire(Event::UpdateStats {
|
||||
engine.events_manager_mut().fire(Event::UpdateStats {
|
||||
sender_id: 0,
|
||||
new_execs: 1,
|
||||
phantom: PhantomData,
|
||||
@ -290,9 +328,10 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct StdFuzzingEngine<EM, E, C, I, R>
|
||||
pub struct StdFuzzer<EM, E, C, I, R>
|
||||
where
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
@ -301,10 +340,9 @@ where
|
||||
R: Rand,
|
||||
{
|
||||
stages: Vec<Box<dyn Stage<EM, E, C, I, R>>>,
|
||||
phantom: PhantomData<EM>,
|
||||
}
|
||||
|
||||
impl<EM, E, C, I, R> FuzzingEngine<EM, E, C, I, R> for StdFuzzingEngine<EM, E, C, I, R>
|
||||
impl<EM, E, C, I, R> Fuzzer<EM, E, C, I, R> for StdFuzzer<EM, E, C, I, R>
|
||||
where
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
@ -321,7 +359,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<EM, E, C, I, R> StdFuzzingEngine<EM, E, C, I, R>
|
||||
impl<EM, E, C, I, R> StdFuzzer<EM, E, C, I, R>
|
||||
where
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
@ -331,12 +369,12 @@ where
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
stages: vec![],
|
||||
phantom: PhantomData,
|
||||
stages: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: no_std test
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(test)]
|
||||
@ -348,7 +386,7 @@ mod tests {
|
||||
use std::io::stderr;
|
||||
|
||||
use crate::corpus::{Corpus, InMemoryCorpus, Testcase};
|
||||
use crate::engines::{Engine, StdEngine, StdState};
|
||||
use crate::engines::{Engine, Fuzzer, StdFuzzer, State};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::events::LoggerEventManager;
|
||||
use crate::executors::inmemory::InMemoryExecutor;
|
||||
@ -371,21 +409,22 @@ mod tests {
|
||||
corpus.add(testcase);
|
||||
|
||||
let executor = InMemoryExecutor::<BytesInput>::new(harness);
|
||||
let mut state = StdState::new(executor);
|
||||
let mut state = State::new();
|
||||
|
||||
let mut events_manager = LoggerEventManager::new(stderr());
|
||||
|
||||
let mut engine = StdEngine::new();
|
||||
let mut engine = Engine::new(executor, events_manager);
|
||||
let mut mutator = StdScheduledMutator::new();
|
||||
mutator.add_mutation(mutation_bitflip);
|
||||
let stage = StdMutationalStage::new(mutator);
|
||||
engine.add_stage(Box::new(stage));
|
||||
let mut fuzzer = StdFuzzer::new();
|
||||
fuzzer.add_stage(Box::new(stage));
|
||||
|
||||
//
|
||||
|
||||
for i in 0..1000 {
|
||||
engine
|
||||
.fuzz_one(&mut rand, &mut state, &mut corpus, &mut events_manager)
|
||||
fuzzer
|
||||
.fuzz_one(&mut rand, &mut state, &mut corpus, &mut engine)
|
||||
.expect(&format!("Error in iter {}", i));
|
||||
}
|
||||
}
|
||||
|
@ -60,35 +60,33 @@ pub unsafe fn llmp_tcp_server_clientloop(client: *mut LlmpClient, _data: *mut c_
|
||||
|
||||
/// Eventmanager for multi-processed application
|
||||
#[cfg(feature = "std")]
|
||||
pub struct LLMPEventManager<S, C, E, I, R>
|
||||
pub struct LLMPEventManager<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
E: Executor<I>,
|
||||
R: Rand,
|
||||
//CE: CustomEvent<S, C, E, I, R>,
|
||||
//CE: CustomEvent<C, E, I, R>,
|
||||
{
|
||||
// TODO...
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
is_broker: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<S, C, E, I, R> EventManager<S, C, E, I, R> for LLMPEventManager<S, C, E, I, R>
|
||||
impl<C, E, I, R> EventManager<C, E, I, R> for LLMPEventManager<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
//CE: CustomEvent<S, C, E, I, R>,
|
||||
//CE: CustomEvent<C, E, I, R>,
|
||||
{
|
||||
fn enabled(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn fire(&mut self, _event: Event<S, C, E, I, R>) -> Result<(), AflError> {
|
||||
fn fire(&mut self, _event: Event<C, E, I, R>) -> Result<(), AflError> {
|
||||
//self.events.push(event);
|
||||
|
||||
// TODO: Serde serialize, llmp send
|
||||
@ -96,7 +94,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process(&mut self, _state: &mut S, _corpus: &mut C) -> Result<usize, AflError> {
|
||||
fn process(&mut self, _state: &mut State<I, R>, _corpus: &mut C) -> Result<usize, AflError> {
|
||||
// TODO: iterators
|
||||
/*
|
||||
let mut handled = vec![];
|
||||
@ -127,9 +125,8 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<S, C, E, I, R> LLMPEventManager<S, C, E, I, R>
|
||||
impl<C, E, I, R> LLMPEventManager<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
E: Executor<I>,
|
||||
|
@ -34,9 +34,9 @@ enum BrokerEventResult {
|
||||
/*
|
||||
|
||||
/// A custom event, in case a user wants to extend the features (at compile time)
|
||||
pub trait CustomEvent<S, C, E, I, R>
|
||||
pub trait CustomEvent<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
S: State<I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
@ -45,81 +45,79 @@ where
|
||||
/// Returns the name of this event
|
||||
fn name(&self) -> &str;
|
||||
/// This method will be called in the broker
|
||||
fn handle_in_broker(&self, broker: &dyn EventManager<S, C, E, I, R, Self>, state: &mut S, corpus: &mut C) -> Result<BrokerEventResult, AflError>;
|
||||
fn handle_in_broker(&self, broker: &dyn EventManager<C, E, I, R, Self>, state: &mut State<I, R>, corpus: &mut C) -> Result<BrokerEventResult, AflError>;
|
||||
/// This method will be called in the clients after handle_in_broker (unless BrokerEventResult::Handled) was returned in handle_in_broker
|
||||
fn handle_in_client(&self, client: &dyn EventManager<S, C, E, I, R, Self>, state: &mut S, corpus: &mut C) -> Result<(), AflError>;
|
||||
fn handle_in_client(&self, client: &dyn EventManager<C, E, I, R, Self>, state: &mut State<I, R>, corpus: &mut C) -> Result<(), AflError>;
|
||||
}
|
||||
|
||||
struct UnusedCustomEvent {}
|
||||
impl<S, C, E, I, R> CustomEvent<S, C, E, I, R> for UnusedCustomEvent<S, C, E, I, R>
|
||||
impl<C, E, I, R> CustomEvent<C, E, I, R> for UnusedCustomEvent<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
S: State<I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
fn name(&self) -> &str {"No custom events"}
|
||||
fn handle_in_broker(&self, broker: &dyn EventManager<S, C, E, I, R, Self>, state: &mut S, corpus: &mut C) {Ok(BrokerEventResult::Handled)}
|
||||
fn handle_in_client(&self, client: &dyn EventManager<S, C, E, I, R, Self>, state: &mut S, corpus: &mut C) {Ok(())}
|
||||
fn handle_in_broker(&self, broker: &dyn EventManager<C, E, I, R, Self>, state: &mut State<I, R>, corpus: &mut C) {Ok(BrokerEventResult::Handled)}
|
||||
fn handle_in_client(&self, client: &dyn EventManager<C, E, I, R, Self>, state: &mut State<I, R>, corpus: &mut C) {Ok(())}
|
||||
}
|
||||
*/
|
||||
|
||||
/// Events sent around in the library
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum Event<S, C, E, I, R>
|
||||
pub enum Event<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
// CE: CustomEvent<S, C, E, I, R>,
|
||||
// CE: CustomEvent<C, E, I, R>,
|
||||
{
|
||||
LoadInitial {
|
||||
sender_id: u64,
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
NewTestcase {
|
||||
sender_id: u64,
|
||||
testcase: Testcase<I>,
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
UpdateStats {
|
||||
sender_id: u64,
|
||||
new_execs: usize,
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
Crash {
|
||||
sender_id: u64,
|
||||
input: I,
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
Timeout {
|
||||
sender_id: u64,
|
||||
input: I,
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
Log {
|
||||
sender_id: u64,
|
||||
severity_level: u8,
|
||||
message: String,
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
None {
|
||||
phantom: PhantomData<(S, C, E, I, R)>,
|
||||
phantom: PhantomData<(C, E, I, R)>,
|
||||
},
|
||||
//Custom {sender_id: u64, custom_event: CE},
|
||||
}
|
||||
|
||||
impl<S, C, E, I, R> Event<S, C, E, I, R>
|
||||
impl<C, E, I, R> Event<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
//CE: CustomEvent<S, C, E, I, R>,
|
||||
//CE: CustomEvent<C, E, I, R>,
|
||||
{
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
@ -160,7 +158,7 @@ where
|
||||
|
||||
fn handle_in_broker(
|
||||
&self,
|
||||
/*broker: &dyn EventManager<S, C, E, I, R>,*/ _state: &mut S,
|
||||
/*broker: &dyn EventManager<C, E, I, R>,*/ _state: &mut State<I, R>,
|
||||
_corpus: &mut C,
|
||||
) -> Result<BrokerEventResult, AflError> {
|
||||
match self {
|
||||
@ -215,7 +213,7 @@ where
|
||||
|
||||
fn handle_in_client(
|
||||
self,
|
||||
/*client: &dyn EventManager<S, C, E, I, R>,*/ _state: &mut S,
|
||||
/*client: &dyn EventManager<C, E, I, R>,*/ _state: &mut State<I, R>,
|
||||
corpus: &mut C,
|
||||
) -> Result<(), AflError> {
|
||||
match self {
|
||||
@ -236,9 +234,8 @@ where
|
||||
// TODO serialize and deserialize, defaults to serde
|
||||
}
|
||||
|
||||
pub trait EventManager<S, C, E, I, R>
|
||||
pub trait EventManager<C, E, I, R>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
@ -249,13 +246,13 @@ where
|
||||
fn enabled(&self) -> bool;
|
||||
|
||||
/// Fire an Event
|
||||
fn fire(&mut self, event: Event<S, C, E, I, R>) -> Result<(), AflError>;
|
||||
fn fire(&mut self, event: Event<C, E, I, R>) -> Result<(), AflError>;
|
||||
|
||||
/// Lookup for incoming events and process them.
|
||||
/// Return the number of processes events or an error
|
||||
fn process(&mut self, state: &mut S, corpus: &mut C) -> Result<usize, AflError>;
|
||||
fn process(&mut self, state: &mut State<I, R>, corpus: &mut C) -> Result<usize, AflError>;
|
||||
|
||||
fn on_recv(&self, _state: &mut S, _corpus: &mut C) -> Result<(), AflError> {
|
||||
fn on_recv(&self, _state: &mut State<I, R>, _corpus: &mut C) -> Result<(), AflError> {
|
||||
// TODO: Better way to move out of testcase, or get ref
|
||||
//Ok(corpus.add(self.testcase.take().unwrap()))
|
||||
Ok(())
|
||||
@ -263,7 +260,7 @@ where
|
||||
}
|
||||
|
||||
/*TODO
|
||||
fn on_recv(&self, state: &mut S, _corpus: &mut C) -> Result<(), AflError> {
|
||||
fn on_recv(&self, state: &mut State<I, R>, _corpus: &mut C) -> Result<(), AflError> {
|
||||
println!(
|
||||
"#{}\t exec/s: {}",
|
||||
state.executions(),
|
||||
@ -275,41 +272,39 @@ where
|
||||
*/
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub struct LoggerEventManager<S, C, E, I, R, W>
|
||||
pub struct LoggerEventManager<C, E, I, R, W>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
E: Executor<I>,
|
||||
R: Rand,
|
||||
W: Write,
|
||||
//CE: CustomEvent<S, C, E, I, R>,
|
||||
//CE: CustomEvent<C, E, I, R>,
|
||||
{
|
||||
events: Vec<Event<S, C, E, I, R>>,
|
||||
events: Vec<Event<C, E, I, R>>,
|
||||
writer: W,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<S, C, E, I, R, W> EventManager<S, C, E, I, R> for LoggerEventManager<S, C, E, I, R, W>
|
||||
impl<C, E, I, R, W> EventManager<C, E, I, R> for LoggerEventManager<C, E, I, R, W>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
W: Write,
|
||||
//CE: CustomEvent<S, C, E, I, R>,
|
||||
//CE: CustomEvent<C, E, I, R>,
|
||||
{
|
||||
fn enabled(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn fire(&mut self, event: Event<S, C, E, I, R>) -> Result<(), AflError> {
|
||||
fn fire(&mut self, event: Event<C, E, I, R>) -> Result<(), AflError> {
|
||||
self.events.push(event);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process(&mut self, state: &mut S, corpus: &mut C) -> Result<usize, AflError> {
|
||||
fn process(&mut self, state: &mut State<I, R>, corpus: &mut C) -> Result<usize, AflError> {
|
||||
// TODO: iterators
|
||||
let mut handled = vec![];
|
||||
for x in self.events.iter() {
|
||||
@ -330,9 +325,8 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<S, C, E, I, R, W> LoggerEventManager<S, C, E, I, R, W>
|
||||
impl<C, E, I, R, W> LoggerEventManager<C, E, I, R, W>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
E: Executor<I>,
|
||||
|
@ -2,7 +2,7 @@ pub mod mutational;
|
||||
pub use mutational::StdMutationalStage;
|
||||
|
||||
use crate::corpus::Corpus;
|
||||
use crate::engines::State;
|
||||
use crate::engines::{Engine, State};
|
||||
use crate::events::EventManager;
|
||||
use crate::executors::Executor;
|
||||
use crate::inputs::Input;
|
||||
@ -21,9 +21,9 @@ where
|
||||
fn perform(
|
||||
&mut self,
|
||||
rand: &mut R,
|
||||
state: &mut State<C, E, I, R>,
|
||||
state: &mut State<I, R>,
|
||||
corpus: &C,
|
||||
events: &mut EM,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
input: &I,
|
||||
) -> Result<(), AflError>;
|
||||
}
|
||||
|
@ -5,18 +5,17 @@ use crate::executors::Executor;
|
||||
use crate::inputs::Input;
|
||||
use crate::mutators::Mutator;
|
||||
use crate::stages::Corpus;
|
||||
use crate::stages::Stage;
|
||||
use crate::stages::{Engine, Stage};
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
use crate::{engines::State, events::Event};
|
||||
|
||||
// TODO multi mutators stage
|
||||
|
||||
pub trait MutationalStage<M, S, EM, E, C, I, R>: Stage<S, EM, E, C, I, R>
|
||||
pub trait MutationalStage<M, EM, E, C, I, R>: Stage<EM, E, C, I, R>
|
||||
where
|
||||
M: Mutator<C, I, R>,
|
||||
S: State<C, E, I, R>,
|
||||
EM: EventManager<S, C, E, I, R>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
@ -38,9 +37,9 @@ where
|
||||
fn perform_mutational(
|
||||
&mut self,
|
||||
rand: &mut R,
|
||||
state: &mut S,
|
||||
state: &mut State<I, R>,
|
||||
corpus: &C,
|
||||
events: &mut EM,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
input: &I,
|
||||
) -> Result<(), AflError> {
|
||||
let num = self.iterations(rand);
|
||||
@ -49,7 +48,7 @@ where
|
||||
self.mutator_mut()
|
||||
.mutate(rand, corpus, &mut input_mut, i as i32)?;
|
||||
|
||||
let fitness = state.evaluate_input(&input_mut)?;
|
||||
let fitness = state.evaluate_input(&input_mut, engine)?;
|
||||
|
||||
self.mutator_mut()
|
||||
.post_exec(fitness, &input_mut, i as i32)?;
|
||||
@ -57,7 +56,7 @@ where
|
||||
let testcase_maybe = state.testcase_if_interesting(input_mut, fitness)?;
|
||||
if let Some(testcase) = testcase_maybe {
|
||||
//corpus.entries()[idx]
|
||||
events.fire(Event::NewTestcase {
|
||||
engine.events_manager_mut().fire(Event::NewTestcase {
|
||||
sender_id: 0,
|
||||
testcase: testcase,
|
||||
phantom: PhantomData,
|
||||
@ -69,26 +68,24 @@ where
|
||||
}
|
||||
|
||||
/// The default mutational stage
|
||||
pub struct StdMutationalStage<M, S, EM, E, C, I, R>
|
||||
pub struct StdMutationalStage<M, EM, E, C, I, R>
|
||||
where
|
||||
M: Mutator<C, I, R>,
|
||||
S: State<C, E, I, R>,
|
||||
EM: EventManager<S, C, E, I, R>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
mutator: M,
|
||||
phantom: PhantomData<(S, EM, E, C, I, R)>,
|
||||
phantom: PhantomData<(EM, E, C, I, R)>,
|
||||
}
|
||||
|
||||
impl<M, S, EM, E, C, I, R> MutationalStage<M, S, EM, E, C, I, R>
|
||||
for StdMutationalStage<M, S, EM, E, C, I, R>
|
||||
impl<M, EM, E, C, I, R> MutationalStage<M, EM, E, C, I, R>
|
||||
for StdMutationalStage<M, EM, E, C, I, R>
|
||||
where
|
||||
M: Mutator<C, I, R>,
|
||||
S: State<C, E, I, R>,
|
||||
EM: EventManager<S, C, E, I, R>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
@ -105,11 +102,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, S, EM, E, C, I, R> Stage<S, EM, E, C, I, R> for StdMutationalStage<M, S, EM, E, C, I, R>
|
||||
impl<M, EM, E, C, I, R> Stage<EM, E, C, I, R> for StdMutationalStage<M, EM, E, C, I, R>
|
||||
where
|
||||
M: Mutator<C, I, R>,
|
||||
S: State<C, E, I, R>,
|
||||
EM: EventManager<S, C, E, I, R>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
@ -118,20 +114,19 @@ where
|
||||
fn perform(
|
||||
&mut self,
|
||||
rand: &mut R,
|
||||
state: &mut S,
|
||||
state: &mut State<I, R>,
|
||||
corpus: &C,
|
||||
events: &mut EM,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
input: &I,
|
||||
) -> Result<(), AflError> {
|
||||
self.perform_mutational(rand, state, corpus, events, input)
|
||||
self.perform_mutational(rand, state, corpus, engine, input)
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, S, EM, E, C, I, R> StdMutationalStage<M, S, EM, E, C, I, R>
|
||||
impl<M, EM, E, C, I, R> StdMutationalStage<M, EM, E, C, I, R>
|
||||
where
|
||||
M: Mutator<C, I, R>,
|
||||
S: State<C, E, I, R>,
|
||||
EM: EventManager<S, C, E, I, R>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
E: Executor<I>,
|
||||
C: Corpus<I, R>,
|
||||
I: Input,
|
||||
|
Loading…
x
Reference in New Issue
Block a user