From 6f6567e2150b7e463f5fa2114e446ccc127efc2f Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Tue, 8 Dec 2020 15:29:14 +0100 Subject: [PATCH] format --- afl/src/engines/mod.rs | 34 +++++++++++++++++----------------- afl/src/executors/inmemory.rs | 2 +- afl/src/executors/mod.rs | 5 +++-- afl/src/feedbacks/mod.rs | 14 +++++++++++--- afl/src/observers/mod.rs | 4 ++-- afl/src/serde_anymap.rs | 35 +++++++++++++++++++++++------------ afl/src/stages/mutational.rs | 3 +-- 7 files changed, 58 insertions(+), 39 deletions(-) diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index 8559fd3037..aa3ca3892c 100644 --- a/afl/src/engines/mod.rs +++ b/afl/src/engines/mod.rs @@ -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>{ + pub fn metadatas(&self) -> &HashMap<&'static str, Box> { &self.metadatas } /// Get all the metadatas into an HashMap (mutable) - pub fn metadatas_mut(&mut self) -> &mut HashMap<&'static str, Box>{ + pub fn metadatas_mut(&mut self) -> &mut HashMap<&'static str, Box> { &mut self.metadatas } @@ -88,12 +88,12 @@ where } /// Returns vector of feebacks - pub fn feedbacks(&self) -> &[Box>]{ + pub fn feedbacks(&self) -> &[Box>] { &self.feedbacks } /// Returns vector of feebacks (mutable) - pub fn feedbacks_mut(&mut self) -> &mut Vec>>{ + pub fn feedbacks_mut(&mut self) -> &mut Vec>> { &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(&mut self, input: &I, engine: &mut Engine) -> Result + pub fn evaluate_input( + &mut self, + input: &I, + engine: &mut Engine, + ) -> Result where C: Corpus, E: Executor, @@ -164,9 +168,9 @@ where corpus: &mut C, input: I, fitness: u32, - ) -> Result, AflError> + ) -> Result, AflError> where - C: Corpus + C: Corpus, { 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 Engine @@ -260,7 +264,7 @@ where Self { executor: executor, manager: events_manager, - phantom: PhantomData + phantom: PhantomData, } } } @@ -328,7 +332,6 @@ where } } } - } pub struct StdFuzzer @@ -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; diff --git a/afl/src/executors/inmemory.rs b/afl/src/executors/inmemory.rs index f1903b2695..bcb2f2fbfd 100644 --- a/afl/src/executors/inmemory.rs +++ b/afl/src/executors/inmemory.rs @@ -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 = fn(&dyn Executor, &[u8]) -> ExitKind; diff --git a/afl/src/executors/mod.rs b/afl/src/executors/mod.rs index f71933454f..698584b1f1 100644 --- a/afl/src/executors/mod.rs +++ b/afl/src/executors/mod.rs @@ -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(()) } } diff --git a/afl/src/feedbacks/mod.rs b/afl/src/feedbacks/mod.rs index e22cc25144..450bfa1b9f 100644 --- a/afl/src/feedbacks/mod.rs +++ b/afl/src/feedbacks/mod.rs @@ -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) -> Result; + fn is_interesting( + &mut self, + input: &I, + observers: &NamedSerdeAnyMap, + ) -> Result; /// Append to the testcase the generated metadata in case of a new corpus item fn append_metadata(&mut self, _testcase: &mut Testcase) -> Result<(), AflError> { @@ -98,7 +102,11 @@ where O: MapObserver + 'static, I: Input, { - fn is_interesting(&mut self, _input: &I, observers: &NamedSerdeAnyMap) -> Result { + fn is_interesting( + &mut self, + _input: &I, + observers: &NamedSerdeAnyMap, + ) -> Result { let mut interesting = 0; // TODO optimize let observer = observers.get::(self.name).unwrap(); diff --git a/afl/src/observers/mod.rs b/afl/src/observers/mod.rs index bc9d9ac8ef..1ed544438f 100644 --- a/afl/src/observers/mod.rs +++ b/afl/src/observers/mod.rs @@ -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(), } } diff --git a/afl/src/serde_anymap.rs b/afl/src/serde_anymap.rs index 7d625e2693..7e89b43228 100644 --- a/afl/src/serde_anymap.rs +++ b/afl/src/serde_anymap.rs @@ -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( - &self, - ) -> Option>, fn(&Box) -> &T>> + pub fn get_all(&self) -> Option>, fn(&Box) -> &T>> where T: Any, { @@ -294,19 +296,23 @@ where pub fn all_by_typeid_mut( &mut self, typeid: &TypeId, - ) -> Option>, fn(&mut Box) -> &mut B>> - { + ) -> Option>, fn(&mut Box) -> &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>>, fn(&u64) -> TypeId> { + pub fn all_typeids( + &self, + ) -> core::iter::Map>>, fn(&u64) -> TypeId> { self.map.keys().map(|x| pack_type_id(*x)) } - pub fn for_each(&self, func: fn(&TypeId, &Box) -> Result<(), AflError>) -> Result<(), AflError> { + pub fn for_each( + &self, + func: fn(&TypeId, &Box) -> 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) -> Result<(), AflError>) -> Result<(), AflError> { + pub fn for_each_mut( + &mut self, + func: fn(&TypeId, &mut Box) -> 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) } } - diff --git a/afl/src/stages/mutational.rs b/afl/src/stages/mutational.rs index 5e323b4f20..6f5ee2ba3b 100644 --- a/afl/src/stages/mutational.rs +++ b/afl/src/stages/mutational.rs @@ -81,8 +81,7 @@ where phantom: PhantomData<(EM, E, C, I, R)>, } -impl MutationalStage - for StdMutationalStage +impl MutationalStage for StdMutationalStage where M: Mutator, EM: EventManager,