From c219502f0fe654927c3f74f9791f786f0740f344 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sat, 27 Feb 2021 15:52:36 +0100 Subject: some rust cleanup --- custom_mutators/rust/example/Cargo.toml | 6 ++- .../rust/example/src/example_mutator.rs | 49 +++++++++++++++++++++ custom_mutators/rust/example/src/lib.rs | 50 ---------------------- 3 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 custom_mutators/rust/example/src/example_mutator.rs delete mode 100644 custom_mutators/rust/example/src/lib.rs (limited to 'custom_mutators/rust/example') diff --git a/custom_mutators/rust/example/Cargo.toml b/custom_mutators/rust/example/Cargo.toml index 0c89b200..070d23b1 100644 --- a/custom_mutators/rust/example/Cargo.toml +++ b/custom_mutators/rust/example/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "example" +name = "example_mutator" version = "0.1.0" authors = ["Julius Hohnerlein "] edition = "2018" @@ -9,5 +9,7 @@ edition = "2018" [dependencies] custom_mutator = { path = "../custom_mutator" } -[lib] +[[example]] +name = "example_mutator" +path = "./src/example_mutator.rs" crate-type = ["cdylib"] \ No newline at end of file diff --git a/custom_mutators/rust/example/src/example_mutator.rs b/custom_mutators/rust/example/src/example_mutator.rs new file mode 100644 index 00000000..9b9d4997 --- /dev/null +++ b/custom_mutators/rust/example/src/example_mutator.rs @@ -0,0 +1,49 @@ +#![allow(unused_variables)] + +use custom_mutator::{export_mutator, CustomMutator}; + +struct ExampleMutator; + +impl CustomMutator for ExampleMutator { + type Error = (); + + fn init(seed: u32) -> Result { + Ok(Self) + } + + fn fuzz<'b, 's: 'b>( + &'s mut self, + buffer: &'b mut [u8], + add_buff: Option<&[u8]>, + max_size: usize, + ) -> Result, Self::Error> { + buffer.reverse(); + Ok(Some(buffer)) + } +} + +struct OwnBufferExampleMutator { + own_buffer: Vec, +} + +impl CustomMutator for OwnBufferExampleMutator { + type Error = (); + + fn init(seed: u32) -> Result { + Ok(Self { + own_buffer: Vec::new(), + }) + } + + fn fuzz<'b, 's: 'b>( + &'s mut self, + buffer: &'b mut [u8], + add_buff: Option<&[u8]>, + max_size: usize, + ) -> Result, ()> { + self.own_buffer.reverse(); + Ok(Some(self.own_buffer.as_slice())) + } +} + +export_mutator!(ExampleMutator); diff --git a/custom_mutators/rust/example/src/lib.rs b/custom_mutators/rust/example/src/lib.rs deleted file mode 100644 index 4f9345c0..00000000 --- a/custom_mutators/rust/example/src/lib.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(unused_variables)] - -use custom_mutator::{export_mutator, CustomMutator}; -use std::os::raw::c_uint; - -struct ExampleMutator; - -impl CustomMutator for ExampleMutator { - type Error = (); - - fn init(seed: c_uint) -> Result { - Ok(Self) - } - - fn fuzz<'b, 's: 'b>( - &'s mut self, - buffer: &'b mut [u8], - add_buff: Option<&[u8]>, - max_size: usize, - ) -> Result, ()> { - buffer.reverse(); - Ok(Some(buffer)) - } -} - -struct OwnBufferExampleMutator { - own_buffer: Vec, -} - -impl CustomMutator for OwnBufferExampleMutator { - type Error = (); - - fn init(seed: c_uint) -> Result { - Ok(Self { - own_buffer: Vec::new(), - }) - } - - fn fuzz<'b, 's: 'b>( - &'s mut self, - buffer: &'b mut [u8], - add_buff: Option<&[u8]>, - max_size: usize, - ) -> Result, ()> { - self.own_buffer.reverse(); - Ok(Some(self.own_buffer.as_slice())) - } -} - -export_mutator!(ExampleMutator); -- cgit 1.4.1