format
This commit is contained in:
parent
3267c93c8d
commit
6f6567e215
@ -48,11 +48,11 @@ where
|
||||
}
|
||||
|
||||
/// Set executions
|
||||
pub fn set_executions(&mut self, executions: usize){
|
||||
pub fn set_executions(&mut self, executions: usize) {
|
||||
self.executions = executions
|
||||
}
|
||||
|
||||
pub fn start_time(&self) -> u64{
|
||||
pub fn start_time(&self) -> u64 {
|
||||
self.start_time
|
||||
}
|
||||
pub fn set_start_time(&mut self, ms: u64) {
|
||||
@ -73,12 +73,12 @@ where
|
||||
}
|
||||
|
||||
/// Get all the metadatas into an HashMap
|
||||
pub fn metadatas(&self) -> &HashMap<&'static str, Box<dyn StateMetadata>>{
|
||||
pub fn metadatas(&self) -> &HashMap<&'static str, Box<dyn StateMetadata>> {
|
||||
&self.metadatas
|
||||
}
|
||||
|
||||
/// Get all the metadatas into an HashMap (mutable)
|
||||
pub fn metadatas_mut(&mut self) -> &mut HashMap<&'static str, Box<dyn StateMetadata>>{
|
||||
pub fn metadatas_mut(&mut self) -> &mut HashMap<&'static str, Box<dyn StateMetadata>> {
|
||||
&mut self.metadatas
|
||||
}
|
||||
|
||||
@ -88,12 +88,12 @@ where
|
||||
}
|
||||
|
||||
/// Returns vector of feebacks
|
||||
pub fn feedbacks(&self) -> &[Box<dyn Feedback<I>>]{
|
||||
pub fn feedbacks(&self) -> &[Box<dyn Feedback<I>>] {
|
||||
&self.feedbacks
|
||||
}
|
||||
|
||||
/// Returns vector of feebacks (mutable)
|
||||
pub fn feedbacks_mut(&mut self) -> &mut Vec<Box<dyn Feedback<I>>>{
|
||||
pub fn feedbacks_mut(&mut self) -> &mut Vec<Box<dyn Feedback<I>>> {
|
||||
&mut self.feedbacks
|
||||
}
|
||||
|
||||
@ -105,7 +105,11 @@ where
|
||||
// TODO move some of these, like evaluate_input, to FuzzingEngine
|
||||
|
||||
/// Runs the input and triggers observers and feedback
|
||||
pub fn evaluate_input<C, E, EM>(&mut self, input: &I, engine: &mut Engine<EM, E, C, I, R>) -> Result<u32, AflError>
|
||||
pub fn evaluate_input<C, E, EM>(
|
||||
&mut self,
|
||||
input: &I,
|
||||
engine: &mut Engine<EM, E, C, I, R>,
|
||||
) -> Result<u32, AflError>
|
||||
where
|
||||
C: Corpus<I, R>,
|
||||
E: Executor<I>,
|
||||
@ -164,9 +168,9 @@ where
|
||||
corpus: &mut C,
|
||||
input: I,
|
||||
fitness: u32,
|
||||
) -> Result<Option<usize>, AflError>
|
||||
) -> Result<Option<usize>, AflError>
|
||||
where
|
||||
C: Corpus<I, R>
|
||||
C: Corpus<I, R>,
|
||||
{
|
||||
if fitness > 0 {
|
||||
let testcase = self.input_to_testcase(input, fitness)?;
|
||||
@ -225,7 +229,7 @@ where
|
||||
{
|
||||
manager: EM,
|
||||
executor: E,
|
||||
phantom: PhantomData<(C, I, R)>
|
||||
phantom: PhantomData<(C, I, R)>,
|
||||
}
|
||||
|
||||
impl<EM, E, C, I, R> Engine<EM, E, C, I, R>
|
||||
@ -260,7 +264,7 @@ where
|
||||
Self {
|
||||
executor: executor,
|
||||
manager: events_manager,
|
||||
phantom: PhantomData
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -328,7 +332,6 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct StdFuzzer<EM, E, C, I, R>
|
||||
@ -368,13 +371,10 @@ where
|
||||
R: Rand,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
stages: vec![]
|
||||
}
|
||||
Self { stages: vec![] }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: no_std test
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(test)]
|
||||
@ -386,7 +386,7 @@ mod tests {
|
||||
use std::io::stderr;
|
||||
|
||||
use crate::corpus::{Corpus, InMemoryCorpus, Testcase};
|
||||
use crate::engines::{Engine, Fuzzer, StdFuzzer, State};
|
||||
use crate::engines::{Engine, Fuzzer, State, StdFuzzer};
|
||||
#[cfg(feature = "std")]
|
||||
use crate::events::LoggerEventManager;
|
||||
use crate::executors::inmemory::InMemoryExecutor;
|
||||
|
@ -3,8 +3,8 @@ use core::ptr;
|
||||
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
use crate::inputs::Input;
|
||||
use crate::serde_anymap::NamedSerdeAnyMap;
|
||||
use crate::observers::Observer;
|
||||
use crate::serde_anymap::NamedSerdeAnyMap;
|
||||
use crate::AflError;
|
||||
|
||||
type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind;
|
||||
|
@ -1,8 +1,8 @@
|
||||
pub mod inmemory;
|
||||
|
||||
use crate::inputs::Input;
|
||||
use crate::serde_anymap::NamedSerdeAnyMap;
|
||||
use crate::observers::Observer;
|
||||
use crate::serde_anymap::NamedSerdeAnyMap;
|
||||
use crate::AflError;
|
||||
|
||||
pub enum ExitKind {
|
||||
@ -39,7 +39,8 @@ where
|
||||
|
||||
/// Run the post exec hook for all the observes linked to this executor
|
||||
fn post_exec_observers(&mut self) -> Result<(), AflError> {
|
||||
self.observers_mut().for_each_mut(|_, x| Ok(x.post_exec()?))?;
|
||||
self.observers_mut()
|
||||
.for_each_mut(|_, x| Ok(x.post_exec()?))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use num::Integer;
|
||||
|
||||
use crate::corpus::{Testcase, TestcaseMetadata};
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::{Observer, MapObserver};
|
||||
use crate::observers::{MapObserver, Observer};
|
||||
use crate::serde_anymap::NamedSerdeAnyMap;
|
||||
use crate::AflError;
|
||||
|
||||
@ -13,7 +13,11 @@ where
|
||||
I: Input,
|
||||
{
|
||||
/// is_interesting should return the "Interestingness" from 0 to 255 (percent times 2.55)
|
||||
fn is_interesting(&mut self, input: &I, observers: &NamedSerdeAnyMap<dyn Observer>) -> Result<u32, AflError>;
|
||||
fn is_interesting(
|
||||
&mut self,
|
||||
input: &I,
|
||||
observers: &NamedSerdeAnyMap<dyn Observer>,
|
||||
) -> Result<u32, AflError>;
|
||||
|
||||
/// Append to the testcase the generated metadata in case of a new corpus item
|
||||
fn append_metadata(&mut self, _testcase: &mut Testcase<I>) -> Result<(), AflError> {
|
||||
@ -98,7 +102,11 @@ where
|
||||
O: MapObserver<T> + 'static,
|
||||
I: Input,
|
||||
{
|
||||
fn is_interesting(&mut self, _input: &I, observers: &NamedSerdeAnyMap<dyn Observer>) -> Result<u32, AflError> {
|
||||
fn is_interesting(
|
||||
&mut self,
|
||||
_input: &I,
|
||||
observers: &NamedSerdeAnyMap<dyn Observer>,
|
||||
) -> Result<u32, AflError> {
|
||||
let mut interesting = 0;
|
||||
// TODO optimize
|
||||
let observer = observers.get::<O>(self.name).unwrap();
|
||||
|
@ -97,14 +97,14 @@ where
|
||||
fn map(&self) -> &[T] {
|
||||
match &self.map {
|
||||
SliceMut::Ref(r) => r,
|
||||
SliceMut::Owned(v) => v.as_slice()
|
||||
SliceMut::Owned(v) => v.as_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
fn map_mut(&mut self) -> &mut [T] {
|
||||
match &mut self.map {
|
||||
SliceMut::Ref(r) => r,
|
||||
SliceMut::Owned(v) => v.as_mut_slice()
|
||||
SliceMut::Owned(v) => v.as_mut_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,9 @@ where
|
||||
pub fn by_typeid(&self, name: &'static str, typeid: &TypeId) -> Option<&B> {
|
||||
match self.map.get(&unpack_type_id(*typeid)) {
|
||||
None => None,
|
||||
Some(h) => h.get(&xxhash_rust::xxh3::xxh3_64(name.as_bytes())).map(|x| x.as_ref()),
|
||||
Some(h) => h
|
||||
.get(&xxhash_rust::xxh3::xxh3_64(name.as_bytes()))
|
||||
.map(|x| x.as_ref()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,13 +252,13 @@ where
|
||||
pub fn by_typeid_mut(&mut self, name: &'static str, typeid: &TypeId) -> Option<&mut B> {
|
||||
match self.map.get_mut(&unpack_type_id(*typeid)) {
|
||||
None => None,
|
||||
Some(h) => h.get_mut(&xxhash_rust::xxh3::xxh3_64(name.as_bytes())).map(|x| x.as_mut()),
|
||||
Some(h) => h
|
||||
.get_mut(&xxhash_rust::xxh3::xxh3_64(name.as_bytes()))
|
||||
.map(|x| x.as_mut()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all<T>(
|
||||
&self,
|
||||
) -> Option<core::iter::Map<Values<'_, u64, Box<B>>, fn(&Box<B>) -> &T>>
|
||||
pub fn get_all<T>(&self) -> Option<core::iter::Map<Values<'_, u64, Box<B>>, fn(&Box<B>) -> &T>>
|
||||
where
|
||||
T: Any,
|
||||
{
|
||||
@ -294,19 +296,23 @@ where
|
||||
pub fn all_by_typeid_mut(
|
||||
&mut self,
|
||||
typeid: &TypeId,
|
||||
) -> Option<core::iter::Map<ValuesMut<'_, u64, Box<B>>, fn(&mut Box<B>) -> &mut B>>
|
||||
{
|
||||
) -> Option<core::iter::Map<ValuesMut<'_, u64, Box<B>>, fn(&mut Box<B>) -> &mut B>> {
|
||||
match self.map.get_mut(&unpack_type_id(*typeid)) {
|
||||
None => None,
|
||||
Some(h) => Some(h.values_mut().map(|x| x.as_mut())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn all_typeids(&self) -> core::iter::Map<Keys<'_, u64, HashMap<u64, Box<B>>>, fn(&u64) -> TypeId> {
|
||||
pub fn all_typeids(
|
||||
&self,
|
||||
) -> core::iter::Map<Keys<'_, u64, HashMap<u64, Box<B>>>, fn(&u64) -> TypeId> {
|
||||
self.map.keys().map(|x| pack_type_id(*x))
|
||||
}
|
||||
|
||||
pub fn for_each(&self, func: fn(&TypeId, &Box<B>) -> Result<(), AflError>) -> Result<(), AflError> {
|
||||
pub fn for_each(
|
||||
&self,
|
||||
func: fn(&TypeId, &Box<B>) -> Result<(), AflError>,
|
||||
) -> Result<(), AflError> {
|
||||
for (id, h) in self.map.iter() {
|
||||
for x in h.values() {
|
||||
func(&pack_type_id(*id), x)?;
|
||||
@ -315,7 +321,10 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn for_each_mut(&mut self, func: fn(&TypeId, &mut Box<B>) -> Result<(), AflError>) -> Result<(), AflError> {
|
||||
pub fn for_each_mut(
|
||||
&mut self,
|
||||
func: fn(&TypeId, &mut Box<B>) -> Result<(), AflError>,
|
||||
) -> Result<(), AflError> {
|
||||
for (id, h) in self.map.iter_mut() {
|
||||
for x in h.values_mut() {
|
||||
func(&pack_type_id(*id), x)?;
|
||||
@ -329,7 +338,10 @@ where
|
||||
if !self.map.contains_key(&id) {
|
||||
self.map.insert(id, HashMap::default());
|
||||
}
|
||||
self.map.get_mut(&id).unwrap().insert(xxhash_rust::xxh3::xxh3_64(name.as_bytes()), val);
|
||||
self.map
|
||||
.get_mut(&id)
|
||||
.unwrap()
|
||||
.insert(xxhash_rust::xxh3::xxh3_64(name.as_bytes()), val);
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
@ -440,4 +452,3 @@ where
|
||||
Deserialize::deserialize(deserializer).map(SliceMut::Owned)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,7 @@ where
|
||||
phantom: PhantomData<(EM, E, C, I, R)>,
|
||||
}
|
||||
|
||||
impl<M, EM, E, C, I, R> MutationalStage<M, EM, E, C, I, R>
|
||||
for StdMutationalStage<M, EM, E, C, I, R>
|
||||
impl<M, EM, E, C, I, R> MutationalStage<M, EM, E, C, I, R> for StdMutationalStage<M, EM, E, C, I, R>
|
||||
where
|
||||
M: Mutator<C, I, R>,
|
||||
EM: EventManager<C, E, I, R>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user