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,
entry: Rc<RefCell<Testcase<I>>>,
) -> Result<bool, AflError> {
{
self.executor_mut().reset_observers()?;
// self.executor_mut().place_input(Box::new(input))?;
self.executor_mut().run_target()?;
self.executor_mut().post_exec_observers()?;
}
self.executor_mut().reset_observers()?;
self.executor_mut().run_target(input)?;
self.executor_mut().post_exec_observers()?;
// 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;
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;
if let Some(m) = meta {
//if new_entry.is_none() {
new_entry = Some(Rc::new(RefCell::new(Testcase::<I>::new(input.clone()))));
//}
if let Some(_) = new_entry {
} else {
new_entry = Some(Rc::new(RefCell::new(Testcase::<I>::new(input.clone()))));
}
new_entry
.unwrap()
.borrow_mut()
@ -89,6 +86,10 @@ where
}
}
if rate_acc >= 25 {
self.corpus_mut().add(new_entry.unwrap().clone());
}
Ok(true)
}
}

View File

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

View File

@ -17,17 +17,8 @@ pub trait Executor<I>
where
I: Input,
{
/// Run the target
fn run_target(&mut self) -> 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>>;
/// Instruct the target about the input and run
fn run_target(&mut self, input: &mut I) -> Result<ExitKind, AflError>;
/// Reset the state of all the observes linked to this executor
fn reset_observers(&mut self) -> Result<(), AflError>;

View File

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