fix mutations

This commit is contained in:
Andrea Fioraldi 2021-02-12 10:17:26 +01:00
parent e78fbc0f0f
commit 27cc1d8af6
2 changed files with 20 additions and 20 deletions

View File

@ -270,10 +270,10 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() == 0 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
let idx = rand.below(input.bytes().len() as u64) as usize;
unsafe {
// moar speed, no bound check
let ptr = input.bytes_mut().get_unchecked_mut(idx) as *mut u8;
@ -297,7 +297,7 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() < 2 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
@ -326,10 +326,10 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() < 4 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
let idx = rand.below(input.bytes().len() as u64 - 3) as usize;
unsafe {
// moar speed, no bound check
let ptr = input.bytes_mut().get_unchecked_mut(idx) as *mut _ as *mut u32;
@ -355,10 +355,10 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() < 8 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
let idx = rand.below(input.bytes().len() as u64 - 7) as usize;
unsafe {
// moar speed, no bound check
let ptr = input.bytes_mut().get_unchecked_mut(idx) as *mut _ as *mut u64;
@ -384,10 +384,10 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() == 0 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
let idx = rand.below(input.bytes().len() as u64) as usize;
let val = INTERESTING_8[rand.below(INTERESTING_8.len() as u64) as usize] as u8;
unsafe {
// moar speed, no bound check
@ -407,7 +407,7 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() < 2 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
@ -435,10 +435,10 @@ where
I: Input + HasBytesVec,
R: Rand,
{
if input.bytes().len() <= 1 {
if input.bytes().len() < 4 {
Ok(MutationResult::Skipped)
} else {
let idx = rand.below(input.bytes().len() as u64 - 1) as usize;
let idx = rand.below(input.bytes().len() as u64 - 3) as usize;
let val = INTERESTING_32[rand.below(INTERESTING_8.len() as u64) as usize] as u32;
unsafe {
// moar speed, no bound check

View File

@ -200,15 +200,15 @@ where
rand: &mut R,
state: &mut S,
input: &mut I,
_stage_idx: i32,
stage_idx: i32,
) -> Result<(), AflError> {
//self.scheduled.mutate(rand, corpus, input, stage_idx);
let num = self.scheduled.iterations(rand, input);
self.scheduled.mutate(rand, state, input, stage_idx)?;
/*let num = self.scheduled.iterations(rand, input);
for _ in 0..num {
let idx = self.scheduled.schedule(14, rand, input);
let mutation = match idx {
0 => mutation_bitflip,
/*1 => mutation_byteflip,
1 => mutation_byteflip,
2 => mutation_byteinc,
3 => mutation_bytedec,
4 => mutation_byteneg,
@ -219,11 +219,11 @@ where
8 => mutation_dwordadd,
9 => mutation_byteinteresting,
10 => mutation_wordinteresting,
11 => mutation_dwordinteresting,*/
11 => mutation_dwordinteresting,
_ => mutation_splice,
};
mutation(self, rand, state, input)?;
}
}*/
Ok(())
}
}
@ -277,7 +277,7 @@ where
pub fn new_default() -> Self {
let mut scheduled = StdScheduledMutator::<C, I, R, S>::new();
scheduled.add_mutation(mutation_bitflip);
/*scheduled.add_mutation(mutation_byteflip);
scheduled.add_mutation(mutation_byteflip);
scheduled.add_mutation(mutation_byteinc);
scheduled.add_mutation(mutation_bytedec);
scheduled.add_mutation(mutation_byteneg);
@ -301,7 +301,7 @@ where
scheduled.add_mutation(mutation_bytesset);
scheduled.add_mutation(mutation_bytesrandset);
scheduled.add_mutation(mutation_bytescopy);
scheduled.add_mutation(mutation_bytesswap);*/
scheduled.add_mutation(mutation_bytesswap);
/* TODO
scheduled.add_mutation(mutation_tokeninsert);