diff --git a/libafl/src/mutators/havoc_mutations.rs b/libafl/src/mutators/havoc_mutations.rs index 7399ba7930..9f586bd461 100644 --- a/libafl/src/mutators/havoc_mutations.rs +++ b/libafl/src/mutators/havoc_mutations.rs @@ -1,11 +1,13 @@ //! [`crate::mutators::Mutator`] collection equivalent to AFL++'s havoc mutations -use libafl_bolts::tuples::{Map, Merge}; +use libafl_bolts::{ + map_tuple_list_type, merge_tuple_list_type, + tuples::{Map, Merge}, +}; use tuple_list::{tuple_list, tuple_list_type}; -use super::{MappingMutator, ToMappingMutator}; use crate::mutators::{ - mapping::{OptionalMutator, ToOptionalMutator}, + mapping::{ToMappingMutator, ToOptionalMutator}, mutations::{ BitFlipMutator, ByteAddMutator, ByteDecMutator, ByteFlipMutator, ByteIncMutator, ByteInterestingMutator, ByteNegMutator, ByteRandMutator, BytesCopyMutator, @@ -56,96 +58,22 @@ pub type MappedHavocCrossoverType = tuple_list_type!( ); /// Tuple type of the mutations that compose the Havoc mutator -pub type HavocMutationsType = tuple_list_type!( - BitFlipMutator, - ByteFlipMutator, - ByteIncMutator, - ByteDecMutator, - ByteNegMutator, - ByteRandMutator, - ByteAddMutator, - WordAddMutator, - DwordAddMutator, - QwordAddMutator, - ByteInterestingMutator, - WordInterestingMutator, - DwordInterestingMutator, - BytesDeleteMutator, - BytesDeleteMutator, - BytesDeleteMutator, - BytesDeleteMutator, - BytesExpandMutator, - BytesInsertMutator, - BytesRandInsertMutator, - BytesSetMutator, - BytesRandSetMutator, - BytesCopyMutator, - BytesInsertCopyMutator, - BytesSwapMutator, - CrossoverInsertMutator, - CrossoverReplaceMutator, -); +pub type HavocMutationsType = + merge_tuple_list_type!(HavocMutationsNoCrossoverType, HavocCrossoverType); /// Tuple type of the mutations that compose the Havoc mutator for mapped input types -pub type MappedHavocMutationsType = tuple_list_type!( - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, - MappingMutator, F1>, - MappingMutator, F1>, +pub type MappedHavocMutationsType = map_tuple_list_type!( + merge_tuple_list_type!(HavocMutationsNoCrossoverType, MappedHavocCrossoverType), + ToMappingMutator ); /// Tuple type of the mutations that compose the Havoc mutator for mapped input types, for optional byte array input parts -pub type OptionMappedHavocMutationsType = tuple_list_type!( - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator, F1>, - MappingMutator>, F1>, - MappingMutator>, F1>, +pub type OptionMappedHavocMutationsType = map_tuple_list_type!( + map_tuple_list_type!( + merge_tuple_list_type!(HavocMutationsNoCrossoverType, MappedHavocCrossoverType), + ToOptionalMutator + ), + ToMappingMutator ); /// Get the mutations that compose the Havoc mutator (only applied to single inputs) diff --git a/libafl_bolts/src/tuples.rs b/libafl_bolts/src/tuples.rs index 0f01ab7587..45990ece5b 100644 --- a/libafl_bolts/src/tuples.rs +++ b/libafl_bolts/src/tuples.rs @@ -925,6 +925,8 @@ impl PlusOne for (Head, Tail) where #[cfg(test)] mod test { + use core::marker::PhantomData; + use tuple_list::{tuple_list, tuple_list_type}; #[cfg(feature = "alloc")] @@ -977,9 +979,9 @@ mod test { #[test] fn test_mapper() { struct W(T); - struct MyMapper; + struct MyMapper

(PhantomData

); - impl MappingFunctor for MyMapper { + impl MappingFunctor for MyMapper

{ type Output = W; fn apply(&mut self, from: T) -> Self::Output { @@ -992,9 +994,9 @@ mod test { struct C; type OrigType = tuple_list_type!(A, B, C); - type MappedType = map_tuple_list_type!(OrigType, MyMapper); + type MappedType = map_tuple_list_type!(OrigType, MyMapper); let orig: OrigType = tuple_list!(A, B, C); - let _mapped: MappedType = orig.map(MyMapper); + let _mapped: MappedType = orig.map(MyMapper(PhantomData::)); } #[test]