better events
This commit is contained in:
commit
2e40ecd660
@ -14,9 +14,7 @@ default = ["std"]
|
||||
std = []
|
||||
|
||||
[dependencies]
|
||||
xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust
|
||||
hashbrown = "0.9" # A faster hashmap, nostd compatible
|
||||
libc = "0.2" # For (*nix) libc
|
||||
num = "*"
|
||||
|
||||
#shared_memory = { version = "0.11.3", optional = true } # shared mem for windows and unix
|
||||
xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust
|
@ -9,9 +9,9 @@ use core::marker::PhantomData;
|
||||
#[cfg(feature = "std")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
|
||||
pub trait HasTestcaseVec<I>
|
||||
where
|
||||
|
@ -1,6 +1,3 @@
|
||||
use crate::inputs::Input;
|
||||
use crate::AflError;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::rc::Rc;
|
||||
use alloc::string::String;
|
||||
@ -10,6 +7,9 @@ use core::default::Default;
|
||||
use core::option::Option;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::inputs::Input;
|
||||
|
||||
// TODO PathBuf for no_std and change filename to PathBuf
|
||||
//#[cfg(feature = "std")]
|
||||
//use std::path::PathBuf;
|
||||
|
@ -6,11 +6,10 @@ use alloc::vec::Vec;
|
||||
use core::cell::RefCell;
|
||||
use core::fmt::Debug;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use hashbrown::HashMap;
|
||||
|
||||
use crate::corpus::{Corpus, HasCorpus, Testcase};
|
||||
use crate::events::{EventManager, LoadInitialEvent};
|
||||
use crate::events::{EventManager, LoadInitialEvent, UpdateStatsEvent};
|
||||
use crate::executors::Executor;
|
||||
use crate::feedbacks::Feedback;
|
||||
use crate::generators::Generator;
|
||||
@ -327,7 +326,7 @@ where
|
||||
let cur = current_milliseconds();
|
||||
if cur - last > 60 * 100 {
|
||||
last = cur;
|
||||
fire_event!(events, LoadInitialEvent)?;
|
||||
fire_event!(events, UpdateStatsEvent)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -385,10 +384,13 @@ where
|
||||
mod tests {
|
||||
|
||||
use alloc::boxed::Box;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::io::stderr;
|
||||
|
||||
use crate::corpus::{Corpus, InMemoryCorpus, Testcase};
|
||||
use crate::engines::{Engine, StdEngine, StdState};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::events::LoggerEventManager;
|
||||
use crate::executors::inmemory::InMemoryExecutor;
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
@ -401,6 +403,7 @@ mod tests {
|
||||
ExitKind::Ok
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[test]
|
||||
fn test_engine() {
|
||||
let mut rand = StdRand::new(0);
|
||||
|
@ -1,13 +1,17 @@
|
||||
#[cfg(feature = "std")]
|
||||
pub mod llmp;
|
||||
#[cfg(feature = "std")]
|
||||
pub mod llmp_translated; // TODO: Abstract away.
|
||||
#[cfg(feature = "std")]
|
||||
pub mod shmem_translated;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use crate::events::llmp::LLMP;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::any::Any;
|
||||
use core::cell::RefCell;
|
||||
//use core::any::TypeId;
|
||||
// TODO use core version
|
||||
#[cfg(feature = "std")]
|
||||
use std::io::Write;
|
||||
|
||||
use crate::corpus::{Corpus, Testcase};
|
||||
@ -17,7 +21,7 @@ use crate::inputs::Input;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
|
||||
pub trait Event: Any {
|
||||
pub trait Event {
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
@ -86,7 +90,7 @@ where
|
||||
testcase: Rc<RefCell<Testcase<I>>>,
|
||||
}
|
||||
|
||||
impl<I> Event<I> for NewTestcaseEvent<I>
|
||||
impl<I> Event for NewTestcaseEvent<I>
|
||||
where
|
||||
I: Input,
|
||||
{
|
||||
@ -102,6 +106,10 @@ where
|
||||
pub fn new(testcase: Rc<RefCell<Testcase<I>>>) -> Self {
|
||||
NewTestcaseEvent { testcase: testcase }
|
||||
}
|
||||
|
||||
pub fn testcase(&self) -> &Rc<RefCell<Testcase<I>>> {
|
||||
&self.testcase
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UpdateStatsEvent {}
|
||||
@ -116,14 +124,16 @@ impl UpdateStatsEvent {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub struct LoggerEventManager<W>
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
events: Vec<Box<dyn Event>>,
|
||||
events: Vec<String>,
|
||||
writer: W,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<S, C, E, I, R, W> EventManager<S, C, E, I, R> for LoggerEventManager<W>
|
||||
where
|
||||
S: State<C, E, I, R>,
|
||||
@ -151,7 +161,7 @@ where
|
||||
where
|
||||
T: Event,
|
||||
{
|
||||
self.events.push(Box::new(event));
|
||||
self.events.push(event.name().to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -162,7 +172,7 @@ where
|
||||
&mut self.writer,
|
||||
"#{}\t[{}] corp: {} exec/s: {}",
|
||||
state.executions(),
|
||||
event.name(),
|
||||
event,
|
||||
state.corpus().entries().len(),
|
||||
state.executions_over_seconds()
|
||||
)?;
|
||||
@ -172,6 +182,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<W> LoggerEventManager<W>
|
||||
where
|
||||
W: Write,
|
||||
|
@ -3,9 +3,9 @@ use core::cell::RefCell;
|
||||
use core::ffi::c_void;
|
||||
use core::ptr;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
use crate::inputs::Input;
|
||||
use crate::AflError;
|
||||
|
||||
type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind;
|
||||
|
||||
|
@ -1,15 +1,14 @@
|
||||
extern crate num;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::boxed::Box;
|
||||
use core::cell::RefCell;
|
||||
use core::marker::PhantomData;
|
||||
use num::Integer;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::corpus::{Testcase, TestcaseMetadata};
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::MapObserver;
|
||||
use crate::AflError;
|
||||
|
||||
pub trait Feedback<I>
|
||||
where
|
||||
|
@ -2,10 +2,10 @@ use alloc::vec::Vec;
|
||||
use core::cmp::min;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::inputs::bytes::BytesInput;
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
|
||||
pub trait Generator<I, R>
|
||||
where
|
||||
|
@ -4,8 +4,8 @@ use alloc::vec::Vec;
|
||||
use core::cell::RefCell;
|
||||
use core::convert::From;
|
||||
|
||||
use crate::inputs::{HasBytesVec, HasTargetBytes, Input};
|
||||
use crate::AflError;
|
||||
use crate::inputs::{HasBytesVec, HasTargetBytes, Input};
|
||||
|
||||
/// A bytes input is the basic input
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
@ -4,14 +4,14 @@ pub use scheduled::HavocBytesMutator;
|
||||
pub use scheduled::ScheduledMutator;
|
||||
pub use scheduled::StdScheduledMutator;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::corpus::Corpus;
|
||||
use crate::corpus::Testcase;
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
pub trait Mutator<C, I, R>
|
||||
where
|
||||
|
@ -1,11 +1,11 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::inputs::{HasBytesVec, Input};
|
||||
use crate::mutators::Corpus;
|
||||
use crate::mutators::Mutator;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
pub enum MutationResult {
|
||||
Mutated,
|
||||
|
@ -1,6 +1,10 @@
|
||||
pub mod mutational;
|
||||
pub use mutational::StdMutationalStage;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::corpus::testcase::Testcase;
|
||||
use crate::corpus::Corpus;
|
||||
use crate::engines::State;
|
||||
@ -8,9 +12,6 @@ use crate::events::EventManager;
|
||||
use crate::executors::Executor;
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
pub trait Stage<S, EM, E, C, I, R>
|
||||
where
|
||||
|
@ -6,13 +6,12 @@ use crate::corpus::testcase::Testcase;
|
||||
use crate::engines::State;
|
||||
use crate::events::{EventManager, NewTestcaseEvent};
|
||||
use crate::executors::Executor;
|
||||
use crate::fire_event;
|
||||
use crate::inputs::Input;
|
||||
use crate::mutators::Mutator;
|
||||
use crate::stages::Corpus;
|
||||
use crate::stages::Stage;
|
||||
use crate::utils::Rand;
|
||||
use crate::AflError;
|
||||
use crate::{fire_event, AflError};
|
||||
|
||||
// TODO multi mutators stage
|
||||
|
||||
@ -53,12 +52,13 @@ where
|
||||
.mutate(rand, state.corpus_mut(), &mut input, i as i32)?;
|
||||
|
||||
let (interesting, new_testcase) = state.evaluate_input(input)?;
|
||||
|
||||
self.mutator_mut()
|
||||
.post_exec(interesting, new_testcase.clone(), i as i32)?;
|
||||
|
||||
if !new_testcase.is_none() {
|
||||
fire_event!(events, NewTestcaseEvent<I>, new_testcase.unwrap())?;
|
||||
}
|
||||
|
||||
self.mutator_mut()
|
||||
.post_exec(interesting, new_testcase, i as i32)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -71,30 +71,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Has a Rand Rc RefCell field (internal mutability), that can be used to get random values
|
||||
pub trait HasRandRR {
|
||||
type R: Rand;
|
||||
|
||||
/// Get the hold Rand instance
|
||||
fn rand(&self) -> &Rc<RefCell<Self::R>>;
|
||||
|
||||
// Gets the next 64 bit value
|
||||
fn rand_next(&self) -> u64 {
|
||||
self.rand().borrow_mut().next()
|
||||
}
|
||||
// Gets a value below the given 64 bit val (inclusive)
|
||||
fn rand_below(&self, upper_bound_excl: u64) -> u64 {
|
||||
self.rand().borrow_mut().below(upper_bound_excl)
|
||||
}
|
||||
|
||||
// Gets a value between the given lower bound (inclusive) and upper bound (inclusive)
|
||||
fn rand_between(&self, lower_bound_incl: u64, upper_bound_incl: u64) -> u64 {
|
||||
self.rand()
|
||||
.borrow_mut()
|
||||
.between(lower_bound_incl, upper_bound_incl)
|
||||
}
|
||||
}
|
||||
|
||||
const HASH_CONST: u64 = 0xa5b35705;
|
||||
|
||||
/// XXH3 Based, hopefully speedy, rnd implementation
|
||||
|
Loading…
x
Reference in New Issue
Block a user