1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::input::HasPackets;
use libafl::{
bolts::{rands::Rand, tuples::Named, HasLen},
inputs::Input,
mutators::{MutationResult, Mutator},
state::{HasMaxSize, HasRand},
Error,
};
use std::marker::PhantomData;
pub struct PacketDeleteMutator<P> {
phantom: PhantomData<P>,
min_packets: usize,
}
impl<P> PacketDeleteMutator<P> {
pub fn new(min_packets: usize) -> Self {
Self {
phantom: PhantomData,
min_packets: std::cmp::max(1, min_packets),
}
}
}
impl<I, S, P> Mutator<I, S> for PacketDeleteMutator<P>
where
I: Input + HasLen + HasPackets<P>,
S: HasRand + HasMaxSize,
{
fn mutate(&mut self, state: &mut S, input: &mut I, _stage_idx: i32) -> Result<MutationResult, Error> {
if input.len() <= self.min_packets {
return Ok(MutationResult::Skipped);
}
let idx = state.rand_mut().below(input.len() as u64) as usize;
input.packets_mut().remove(idx);
Ok(MutationResult::Mutated)
}
}
impl<P> Named for PacketDeleteMutator<P> {
fn name(&self) -> &str {
"PacketDeleteMutator"
}
}