Struct hyperpom::mutator::Mutator

source ·
pub struct Mutator {
    pub rand: Random,
}
Expand description

The mutator engine used to mutate testcases randomly.

Role of the Mutator in the Fuzzer.

Since this fuzzer is mutation-based, each testcase, before being run, is mutated. The idea is to take an existing testcase and alter it. The changes introduced should be small enough to prevent the program from outright rejecting the testcase, but sufficient to explore new paths.

This mutator implements basic mutation strategies:

  • bitflips;
  • add, subtract, xor and negate operations on 8/16/32/64 bits of data;
  • magic values insertion and overwrite;
  • random values insertion and overwrite;
  • 1-byte repetitions insertion and overwrite;
  • shrinking and extension.

These methods are called randomly but are given arbitrary weights to prevent expensive operations from being called too often (refer to the source code of Mutator::mutate for more information). In the future, these weights might be changed or made user-controllable.

Example

// Creates a new random generator.
let rand = Random::new(0xa5a5a5a5a5a5a5);

// Creates a new mutator.
let mut mutator = Mutator::new(rand);

// The data to mutate
let mut data = vec![0x42, 0x42, 0x42, 0x42];

// Mutations
mutator.bitflip(&mut data, 0x100);
mutator.byte_op(&mut data, 0x100);
mutator.extend(&mut data, 0x100);
mutator.shrink(&mut data, 0x100);
mutator.magic_replace(&mut data, 0x100);
mutator.magic_insert(&mut data, 0x100);
mutator.random_replace(&mut data, 0x100);
mutator.random_insert(&mut data, 0x100);
mutator.repetition_replace(&mut data, 0x100);
mutator.repetition_insert(&mut data, 0x100);

Fields

rand: Random

Implementations

Creates a new mutator from a PRNG.

Randomly mutates a testcase.

Performs a bitflip of 1, 2, 3 or 4 bits at a random location in the testcase.

Adds, subtracts, XORs or negates bytes in the testcase with random values.

Extends a testcase with a random amount of null bytes.

Shrinks a testcase by a random amount.

Replaces bytes at a random position with a magic value.

Inserts a magic value at a random position.

Replaces bytes at a random position with random bytes.

Inserts random bytes at a random position.

Replaces all bytes in a random range by the same byte.

Inserts a repetition of the same byte at a random position.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.