renamed to StaticMapObserver, code fmt

This commit is contained in:
Dominik Maier 2020-10-29 11:55:16 +01:00
parent 9a0352d820
commit 89961c31c3
3 changed files with 25 additions and 27 deletions

View File

@ -178,19 +178,20 @@ impl InMemoryExecutor {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::executors::{Executor, ExitKind, InMemoryExecutor}; use crate::executors::{Executor, ExitKind, InMemoryExecutor};
use crate::observers::Observer;
use crate::inputs::Input; use crate::inputs::Input;
use crate::observers::Observer;
use crate::AflError; use crate::AflError;
struct NopInput {} struct NopInput {}
impl Input for NopInput { impl Input for NopInput {
fn serialize(&self) -> Result<&[u8], AflError> {Ok("NOP".as_bytes())} fn serialize(&self) -> Result<&[u8], AflError> {
Ok("NOP".as_bytes())
}
fn deserialize(&mut self, _buf: &[u8]) -> Result<(), AflError> { fn deserialize(&mut self, _buf: &[u8]) -> Result<(), AflError> {
Ok(()) Ok(())
} }
} }
struct Nopserver {} struct Nopserver {}
impl Observer for Nopserver { impl Observer for Nopserver {

View File

@ -2,7 +2,5 @@ use crate::corpus::Testcase;
use crate::executors::Executor; use crate::executors::Executor;
pub trait Feedback { pub trait Feedback {
fn is_interesting(&mut self, executor: &dyn Executor, entry: &dyn Testcase) -> f64; fn is_interesting(&mut self, executor: &dyn Executor, entry: &dyn Testcase) -> f64;
} }

View File

@ -1,6 +1,8 @@
use crate::AflError; use crate::AflError;
use std::slice::from_raw_parts_mut; use std::slice::from_raw_parts_mut;
/// Observers observe different information about the target.
/// They can then be used by various sorts of feedback.
pub trait Observer { pub trait Observer {
fn flush(&mut self) -> Result<(), AflError> { fn flush(&mut self) -> Result<(), AflError> {
Ok(()) Ok(())
@ -13,33 +15,28 @@ pub trait Observer {
} }
} }
/// A MapObserver contains a map with values, collected from the child.
pub trait MapObserver<MapT>: Observer { pub trait MapObserver<MapT>: Observer {
// TODO: Rust
fn get_map(&self) -> &[MapT]; fn get_map(&self) -> &[MapT];
//fn get_map_mut(&mut self) -> &mut Vec<MapT>; fn get_map_mut(&mut self) -> &mut [MapT];
fn get_map_mut(&mut self) -> &mut [u8];
} }
pub struct U8MapObserver { /// A staticMapObserver observes the static map, as oftentimes used for afl-like coverage information
pub struct StaticMapObserver {
map: &'static mut [u8], map: &'static mut [u8],
} }
impl Observer for U8MapObserver { impl Observer for StaticMapObserver {
fn reset(&mut self) -> Result<(), AflError> { fn reset(&mut self) -> Result<(), AflError> {
// Normal memset, see https://rust.godbolt.org/z/Trs5hv
// TODO: Clear for i in self.map.iter_mut() {
Err(AflError::Unknown) *i = 0;
}
Ok(())
} }
} }
impl MapObserver<u8> for U8MapObserver { impl MapObserver<u8> for StaticMapObserver {
fn get_map(&self) -> &[u8] { fn get_map(&self) -> &[u8] {
self.map self.map
} }
@ -47,13 +44,15 @@ impl MapObserver<u8> for U8MapObserver {
fn get_map_mut(&mut self) -> &mut [u8] { fn get_map_mut(&mut self) -> &mut [u8] {
self.map self.map
} }
} }
impl U8MapObserver { impl StaticMapObserver {
/// Creates a new StaticMapObserver from a raw pointer.
pub fn new(map_ptr: *mut u8, len: usize) -> Self { pub fn new(map_ptr: *mut u8, len: usize) -> Self {
unsafe { unsafe {
U8MapObserver{map: from_raw_parts_mut(map_ptr, len)} StaticMapObserver {
map: from_raw_parts_mut(map_ptr, len),
}
} }
} }
} }