in memory executor first impl

This commit is contained in:
Andrea Fioraldi 2020-10-27 20:45:49 +01:00
parent 89e0b01706
commit ce9413bfa4

View File

@ -13,7 +13,7 @@ pub trait Executor {
fn run_target(&mut self) -> Result<ExitKind, AflError>; fn run_target(&mut self) -> Result<ExitKind, AflError>;
fn place_input(&mut self, entry: Box<dyn Input>) -> Result<(), AflError>; fn place_input(&mut self, input: Box<dyn Input>) -> Result<(), AflError>;
} }
@ -24,3 +24,29 @@ pub struct ExecutorBase {
cur_input: Box<dyn Input> cur_input: Box<dyn Input>
} }
type HarnessFunction = fn(&dyn Executor, &[u8]) -> ExitKind;
pub struct InMemoryExecutor {
base: ExecutorBase,
harness: HarnessFunction,
}
impl Executor for InMemoryExecutor {
fn run_target(&mut self) -> Result<ExitKind, AflError> {
let bytes = self.base.cur_input.serialize();
return match bytes {
Ok(b) => Ok((self.harness)(self, b)),
Err(e) => Err(e)
}
}
fn place_input(&mut self, input: Box<dyn Input>) -> Result<(), AflError> {
self.base.cur_input = input;
Ok(())
}
}