started working

This commit is contained in:
Andrea Fioraldi 2020-12-07 18:15:35 +01:00
parent 80d1c2c729
commit 5d2e7b5bc2
4 changed files with 33 additions and 37 deletions

View File

@ -66,33 +66,6 @@ where
self.metadatas_mut().insert(meta.name(), meta); self.metadatas_mut().insert(meta.name(), meta);
} }
/// Get the linked observers
fn observers(&self) -> &[Rc<RefCell<dyn Observer>>];
/// Get the linked observers
fn observers_mut(&mut self) -> &mut Vec<Rc<RefCell<dyn Observer>>>;
/// Add a linked observer
fn add_observer(&mut self, observer: Rc<RefCell<dyn Observer>>) {
self.observers_mut().push(observer);
}
/// Reset the state of all the observes linked to this executor
fn reset_observers(&mut self) -> Result<(), AflError> {
for observer in self.observers() {
observer.borrow_mut().reset()?;
}
Ok(())
}
/// Run the post exec hook for all the observes linked to this executor
fn post_exec_observers(&mut self) -> Result<(), AflError> {
self.observers()
.iter()
.map(|x| x.borrow_mut().post_exec())
.fold(Ok(()), |acc, x| if x.is_err() { x } else { acc })
}
/// Returns vector of feebacks /// Returns vector of feebacks
fn feedbacks(&self) -> &[Box<dyn Feedback<I>>]; fn feedbacks(&self) -> &[Box<dyn Feedback<I>>];

View File

@ -5,6 +5,7 @@ use core::ptr;
use crate::executors::{Executor, ExitKind}; use crate::executors::{Executor, ExitKind};
use crate::inputs::Input; use crate::inputs::Input;
use crate::metamap::NamedAnyMap;
use crate::AflError; use crate::AflError;
type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind; type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind;
@ -14,15 +15,7 @@ where
I: Input, I: Input,
{ {
harness: HarnessFunction<I>, harness: HarnessFunction<I>,
} observers: NamedAnyMap,
impl<I> Into<Rc<RefCell<Self>>> for InMemoryExecutor<I>
where
I: Input,
{
fn into(self) -> Rc<RefCell<Self>> {
Rc::new(RefCell::new(self))
}
} }
static mut CURRENT_INMEMORY_EXECUTOR_PTR: *const c_void = ptr::null(); static mut CURRENT_INMEMORY_EXECUTOR_PTR: *const c_void = ptr::null();

View File

@ -1,6 +1,8 @@
pub mod inmemory; pub mod inmemory;
use crate::inputs::Input; use crate::inputs::Input;
use crate::observers::Observer;
use crate::metamap::NamedAnyMap;
use crate::AflError; use crate::AflError;
pub enum ExitKind { pub enum ExitKind {
@ -18,4 +20,31 @@ where
{ {
/// Instruct the target about the input and run /// Instruct the target about the input and run
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError>; fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError>;
/// Get the linked observers
fn observers(&self) -> &NamedAnyMap;
/// Get the linked observers
fn observers_mut(&mut self) -> &mut NamedAnyMap;
/// Add a linked observer
fn add_observer(&mut self, observer: Box<dyn Observer>, name: &'static str) {
self.observers_mut().push(observer);
}
/// Reset the state of all the observes linked to this executor
fn reset_observers(&mut self) -> Result<(), AflError> {
for observer in self.observers_mut() {
observer.reset()?;
}
Ok(())
}
/// Run the post exec hook for all the observes linked to this executor
fn post_exec_observers(&mut self) -> Result<(), AflError> {
self.observers_mut()
.iter()
.map(|x| x.post_exec())
.fold(Ok(()), |acc, x| if x.is_err() { x } else { acc })
}
} }

View File

@ -3,13 +3,14 @@ extern crate num;
use alloc::rc::Rc; use alloc::rc::Rc;
use core::cell::RefCell; use core::cell::RefCell;
use core::slice::from_raw_parts_mut; use core::slice::from_raw_parts_mut;
use core::any::Any;
use num::Integer; use num::Integer;
use crate::AflError; use crate::AflError;
/// Observers observe different information about the target. /// Observers observe different information about the target.
/// They can then be used by various sorts of feedback. /// They can then be used by various sorts of feedback.
pub trait Observer { pub trait Observer: Any {
fn flush(&mut self) -> Result<(), AflError> { fn flush(&mut self) -> Result<(), AflError> {
Ok(()) Ok(())
} }