renamed to StaticMapObserver, code fmt
This commit is contained in:
parent
9a0352d820
commit
89961c31c3
@ -178,19 +178,20 @@ impl InMemoryExecutor {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::executors::{Executor, ExitKind, InMemoryExecutor};
|
||||
use crate::observers::Observer;
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::Observer;
|
||||
use crate::AflError;
|
||||
|
||||
struct NopInput {}
|
||||
impl Input for NopInput{
|
||||
fn serialize(&self) -> Result<&[u8], AflError> {Ok("NOP".as_bytes())}
|
||||
impl Input for NopInput {
|
||||
fn serialize(&self) -> Result<&[u8], AflError> {
|
||||
Ok("NOP".as_bytes())
|
||||
}
|
||||
fn deserialize(&mut self, _buf: &[u8]) -> Result<(), AflError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct Nopserver {}
|
||||
|
||||
impl Observer for Nopserver {
|
||||
@ -218,7 +219,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_inmem_exec() {
|
||||
let mut in_mem_executor = InMemoryExecutor::new(test_harness_fn_nop);
|
||||
let input = NopInput{};
|
||||
let input = NopInput {};
|
||||
assert!(in_mem_executor.place_input(Box::new(input)).is_ok());
|
||||
assert!(in_mem_executor.run_target().is_ok());
|
||||
}
|
||||
|
@ -2,7 +2,5 @@ use crate::corpus::Testcase;
|
||||
use crate::executors::Executor;
|
||||
|
||||
pub trait Feedback {
|
||||
|
||||
fn is_interesting(&mut self, executor: &dyn Executor, entry: &dyn Testcase) -> f64;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
use crate::AflError;
|
||||
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 {
|
||||
fn flush(&mut self) -> Result<(), AflError> {
|
||||
Ok(())
|
||||
@ -13,33 +15,28 @@ pub trait Observer {
|
||||
}
|
||||
}
|
||||
|
||||
/// A MapObserver contains a map with values, collected from the child.
|
||||
pub trait MapObserver<MapT>: Observer {
|
||||
|
||||
// TODO: Rust
|
||||
fn get_map(&self) -> &[MapT];
|
||||
//fn get_map_mut(&mut self) -> &mut Vec<MapT>;
|
||||
|
||||
fn get_map_mut(&mut self) -> &mut [u8];
|
||||
|
||||
fn get_map_mut(&mut self) -> &mut [MapT];
|
||||
}
|
||||
|
||||
pub struct U8MapObserver {
|
||||
|
||||
/// A staticMapObserver observes the static map, as oftentimes used for afl-like coverage information
|
||||
pub struct StaticMapObserver {
|
||||
map: &'static mut [u8],
|
||||
|
||||
}
|
||||
|
||||
impl Observer for U8MapObserver {
|
||||
impl Observer for StaticMapObserver {
|
||||
fn reset(&mut self) -> Result<(), AflError> {
|
||||
|
||||
// TODO: Clear
|
||||
Err(AflError::Unknown)
|
||||
|
||||
// Normal memset, see https://rust.godbolt.org/z/Trs5hv
|
||||
for i in self.map.iter_mut() {
|
||||
*i = 0;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl MapObserver<u8> for U8MapObserver {
|
||||
|
||||
impl MapObserver<u8> for StaticMapObserver {
|
||||
fn get_map(&self) -> &[u8] {
|
||||
self.map
|
||||
}
|
||||
@ -47,13 +44,15 @@ impl MapObserver<u8> for U8MapObserver {
|
||||
fn get_map_mut(&mut self) -> &mut [u8] {
|
||||
self.map
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl U8MapObserver {
|
||||
impl StaticMapObserver {
|
||||
/// Creates a new StaticMapObserver from a raw pointer.
|
||||
pub fn new(map_ptr: *mut u8, len: usize) -> Self {
|
||||
unsafe {
|
||||
U8MapObserver{map: from_raw_parts_mut(map_ptr, len)}
|
||||
StaticMapObserver {
|
||||
map: from_raw_parts_mut(map_ptr, len),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user