Skip to content

Commit

Permalink
Rename HasMutatorBytes to HasFixedMutatorBytes, and `HasMutatorRe…
Browse files Browse the repository at this point in the history
…sizableBytes` to `HasMutatorBytes`.

As discussed in #2856 (comment).

Sorry about that!
  • Loading branch information
Railroad6230 committed Jan 17, 2025
1 parent f8ad61e commit c9bc133
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
6 changes: 3 additions & 3 deletions libafl/src/inputs/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::cell::RefCell;
use libafl_bolts::{ownedref::OwnedSlice, HasLen};

use super::ValueInput;
use crate::inputs::{HasMutatorBytes, HasMutatorResizableBytes, HasTargetBytes};
use crate::inputs::{HasFixedMutatorBytes, HasMutatorBytes, HasTargetBytes};

/// A bytes input is the basic input
pub type BytesInput = ValueInput<Vec<u8>>;
Expand All @@ -23,7 +23,7 @@ impl From<BytesInput> for Rc<RefCell<BytesInput>> {
}
}

impl HasMutatorBytes for BytesInput {
impl HasFixedMutatorBytes for BytesInput {
fn bytes(&self) -> &[u8] {
self.as_ref()
}
Expand All @@ -33,7 +33,7 @@ impl HasMutatorBytes for BytesInput {
}
}

impl HasMutatorResizableBytes for BytesInput {
impl HasMutatorBytes for BytesInput {
fn resize(&mut self, new_len: usize, value: u8) {
self.as_mut().resize(new_len, value);
}
Expand Down
24 changes: 12 additions & 12 deletions libafl/src/inputs/bytessub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ use libafl_bolts::{
HasLen,
};

use crate::inputs::{HasMutatorBytes, HasMutatorResizableBytes};
use crate::inputs::{HasFixedMutatorBytes, HasMutatorBytes};

/// The [`BytesSubInput`] makes it possible to use [`crate::mutators::Mutator`]`s` that work on
/// inputs implementing the [`HasMutatorBytes`] for a sub-range of this input.
/// inputs implementing the [`HasFixedMutatorBytes`] for a sub-range of this input.
///
/// For example, we can do the following:
/// ```rust
/// # extern crate alloc;
/// # extern crate libafl;
/// # use libafl::inputs::{BytesInput, HasMutatorBytes};
/// # use libafl::inputs::{BytesInput, HasFixedMutatorBytes};
/// # use alloc::vec::Vec;
/// #
/// # #[cfg(not(feature = "std"))]
Expand All @@ -37,15 +37,15 @@ use crate::inputs::{HasMutatorBytes, HasMutatorResizableBytes};
/// assert_eq!(bytes_input.bytes()[1], 42);
/// ```
///
/// If inputs implement the [`HasMutatorResizableBytes`] trait, growing or shrinking the sub input
/// If inputs implement the [`HasMutatorBytes`] trait, growing or shrinking the sub input
/// will grow or shrink the parent input,
/// and keep elements around the current range untouched / move them accordingly.
///
/// For example:
/// ```rust
/// # extern crate alloc;
/// # extern crate libafl;
/// # use libafl::inputs::{BytesInput, HasMutatorBytes, HasMutatorResizableBytes};
/// # use libafl::inputs::{BytesInput, HasFixedMutatorBytes, HasMutatorBytes};
/// # use alloc::vec::Vec;
/// #
/// # #[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct BytesSubInput<'a, I: ?Sized> {

impl<'a, I> BytesSubInput<'a, I>
where
I: HasMutatorBytes + ?Sized,
I: HasFixedMutatorBytes + ?Sized,
{
/// Creates a new [`BytesSubInput`] that's a view on an input with mutator bytes.
/// The sub input can then be used to mutate parts of the original input.
Expand All @@ -97,9 +97,9 @@ where
}
}

impl<I> HasMutatorBytes for BytesSubInput<'_, I>
impl<I> HasFixedMutatorBytes for BytesSubInput<'_, I>
where
I: HasMutatorBytes,
I: HasFixedMutatorBytes,
{
#[inline]
fn bytes(&self) -> &[u8] {
Expand All @@ -112,9 +112,9 @@ where
}
}

impl<I> HasMutatorResizableBytes for BytesSubInput<'_, I>
impl<I> HasMutatorBytes for BytesSubInput<'_, I>
where
I: HasMutatorResizableBytes,
I: HasMutatorBytes,
{
fn resize(&mut self, new_len: usize, value: u8) {
let start_index = self.range.start;
Expand Down Expand Up @@ -200,7 +200,7 @@ where

impl<I> HasLen for BytesSubInput<'_, I>
where
I: HasMutatorBytes,
I: HasFixedMutatorBytes,
{
#[inline]
fn len(&self) -> usize {
Expand All @@ -214,7 +214,7 @@ mod tests {
use libafl_bolts::HasLen;

use crate::{
inputs::{BytesInput, HasMutatorBytes, HasMutatorResizableBytes, NopInput},
inputs::{BytesInput, HasFixedMutatorBytes, HasMutatorBytes, NopInput},
mutators::{havoc_mutations_no_crossover, MutatorsTuple},
state::NopState,
};
Expand Down
12 changes: 6 additions & 6 deletions libafl/src/inputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub trait HasTargetBytes {
}

/// Contains mutable bytes
pub trait HasMutatorBytes: HasLen {
pub trait HasFixedMutatorBytes: HasLen {
/// The bytes
fn bytes(&self) -> &[u8];

Expand Down Expand Up @@ -188,7 +188,7 @@ pub trait HasMutatorBytes: HasLen {
}
}

impl HasMutatorBytes for Vec<u8> {
impl HasFixedMutatorBytes for Vec<u8> {
fn bytes(&self) -> &[u8] {
self.as_ref()
}
Expand All @@ -202,7 +202,7 @@ impl HasMutatorBytes for Vec<u8> {
#[deprecated(since = "0.15.0", note = "Use &mut Vec<u8> directly")]
pub type MutVecInput<'a> = &'a mut Vec<u8>;

impl HasMutatorBytes for &'_ mut Vec<u8> {
impl HasFixedMutatorBytes for &'_ mut Vec<u8> {
fn bytes(&self) -> &[u8] {
self
}
Expand All @@ -213,7 +213,7 @@ impl HasMutatorBytes for &'_ mut Vec<u8> {
}

/// Contains mutable and resizable bytes
pub trait HasMutatorResizableBytes: HasMutatorBytes {
pub trait HasMutatorBytes: HasFixedMutatorBytes {
/// Resize the mutator bytes to a given new size.
/// Use `value` to fill new slots in case the buffer grows.
/// See [`Vec::splice`].
Expand All @@ -234,7 +234,7 @@ pub trait HasMutatorResizableBytes: HasMutatorBytes {
R: RangeBounds<usize>;
}

impl HasMutatorResizableBytes for Vec<u8> {
impl HasMutatorBytes for Vec<u8> {
fn resize(&mut self, new_len: usize, value: u8) {
<Vec<u8>>::resize(self, new_len, value);
}
Expand All @@ -259,7 +259,7 @@ impl HasMutatorResizableBytes for Vec<u8> {
}
}

impl HasMutatorResizableBytes for &mut Vec<u8> {
impl HasMutatorBytes for &mut Vec<u8> {
fn resize(&mut self, new_len: usize, value: u8) {
self.deref_mut().resize(new_len, value);
}
Expand Down
6 changes: 3 additions & 3 deletions libafl/src/mutators/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libafl_bolts::{rands::Rand, Error};
use crate::{
corpus::{Corpus, CorpusId},
impl_default_multipart,
inputs::{multi::MultipartInput, HasMutatorResizableBytes, Input},
inputs::{multi::MultipartInput, HasMutatorBytes, Input},
mutators::{
mutations::{
rand_range, BitFlipMutator, ByteAddMutator, ByteDecMutator, ByteFlipMutator,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl_default_multipart!(
impl<I, S> Mutator<MultipartInput<I>, S> for CrossoverInsertMutator
where
S: HasCorpus<MultipartInput<I>> + HasMaxSize + HasRand,
I: Input + HasMutatorResizableBytes,
I: Input + HasMutatorBytes,
{
fn mutate(
&mut self,
Expand Down Expand Up @@ -254,7 +254,7 @@ where
impl<I, S> Mutator<MultipartInput<I>, S> for CrossoverReplaceMutator
where
S: HasCorpus<MultipartInput<I>> + HasMaxSize + HasRand,
I: Input + HasMutatorResizableBytes,
I: Input + HasMutatorBytes,
{
fn mutate(
&mut self,
Expand Down
Loading

0 comments on commit c9bc133

Please sign in to comment.