update broken engine

This commit is contained in:
Andrea Fioraldi 2020-11-05 20:12:20 +01:00
parent 5e51f8f143
commit 3e6bca34f1
4 changed files with 25 additions and 62 deletions

View File

@ -63,25 +63,22 @@ where
input: &mut I, input: &mut I,
entry: Rc<RefCell<Testcase<I>>>, entry: Rc<RefCell<Testcase<I>>>,
) -> Result<bool, AflError> { ) -> Result<bool, AflError> {
{ self.executor_mut().reset_observers()?;
self.executor_mut().reset_observers()?; self.executor_mut().run_target(input)?;
// self.executor_mut().place_input(Box::new(input))?; self.executor_mut().post_exec_observers()?;
self.executor_mut().run_target()?;
self.executor_mut().post_exec_observers()?;
}
// TODO new method for this shit // TODO new method for this shit
let mut new_entry: Option<Rc<RefCell<Testcase<I>>>> = None; // lazy init let mut new_entry: Rc<RefCell<Testcase<I>>> =
Rc::new(RefCell::new(Testcase::<I>::default())); // lazy init
let mut rate_acc = 0; let mut rate_acc = 0;
for feedback in self.feedbacks_mut() { for feedback in self.feedbacks_mut() {
let (rate, meta) = feedback.is_interesting(self.executor_mut()); let (rate, meta) = feedback.is_interesting(input);
rate_acc += rate; rate_acc += rate;
if let Some(m) = meta { if let Some(m) = meta {
//if new_entry.is_none() { if let Some(_) = new_entry {
new_entry = Some(Rc::new(RefCell::new(Testcase::<I>::new(input.clone())))); } else {
//} new_entry = Some(Rc::new(RefCell::new(Testcase::<I>::new(input.clone()))));
}
new_entry new_entry
.unwrap() .unwrap()
.borrow_mut() .borrow_mut()
@ -89,6 +86,10 @@ where
} }
} }
if rate_acc >= 25 {
self.corpus_mut().add(new_entry.unwrap().clone());
}
Ok(true) Ok(true)
} }
} }

View File

@ -13,7 +13,6 @@ pub struct InMemoryExecutor<I>
where where
I: Input, I: Input,
{ {
cur_input: Option<Box<I>>,
observers: Vec<Box<dyn Observer>>, observers: Vec<Box<dyn Observer>>,
harness: HarnessFunction<I>, harness: HarnessFunction<I>,
} }
@ -24,35 +23,16 @@ impl<I> Executor<I> for InMemoryExecutor<I>
where where
I: Input, I: Input,
{ {
fn run_target(&mut self) -> Result<ExitKind, AflError> { fn run_target(&mut self, input: &mut I) -> Result<ExitKind, AflError> {
let bytes = match self.cur_input.as_ref() { let bytes = input.serialize()?;
Some(i) => i.serialize(),
None => return Err(AflError::Empty("cur_input".to_string())),
};
unsafe { unsafe {
CURRENT_INMEMORY_EXECUTOR_PTR = self as *const InMemoryExecutor<I> as *const c_void; CURRENT_INMEMORY_EXECUTOR_PTR = self as *const InMemoryExecutor<I> as *const c_void;
} }
let ret = match bytes { let ret = (self.harness)(self, bytes);
Ok(b) => Ok((self.harness)(self, b)),
Err(e) => Err(e),
};
unsafe { unsafe {
CURRENT_INMEMORY_EXECUTOR_PTR = ptr::null(); CURRENT_INMEMORY_EXECUTOR_PTR = ptr::null();
} }
ret Ok(ret)
}
fn place_input(&mut self, input: Box<I>) -> Result<(), AflError> {
self.cur_input = Some(input);
Ok(())
}
fn cur_input(&self) -> &Option<Box<I>> {
&self.cur_input
}
fn cur_input_mut(&mut self) -> &mut Option<Box<I>> {
&mut self.cur_input
} }
fn reset_observers(&mut self) -> Result<(), AflError> { fn reset_observers(&mut self) -> Result<(), AflError> {
@ -87,7 +67,6 @@ where
os_signals::setup_crash_handlers::<I, Self>(); os_signals::setup_crash_handlers::<I, Self>();
} }
InMemoryExecutor { InMemoryExecutor {
cur_input: None,
observers: vec![], observers: vec![],
harness: harness_fn, harness: harness_fn,
} }
@ -232,8 +211,7 @@ mod tests {
#[test] #[test]
fn test_inmem_exec() { fn test_inmem_exec() {
let mut in_mem_executor = InMemoryExecutor::new(test_harness_fn_nop); let mut in_mem_executor = InMemoryExecutor::new(test_harness_fn_nop);
let input = NopInput {}; let mut input = NopInput {};
assert!(in_mem_executor.place_input(Box::new(input)).is_ok()); assert!(in_mem_executor.run_target(&mut input).is_ok());
assert!(in_mem_executor.run_target().is_ok());
} }
} }

View File

@ -17,17 +17,8 @@ pub trait Executor<I>
where where
I: Input, I: Input,
{ {
/// Run the target /// Instruct the target about the input and run
fn run_target(&mut self) -> Result<ExitKind, AflError>; fn run_target(&mut self, input: &mut I) -> Result<ExitKind, AflError>;
/// Instruct the target about the input before the run
fn place_input(&mut self, input: Box<I>) -> Result<(), AflError>;
/// Get the current input, if any
fn cur_input(&self) -> &Option<Box<I>>;
/// Get the current input, if any (mutable)
fn cur_input_mut(&mut self) -> &mut Option<Box<I>>;
/// Reset the state of all the observes linked to this executor /// Reset the state of all the observes linked to this executor
fn reset_observers(&mut self) -> Result<(), AflError>; fn reset_observers(&mut self) -> Result<(), AflError>;

View File

@ -1,7 +1,6 @@
extern crate num; extern crate num;
use crate::corpus::{Testcase, TestcaseMetadata}; use crate::corpus::TestcaseMetadata;
use crate::executors::Executor;
use crate::inputs::Input; use crate::inputs::Input;
use crate::observers::MapObserver; use crate::observers::MapObserver;
@ -14,10 +13,7 @@ where
I: Input, I: Input,
{ {
/// is_interesting should return the "Interestingness" from 0 to 255 (percent times 2.55) /// is_interesting should return the "Interestingness" from 0 to 255 (percent times 2.55)
fn is_interesting( fn is_interesting(&mut self, input: &I) -> (u32, Option<Box<dyn TestcaseMetadata>>);
&mut self,
executor: &dyn Executor<I>,
) -> (u32, Option<Box<dyn TestcaseMetadata>>);
} }
/// A Reducer function is used to aggregate values for the novelty search /// A Reducer function is used to aggregate values for the novelty search
@ -90,10 +86,7 @@ where
O: MapObserver<T>, O: MapObserver<T>,
I: Input, I: Input,
{ {
fn is_interesting( fn is_interesting(&mut self, _input: &I) -> (u32, Option<Box<dyn TestcaseMetadata>>) {
&mut self,
_executor: &dyn Executor<I>,
) -> (u32, Option<Box<dyn TestcaseMetadata>>) {
let mut interesting = 0; let mut interesting = 0;
// TODO: impl. correctly, optimize // TODO: impl. correctly, optimize