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