started corpus
This commit is contained in:
parent
d91717a34c
commit
abc3eb8664
@ -8,3 +8,4 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
xxhrs = { version = "2.0.0", features = [] } #"random_entropy"] }
|
||||
thiserror = "1.0"
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::inputs::Input;
|
||||
|
||||
use std::io::Error;
|
||||
|
||||
use crate::AflError;
|
||||
use crate::inputs::Input;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct BytesInput {
|
||||
bytes: Vec<u8>,
|
||||
@ -9,10 +10,10 @@ pub struct BytesInput {
|
||||
|
||||
impl Input for BytesInput {
|
||||
|
||||
fn serialize(&self) -> Result<&[u8], Error> {
|
||||
fn serialize(&self) -> Result<&[u8], AflError> {
|
||||
Ok(&self.bytes)
|
||||
}
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error> {
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError> {
|
||||
self.bytes.truncate(0);
|
||||
self.bytes.extend_from_slice(buf);
|
||||
Ok(())
|
||||
|
@ -5,15 +5,17 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::io::Read;
|
||||
|
||||
use crate::AflError;
|
||||
|
||||
pub trait Input {
|
||||
|
||||
fn to_file(&self, path: &str) -> Result<(), Error> {
|
||||
fn to_file(&self, path: &str) -> Result<(), AflError> {
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(self.serialize()?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn from_file(&mut self, path: &str) -> Result<(), Error> {
|
||||
fn from_file(&mut self, path: &str) -> Result<(), AflError> {
|
||||
let mut file = File::create(path)?;
|
||||
let mut buf = vec![];
|
||||
file.read_to_end(&mut buf)?;
|
||||
@ -21,8 +23,8 @@ pub trait Input {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize(&self) -> Result<&[u8], Error>;
|
||||
fn serialize(&self) -> Result<&[u8], AflError>;
|
||||
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), Error>;
|
||||
fn deserialize(&mut self, buf: &[u8]) -> Result<(), AflError>;
|
||||
|
||||
}
|
17
src/lib.rs
17
src/lib.rs
@ -1,3 +1,7 @@
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod corpus;
|
||||
pub mod engines;
|
||||
pub mod executors;
|
||||
pub mod feedbacks;
|
||||
@ -7,6 +11,19 @@ pub mod mutators;
|
||||
pub mod stages;
|
||||
pub mod utils;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum AflError {
|
||||
#[error("Error in Serialization: `{0}`")]
|
||||
Serialize(String),
|
||||
#[error("File IO failed")]
|
||||
File(#[from] io::Error),
|
||||
#[error("Key `{0}` not in Corpus")]
|
||||
KeyNotFound(String),
|
||||
#[error("Unknown error")]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
12
src/main.rs
12
src/main.rs
@ -1,12 +0,0 @@
|
||||
pub mod engines;
|
||||
pub mod executors;
|
||||
pub mod feedbacks;
|
||||
pub mod inputs;
|
||||
pub mod monitors;
|
||||
pub mod mutators;
|
||||
pub mod stages;
|
||||
pub mod utils;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user