AflError -> Error & AflShmem -> UnixShMem
This commit is contained in:
parent
6875f00736
commit
8059a765ed
@ -7,15 +7,15 @@ use core::{convert::TryInto, time::Duration};
|
|||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
use afl::{
|
use afl::{
|
||||||
bolts::{llmp, shmem::AflShmem},
|
bolts::{llmp, shmem::UnixShMem},
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
const TAG_SIMPLE_U32_V1: u32 = 0x51300321;
|
const TAG_SIMPLE_U32_V1: u32 = 0x51300321;
|
||||||
const TAG_MATH_RESULT_V1: u32 = 0x77474331;
|
const TAG_MATH_RESULT_V1: u32 = 0x77474331;
|
||||||
|
|
||||||
fn adder_loop(port: u16) -> ! {
|
fn adder_loop(port: u16) -> ! {
|
||||||
let mut client = llmp::LlmpClient::<AflShmem>::create_attach_to_tcp(port).unwrap();
|
let mut client = llmp::LlmpClient::<UnixShMem>::create_attach_to_tcp(port).unwrap();
|
||||||
let mut last_result: u32 = 0;
|
let mut last_result: u32 = 0;
|
||||||
let mut current_result: u32 = 0;
|
let mut current_result: u32 = 0;
|
||||||
loop {
|
loop {
|
||||||
@ -55,7 +55,7 @@ fn broker_message_hook(
|
|||||||
client_id: u32,
|
client_id: u32,
|
||||||
tag: llmp::Tag,
|
tag: llmp::Tag,
|
||||||
message: &[u8],
|
message: &[u8],
|
||||||
) -> Result<llmp::LlmpMsgHookResult, AflError> {
|
) -> Result<llmp::LlmpMsgHookResult, Error> {
|
||||||
match tag {
|
match tag {
|
||||||
TAG_SIMPLE_U32_V1 => {
|
TAG_SIMPLE_U32_V1 => {
|
||||||
println!(
|
println!(
|
||||||
@ -94,7 +94,7 @@ fn main() {
|
|||||||
|
|
||||||
match mode.as_str() {
|
match mode.as_str() {
|
||||||
"broker" => {
|
"broker" => {
|
||||||
let mut broker = llmp::LlmpBroker::<AflShmem>::new().unwrap();
|
let mut broker = llmp::LlmpBroker::<UnixShMem>::new().unwrap();
|
||||||
broker
|
broker
|
||||||
.launch_tcp_listener(
|
.launch_tcp_listener(
|
||||||
std::net::TcpListener::bind(format!("127.0.0.1:{}", port)).unwrap(),
|
std::net::TcpListener::bind(format!("127.0.0.1:{}", port)).unwrap(),
|
||||||
@ -103,7 +103,7 @@ fn main() {
|
|||||||
broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5)))
|
broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5)))
|
||||||
}
|
}
|
||||||
"ctr" => {
|
"ctr" => {
|
||||||
let mut client = llmp::LlmpClient::<AflShmem>::create_attach_to_tcp(port).unwrap();
|
let mut client = llmp::LlmpClient::<UnixShMem>::create_attach_to_tcp(port).unwrap();
|
||||||
let mut counter: u32 = 0;
|
let mut counter: u32 = 0;
|
||||||
loop {
|
loop {
|
||||||
counter = counter.wrapping_add(1);
|
counter = counter.wrapping_add(1);
|
||||||
|
@ -67,7 +67,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::shmem::{ShMem, ShMemDescription};
|
use super::shmem::{ShMem, ShMemDescription};
|
||||||
use crate::AflError;
|
use crate::Error;
|
||||||
|
|
||||||
/// We'll start off with 256 megabyte maps per fuzzer client
|
/// We'll start off with 256 megabyte maps per fuzzer client
|
||||||
const LLMP_PREF_INITIAL_MAP_SIZE: usize = 1 << 28;
|
const LLMP_PREF_INITIAL_MAP_SIZE: usize = 1 << 28;
|
||||||
@ -140,7 +140,7 @@ const fn llmp_align(to_align: usize) -> usize {
|
|||||||
/// If the content of the env is _NULL, returns None
|
/// If the content of the env is _NULL, returns None
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, AflError> {
|
fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, Error> {
|
||||||
let msg_offset_str = env::var(&format!("{}_OFFSET", env_name))?;
|
let msg_offset_str = env::var(&format!("{}_OFFSET", env_name))?;
|
||||||
Ok(if msg_offset_str == _NULL_ENV_STR {
|
Ok(if msg_offset_str == _NULL_ENV_STR {
|
||||||
None
|
None
|
||||||
@ -191,7 +191,7 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
|
|||||||
map: &mut LlmpSharedMap<SH>,
|
map: &mut LlmpSharedMap<SH>,
|
||||||
last_msg: *const LlmpMsg,
|
last_msg: *const LlmpMsg,
|
||||||
alloc_size: usize,
|
alloc_size: usize,
|
||||||
) -> Result<*mut LlmpMsg, AflError> {
|
) -> Result<*mut LlmpMsg, Error> {
|
||||||
let page = map.page_mut();
|
let page = map.page_mut();
|
||||||
let map_size = map.shmem.map().len();
|
let map_size = map.shmem.map().len();
|
||||||
let msg_begin_min = (page as *const u8).offset(size_of::<LlmpPage>() as isize);
|
let msg_begin_min = (page as *const u8).offset(size_of::<LlmpPage>() as isize);
|
||||||
@ -202,7 +202,7 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
|
|||||||
if next_ptr >= msg_begin_min && next_ptr <= msg_begin_max {
|
if next_ptr >= msg_begin_min && next_ptr <= msg_begin_max {
|
||||||
Ok(next)
|
Ok(next)
|
||||||
} else {
|
} else {
|
||||||
Err(AflError::IllegalState(format!(
|
Err(Error::IllegalState(format!(
|
||||||
"Inconsistent data on sharedmap, or Bug (next_ptr was {:x}, sharedmap page was {:x})",
|
"Inconsistent data on sharedmap, or Bug (next_ptr was {:x}, sharedmap page was {:x})",
|
||||||
next_ptr as usize, page as usize
|
next_ptr as usize, page as usize
|
||||||
)))
|
)))
|
||||||
@ -265,12 +265,12 @@ impl LlmpMsg {
|
|||||||
|
|
||||||
/// Gets the buffer from this message as slice, with the corrent length.
|
/// Gets the buffer from this message as slice, with the corrent length.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_slice<SH: ShMem>(&self, map: &mut LlmpSharedMap<SH>) -> Result<&[u8], AflError> {
|
pub fn as_slice<SH: ShMem>(&self, map: &mut LlmpSharedMap<SH>) -> Result<&[u8], Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if self.in_map(map) {
|
if self.in_map(map) {
|
||||||
Ok(self.as_slice_unsafe())
|
Ok(self.as_slice_unsafe())
|
||||||
} else {
|
} else {
|
||||||
Err(AflError::IllegalState("Current message not in page. The sharedmap get tampered with or we have a BUG.".into()))
|
Err(Error::IllegalState("Current message not in page. The sharedmap get tampered with or we have a BUG.".into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ where
|
|||||||
{
|
{
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
/// Creates either a broker, if the tcp port is not bound, or a client, connected to this port.
|
/// Creates either a broker, if the tcp port is not bound, or a client, connected to this port.
|
||||||
pub fn on_port(port: u16) -> Result<Self, AflError> {
|
pub fn on_port(port: u16) -> Result<Self, Error> {
|
||||||
match TcpListener::bind(format!("127.0.0.1:{}", port)) {
|
match TcpListener::bind(format!("127.0.0.1:{}", port)) {
|
||||||
Ok(listener) => {
|
Ok(listener) => {
|
||||||
// We got the port. We are the broker! :)
|
// We got the port. We are the broker! :)
|
||||||
@ -332,14 +332,14 @@ where
|
|||||||
client: LlmpClient::create_attach_to_tcp(port)?,
|
client: LlmpClient::create_attach_to_tcp(port)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => Err(AflError::File(e)),
|
_ => Err(Error::File(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describe this in a reproducable fashion, if it's a client
|
/// Describe this in a reproducable fashion, if it's a client
|
||||||
pub fn describe(&self) -> Result<LlmpClientDescription, AflError> {
|
pub fn describe(&self) -> Result<LlmpClientDescription, Error> {
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
LlmpConnection::IsClient { client } => client.describe()?,
|
LlmpConnection::IsClient { client } => client.describe()?,
|
||||||
_ => todo!("Only client can be described atm."),
|
_ => todo!("Only client can be described atm."),
|
||||||
@ -349,14 +349,14 @@ where
|
|||||||
/// Recreate an existing client from the stored description
|
/// Recreate an existing client from the stored description
|
||||||
pub fn existing_client_from_description(
|
pub fn existing_client_from_description(
|
||||||
description: &LlmpClientDescription,
|
description: &LlmpClientDescription,
|
||||||
) -> Result<LlmpConnection<SH>, AflError> {
|
) -> Result<LlmpConnection<SH>, Error> {
|
||||||
Ok(LlmpConnection::IsClient {
|
Ok(LlmpConnection::IsClient {
|
||||||
client: LlmpClient::existing_client_from_description(description)?,
|
client: LlmpClient::existing_client_from_description(description)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends the given buffer over this connection, no matter if client or broker.
|
/// Sends the given buffer over this connection, no matter if client or broker.
|
||||||
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> {
|
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> {
|
||||||
match self {
|
match self {
|
||||||
LlmpConnection::IsBroker { broker } => broker.send_buf(tag, buf),
|
LlmpConnection::IsBroker { broker } => broker.send_buf(tag, buf),
|
||||||
LlmpConnection::IsClient { client } => client.send_buf(tag, buf),
|
LlmpConnection::IsClient { client } => client.send_buf(tag, buf),
|
||||||
@ -428,7 +428,7 @@ impl<SH> LlmpSender<SH>
|
|||||||
where
|
where
|
||||||
SH: ShMem,
|
SH: ShMem,
|
||||||
{
|
{
|
||||||
pub fn new(id: u32, keep_pages_forever: bool) -> Result<Self, AflError> {
|
pub fn new(id: u32, keep_pages_forever: bool) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
last_msg_sent: ptr::null_mut(),
|
last_msg_sent: ptr::null_mut(),
|
||||||
@ -451,7 +451,7 @@ where
|
|||||||
|
|
||||||
/// Reattach to a vacant out_map, to with a previous sender stored the information in an env before.
|
/// Reattach to a vacant out_map, to with a previous sender stored the information in an env before.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn on_existing_from_env(env_name: &str) -> Result<Self, AflError> {
|
pub fn on_existing_from_env(env_name: &str) -> Result<Self, Error> {
|
||||||
let msg_sent_offset = msg_offset_from_env(env_name)?;
|
let msg_sent_offset = msg_offset_from_env(env_name)?;
|
||||||
Self::on_existing_map(SH::existing_from_env(env_name)?, msg_sent_offset)
|
Self::on_existing_map(SH::existing_from_env(env_name)?, msg_sent_offset)
|
||||||
}
|
}
|
||||||
@ -459,7 +459,7 @@ where
|
|||||||
/// Store the info to this sender to env.
|
/// Store the info to this sender to env.
|
||||||
/// A new client can reattach to it using on_existing_from_env
|
/// A new client can reattach to it using on_existing_from_env
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn to_env(&self, env_name: &str) -> Result<(), AflError> {
|
pub fn to_env(&self, env_name: &str) -> Result<(), Error> {
|
||||||
let current_out_map = self.out_maps.last().unwrap();
|
let current_out_map = self.out_maps.last().unwrap();
|
||||||
current_out_map.shmem.write_to_env(env_name)?;
|
current_out_map.shmem.write_to_env(env_name)?;
|
||||||
current_out_map.msg_to_env(self.last_msg_sent, env_name)
|
current_out_map.msg_to_env(self.last_msg_sent, env_name)
|
||||||
@ -491,7 +491,7 @@ where
|
|||||||
pub fn on_existing_map(
|
pub fn on_existing_map(
|
||||||
current_out_map: SH,
|
current_out_map: SH,
|
||||||
last_msg_sent_offset: Option<u64>,
|
last_msg_sent_offset: Option<u64>,
|
||||||
) -> Result<Self, AflError> {
|
) -> Result<Self, Error> {
|
||||||
let mut out_map = LlmpSharedMap::existing(current_out_map);
|
let mut out_map = LlmpSharedMap::existing(current_out_map);
|
||||||
let last_msg_sent = match last_msg_sent_offset {
|
let last_msg_sent = match last_msg_sent_offset {
|
||||||
Some(offset) => out_map.msg_from_offset(offset)?,
|
Some(offset) => out_map.msg_from_offset(offset)?,
|
||||||
@ -529,7 +529,7 @@ where
|
|||||||
/// The normal alloc will fail if there is not enough space for buf_len_padded + EOP
|
/// The normal alloc will fail if there is not enough space for buf_len_padded + EOP
|
||||||
/// So if alloc_next fails, create new page if necessary, use this function,
|
/// So if alloc_next fails, create new page if necessary, use this function,
|
||||||
/// place EOP, commit EOP, reset, alloc again on the new space.
|
/// place EOP, commit EOP, reset, alloc again on the new space.
|
||||||
unsafe fn alloc_eop(&mut self) -> Result<*mut LlmpMsg, AflError> {
|
unsafe fn alloc_eop(&mut self) -> Result<*mut LlmpMsg, Error> {
|
||||||
let mut map = self.out_maps.last_mut().unwrap();
|
let mut map = self.out_maps.last_mut().unwrap();
|
||||||
let page = map.page_mut();
|
let page = map.page_mut();
|
||||||
let last_msg = self.last_msg_sent;
|
let last_msg = self.last_msg_sent;
|
||||||
@ -650,7 +650,7 @@ where
|
|||||||
/// After commiting, the msg shall no longer be altered!
|
/// After commiting, the msg shall no longer be altered!
|
||||||
/// It will be read by the consuming threads (broker->clients or client->broker)
|
/// It will be read by the consuming threads (broker->clients or client->broker)
|
||||||
#[inline(never)] // Not inlined to make cpu-level reodering (hopefully?) improbable
|
#[inline(never)] // Not inlined to make cpu-level reodering (hopefully?) improbable
|
||||||
unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), AflError> {
|
unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), Error> {
|
||||||
if self.last_msg_sent == msg {
|
if self.last_msg_sent == msg {
|
||||||
panic!("Message sent twice!");
|
panic!("Message sent twice!");
|
||||||
}
|
}
|
||||||
@ -659,7 +659,7 @@ where
|
|||||||
}
|
}
|
||||||
let page = self.out_maps.last_mut().unwrap().page_mut();
|
let page = self.out_maps.last_mut().unwrap().page_mut();
|
||||||
if msg.is_null() || !llmp_msg_in_page(page, msg) {
|
if msg.is_null() || !llmp_msg_in_page(page, msg) {
|
||||||
return Err(AflError::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Llmp Message {:?} is null or not in current page",
|
"Llmp Message {:?} is null or not in current page",
|
||||||
msg
|
msg
|
||||||
)));
|
)));
|
||||||
@ -673,7 +673,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// listener about it using a EOP message.
|
/// listener about it using a EOP message.
|
||||||
unsafe fn handle_out_eop(&mut self) -> Result<(), AflError> {
|
unsafe fn handle_out_eop(&mut self) -> Result<(), Error> {
|
||||||
let old_map = self.out_maps.last_mut().unwrap().page_mut();
|
let old_map = self.out_maps.last_mut().unwrap().page_mut();
|
||||||
|
|
||||||
// Create a new shard page.
|
// Create a new shard page.
|
||||||
@ -710,7 +710,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Allocates the next space on this sender page
|
/// Allocates the next space on this sender page
|
||||||
pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, AflError> {
|
pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
|
||||||
match self.alloc_next_if_space(buf_len) {
|
match self.alloc_next_if_space(buf_len) {
|
||||||
Some(msg) => return Ok(msg),
|
Some(msg) => return Ok(msg),
|
||||||
_ => (),
|
_ => (),
|
||||||
@ -721,7 +721,7 @@ where
|
|||||||
|
|
||||||
match self.alloc_next_if_space(buf_len) {
|
match self.alloc_next_if_space(buf_len) {
|
||||||
Some(msg) => Ok(msg),
|
Some(msg) => Ok(msg),
|
||||||
None => Err(AflError::Unknown(format!(
|
None => Err(Error::Unknown(format!(
|
||||||
"Error allocating {} bytes in shmap",
|
"Error allocating {} bytes in shmap",
|
||||||
buf_len
|
buf_len
|
||||||
))),
|
))),
|
||||||
@ -738,14 +738,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Allocates a message of the given size, tags it, and sends it off.
|
/// Allocates a message of the given size, tags it, and sends it off.
|
||||||
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> {
|
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> {
|
||||||
// Make sure we don't reuse already allocated tags
|
// Make sure we don't reuse already allocated tags
|
||||||
if tag == LLMP_TAG_NEW_SHM_CLIENT
|
if tag == LLMP_TAG_NEW_SHM_CLIENT
|
||||||
|| tag == LLMP_TAG_END_OF_PAGE
|
|| tag == LLMP_TAG_END_OF_PAGE
|
||||||
|| tag == LLMP_TAG_UNINITIALIZED
|
|| tag == LLMP_TAG_UNINITIALIZED
|
||||||
|| tag == LLMP_TAG_UNSET
|
|| tag == LLMP_TAG_UNSET
|
||||||
{
|
{
|
||||||
return Err(AflError::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Reserved tag supplied to send_buf ({:#X})",
|
"Reserved tag supplied to send_buf ({:#X})",
|
||||||
tag
|
tag
|
||||||
)));
|
)));
|
||||||
@ -760,7 +760,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Describe this cient in a way, that it can be restored later with `Self::on_existing_from_description`
|
// Describe this cient in a way, that it can be restored later with `Self::on_existing_from_description`
|
||||||
pub fn describe(&self) -> Result<LlmpDescription, AflError> {
|
pub fn describe(&self) -> Result<LlmpDescription, Error> {
|
||||||
let map = self.out_maps.last().unwrap();
|
let map = self.out_maps.last().unwrap();
|
||||||
let last_message_offset = if self.last_msg_sent.is_null() {
|
let last_message_offset = if self.last_msg_sent.is_null() {
|
||||||
None
|
None
|
||||||
@ -774,7 +774,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create this client on an existing map from the given description. acquired with `self.describe`
|
// Create this client on an existing map from the given description. acquired with `self.describe`
|
||||||
pub fn on_existing_from_description(description: &LlmpDescription) -> Result<Self, AflError> {
|
pub fn on_existing_from_description(description: &LlmpDescription) -> Result<Self, Error> {
|
||||||
Self::on_existing_map(
|
Self::on_existing_map(
|
||||||
SH::existing_from_description(&description.shmem)?,
|
SH::existing_from_description(&description.shmem)?,
|
||||||
description.last_message_offset,
|
description.last_message_offset,
|
||||||
@ -802,7 +802,7 @@ where
|
|||||||
{
|
{
|
||||||
/// Reattach to a vacant recv_map, to with a previous sender stored the information in an env before.
|
/// Reattach to a vacant recv_map, to with a previous sender stored the information in an env before.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn on_existing_from_env(env_name: &str) -> Result<Self, AflError> {
|
pub fn on_existing_from_env(env_name: &str) -> Result<Self, Error> {
|
||||||
Self::on_existing_map(
|
Self::on_existing_map(
|
||||||
SH::existing_from_env(env_name)?,
|
SH::existing_from_env(env_name)?,
|
||||||
msg_offset_from_env(env_name)?,
|
msg_offset_from_env(env_name)?,
|
||||||
@ -812,7 +812,7 @@ where
|
|||||||
/// Store the info to this receiver to env.
|
/// Store the info to this receiver to env.
|
||||||
/// A new client can reattach to it using on_existing_from_env
|
/// A new client can reattach to it using on_existing_from_env
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn to_env(&self, env_name: &str) -> Result<(), AflError> {
|
pub fn to_env(&self, env_name: &str) -> Result<(), Error> {
|
||||||
let current_out_map = &self.current_recv_map;
|
let current_out_map = &self.current_recv_map;
|
||||||
current_out_map.shmem.write_to_env(env_name)?;
|
current_out_map.shmem.write_to_env(env_name)?;
|
||||||
current_out_map.msg_to_env(self.last_msg_recvd, env_name)
|
current_out_map.msg_to_env(self.last_msg_recvd, env_name)
|
||||||
@ -824,7 +824,7 @@ where
|
|||||||
pub fn on_existing_map(
|
pub fn on_existing_map(
|
||||||
current_sender_map: SH,
|
current_sender_map: SH,
|
||||||
last_msg_recvd_offset: Option<u64>,
|
last_msg_recvd_offset: Option<u64>,
|
||||||
) -> Result<Self, AflError> {
|
) -> Result<Self, Error> {
|
||||||
let mut current_recv_map = LlmpSharedMap::existing(current_sender_map);
|
let mut current_recv_map = LlmpSharedMap::existing(current_sender_map);
|
||||||
let last_msg_recvd = match last_msg_recvd_offset {
|
let last_msg_recvd = match last_msg_recvd_offset {
|
||||||
Some(offset) => current_recv_map.msg_from_offset(offset)?,
|
Some(offset) => current_recv_map.msg_from_offset(offset)?,
|
||||||
@ -841,7 +841,7 @@ where
|
|||||||
// Never inline, to not get some strange effects
|
// Never inline, to not get some strange effects
|
||||||
/// Read next message.
|
/// Read next message.
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, AflError> {
|
unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, Error> {
|
||||||
/* DBG("recv %p %p\n", page, last_msg); */
|
/* DBG("recv %p %p\n", page, last_msg); */
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
let page = self.current_recv_map.page_mut();
|
let page = self.current_recv_map.page_mut();
|
||||||
@ -871,7 +871,7 @@ where
|
|||||||
match ret {
|
match ret {
|
||||||
Some(msg) => {
|
Some(msg) => {
|
||||||
if !(*msg).in_map(&mut self.current_recv_map) {
|
if !(*msg).in_map(&mut self.current_recv_map) {
|
||||||
return Err(AflError::IllegalState("Unexpected message in map (out of map bounds) - bugy client or tampered shared map detedted!".into()));
|
return Err(Error::IllegalState("Unexpected message in map (out of map bounds) - bugy client or tampered shared map detedted!".into()));
|
||||||
}
|
}
|
||||||
// Handle special, LLMP internal, messages.
|
// Handle special, LLMP internal, messages.
|
||||||
match (*msg).tag {
|
match (*msg).tag {
|
||||||
@ -923,7 +923,7 @@ where
|
|||||||
|
|
||||||
/// Blocks/spins until the next message gets posted to the page,
|
/// Blocks/spins until the next message gets posted to the page,
|
||||||
/// then returns that message.
|
/// then returns that message.
|
||||||
pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, AflError> {
|
pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, Error> {
|
||||||
let mut current_msg_id = 0;
|
let mut current_msg_id = 0;
|
||||||
let page = self.current_recv_map.page_mut();
|
let page = self.current_recv_map.page_mut();
|
||||||
let last_msg = self.last_msg_recvd;
|
let last_msg = self.last_msg_recvd;
|
||||||
@ -946,7 +946,7 @@ where
|
|||||||
|
|
||||||
/// Returns the next message, tag, buf, if avaliable, else None
|
/// Returns the next message, tag, buf, if avaliable, else None
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, AflError> {
|
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Ok(match self.recv()? {
|
Ok(match self.recv()? {
|
||||||
Some(msg) => Some((
|
Some(msg) => Some((
|
||||||
@ -961,7 +961,7 @@ where
|
|||||||
|
|
||||||
/// Returns the next sender, tag, buf, looping until it becomes available
|
/// Returns the next sender, tag, buf, looping until it becomes available
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), AflError> {
|
pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let msg = self.recv_blocking()?;
|
let msg = self.recv_blocking()?;
|
||||||
Ok((
|
Ok((
|
||||||
@ -973,7 +973,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Describe this cient in a way, that it can be restored later with `Self::on_existing_from_description`
|
// Describe this cient in a way, that it can be restored later with `Self::on_existing_from_description`
|
||||||
pub fn describe(&self) -> Result<LlmpDescription, AflError> {
|
pub fn describe(&self) -> Result<LlmpDescription, Error> {
|
||||||
let map = &self.current_recv_map;
|
let map = &self.current_recv_map;
|
||||||
let last_message_offset = if self.last_msg_recvd.is_null() {
|
let last_message_offset = if self.last_msg_recvd.is_null() {
|
||||||
None
|
None
|
||||||
@ -987,7 +987,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create this client on an existing map from the given description. acquired with `self.describe`
|
// Create this client on an existing map from the given description. acquired with `self.describe`
|
||||||
pub fn on_existing_from_description(description: &LlmpDescription) -> Result<Self, AflError> {
|
pub fn on_existing_from_description(description: &LlmpDescription) -> Result<Self, Error> {
|
||||||
Self::on_existing_map(
|
Self::on_existing_map(
|
||||||
SH::existing_from_description(&description.shmem)?,
|
SH::existing_from_description(&description.shmem)?,
|
||||||
description.last_message_offset,
|
description.last_message_offset,
|
||||||
@ -1054,14 +1054,14 @@ where
|
|||||||
|
|
||||||
/// Gets the offset of a message on this here page.
|
/// Gets the offset of a message on this here page.
|
||||||
/// Will return IllegalArgument error if msg is not on page.
|
/// Will return IllegalArgument error if msg is not on page.
|
||||||
pub fn msg_to_offset(&self, msg: *const LlmpMsg) -> Result<u64, AflError> {
|
pub fn msg_to_offset(&self, msg: *const LlmpMsg) -> Result<u64, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let page = self.page();
|
let page = self.page();
|
||||||
if llmp_msg_in_page(page, msg) {
|
if llmp_msg_in_page(page, msg) {
|
||||||
// Cast both sides to u8 arrays, get the offset, then cast the return isize to u64
|
// Cast both sides to u8 arrays, get the offset, then cast the return isize to u64
|
||||||
Ok((msg as *const u8).offset_from((*page).messages.as_ptr() as *const u8) as u64)
|
Ok((msg as *const u8).offset_from((*page).messages.as_ptr() as *const u8) as u64)
|
||||||
} else {
|
} else {
|
||||||
Err(AflError::IllegalArgument(format!(
|
Err(Error::IllegalArgument(format!(
|
||||||
"Message (0x{:X}) not in page (0x{:X})",
|
"Message (0x{:X}) not in page (0x{:X})",
|
||||||
page as u64, msg as u64
|
page as u64, msg as u64
|
||||||
)))
|
)))
|
||||||
@ -1072,7 +1072,7 @@ where
|
|||||||
/// Retrieve the stored msg from env_name + _OFFSET.
|
/// Retrieve the stored msg from env_name + _OFFSET.
|
||||||
/// It will restore the stored offset by env_name and return the message.
|
/// It will restore the stored offset by env_name and return the message.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn msg_from_env(&mut self, map_env_name: &str) -> Result<*mut LlmpMsg, AflError> {
|
pub fn msg_from_env(&mut self, map_env_name: &str) -> Result<*mut LlmpMsg, Error> {
|
||||||
match msg_offset_from_env(map_env_name)? {
|
match msg_offset_from_env(map_env_name)? {
|
||||||
Some(offset) => self.msg_from_offset(offset),
|
Some(offset) => self.msg_from_offset(offset),
|
||||||
None => Ok(ptr::null_mut()),
|
None => Ok(ptr::null_mut()),
|
||||||
@ -1082,7 +1082,7 @@ where
|
|||||||
/// Store this msg offset to env_name + _OFFSET env variable.
|
/// Store this msg offset to env_name + _OFFSET env variable.
|
||||||
/// It can be restored using msg_from_env with the same env_name later.
|
/// It can be restored using msg_from_env with the same env_name later.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), AflError> {
|
pub fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), Error> {
|
||||||
if msg.is_null() {
|
if msg.is_null() {
|
||||||
env::set_var(&format!("{}_OFFSET", map_env_name), _NULL_ENV_STR)
|
env::set_var(&format!("{}_OFFSET", map_env_name), _NULL_ENV_STR)
|
||||||
} else {
|
} else {
|
||||||
@ -1096,12 +1096,12 @@ where
|
|||||||
|
|
||||||
/// Gets this message from this page, at the indicated offset.
|
/// Gets this message from this page, at the indicated offset.
|
||||||
/// Will return IllegalArgument error if the offset is out of bounds.
|
/// Will return IllegalArgument error if the offset is out of bounds.
|
||||||
pub fn msg_from_offset(&mut self, offset: u64) -> Result<*mut LlmpMsg, AflError> {
|
pub fn msg_from_offset(&mut self, offset: u64) -> Result<*mut LlmpMsg, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let page = self.page_mut();
|
let page = self.page_mut();
|
||||||
let page_size = self.shmem.map().len() - size_of::<LlmpPage>();
|
let page_size = self.shmem.map().len() - size_of::<LlmpPage>();
|
||||||
if offset as isize > page_size as isize {
|
if offset as isize > page_size as isize {
|
||||||
Err(AflError::IllegalArgument(format!(
|
Err(Error::IllegalArgument(format!(
|
||||||
"Msg offset out of bounds (size: {}, requested offset: {})",
|
"Msg offset out of bounds (size: {}, requested offset: {})",
|
||||||
page_size, offset
|
page_size, offset
|
||||||
)))
|
)))
|
||||||
@ -1136,7 +1136,7 @@ where
|
|||||||
SH: ShMem,
|
SH: ShMem,
|
||||||
{
|
{
|
||||||
/// Create and initialize a new llmp_broker
|
/// Create and initialize a new llmp_broker
|
||||||
pub fn new() -> Result<Self, AflError> {
|
pub fn new() -> Result<Self, Error> {
|
||||||
let broker = LlmpBroker {
|
let broker = LlmpBroker {
|
||||||
llmp_out: LlmpSender {
|
llmp_out: LlmpSender {
|
||||||
id: 0,
|
id: 0,
|
||||||
@ -1153,7 +1153,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate the next message on the outgoing map
|
/// Allocate the next message on the outgoing map
|
||||||
unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, AflError> {
|
unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
|
||||||
self.llmp_out.alloc_next(buf_len)
|
self.llmp_out.alloc_next(buf_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1172,7 +1172,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// For internal use: Forward the current message to the out map.
|
/// For internal use: Forward the current message to the out map.
|
||||||
unsafe fn forward_msg(&mut self, msg: *mut LlmpMsg) -> Result<(), AflError> {
|
unsafe fn forward_msg(&mut self, msg: *mut LlmpMsg) -> Result<(), Error> {
|
||||||
let mut out: *mut LlmpMsg = self.alloc_next((*msg).buf_len_padded as usize)?;
|
let mut out: *mut LlmpMsg = self.alloc_next((*msg).buf_len_padded as usize)?;
|
||||||
|
|
||||||
/* Copy over the whole message.
|
/* Copy over the whole message.
|
||||||
@ -1193,9 +1193,9 @@ where
|
|||||||
/// The broker walks all pages and looks for changes, then broadcasts them on
|
/// The broker walks all pages and looks for changes, then broadcasts them on
|
||||||
/// its own shared page, once.
|
/// its own shared page, once.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn once<F>(&mut self, on_new_msg: &mut F) -> Result<(), AflError>
|
pub fn once<F>(&mut self, on_new_msg: &mut F) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, AflError>,
|
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
|
||||||
{
|
{
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
for i in 0..self.llmp_clients.len() {
|
for i in 0..self.llmp_clients.len() {
|
||||||
@ -1211,7 +1211,7 @@ where
|
|||||||
/// 5 millis of sleep can't hurt to keep busywait not at 100%
|
/// 5 millis of sleep can't hurt to keep busywait not at 100%
|
||||||
pub fn loop_forever<F>(&mut self, on_new_msg: &mut F, sleep_time: Option<Duration>) -> !
|
pub fn loop_forever<F>(&mut self, on_new_msg: &mut F, sleep_time: Option<Duration>) -> !
|
||||||
where
|
where
|
||||||
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, AflError>,
|
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
|
||||||
{
|
{
|
||||||
loop {
|
loop {
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
@ -1235,7 +1235,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Broadcasts the given buf to all lients
|
/// Broadcasts the given buf to all lients
|
||||||
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> {
|
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> {
|
||||||
self.llmp_out.send_buf(tag, buf)
|
self.llmp_out.send_buf(tag, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1245,7 +1245,7 @@ where
|
|||||||
pub fn launch_tcp_listener_on(
|
pub fn launch_tcp_listener_on(
|
||||||
&mut self,
|
&mut self,
|
||||||
port: u16,
|
port: u16,
|
||||||
) -> Result<thread::JoinHandle<()>, AflError> {
|
) -> Result<thread::JoinHandle<()>, Error> {
|
||||||
let listener = TcpListener::bind(format!("127.0.0.1:{}", port))?;
|
let listener = TcpListener::bind(format!("127.0.0.1:{}", port))?;
|
||||||
// accept connections and process them, spawning a new thread for each one
|
// accept connections and process them, spawning a new thread for each one
|
||||||
println!("Server listening on port {}", port);
|
println!("Server listening on port {}", port);
|
||||||
@ -1257,7 +1257,7 @@ where
|
|||||||
pub fn launch_tcp_listener(
|
pub fn launch_tcp_listener(
|
||||||
&mut self,
|
&mut self,
|
||||||
listener: TcpListener,
|
listener: TcpListener,
|
||||||
) -> Result<thread::JoinHandle<()>, AflError> {
|
) -> Result<thread::JoinHandle<()>, Error> {
|
||||||
// Later in the execution, after the initial map filled up,
|
// Later in the execution, after the initial map filled up,
|
||||||
// the current broacast map will will point to a different map.
|
// the current broacast map will will point to a different map.
|
||||||
// However, the original map is (as of now) never freed, new clients will start
|
// However, the original map is (as of now) never freed, new clients will start
|
||||||
@ -1336,9 +1336,9 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
client_id: u32,
|
client_id: u32,
|
||||||
on_new_msg: &mut F,
|
on_new_msg: &mut F,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, AflError>,
|
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
|
||||||
{
|
{
|
||||||
let mut next_id = self.llmp_clients.len() as u32;
|
let mut next_id = self.llmp_clients.len() as u32;
|
||||||
|
|
||||||
@ -1365,7 +1365,7 @@ where
|
|||||||
size_of::<LlmpPayloadSharedMapInfo>()
|
size_of::<LlmpPayloadSharedMapInfo>()
|
||||||
);
|
);
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
return Err(AflError::Unknown(format!("Broken CLIENT_ADDED msg with incorrect size received. Expected {} but got {}",
|
return Err(Error::Unknown(format!("Broken CLIENT_ADDED msg with incorrect size received. Expected {} but got {}",
|
||||||
(*msg).buf_len_padded,
|
(*msg).buf_len_padded,
|
||||||
size_of::<LlmpPayloadSharedMapInfo>()
|
size_of::<LlmpPayloadSharedMapInfo>()
|
||||||
)));
|
)));
|
||||||
@ -1388,7 +1388,7 @@ where
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
println!("Error adding client! Ignoring: {:?}", e);
|
println!("Error adding client! Ignoring: {:?}", e);
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
return Err(AflError::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Error adding client! PANIC! {:?}",
|
"Error adding client! PANIC! {:?}",
|
||||||
e
|
e
|
||||||
)));
|
)));
|
||||||
@ -1448,7 +1448,7 @@ where
|
|||||||
last_msg_sent_offset: Option<u64>,
|
last_msg_sent_offset: Option<u64>,
|
||||||
current_broker_map: SH,
|
current_broker_map: SH,
|
||||||
last_msg_recvd_offset: Option<u64>,
|
last_msg_recvd_offset: Option<u64>,
|
||||||
) -> Result<Self, AflError> {
|
) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
receiver: LlmpReceiver::on_existing_map(current_broker_map, last_msg_recvd_offset)?,
|
receiver: LlmpReceiver::on_existing_map(current_broker_map, last_msg_recvd_offset)?,
|
||||||
sender: LlmpSender::on_existing_map(current_out_map, last_msg_sent_offset)?,
|
sender: LlmpSender::on_existing_map(current_out_map, last_msg_sent_offset)?,
|
||||||
@ -1457,7 +1457,7 @@ where
|
|||||||
|
|
||||||
/// Recreate this client from a previous client.to_env
|
/// Recreate this client from a previous client.to_env
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn on_existing_from_env(env_name: &str) -> Result<Self, AflError> {
|
pub fn on_existing_from_env(env_name: &str) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
sender: LlmpSender::on_existing_from_env(&format!("{}_SENDER", env_name))?,
|
sender: LlmpSender::on_existing_from_env(&format!("{}_SENDER", env_name))?,
|
||||||
receiver: LlmpReceiver::on_existing_from_env(&format!("{}_RECEIVER", env_name))?,
|
receiver: LlmpReceiver::on_existing_from_env(&format!("{}_RECEIVER", env_name))?,
|
||||||
@ -1467,13 +1467,13 @@ where
|
|||||||
/// Write the current state to env.
|
/// Write the current state to env.
|
||||||
/// A new client can attach to exactly the same state by calling on_existing_map.
|
/// A new client can attach to exactly the same state by calling on_existing_map.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn to_env(&self, env_name: &str) -> Result<(), AflError> {
|
pub fn to_env(&self, env_name: &str) -> Result<(), Error> {
|
||||||
self.sender.to_env(&format!("{}_SENDER", env_name))?;
|
self.sender.to_env(&format!("{}_SENDER", env_name))?;
|
||||||
self.receiver.to_env(&format!("{}_RECEIVER", env_name))
|
self.receiver.to_env(&format!("{}_RECEIVER", env_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describe this client in a way that it can be recreated, for example after crash
|
/// Describe this client in a way that it can be recreated, for example after crash
|
||||||
fn describe(&self) -> Result<LlmpClientDescription, AflError> {
|
fn describe(&self) -> Result<LlmpClientDescription, Error> {
|
||||||
Ok(LlmpClientDescription {
|
Ok(LlmpClientDescription {
|
||||||
sender: self.sender.describe()?,
|
sender: self.sender.describe()?,
|
||||||
receiver: self.receiver.describe()?,
|
receiver: self.receiver.describe()?,
|
||||||
@ -1483,7 +1483,7 @@ where
|
|||||||
/// Create an existing client from description
|
/// Create an existing client from description
|
||||||
fn existing_client_from_description(
|
fn existing_client_from_description(
|
||||||
description: &LlmpClientDescription,
|
description: &LlmpClientDescription,
|
||||||
) -> Result<Self, AflError> {
|
) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
sender: LlmpSender::on_existing_from_description(&description.sender)?,
|
sender: LlmpSender::on_existing_from_description(&description.sender)?,
|
||||||
receiver: LlmpReceiver::on_existing_from_description(&description.receiver)?,
|
receiver: LlmpReceiver::on_existing_from_description(&description.receiver)?,
|
||||||
@ -1502,7 +1502,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new LlmpClient
|
/// Creates a new LlmpClient
|
||||||
pub fn new(initial_broker_map: LlmpSharedMap<SH>) -> Result<Self, AflError> {
|
pub fn new(initial_broker_map: LlmpSharedMap<SH>) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
sender: LlmpSender {
|
sender: LlmpSender {
|
||||||
id: 0,
|
id: 0,
|
||||||
@ -1524,12 +1524,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Commits a msg to the client's out map
|
/// Commits a msg to the client's out map
|
||||||
pub unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), AflError> {
|
pub unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), Error> {
|
||||||
self.sender.send(msg)
|
self.sender.send(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocates a message of the given size, tags it, and sends it off.
|
/// Allocates a message of the given size, tags it, and sends it off.
|
||||||
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> {
|
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> {
|
||||||
self.sender.send_buf(tag, buf)
|
self.sender.send_buf(tag, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1538,7 +1538,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
shm_str: &[u8; 20],
|
shm_str: &[u8; 20],
|
||||||
shm_id: usize,
|
shm_id: usize,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
// We write this by hand to get around checks in send_buf
|
// We write this by hand to get around checks in send_buf
|
||||||
unsafe {
|
unsafe {
|
||||||
let msg = self
|
let msg = self
|
||||||
@ -1555,45 +1555,45 @@ where
|
|||||||
/// A client receives a broadcast message.
|
/// A client receives a broadcast message.
|
||||||
/// Returns null if no message is availiable
|
/// Returns null if no message is availiable
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, AflError> {
|
pub unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, Error> {
|
||||||
self.receiver.recv()
|
self.receiver.recv()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A client blocks/spins until the next message gets posted to the page,
|
/// A client blocks/spins until the next message gets posted to the page,
|
||||||
/// then returns that message.
|
/// then returns that message.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, AflError> {
|
pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, Error> {
|
||||||
self.receiver.recv_blocking()
|
self.receiver.recv_blocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The current page could have changed in recv (EOP)
|
/// The current page could have changed in recv (EOP)
|
||||||
/// Alloc the next message, internally handling end of page by allocating a new one.
|
/// Alloc the next message, internally handling end of page by allocating a new one.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, AflError> {
|
pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
|
||||||
self.sender.alloc_next(buf_len)
|
self.sender.alloc_next(buf_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the next message, tag, buf, if avaliable, else None
|
/// Returns the next message, tag, buf, if avaliable, else None
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, AflError> {
|
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, Error> {
|
||||||
self.receiver.recv_buf()
|
self.receiver.recv_buf()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receives a buf from the broker, looping until a messages becomes avaliable
|
/// Receives a buf from the broker, looping until a messages becomes avaliable
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), AflError> {
|
pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), Error> {
|
||||||
self.receiver.recv_buf_blocking()
|
self.receiver.recv_buf_blocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
/// Creates a new LlmpClient, reading the map id and len from env
|
/// Creates a new LlmpClient, reading the map id and len from env
|
||||||
pub fn create_using_env(env_var: &str) -> Result<Self, AflError> {
|
pub fn create_using_env(env_var: &str) -> Result<Self, Error> {
|
||||||
Self::new(LlmpSharedMap::existing(SH::existing_from_env(env_var)?))
|
Self::new(LlmpSharedMap::existing(SH::existing_from_env(env_var)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
/// Create a LlmpClient, getting the ID from a given port
|
/// Create a LlmpClient, getting the ID from a given port
|
||||||
pub fn create_attach_to_tcp(port: u16) -> Result<Self, AflError> {
|
pub fn create_attach_to_tcp(port: u16) -> Result<Self, Error> {
|
||||||
let mut stream = TcpStream::connect(format!("127.0.0.1:{}", port))?;
|
let mut stream = TcpStream::connect(format!("127.0.0.1:{}", port))?;
|
||||||
println!("Connected to port {}", port);
|
println!("Connected to port {}", port);
|
||||||
|
|
||||||
@ -1624,18 +1624,18 @@ mod tests {
|
|||||||
Tag,
|
Tag,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use crate::bolts::shmem::AflShmem;
|
use crate::bolts::shmem::UnixShMem;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[test]
|
#[test]
|
||||||
pub fn llmp_connection() {
|
pub fn llmp_connection() {
|
||||||
let mut broker = match LlmpConnection::<AflShmem>::on_port(1337).unwrap() {
|
let mut broker = match LlmpConnection::<UnixShMem>::on_port(1337).unwrap() {
|
||||||
IsClient { client: _ } => panic!("Could not bind to port as broker"),
|
IsClient { client: _ } => panic!("Could not bind to port as broker"),
|
||||||
IsBroker { broker } => broker,
|
IsBroker { broker } => broker,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the first client (2nd, actually, because of the tcp listener client)
|
// Add the first client (2nd, actually, because of the tcp listener client)
|
||||||
let mut client = match LlmpConnection::<AflShmem>::on_port(1337).unwrap() {
|
let mut client = match LlmpConnection::<UnixShMem>::on_port(1337).unwrap() {
|
||||||
IsBroker { broker: _ } => panic!("Second connect should be a client!"),
|
IsBroker { broker: _ } => panic!("Second connect should be a client!"),
|
||||||
IsClient { client } => client,
|
IsClient { client } => client,
|
||||||
};
|
};
|
||||||
@ -1659,7 +1659,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* recreate the client from env, check if it still works */
|
/* recreate the client from env, check if it still works */
|
||||||
client = LlmpClient::<AflShmem>::on_existing_from_env("_ENV_TEST").unwrap();
|
client = LlmpClient::<UnixShMem>::on_existing_from_env("_ENV_TEST").unwrap();
|
||||||
|
|
||||||
client.send_buf(tag, &arr).unwrap();
|
client.send_buf(tag, &arr).unwrap();
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ macro_rules! create_serde_registry_for_trait {
|
|||||||
use $crate::bolts::serdeany::{
|
use $crate::bolts::serdeany::{
|
||||||
pack_type_id, unpack_type_id, DeserializeCallback, DeserializeCallbackSeed,
|
pack_type_id, unpack_type_id, DeserializeCallback, DeserializeCallbackSeed,
|
||||||
};
|
};
|
||||||
use $crate::AflError;
|
use $crate::Error;
|
||||||
|
|
||||||
pub struct BoxDynVisitor {}
|
pub struct BoxDynVisitor {}
|
||||||
impl<'de> serde::de::Visitor<'de> for BoxDynVisitor {
|
impl<'de> serde::de::Visitor<'de> for BoxDynVisitor {
|
||||||
@ -398,8 +398,8 @@ macro_rules! create_serde_registry_for_trait {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn for_each(
|
pub fn for_each(
|
||||||
&self,
|
&self,
|
||||||
func: fn(&TypeId, &Box<dyn $trait_name>) -> Result<(), AflError>,
|
func: fn(&TypeId, &Box<dyn $trait_name>) -> Result<(), Error>,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
for (id, h) in self.map.iter() {
|
for (id, h) in self.map.iter() {
|
||||||
for x in h.values() {
|
for x in h.values() {
|
||||||
func(&pack_type_id(*id), x)?;
|
func(&pack_type_id(*id), x)?;
|
||||||
@ -411,8 +411,8 @@ macro_rules! create_serde_registry_for_trait {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn for_each_mut(
|
pub fn for_each_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
func: fn(&TypeId, &mut Box<dyn $trait_name>) -> Result<(), AflError>,
|
func: fn(&TypeId, &mut Box<dyn $trait_name>) -> Result<(), Error>,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
for (id, h) in self.map.iter_mut() {
|
for (id, h) in self.map.iter_mut() {
|
||||||
for x in h.values_mut() {
|
for x in h.values_mut() {
|
||||||
func(&pack_type_id(*id), x)?;
|
func(&pack_type_id(*id), x)?;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub use shmem::AflShmem;
|
pub use shmem::UnixShMem;
|
||||||
|
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use crate::AflError;
|
use crate::Error;
|
||||||
|
|
||||||
/// Description of a shared map.
|
/// Description of a shared map.
|
||||||
/// May be used to restore the map by id.
|
/// May be used to restore the map by id.
|
||||||
@ -26,19 +26,19 @@ pub struct ShMemDescription {
|
|||||||
/// A Shared map
|
/// A Shared map
|
||||||
pub trait ShMem: Sized + Debug {
|
pub trait ShMem: Sized + Debug {
|
||||||
/// Creates a new map with the given size
|
/// Creates a new map with the given size
|
||||||
fn new_map(map_size: usize) -> Result<Self, AflError>;
|
fn new_map(map_size: usize) -> Result<Self, Error>;
|
||||||
|
|
||||||
/// Creates a new reference to the same map
|
/// Creates a new reference to the same map
|
||||||
fn clone_ref(old_ref: &Self) -> Result<Self, AflError> {
|
fn clone_ref(old_ref: &Self) -> Result<Self, Error> {
|
||||||
Self::existing_from_shm_slice(old_ref.shm_slice(), old_ref.map().len())
|
Self::existing_from_shm_slice(old_ref.shm_slice(), old_ref.map().len())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a nes variable with the given name, strigified to 20 bytes.
|
/// Creates a nes variable with the given name, strigified to 20 bytes.
|
||||||
fn existing_from_shm_slice(map_str_bytes: &[u8; 20], map_size: usize)
|
fn existing_from_shm_slice(map_str_bytes: &[u8; 20], map_size: usize)
|
||||||
-> Result<Self, AflError>;
|
-> Result<Self, Error>;
|
||||||
|
|
||||||
/// Initialize from a shm_str with fixed len of 20
|
/// Initialize from a shm_str with fixed len of 20
|
||||||
fn existing_from_shm_str(shm_str: &str, map_size: usize) -> Result<Self, AflError> {
|
fn existing_from_shm_str(shm_str: &str, map_size: usize) -> Result<Self, Error> {
|
||||||
let mut slice: [u8; 20] = [0; 20];
|
let mut slice: [u8; 20] = [0; 20];
|
||||||
for (i, val) in shm_str.as_bytes().iter().enumerate() {
|
for (i, val) in shm_str.as_bytes().iter().enumerate() {
|
||||||
slice[i] = *val;
|
slice[i] = *val;
|
||||||
@ -73,13 +73,13 @@ pub trait ShMem: Sized + Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a map from a map description
|
/// Create a map from a map description
|
||||||
fn existing_from_description(description: &ShMemDescription) -> Result<Self, AflError> {
|
fn existing_from_description(description: &ShMemDescription) -> Result<Self, Error> {
|
||||||
Self::existing_from_shm_slice(&description.str_bytes, description.size)
|
Self::existing_from_shm_slice(&description.str_bytes, description.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write this map's config to env
|
/// Write this map's config to env
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn write_to_env(&self, env_name: &str) -> Result<(), AflError> {
|
fn write_to_env(&self, env_name: &str) -> Result<(), Error> {
|
||||||
let map_size = self.map().len();
|
let map_size = self.map().len();
|
||||||
let map_size_env = format!("{}_SIZE", env_name);
|
let map_size_env = format!("{}_SIZE", env_name);
|
||||||
env::set_var(env_name, self.shm_str());
|
env::set_var(env_name, self.shm_str());
|
||||||
@ -89,7 +89,7 @@ pub trait ShMem: Sized + Debug {
|
|||||||
|
|
||||||
/// Reads an existing map config from env vars, then maps it
|
/// Reads an existing map config from env vars, then maps it
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn existing_from_env(env_name: &str) -> Result<Self, AflError> {
|
fn existing_from_env(env_name: &str) -> Result<Self, Error> {
|
||||||
let map_shm_str = env::var(env_name)?;
|
let map_shm_str = env::var(env_name)?;
|
||||||
let map_size = str::parse::<usize>(&env::var(format!("{}_SIZE", env_name))?)?;
|
let map_size = str::parse::<usize>(&env::var(format!("{}_SIZE", env_name))?)?;
|
||||||
Self::existing_from_shm_str(&map_shm_str, map_size)
|
Self::existing_from_shm_str(&map_shm_str, map_size)
|
||||||
@ -104,7 +104,7 @@ pub mod shmem {
|
|||||||
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void};
|
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
|
|
||||||
use crate::AflError;
|
use crate::Error;
|
||||||
|
|
||||||
use super::ShMem;
|
use super::ShMem;
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ pub mod shmem {
|
|||||||
/// The default Sharedmap impl for unix using shmctl & shmget
|
/// The default Sharedmap impl for unix using shmctl & shmget
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AflShmem {
|
pub struct UnixShMem {
|
||||||
pub shm_str: [u8; 20],
|
pub shm_str: [u8; 20],
|
||||||
pub shm_id: c_int,
|
pub shm_id: c_int,
|
||||||
pub map: *mut u8,
|
pub map: *mut u8,
|
||||||
@ -166,18 +166,18 @@ pub mod shmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl ShMem for AflShmem {
|
impl ShMem for UnixShMem {
|
||||||
fn existing_from_shm_slice(
|
fn existing_from_shm_slice(
|
||||||
map_str_bytes: &[u8; 20],
|
map_str_bytes: &[u8; 20],
|
||||||
map_size: usize,
|
map_size: usize,
|
||||||
) -> Result<Self, AflError> {
|
) -> Result<Self, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let str_bytes = map_str_bytes as *const [u8; 20] as *const libc::c_char;
|
let str_bytes = map_str_bytes as *const [u8; 20] as *const libc::c_char;
|
||||||
Self::from_str(CStr::from_ptr(str_bytes), map_size)
|
Self::from_str(CStr::from_ptr(str_bytes), map_size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_map(map_size: usize) -> Result<Self, AflError> {
|
fn new_map(map_size: usize) -> Result<Self, Error> {
|
||||||
Self::new(map_size)
|
Self::new(map_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ pub mod shmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deinit sharedmaps on drop
|
/// Deinit sharedmaps on drop
|
||||||
impl Drop for AflShmem {
|
impl Drop for UnixShMem {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
afl_shmem_deinit(self);
|
afl_shmem_deinit(self);
|
||||||
@ -205,8 +205,8 @@ pub mod shmem {
|
|||||||
|
|
||||||
/// Create an uninitialized shmap
|
/// Create an uninitialized shmap
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
const fn afl_shmem_unitialized() -> AflShmem {
|
const fn afl_shmem_unitialized() -> UnixShMem {
|
||||||
AflShmem {
|
UnixShMem {
|
||||||
shm_str: [0; 20],
|
shm_str: [0; 20],
|
||||||
shm_id: -1,
|
shm_id: -1,
|
||||||
map: 0 as *mut c_uchar,
|
map: 0 as *mut c_uchar,
|
||||||
@ -215,27 +215,27 @@ pub mod shmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl AflShmem {
|
impl UnixShMem {
|
||||||
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, AflError> {
|
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, Error> {
|
||||||
let mut ret = afl_shmem_unitialized();
|
let mut ret = afl_shmem_unitialized();
|
||||||
let map = unsafe { afl_shmem_by_str(&mut ret, shm_str, map_size) };
|
let map = unsafe { afl_shmem_by_str(&mut ret, shm_str, map_size) };
|
||||||
if map != 0 as *mut u8 {
|
if map != 0 as *mut u8 {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
} else {
|
} else {
|
||||||
Err(AflError::Unknown(format!(
|
Err(Error::Unknown(format!(
|
||||||
"Could not allocate map with id {:?} and size {}",
|
"Could not allocate map with id {:?} and size {}",
|
||||||
shm_str, map_size
|
shm_str, map_size
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(map_size: usize) -> Result<Self, AflError> {
|
pub fn new(map_size: usize) -> Result<Self, Error> {
|
||||||
let mut ret = afl_shmem_unitialized();
|
let mut ret = afl_shmem_unitialized();
|
||||||
let map = unsafe { afl_shmem_init(&mut ret, map_size) };
|
let map = unsafe { afl_shmem_init(&mut ret, map_size) };
|
||||||
if map != 0 as *mut u8 {
|
if map != 0 as *mut u8 {
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
} else {
|
} else {
|
||||||
Err(AflError::Unknown(format!(
|
Err(Error::Unknown(format!(
|
||||||
"Could not allocate map of size {}",
|
"Could not allocate map of size {}",
|
||||||
map_size
|
map_size
|
||||||
)))
|
)))
|
||||||
@ -244,7 +244,7 @@ pub mod shmem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deinitialize this shmem instance
|
/// Deinitialize this shmem instance
|
||||||
unsafe fn afl_shmem_deinit(shm: *mut AflShmem) {
|
unsafe fn afl_shmem_deinit(shm: *mut UnixShMem) {
|
||||||
if shm.is_null() || (*shm).map.is_null() {
|
if shm.is_null() || (*shm).map.is_null() {
|
||||||
/* Serialized map id */
|
/* Serialized map id */
|
||||||
// Not set or not initialized;
|
// Not set or not initialized;
|
||||||
@ -257,7 +257,7 @@ pub mod shmem {
|
|||||||
|
|
||||||
/// Functions to create Shared memory region, for observation channels and
|
/// Functions to create Shared memory region, for observation channels and
|
||||||
/// opening inputs and stuff.
|
/// opening inputs and stuff.
|
||||||
unsafe fn afl_shmem_init(shm: *mut AflShmem, map_size: usize) -> *mut c_uchar {
|
unsafe fn afl_shmem_init(shm: *mut UnixShMem, map_size: usize) -> *mut c_uchar {
|
||||||
(*shm).map_size = map_size;
|
(*shm).map_size = map_size;
|
||||||
(*shm).map = 0 as *mut c_uchar;
|
(*shm).map = 0 as *mut c_uchar;
|
||||||
(*shm).shm_id = shmget(
|
(*shm).shm_id = shmget(
|
||||||
@ -290,7 +290,7 @@ pub mod shmem {
|
|||||||
|
|
||||||
/// Uses a shmap id string to open a shared map
|
/// Uses a shmap id string to open a shared map
|
||||||
unsafe fn afl_shmem_by_str(
|
unsafe fn afl_shmem_by_str(
|
||||||
shm: *mut AflShmem,
|
shm: *mut UnixShMem,
|
||||||
shm_str: &CStr,
|
shm_str: &CStr,
|
||||||
map_size: usize,
|
map_size: usize,
|
||||||
) -> *mut c_uchar {
|
) -> *mut c_uchar {
|
||||||
@ -324,7 +324,7 @@ pub mod shmem {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use super::{AflShmem, ShMem};
|
use super::{UnixShMem, ShMem};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[test]
|
#[test]
|
||||||
@ -333,7 +333,7 @@ mod tests {
|
|||||||
shm_str[0] = 'A' as u8;
|
shm_str[0] = 'A' as u8;
|
||||||
shm_str[1] = 'B' as u8;
|
shm_str[1] = 'B' as u8;
|
||||||
shm_str[2] = 'C' as u8;
|
shm_str[2] = 'C' as u8;
|
||||||
let faux_shmem = AflShmem {
|
let faux_shmem = UnixShMem {
|
||||||
shm_id: 0,
|
shm_id: 0,
|
||||||
shm_str,
|
shm_str,
|
||||||
map: 0 as *mut u8,
|
map: 0 as *mut u8,
|
||||||
|
@ -5,7 +5,7 @@ use core::{cell::RefCell, marker::PhantomData};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, AflError,
|
corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A corpus handling all important fuzzing in memory.
|
/// A corpus handling all important fuzzing in memory.
|
||||||
@ -41,9 +41,9 @@ where
|
|||||||
{
|
{
|
||||||
/// Gets the next entry
|
/// Gets the next entry
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError> {
|
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error> {
|
||||||
if self.count() == 0 {
|
if self.count() == 0 {
|
||||||
Err(AflError::Empty("No entries in corpus".to_owned()))
|
Err(Error::Empty("No entries in corpus".to_owned()))
|
||||||
} else {
|
} else {
|
||||||
let len = { self.entries().len() };
|
let len = { self.entries().len() };
|
||||||
let id = rand.below(len as u64) as usize;
|
let id = rand.below(len as u64) as usize;
|
||||||
|
@ -18,7 +18,7 @@ pub use queue::QueueCorpus;
|
|||||||
use alloc::{borrow::ToOwned, vec::Vec};
|
use alloc::{borrow::ToOwned, vec::Vec};
|
||||||
use core::{cell::RefCell, ptr};
|
use core::{cell::RefCell, ptr};
|
||||||
|
|
||||||
use crate::{inputs::Input, utils::Rand, AflError};
|
use crate::{inputs::Input, utils::Rand, Error};
|
||||||
|
|
||||||
/// A way to obtain the containing testcase entries
|
/// A way to obtain the containing testcase entries
|
||||||
pub trait HasTestcaseVec<I>
|
pub trait HasTestcaseVec<I>
|
||||||
@ -52,9 +52,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces the testcase at the given idx
|
/// Replaces the testcase at the given idx
|
||||||
fn replace(&mut self, idx: usize, testcase: Testcase<I>) -> Result<(), AflError> {
|
fn replace(&mut self, idx: usize, testcase: Testcase<I>) -> Result<(), Error> {
|
||||||
if self.entries_mut().len() < idx {
|
if self.entries_mut().len() < idx {
|
||||||
return Err(AflError::KeyNotFound(format!(
|
return Err(Error::KeyNotFound(format!(
|
||||||
"Index {} out of bounds",
|
"Index {} out of bounds",
|
||||||
idx
|
idx
|
||||||
)));
|
)));
|
||||||
@ -84,9 +84,9 @@ where
|
|||||||
|
|
||||||
/// Gets a random entry
|
/// Gets a random entry
|
||||||
#[inline]
|
#[inline]
|
||||||
fn random_entry(&self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError> {
|
fn random_entry(&self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error> {
|
||||||
if self.count() == 0 {
|
if self.count() == 0 {
|
||||||
Err(AflError::Empty("No entries in corpus".to_owned()))
|
Err(Error::Empty("No entries in corpus".to_owned()))
|
||||||
} else {
|
} else {
|
||||||
let len = { self.entries().len() };
|
let len = { self.entries().len() };
|
||||||
let id = rand.below(len as u64) as usize;
|
let id = rand.below(len as u64) as usize;
|
||||||
@ -96,7 +96,7 @@ where
|
|||||||
|
|
||||||
// TODO: IntoIter
|
// TODO: IntoIter
|
||||||
/// Gets the next entry
|
/// Gets the next entry
|
||||||
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError>;
|
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error>;
|
||||||
|
|
||||||
/// Returns the testacase we currently use
|
/// Returns the testacase we currently use
|
||||||
fn current_testcase(&self) -> (&RefCell<Testcase<I>>, usize);
|
fn current_testcase(&self) -> (&RefCell<Testcase<I>>, usize);
|
||||||
|
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, AflError,
|
corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A corpus able to store testcases to disk, and load them from disk, when they are being used.
|
/// A corpus able to store testcases to disk, and load them from disk, when they are being used.
|
||||||
@ -73,9 +73,9 @@ where
|
|||||||
|
|
||||||
/// Gets the next entry
|
/// Gets the next entry
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError> {
|
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error> {
|
||||||
if self.count() == 0 {
|
if self.count() == 0 {
|
||||||
Err(AflError::Empty("No entries in corpus".to_owned()))
|
Err(Error::Empty("No entries in corpus".to_owned()))
|
||||||
} else {
|
} else {
|
||||||
let len = { self.entries().len() };
|
let len = { self.entries().len() };
|
||||||
let id = rand.below(len as u64) as usize;
|
let id = rand.below(len as u64) as usize;
|
||||||
|
@ -5,7 +5,7 @@ use core::{cell::RefCell, marker::PhantomData};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, AflError,
|
corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A Queue-like corpus, wrapping an existing Corpus instance
|
/// A Queue-like corpus, wrapping an existing Corpus instance
|
||||||
@ -64,7 +64,7 @@ where
|
|||||||
|
|
||||||
/// Gets a random entry
|
/// Gets a random entry
|
||||||
#[inline]
|
#[inline]
|
||||||
fn random_entry(&self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError> {
|
fn random_entry(&self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error> {
|
||||||
self.corpus.random_entry(rand)
|
self.corpus.random_entry(rand)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,10 +76,10 @@ where
|
|||||||
|
|
||||||
/// Gets the next entry
|
/// Gets the next entry
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self, _rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError> {
|
fn next(&mut self, _rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error> {
|
||||||
self.pos += 1;
|
self.pos += 1;
|
||||||
if self.corpus.count() == 0 {
|
if self.corpus.count() == 0 {
|
||||||
return Err(AflError::Empty("Corpus".to_owned()));
|
return Err(Error::Empty("Corpus".to_owned()));
|
||||||
}
|
}
|
||||||
if self.pos > self.corpus.count() {
|
if self.pos > self.corpus.count() {
|
||||||
// TODO: Always loop or return informational error?
|
// TODO: Always loop or return informational error?
|
||||||
|
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
bolts::serdeany::{SerdeAny, SerdeAnyMap},
|
bolts::serdeany::{SerdeAny, SerdeAnyMap},
|
||||||
inputs::Input,
|
inputs::Input,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An entry in the Testcase Corpus
|
/// An entry in the Testcase Corpus
|
||||||
@ -34,7 +34,7 @@ where
|
|||||||
I: Input,
|
I: Input,
|
||||||
{
|
{
|
||||||
/// Returns this testcase with a loaded input
|
/// Returns this testcase with a loaded input
|
||||||
pub fn load_input(&mut self) -> Result<&I, AflError> {
|
pub fn load_input(&mut self) -> Result<&I, Error> {
|
||||||
if self.input.is_none() {
|
if self.input.is_none() {
|
||||||
self.input = Some(I::from_file(self.filename.as_ref().unwrap())?);
|
self.input = Some(I::from_file(self.filename.as_ref().unwrap())?);
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Store the input to disk if possible
|
/// Store the input to disk if possible
|
||||||
pub fn store_input(&mut self) -> Result<bool, AflError> {
|
pub fn store_input(&mut self) -> Result<bool, Error> {
|
||||||
let fname;
|
let fname;
|
||||||
match self.filename() {
|
match self.filename() {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
|
@ -10,7 +10,7 @@ use std::{env, process::Command};
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::bolts::shmem::AflShmem;
|
use crate::bolts::shmem::UnixShMem;
|
||||||
use crate::{
|
use crate::{
|
||||||
bolts::{
|
bolts::{
|
||||||
llmp::{self, LlmpClient, LlmpClientDescription, Tag},
|
llmp::{self, LlmpClient, LlmpClientDescription, Tag},
|
||||||
@ -24,7 +24,7 @@ use crate::{
|
|||||||
state::State,
|
state::State,
|
||||||
stats::Stats,
|
stats::Stats,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Forward this to the client
|
/// Forward this to the client
|
||||||
@ -53,7 +53,7 @@ where
|
|||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl<I, ST> LlmpEventManager<I, AflShmem, ST>
|
impl<I, ST> LlmpEventManager<I, UnixShMem, ST>
|
||||||
where
|
where
|
||||||
I: Input,
|
I: Input,
|
||||||
ST: Stats,
|
ST: Stats,
|
||||||
@ -62,7 +62,7 @@ where
|
|||||||
/// If the port is not yet bound, it will act as broker
|
/// If the port is not yet bound, it will act as broker
|
||||||
/// Else, it will act as client.
|
/// Else, it will act as client.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn new_on_port_std(stats: ST, port: u16) -> Result<Self, AflError> {
|
pub fn new_on_port_std(stats: ST, port: u16) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
stats: Some(stats),
|
stats: Some(stats),
|
||||||
llmp: llmp::LlmpConnection::on_port(port)?,
|
llmp: llmp::LlmpConnection::on_port(port)?,
|
||||||
@ -71,9 +71,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// If a client respawns, it may reuse the existing connection, previously stored by LlmpClient::to_env
|
/// If a client respawns, it may reuse the existing connection, previously stored by LlmpClient::to_env
|
||||||
/// Std uses AflShmem.
|
/// Std uses UnixShMem.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn existing_client_from_env_std(env_name: &str) -> Result<Self, AflError> {
|
pub fn existing_client_from_env_std(env_name: &str) -> Result<Self, Error> {
|
||||||
Self::existing_client_from_env(env_name)
|
Self::existing_client_from_env(env_name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ where
|
|||||||
/// If the port is not yet bound, it will act as broker
|
/// If the port is not yet bound, it will act as broker
|
||||||
/// Else, it will act as client.
|
/// Else, it will act as client.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn new_on_port(stats: ST, port: u16) -> Result<Self, AflError> {
|
pub fn new_on_port(stats: ST, port: u16) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
stats: Some(stats),
|
stats: Some(stats),
|
||||||
llmp: llmp::LlmpConnection::on_port(port)?,
|
llmp: llmp::LlmpConnection::on_port(port)?,
|
||||||
@ -110,7 +110,7 @@ where
|
|||||||
|
|
||||||
/// If a client respawns, it may reuse the existing connection, previously stored by LlmpClient::to_env
|
/// If a client respawns, it may reuse the existing connection, previously stored by LlmpClient::to_env
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn existing_client_from_env(env_name: &str) -> Result<Self, AflError> {
|
pub fn existing_client_from_env(env_name: &str) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
stats: None,
|
stats: None,
|
||||||
llmp: llmp::LlmpConnection::IsClient {
|
llmp: llmp::LlmpConnection::IsClient {
|
||||||
@ -123,14 +123,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Describe the client event mgr's llmp parts in a restorable fashion
|
/// Describe the client event mgr's llmp parts in a restorable fashion
|
||||||
pub fn describe(&self) -> Result<LlmpClientDescription, AflError> {
|
pub fn describe(&self) -> Result<LlmpClientDescription, Error> {
|
||||||
self.llmp.describe()
|
self.llmp.describe()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an existing client from description
|
/// Create an existing client from description
|
||||||
pub fn existing_client_from_description(
|
pub fn existing_client_from_description(
|
||||||
description: &LlmpClientDescription,
|
description: &LlmpClientDescription,
|
||||||
) -> Result<Self, AflError> {
|
) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
stats: None,
|
stats: None,
|
||||||
llmp: llmp::LlmpConnection::existing_client_from_description(description)?,
|
llmp: llmp::LlmpConnection::existing_client_from_description(description)?,
|
||||||
@ -169,7 +169,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run forever in the broker
|
/// Run forever in the broker
|
||||||
pub fn broker_loop(&mut self) -> Result<(), AflError> {
|
pub fn broker_loop(&mut self) -> Result<(), Error> {
|
||||||
match &mut self.llmp {
|
match &mut self.llmp {
|
||||||
llmp::LlmpConnection::IsBroker { broker } => {
|
llmp::LlmpConnection::IsBroker { broker } => {
|
||||||
let stats = self.stats.as_mut().unwrap();
|
let stats = self.stats.as_mut().unwrap();
|
||||||
@ -190,7 +190,7 @@ where
|
|||||||
Some(Duration::from_millis(5)),
|
Some(Duration::from_millis(5)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => Err(AflError::IllegalState(
|
_ => Err(Error::IllegalState(
|
||||||
"Called broker loop in the client".into(),
|
"Called broker loop in the client".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ where
|
|||||||
stats: &mut ST,
|
stats: &mut ST,
|
||||||
sender_id: u32,
|
sender_id: u32,
|
||||||
event: &Event<I>,
|
event: &Event<I>,
|
||||||
) -> Result<BrokerEventResult, AflError> {
|
) -> Result<BrokerEventResult, Error> {
|
||||||
match &event {
|
match &event {
|
||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
input: _,
|
input: _,
|
||||||
@ -257,7 +257,7 @@ where
|
|||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
_sender_id: u32,
|
_sender_id: u32,
|
||||||
event: Event<I>,
|
event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -284,7 +284,7 @@ where
|
|||||||
state.add_if_interesting(input, interestingness)?;
|
state.add_if_interesting(input, interestingness)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(AflError::Unknown(format!(
|
_ => Err(Error::Unknown(format!(
|
||||||
"Received illegal message that message should not have arrived: {:?}.",
|
"Received illegal message that message should not have arrived: {:?}.",
|
||||||
event.name()
|
event.name()
|
||||||
))),
|
))),
|
||||||
@ -313,7 +313,7 @@ where
|
|||||||
fn process<C, FT, OC, OFT, R>(
|
fn process<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<usize, AflError>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -352,7 +352,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
event: Event<I>,
|
event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -373,7 +373,7 @@ where
|
|||||||
pub fn serialize_state_mgr<C, FT, I, OC, OFT, R, SH, ST>(
|
pub fn serialize_state_mgr<C, FT, I, OC, OFT, R, SH, ST>(
|
||||||
state: &State<C, FT, I, OC, OFT, R>,
|
state: &State<C, FT, I, OC, OFT, R>,
|
||||||
mgr: &LlmpEventManager<I, SH, ST>,
|
mgr: &LlmpEventManager<I, SH, ST>,
|
||||||
) -> Result<Vec<u8>, AflError>
|
) -> Result<Vec<u8>, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -390,7 +390,7 @@ where
|
|||||||
/// Deserialize the state and corpus tuple, previously serialized with `serialize_state_corpus(...)`
|
/// Deserialize the state and corpus tuple, previously serialized with `serialize_state_corpus(...)`
|
||||||
pub fn deserialize_state_mgr<C, FT, I, OC, OFT, R, SH, ST>(
|
pub fn deserialize_state_mgr<C, FT, I, OC, OFT, R, SH, ST>(
|
||||||
state_corpus_serialized: &[u8],
|
state_corpus_serialized: &[u8],
|
||||||
) -> Result<(State<C, FT, I, OC, OFT, R>, LlmpEventManager<I, SH, ST>), AflError>
|
) -> Result<(State<C, FT, I, OC, OFT, R>, LlmpEventManager<I, SH, ST>), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -440,7 +440,7 @@ where
|
|||||||
fn on_restart<C, FT, OC, OFT, R>(
|
fn on_restart<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -458,7 +458,7 @@ where
|
|||||||
fn process<C, FT, OC, OFT, R>(
|
fn process<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<usize, AflError>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -473,7 +473,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
event: Event<I>,
|
event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -526,7 +526,7 @@ pub fn setup_restarting_mgr<I, C, FT, OC, OFT, R, SH, ST>(
|
|||||||
Option<State<C, FT, I, OC, OFT, R>>,
|
Option<State<C, FT, I, OC, OFT, R>>,
|
||||||
LlmpRestartingEventManager<I, SH, ST>,
|
LlmpRestartingEventManager<I, SH, ST>,
|
||||||
),
|
),
|
||||||
AflError,
|
Error,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
I: Input,
|
I: Input,
|
||||||
|
@ -10,7 +10,7 @@ use crate::{
|
|||||||
state::State,
|
state::State,
|
||||||
stats::Stats,
|
stats::Stats,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A simple, single-threaded event manager that just logs
|
/// A simple, single-threaded event manager that just logs
|
||||||
@ -34,7 +34,7 @@ where
|
|||||||
fn process<C, FT, OC, OFT, R>(
|
fn process<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<usize, AflError>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -54,7 +54,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
event: Event<I>,
|
event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -87,7 +87,7 @@ where
|
|||||||
stats: &mut ST,
|
stats: &mut ST,
|
||||||
_sender_id: u32,
|
_sender_id: u32,
|
||||||
event: &Event<I>,
|
event: &Event<I>,
|
||||||
) -> Result<BrokerEventResult, AflError> {
|
) -> Result<BrokerEventResult, Error> {
|
||||||
match event {
|
match event {
|
||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
input: _,
|
input: _,
|
||||||
@ -137,7 +137,7 @@ where
|
|||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
_sender_id: u32,
|
_sender_id: u32,
|
||||||
event: Event<I>,
|
event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -146,7 +146,7 @@ where
|
|||||||
OFT: FeedbacksTuple<I>,
|
OFT: FeedbacksTuple<I>,
|
||||||
{
|
{
|
||||||
match event {
|
match event {
|
||||||
_ => Err(AflError::Unknown(format!(
|
_ => Err(Error::Unknown(format!(
|
||||||
"Received illegal message that message should not have arrived: {:?}.",
|
"Received illegal message that message should not have arrived: {:?}.",
|
||||||
event
|
event
|
||||||
))),
|
))),
|
||||||
|
@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
corpus::Corpus, feedbacks::FeedbacksTuple, inputs::Input, observers::ObserversTuple,
|
corpus::Corpus, feedbacks::FeedbacksTuple, inputs::Input, observers::ObserversTuple,
|
||||||
state::State, utils::Rand, AflError,
|
state::State, utils::Rand, Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The log event severity
|
/// The log event severity
|
||||||
@ -55,9 +55,9 @@ where
|
|||||||
/// Returns the name of this event
|
/// Returns the name of this event
|
||||||
fn name(&self) -> &str;
|
fn name(&self) -> &str;
|
||||||
/// This method will be called in the broker
|
/// This method will be called in the broker
|
||||||
fn handle_in_broker(&self) -> Result<BrokerEventResult, AflError>;
|
fn handle_in_broker(&self) -> Result<BrokerEventResult, Error>;
|
||||||
/// This method will be called in the clients after handle_in_broker (unless BrokerEventResult::Handled) was returned in handle_in_broker
|
/// This method will be called in the clients after handle_in_broker (unless BrokerEventResult::Handled) was returned in handle_in_broker
|
||||||
fn handle_in_client(&self) -> Result<(), AflError>;
|
fn handle_in_client(&self) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -158,14 +158,14 @@ where
|
|||||||
I: Input,
|
I: Input,
|
||||||
{
|
{
|
||||||
/// Fire an Event
|
/// Fire an Event
|
||||||
//fn fire<'a>(&mut self, event: Event<I>) -> Result<(), AflError>;
|
//fn fire<'a>(&mut self, event: Event<I>) -> Result<(), Error>;
|
||||||
|
|
||||||
/// Lookup for incoming events and process them.
|
/// Lookup for incoming events and process them.
|
||||||
/// Return the number of processes events or an error
|
/// Return the number of processes events or an error
|
||||||
fn process<C, FT, OC, OFT, R>(
|
fn process<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<usize, AflError>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -174,7 +174,7 @@ where
|
|||||||
OFT: FeedbacksTuple<I>;
|
OFT: FeedbacksTuple<I>;
|
||||||
|
|
||||||
/// Serialize all observers for this type and manager
|
/// Serialize all observers for this type and manager
|
||||||
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Vec<u8>, AflError>
|
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Vec<u8>, Error>
|
||||||
where
|
where
|
||||||
OT: ObserversTuple,
|
OT: ObserversTuple,
|
||||||
{
|
{
|
||||||
@ -182,7 +182,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialize all observers for this type and manager
|
/// Deserialize all observers for this type and manager
|
||||||
fn deserialize_observers<OT>(&mut self, observers_buf: &[u8]) -> Result<OT, AflError>
|
fn deserialize_observers<OT>(&mut self, observers_buf: &[u8]) -> Result<OT, Error>
|
||||||
where
|
where
|
||||||
OT: ObserversTuple,
|
OT: ObserversTuple,
|
||||||
{
|
{
|
||||||
@ -194,7 +194,7 @@ where
|
|||||||
fn on_restart<C, FT, OC, OFT, R>(
|
fn on_restart<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -214,7 +214,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
event: Event<I>,
|
event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -235,7 +235,7 @@ where
|
|||||||
fn process<C, FT, OC, OFT, R>(
|
fn process<C, FT, OC, OFT, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
) -> Result<usize, AflError>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -250,7 +250,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
_event: Event<I>,
|
_event: Event<I>,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
|
@ -16,7 +16,7 @@ use crate::{
|
|||||||
observers::ObserversTuple,
|
observers::ObserversTuple,
|
||||||
state::State,
|
state::State,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@ -59,7 +59,7 @@ where
|
|||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
_event_mgr: &mut EM,
|
_event_mgr: &mut EM,
|
||||||
_input: &I,
|
_input: &I,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
R: Rand,
|
R: Rand,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -87,7 +87,7 @@ where
|
|||||||
_state: &State<C, FT, I, OC, OFT, R>,
|
_state: &State<C, FT, I, OC, OFT, R>,
|
||||||
_event_mgr: &mut EM,
|
_event_mgr: &mut EM,
|
||||||
_input: &I,
|
_input: &I,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
R: Rand,
|
R: Rand,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -105,7 +105,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError> {
|
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
|
||||||
let bytes = input.target_bytes();
|
let bytes = input.target_bytes();
|
||||||
let ret = (self.harness_fn)(self, bytes.as_slice());
|
let ret = (self.harness_fn)(self, bytes.as_slice());
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
|
@ -17,7 +17,7 @@ use crate::{
|
|||||||
observers::ObserversTuple,
|
observers::ObserversTuple,
|
||||||
state::State,
|
state::State,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// How an execution finished.
|
/// How an execution finished.
|
||||||
@ -41,13 +41,13 @@ where
|
|||||||
|
|
||||||
/// Reset the state of all the observes linked to this executor
|
/// Reset the state of all the observes linked to this executor
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pre_exec_observers(&mut self) -> Result<(), AflError> {
|
fn pre_exec_observers(&mut self) -> Result<(), Error> {
|
||||||
self.observers_mut().pre_exec_all()
|
self.observers_mut().pre_exec_all()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the post exec hook for all the observes linked to this executor
|
/// Run the post exec hook for all the observes linked to this executor
|
||||||
#[inline]
|
#[inline]
|
||||||
fn post_exec_observers(&mut self) -> Result<(), AflError> {
|
fn post_exec_observers(&mut self) -> Result<(), Error> {
|
||||||
self.observers_mut().post_exec_all()
|
self.observers_mut().post_exec_all()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,9 +62,9 @@ impl<I> Executor<I> for NopExecutor<I>
|
|||||||
where
|
where
|
||||||
I: Input + HasTargetBytes,
|
I: Input + HasTargetBytes,
|
||||||
{
|
{
|
||||||
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError> {
|
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
|
||||||
if input.target_bytes().as_slice().len() == 0 {
|
if input.target_bytes().as_slice().len() == 0 {
|
||||||
Err(AflError::Empty("Input Empty".into()))
|
Err(Error::Empty("Input Empty".into()))
|
||||||
} else {
|
} else {
|
||||||
Ok(ExitKind::Ok)
|
Ok(ExitKind::Ok)
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ where
|
|||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
_event_mgr: &mut EM,
|
_event_mgr: &mut EM,
|
||||||
_input: &I,
|
_input: &I,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
R: Rand,
|
R: Rand,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -108,7 +108,7 @@ where
|
|||||||
_state: &State<C, FT, I, OC, OFT, R>,
|
_state: &State<C, FT, I, OC, OFT, R>,
|
||||||
_event_mgr: &mut EM,
|
_event_mgr: &mut EM,
|
||||||
_input: &I,
|
_input: &I,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
R: Rand,
|
R: Rand,
|
||||||
FT: FeedbacksTuple<I>,
|
FT: FeedbacksTuple<I>,
|
||||||
@ -121,7 +121,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instruct the target about the input and run
|
/// Instruct the target about the input and run
|
||||||
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError>;
|
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ExecutorsTuple<I>: MatchType + MatchNameAndType
|
pub trait ExecutorsTuple<I>: MatchType + MatchNameAndType
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
feedbacks::Feedback,
|
feedbacks::Feedback,
|
||||||
inputs::Input,
|
inputs::Input,
|
||||||
observers::{MapObserver, Observer, ObserversTuple},
|
observers::{MapObserver, Observer, ObserversTuple},
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type MaxMapFeedback<T, O> = MapFeedback<T, MaxReducer<T>, O>;
|
pub type MaxMapFeedback<T, O> = MapFeedback<T, MaxReducer<T>, O>;
|
||||||
@ -108,7 +108,7 @@ where
|
|||||||
_input: &I,
|
_input: &I,
|
||||||
observers: &OT,
|
observers: &OT,
|
||||||
_exit_kind: ExitKind,
|
_exit_kind: ExitKind,
|
||||||
) -> Result<u32, AflError> {
|
) -> Result<u32, Error> {
|
||||||
let mut interesting = 0;
|
let mut interesting = 0;
|
||||||
// TODO optimize
|
// TODO optimize
|
||||||
let observer = observers.match_name_type::<O>(&self.name).unwrap();
|
let observer = observers.match_name_type::<O>(&self.name).unwrap();
|
||||||
@ -245,7 +245,7 @@ where
|
|||||||
O: MapObserver<T>,
|
O: MapObserver<T>,
|
||||||
I: Input,
|
I: Input,
|
||||||
{
|
{
|
||||||
fn is_interesting(&mut self, _input: &I) -> Result<u32, AflError> {
|
fn is_interesting(&mut self, _input: &I) -> Result<u32, Error> {
|
||||||
let mut interesting = 0;
|
let mut interesting = 0;
|
||||||
|
|
||||||
// TODO optimize
|
// TODO optimize
|
||||||
@ -266,14 +266,14 @@ where
|
|||||||
Ok(interesting)
|
Ok(interesting)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> Result<(), AflError> {
|
fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> Result<(), Error> {
|
||||||
let meta = MapNoveltiesMetadata::new(core::mem::take(&mut self.novelties));
|
let meta = MapNoveltiesMetadata::new(core::mem::take(&mut self.novelties));
|
||||||
testcase.add_metadata(meta);
|
testcase.add_metadata(meta);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discard the stored metadata in case that the testcase is not added to the corpus
|
/// Discard the stored metadata in case that the testcase is not added to the corpus
|
||||||
fn discard_metadata(&mut self, _input: &I) -> Result<(), AflError> {
|
fn discard_metadata(&mut self, _input: &I) -> Result<(), Error> {
|
||||||
self.novelties.clear();
|
self.novelties.clear();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
executors::ExitKind,
|
executors::ExitKind,
|
||||||
inputs::Input,
|
inputs::Input,
|
||||||
observers::ObserversTuple,
|
observers::ObserversTuple,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Feedbacks evaluate the observers.
|
/// Feedbacks evaluate the observers.
|
||||||
@ -28,17 +28,17 @@ where
|
|||||||
input: &I,
|
input: &I,
|
||||||
observers: &OT,
|
observers: &OT,
|
||||||
exit_kind: ExitKind,
|
exit_kind: ExitKind,
|
||||||
) -> Result<u32, AflError>;
|
) -> Result<u32, Error>;
|
||||||
|
|
||||||
/// Append to the testcase the generated metadata in case of a new corpus item
|
/// Append to the testcase the generated metadata in case of a new corpus item
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_metadata(&mut self, _testcase: &mut Testcase<I>) -> Result<(), AflError> {
|
fn append_metadata(&mut self, _testcase: &mut Testcase<I>) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discard the stored metadata in case that the testcase is not added to the corpus
|
/// Discard the stored metadata in case that the testcase is not added to the corpus
|
||||||
#[inline]
|
#[inline]
|
||||||
fn discard_metadata(&mut self, _input: &I) -> Result<(), AflError> {
|
fn discard_metadata(&mut self, _input: &I) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,19 +49,19 @@ where
|
|||||||
/// Example:
|
/// Example:
|
||||||
/// >> The virgin_bits map in AFL needs to be in sync with the corpus
|
/// >> The virgin_bits map in AFL needs to be in sync with the corpus
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize_state(&mut self) -> Result<Vec<u8>, AflError> {
|
fn serialize_state(&mut self) -> Result<Vec<u8>, Error> {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore the state from a given vec, priviously stored using `serialize_state`
|
/// Restore the state from a given vec, priviously stored using `serialize_state`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), AflError> {
|
fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), Error> {
|
||||||
let _ = serialized_state;
|
let _ = serialized_state;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Restore_from
|
// TODO: Restore_from
|
||||||
fn restore_from(&mut self, restore_from: Self) -> Result<(), AflError> {
|
fn restore_from(&mut self, restore_from: Self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -77,18 +77,18 @@ where
|
|||||||
input: &I,
|
input: &I,
|
||||||
observers: &OT,
|
observers: &OT,
|
||||||
exit_kind: ExitKind,
|
exit_kind: ExitKind,
|
||||||
) -> Result<u32, AflError>;
|
) -> Result<u32, Error>;
|
||||||
|
|
||||||
/// Write metadata for this testcase
|
/// Write metadata for this testcase
|
||||||
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> Result<(), AflError>;
|
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> Result<(), Error>;
|
||||||
|
|
||||||
/// Discards metadata - the end of this input's execution
|
/// Discards metadata - the end of this input's execution
|
||||||
fn discard_metadata_all(&mut self, input: &I) -> Result<(), AflError>;
|
fn discard_metadata_all(&mut self, input: &I) -> Result<(), Error>;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// Restores the state from each of the containing feedbacks in a list of the same shape.
|
/// Restores the state from each of the containing feedbacks in a list of the same shape.
|
||||||
/// Used (prette exclusively) to restore the feedback states after a crash.
|
/// Used (prette exclusively) to restore the feedback states after a crash.
|
||||||
fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), AflError>;
|
fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), Error>;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,22 +102,22 @@ where
|
|||||||
_: &I,
|
_: &I,
|
||||||
_: &OT,
|
_: &OT,
|
||||||
_: ExitKind,
|
_: ExitKind,
|
||||||
) -> Result<u32, AflError> {
|
) -> Result<u32, Error> {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_metadata_all(&mut self, _testcase: &mut Testcase<I>) -> Result<(), AflError> {
|
fn append_metadata_all(&mut self, _testcase: &mut Testcase<I>) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn discard_metadata_all(&mut self, _input: &I) -> Result<(), AflError> {
|
fn discard_metadata_all(&mut self, _input: &I) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), AflError> {
|
fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -134,23 +134,23 @@ where
|
|||||||
input: &I,
|
input: &I,
|
||||||
observers: &OT,
|
observers: &OT,
|
||||||
exit_kind: ExitKind,
|
exit_kind: ExitKind,
|
||||||
) -> Result<u32, AflError> {
|
) -> Result<u32, Error> {
|
||||||
Ok(self.0.is_interesting(input, observers, exit_kind.clone())?
|
Ok(self.0.is_interesting(input, observers, exit_kind.clone())?
|
||||||
+ self.1.is_interesting_all(input, observers, exit_kind)?)
|
+ self.1.is_interesting_all(input, observers, exit_kind)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> Result<(), AflError> {
|
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> Result<(), Error> {
|
||||||
self.0.append_metadata(testcase)?;
|
self.0.append_metadata(testcase)?;
|
||||||
self.1.append_metadata_all(testcase)
|
self.1.append_metadata_all(testcase)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn discard_metadata_all(&mut self, input: &I) -> Result<(), AflError> {
|
fn discard_metadata_all(&mut self, input: &I) -> Result<(), Error> {
|
||||||
self.0.discard_metadata(input)?;
|
self.0.discard_metadata(input)?;
|
||||||
self.1.discard_metadata_all(input)
|
self.1.discard_metadata_all(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), AflError> {
|
fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), Error> {
|
||||||
self.0.restore_from(restore_from.0)?;
|
self.0.restore_from(restore_from.0)?;
|
||||||
self.1.restore_state_from_all(restore_from.1)?;
|
self.1.restore_state_from_all(restore_from.1)?;
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ where
|
|||||||
_input: &I,
|
_input: &I,
|
||||||
_observers: &OT,
|
_observers: &OT,
|
||||||
exit_kind: ExitKind,
|
exit_kind: ExitKind,
|
||||||
) -> Result<u32, AflError> {
|
) -> Result<u32, Error> {
|
||||||
if exit_kind == ExitKind::Crash {
|
if exit_kind == ExitKind::Crash {
|
||||||
Ok(1)
|
Ok(1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,7 @@ use core::{cmp::min, marker::PhantomData};
|
|||||||
use crate::{
|
use crate::{
|
||||||
inputs::{bytes::BytesInput, Input},
|
inputs::{bytes::BytesInput, Input},
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The maximum size of dummy bytes generated by _dummy generator methods
|
/// The maximum size of dummy bytes generated by _dummy generator methods
|
||||||
@ -19,7 +19,7 @@ where
|
|||||||
R: Rand,
|
R: Rand,
|
||||||
{
|
{
|
||||||
/// Generate a new input
|
/// Generate a new input
|
||||||
fn generate(&mut self, rand: &mut R) -> Result<I, AflError>;
|
fn generate(&mut self, rand: &mut R) -> Result<I, Error>;
|
||||||
|
|
||||||
/// Generate a new dummy input
|
/// Generate a new dummy input
|
||||||
fn generate_dummy(&self) -> I;
|
fn generate_dummy(&self) -> I;
|
||||||
@ -39,7 +39,7 @@ impl<R> Generator<BytesInput, R> for RandBytesGenerator<R>
|
|||||||
where
|
where
|
||||||
R: Rand,
|
R: Rand,
|
||||||
{
|
{
|
||||||
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, AflError> {
|
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, Error> {
|
||||||
let mut size = rand.below(self.max_size as u64);
|
let mut size = rand.below(self.max_size as u64);
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
size = 1;
|
size = 1;
|
||||||
@ -78,7 +78,7 @@ impl<R> Generator<BytesInput, R> for RandPrintablesGenerator<R>
|
|||||||
where
|
where
|
||||||
R: Rand,
|
R: Rand,
|
||||||
{
|
{
|
||||||
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, AflError> {
|
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, Error> {
|
||||||
let mut size = rand.below(self.max_size as u64);
|
let mut size = rand.below(self.max_size as u64);
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
size = 1;
|
size = 1;
|
||||||
|
@ -14,13 +14,13 @@ use std::{
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::AflError;
|
use crate::Error;
|
||||||
|
|
||||||
/// An input for the target
|
/// An input for the target
|
||||||
pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug {
|
pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
/// Write this input to the file
|
/// Write this input to the file
|
||||||
fn to_file<P>(&self, path: P) -> Result<(), AflError>
|
fn to_file<P>(&self, path: P) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
@ -32,14 +32,14 @@ pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug
|
|||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
/// Write this input to the file
|
/// Write this input to the file
|
||||||
fn to_file<P>(&self, _path: P) -> Result<(), AflError>
|
fn to_file<P>(&self, _path: P) -> Result<(), Error>
|
||||||
where {
|
where {
|
||||||
Err(AflError::NotImplemented("Not suppored in no_std".into()))
|
Err(Error::NotImplemented("Not suppored in no_std".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load the contents of this input from a file
|
/// Load the contents of this input from a file
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn from_file<P>(path: P) -> Result<Self, AflError>
|
fn from_file<P>(path: P) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
@ -51,9 +51,9 @@ where {
|
|||||||
|
|
||||||
/// Write this input to the file
|
/// Write this input to the file
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
fn from_file<P>(_path: P) -> Result<Self, AflError>
|
fn from_file<P>(_path: P) -> Result<Self, Error>
|
||||||
where {
|
where {
|
||||||
Err(AflError::NotImplemented("Not suppored in no_std".into()))
|
Err(Error::NotImplemented("Not suppored in no_std".into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ where
|
|||||||
executor: &mut E,
|
executor: &mut E,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
) -> Result<usize, AflError> {
|
) -> Result<usize, Error> {
|
||||||
let (_, idx) = state.corpus_mut().next(rand)?;
|
let (_, idx) = state.corpus_mut().next(rand)?;
|
||||||
|
|
||||||
self.stages_mut()
|
self.stages_mut()
|
||||||
@ -78,7 +78,7 @@ where
|
|||||||
executor: &mut E,
|
executor: &mut E,
|
||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
let mut last = current_milliseconds();
|
let mut last = current_milliseconds();
|
||||||
loop {
|
loop {
|
||||||
self.fuzz_one(rand, executor, state, manager)?;
|
self.fuzz_one(rand, executor, state, manager)?;
|
||||||
@ -163,7 +163,7 @@ where
|
|||||||
|
|
||||||
/// Main error struct for AFL
|
/// Main error struct for AFL
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AflError {
|
pub enum Error {
|
||||||
/// Serialization error
|
/// Serialization error
|
||||||
Serialize(String),
|
Serialize(String),
|
||||||
/// File related error
|
/// File related error
|
||||||
@ -187,7 +187,7 @@ pub enum AflError {
|
|||||||
Unknown(String),
|
Unknown(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for AflError {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Serialize(s) => write!(f, "Error in Serialization: `{0}`", &s),
|
Self::Serialize(s) => write!(f, "Error in Serialization: `{0}`", &s),
|
||||||
@ -208,7 +208,7 @@ impl fmt::Display for AflError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stringify the postcard serializer error
|
/// Stringify the postcard serializer error
|
||||||
impl From<postcard::Error> for AflError {
|
impl From<postcard::Error> for Error {
|
||||||
fn from(err: postcard::Error) -> Self {
|
fn from(err: postcard::Error) -> Self {
|
||||||
Self::Serialize(format!("{:?}", err))
|
Self::Serialize(format!("{:?}", err))
|
||||||
}
|
}
|
||||||
@ -216,28 +216,28 @@ impl From<postcard::Error> for AflError {
|
|||||||
|
|
||||||
/// Create an AFL Error from io Error
|
/// Create an AFL Error from io Error
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl From<io::Error> for AflError {
|
impl From<io::Error> for Error {
|
||||||
fn from(err: io::Error) -> Self {
|
fn from(err: io::Error) -> Self {
|
||||||
Self::File(err)
|
Self::File(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl From<FromUtf8Error> for AflError {
|
impl From<FromUtf8Error> for Error {
|
||||||
fn from(err: FromUtf8Error) -> Self {
|
fn from(err: FromUtf8Error) -> Self {
|
||||||
Self::Unknown(format!("Could not convert byte to utf-8: {:?}", err))
|
Self::Unknown(format!("Could not convert byte to utf-8: {:?}", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl From<VarError> for AflError {
|
impl From<VarError> for Error {
|
||||||
fn from(err: VarError) -> Self {
|
fn from(err: VarError) -> Self {
|
||||||
Self::Empty(format!("Could not get env var: {:?}", err))
|
Self::Empty(format!("Could not get env var: {:?}", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl From<ParseIntError> for AflError {
|
impl From<ParseIntError> for Error {
|
||||||
fn from(err: ParseIntError) -> Self {
|
fn from(err: ParseIntError) -> Self {
|
||||||
Self::Unknown(format!("Failed to parse Int: {:?}", err))
|
Self::Unknown(format!("Failed to parse Int: {:?}", err))
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
inputs::Input,
|
inputs::Input,
|
||||||
state::{HasCorpus, HasMetadata},
|
state::{HasCorpus, HasMetadata},
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO mutator stats method that produces something that can be sent with the NewTestcase event
|
// TODO mutator stats method that produces something that can be sent with the NewTestcase event
|
||||||
@ -34,7 +34,7 @@ where
|
|||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
stage_idx: i32,
|
stage_idx: i32,
|
||||||
) -> Result<(), AflError>;
|
) -> Result<(), Error>;
|
||||||
|
|
||||||
/// Post-process given the outcome of the execution
|
/// Post-process given the outcome of the execution
|
||||||
fn post_exec(
|
fn post_exec(
|
||||||
@ -42,7 +42,7 @@ where
|
|||||||
_state: &mut S,
|
_state: &mut S,
|
||||||
_is_interesting: u32,
|
_is_interesting: u32,
|
||||||
_stage_idx: i32,
|
_stage_idx: i32,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use crate::{
|
|||||||
mutators::Corpus,
|
mutators::Corpus,
|
||||||
mutators::*,
|
mutators::*,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
use alloc::{borrow::ToOwned, vec::Vec};
|
use alloc::{borrow::ToOwned, vec::Vec};
|
||||||
@ -63,7 +63,7 @@ pub enum MutationResult {
|
|||||||
// TODO maybe the mutator arg is not needed
|
// TODO maybe the mutator arg is not needed
|
||||||
/// The generic function type that identifies mutations
|
/// The generic function type that identifies mutations
|
||||||
pub type MutationFunction<I, M, R, S> =
|
pub type MutationFunction<I, M, R, S> =
|
||||||
fn(&mut M, &mut R, &mut S, &mut I) -> Result<MutationResult, AflError>;
|
fn(&mut M, &mut R, &mut S, &mut I) -> Result<MutationResult, Error>;
|
||||||
|
|
||||||
pub trait ComposedByMutations<C, I, R, S>
|
pub trait ComposedByMutations<C, I, R, S>
|
||||||
where
|
where
|
||||||
@ -131,7 +131,7 @@ pub fn mutation_bitflip<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -153,7 +153,7 @@ pub fn mutation_byteflip<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -175,7 +175,7 @@ pub fn mutation_byteinc<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -198,7 +198,7 @@ pub fn mutation_bytedec<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -221,7 +221,7 @@ pub fn mutation_byteneg<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -243,7 +243,7 @@ pub fn mutation_byterand<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -265,7 +265,7 @@ pub fn mutation_byteadd<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -292,7 +292,7 @@ pub fn mutation_wordadd<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -321,7 +321,7 @@ pub fn mutation_dwordadd<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -350,7 +350,7 @@ pub fn mutation_qwordadd<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -379,7 +379,7 @@ pub fn mutation_byteinteresting<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -402,7 +402,7 @@ pub fn mutation_wordinteresting<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -430,7 +430,7 @@ pub fn mutation_dwordinteresting<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -458,7 +458,7 @@ pub fn mutation_bytesdelete<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -481,7 +481,7 @@ pub fn mutation_bytesexpand<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
M: HasMaxSize,
|
M: HasMaxSize,
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
@ -510,7 +510,7 @@ pub fn mutation_bytesinsert<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
M: HasMaxSize,
|
M: HasMaxSize,
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
@ -542,7 +542,7 @@ pub fn mutation_bytesrandinsert<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
M: HasMaxSize,
|
M: HasMaxSize,
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
@ -574,7 +574,7 @@ pub fn mutation_bytesset<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -598,7 +598,7 @@ pub fn mutation_bytesrandset<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -622,7 +622,7 @@ pub fn mutation_bytescopy<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -646,7 +646,7 @@ pub fn mutation_bytesswap<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
_: &mut S,
|
_: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
@ -673,7 +673,7 @@ pub fn mutation_crossover_insert<C, I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
M: HasMaxSize,
|
M: HasMaxSize,
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
@ -722,7 +722,7 @@ pub fn mutation_crossover_replace<C, I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
@ -776,7 +776,7 @@ pub fn mutation_splice<C, I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
@ -814,7 +814,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Converts a hex u8 to its u8 value: 'A' -> 10 etc.
|
// Converts a hex u8 to its u8 value: 'A' -> 10 etc.
|
||||||
fn from_hex(hex: u8) -> Result<u8, AflError> {
|
fn from_hex(hex: u8) -> Result<u8, Error> {
|
||||||
if hex >= 48 && hex <= 57 {
|
if hex >= 48 && hex <= 57 {
|
||||||
return Ok(hex - 48);
|
return Ok(hex - 48);
|
||||||
}
|
}
|
||||||
@ -824,11 +824,11 @@ fn from_hex(hex: u8) -> Result<u8, AflError> {
|
|||||||
if hex >= 97 && hex <= 102 {
|
if hex >= 97 && hex <= 102 {
|
||||||
return Ok(hex - 87);
|
return Ok(hex - 87);
|
||||||
}
|
}
|
||||||
return Err(AflError::IllegalArgument("".to_owned()));
|
return Err(Error::IllegalArgument("".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decodes a dictionary token: 'foo\x41\\and\"bar' -> 'fooA\and"bar'
|
/// Decodes a dictionary token: 'foo\x41\\and\"bar' -> 'fooA\and"bar'
|
||||||
pub fn str_decode(item: &str) -> Result<Vec<u8>, AflError> {
|
pub fn str_decode(item: &str) -> Result<Vec<u8>, Error> {
|
||||||
let mut token: Vec<u8> = Vec::new();
|
let mut token: Vec<u8> = Vec::new();
|
||||||
let item: Vec<u8> = item.as_bytes().to_vec();
|
let item: Vec<u8> = item.as_bytes().to_vec();
|
||||||
let backslash: u8 = 92; // '\\'
|
let backslash: u8 = 92; // '\\'
|
||||||
@ -872,7 +872,7 @@ pub fn add_token(tokens: &mut Vec<Vec<u8>>, token: &Vec<u8>) -> u32 {
|
|||||||
|
|
||||||
/// Read a dictionary file and return the number of entries read
|
/// Read a dictionary file and return the number of entries read
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, AflError> {
|
pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, Error> {
|
||||||
let mut entries = 0;
|
let mut entries = 0;
|
||||||
|
|
||||||
println!("Loading tokens file {:?} ...", &f);
|
println!("Loading tokens file {:?} ...", &f);
|
||||||
@ -892,13 +892,13 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, AflEr
|
|||||||
let pos_quote = match line.find("\"") {
|
let pos_quote = match line.find("\"") {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(AflError::IllegalArgument(
|
return Err(Error::IllegalArgument(
|
||||||
"Illegal line: ".to_owned() + line,
|
"Illegal line: ".to_owned() + line,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if line.chars().nth(line.len() - 1) != Some('"') {
|
if line.chars().nth(line.len() - 1) != Some('"') {
|
||||||
return Err(AflError::IllegalArgument(
|
return Err(Error::IllegalArgument(
|
||||||
"Illegal line: ".to_owned() + line,
|
"Illegal line: ".to_owned() + line,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -907,7 +907,7 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, AflEr
|
|||||||
let item = match line.get(pos_quote + 1..line.len() - 1) {
|
let item = match line.get(pos_quote + 1..line.len() - 1) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(AflError::IllegalArgument(
|
return Err(Error::IllegalArgument(
|
||||||
"Illegal line: ".to_owned() + line,
|
"Illegal line: ".to_owned() + line,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -920,7 +920,7 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, AflEr
|
|||||||
let token: Vec<u8> = match str_decode(item) {
|
let token: Vec<u8> = match str_decode(item) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
return Err(AflError::IllegalArgument(
|
return Err(Error::IllegalArgument(
|
||||||
"Illegal line (hex decoding): ".to_owned() + line,
|
"Illegal line (hex decoding): ".to_owned() + line,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
mutators::{Corpus, *},
|
mutators::{Corpus, *},
|
||||||
state::{HasCorpus, HasMetadata},
|
state::{HasCorpus, HasMetadata},
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait ScheduledMutator<C, I, R, S>:
|
pub trait ScheduledMutator<C, I, R, S>:
|
||||||
@ -39,7 +39,7 @@ where
|
|||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
_stage_idx: i32,
|
_stage_idx: i32,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
let num = self.iterations(rand, input);
|
let num = self.iterations(rand, input);
|
||||||
for _ in 0..num {
|
for _ in 0..num {
|
||||||
let idx = self.schedule(self.mutations_count(), rand, input);
|
let idx = self.schedule(self.mutations_count(), rand, input);
|
||||||
@ -92,7 +92,7 @@ where
|
|||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
_stage_idx: i32,
|
_stage_idx: i32,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
self.scheduled_mutate(rand, state, input, _stage_idx)
|
self.scheduled_mutate(rand, state, input, _stage_idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ where
|
|||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
stage_idx: i32,
|
stage_idx: i32,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
self.scheduled.mutate(rand, state, input, stage_idx)?;
|
self.scheduled.mutate(rand, state, input, stage_idx)?;
|
||||||
/*let num = self.scheduled.iterations(rand, input);
|
/*let num = self.scheduled.iterations(rand, input);
|
||||||
for _ in 0..num {
|
for _ in 0..num {
|
||||||
|
@ -6,7 +6,7 @@ use crate::{
|
|||||||
inputs::{HasBytesVec, Input},
|
inputs::{HasBytesVec, Input},
|
||||||
mutators::*,
|
mutators::*,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
@ -43,7 +43,7 @@ pub fn mutation_tokeninsert<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
M: HasMaxSize,
|
M: HasMaxSize,
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
@ -89,7 +89,7 @@ pub fn mutation_tokenreplace<I, M, R, S>(
|
|||||||
rand: &mut R,
|
rand: &mut R,
|
||||||
state: &mut S,
|
state: &mut S,
|
||||||
input: &mut I,
|
input: &mut I,
|
||||||
) -> Result<MutationResult, AflError>
|
) -> Result<MutationResult, Error>
|
||||||
where
|
where
|
||||||
I: Input + HasBytesVec,
|
I: Input + HasBytesVec,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
tuples::Named,
|
tuples::Named,
|
||||||
},
|
},
|
||||||
observers::Observer,
|
observers::Observer,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A MapObserver observes the static map, as oftentimes used for afl-like coverage information
|
/// A MapObserver observes the static map, as oftentimes used for afl-like coverage information
|
||||||
@ -37,7 +37,7 @@ where
|
|||||||
|
|
||||||
/// Reset the map
|
/// Reset the map
|
||||||
#[inline]
|
#[inline]
|
||||||
fn reset_map(&mut self) -> Result<(), AflError> {
|
fn reset_map(&mut self) -> Result<(), Error> {
|
||||||
// Normal memset, see https://rust.godbolt.org/z/Trs5hv
|
// Normal memset, see https://rust.godbolt.org/z/Trs5hv
|
||||||
let initial = self.initial();
|
let initial = self.initial();
|
||||||
let cnt = self.usable_count();
|
let cnt = self.usable_count();
|
||||||
@ -67,7 +67,7 @@ where
|
|||||||
T: Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned,
|
T: Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pre_exec(&mut self) -> Result<(), AflError> {
|
fn pre_exec(&mut self) -> Result<(), Error> {
|
||||||
self.reset_map()
|
self.reset_map()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
T: Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned,
|
T: Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pre_exec(&mut self) -> Result<(), AflError> {
|
fn pre_exec(&mut self) -> Result<(), Error> {
|
||||||
self.reset_map()
|
self.reset_map()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,12 +271,12 @@ where
|
|||||||
M: MapObserver<u8>,
|
M: MapObserver<u8>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pre_exec(&mut self) -> Result<(), AflError> {
|
fn pre_exec(&mut self) -> Result<(), Error> {
|
||||||
self.reset_map()
|
self.reset_map()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn post_exec(&mut self) -> Result<(), AflError> {
|
fn post_exec(&mut self) -> Result<(), Error> {
|
||||||
for x in self.map_mut().iter_mut() {
|
for x in self.map_mut().iter_mut() {
|
||||||
*x = COUNT_CLASS_LOOKUP[*x as usize];
|
*x = COUNT_CLASS_LOOKUP[*x as usize];
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
bolts::tuples::{MatchNameAndType, MatchType, Named, TupleList},
|
bolts::tuples::{MatchNameAndType, MatchType, Named, TupleList},
|
||||||
utils::current_time,
|
utils::current_time,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Observers observe different information about the target.
|
/// Observers observe different information about the target.
|
||||||
@ -16,16 +16,16 @@ use crate::{
|
|||||||
pub trait Observer: Named + serde::Serialize + serde::de::DeserializeOwned + 'static {
|
pub trait Observer: Named + serde::Serialize + serde::de::DeserializeOwned + 'static {
|
||||||
/// The testcase finished execution, calculate any changes.
|
/// The testcase finished execution, calculate any changes.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<(), AflError> {
|
fn flush(&mut self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets the observer
|
/// Resets the observer
|
||||||
fn pre_exec(&mut self) -> Result<(), AflError>;
|
fn pre_exec(&mut self) -> Result<(), Error>;
|
||||||
|
|
||||||
/// This function is executed after each fuzz run
|
/// This function is executed after each fuzz run
|
||||||
#[inline]
|
#[inline]
|
||||||
fn post_exec(&mut self) -> Result<(), AflError> {
|
fn post_exec(&mut self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ pub trait Observer: Named + serde::Serialize + serde::de::DeserializeOwned + 'st
|
|||||||
/// Example:
|
/// Example:
|
||||||
/// >> The virgin_bits map in AFL needs to be in sync with the corpus
|
/// >> The virgin_bits map in AFL needs to be in sync with the corpus
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize_state(&mut self) -> Result<Vec<u8>, AflError> {
|
fn serialize_state(&mut self) -> Result<Vec<u8>, Error> {
|
||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restore the state from a given vec, priviously stored using `serialize_state`
|
/// Restore the state from a given vec, priviously stored using `serialize_state`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), AflError> {
|
fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), Error> {
|
||||||
let _ = serialized_state;
|
let _ = serialized_state;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -53,29 +53,29 @@ pub trait ObserversTuple:
|
|||||||
{
|
{
|
||||||
/// Reset all executors in the tuple
|
/// Reset all executors in the tuple
|
||||||
/// This is called right before the next execution.
|
/// This is called right before the next execution.
|
||||||
fn pre_exec_all(&mut self) -> Result<(), AflError>;
|
fn pre_exec_all(&mut self) -> Result<(), Error>;
|
||||||
/// Do whatever you need to do after a run.
|
/// Do whatever you need to do after a run.
|
||||||
/// This is called right after the last execution
|
/// This is called right after the last execution
|
||||||
fn post_exec_all(&mut self) -> Result<(), AflError>;
|
fn post_exec_all(&mut self) -> Result<(), Error>;
|
||||||
//fn for_each(&self, f: fn(&dyn Observer));
|
//fn for_each(&self, f: fn(&dyn Observer));
|
||||||
//fn for_each_mut(&mut self, f: fn(&mut dyn Observer));
|
//fn for_each_mut(&mut self, f: fn(&mut dyn Observer));
|
||||||
|
|
||||||
/// Serialize this tuple to a buf
|
/// Serialize this tuple to a buf
|
||||||
fn serialize(&self) -> Result<Vec<u8>, AflError> {
|
fn serialize(&self) -> Result<Vec<u8>, Error> {
|
||||||
Ok(postcard::to_allocvec(&self)?)
|
Ok(postcard::to_allocvec(&self)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserilaize
|
/// Deserilaize
|
||||||
fn deserialize(&self, serialized: &[u8]) -> Result<Self, AflError> {
|
fn deserialize(&self, serialized: &[u8]) -> Result<Self, Error> {
|
||||||
Ok(postcard::from_bytes(serialized)?)
|
Ok(postcard::from_bytes(serialized)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObserversTuple for () {
|
impl ObserversTuple for () {
|
||||||
fn pre_exec_all(&mut self) -> Result<(), AflError> {
|
fn pre_exec_all(&mut self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn post_exec_all(&mut self) -> Result<(), AflError> {
|
fn post_exec_all(&mut self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +88,12 @@ where
|
|||||||
Head: Observer,
|
Head: Observer,
|
||||||
Tail: ObserversTuple + TupleList,
|
Tail: ObserversTuple + TupleList,
|
||||||
{
|
{
|
||||||
fn pre_exec_all(&mut self) -> Result<(), AflError> {
|
fn pre_exec_all(&mut self) -> Result<(), Error> {
|
||||||
self.0.pre_exec()?;
|
self.0.pre_exec()?;
|
||||||
self.1.pre_exec_all()
|
self.1.pre_exec_all()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn post_exec_all(&mut self) -> Result<(), AflError> {
|
fn post_exec_all(&mut self) -> Result<(), Error> {
|
||||||
self.0.post_exec()?;
|
self.0.post_exec()?;
|
||||||
self.1.post_exec_all()
|
self.1.post_exec_all()
|
||||||
}
|
}
|
||||||
@ -129,13 +129,13 @@ impl TimeObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Observer for TimeObserver {
|
impl Observer for TimeObserver {
|
||||||
fn pre_exec(&mut self) -> Result<(), AflError> {
|
fn pre_exec(&mut self) -> Result<(), Error> {
|
||||||
self.last_runtime = None;
|
self.last_runtime = None;
|
||||||
self.start_time = current_time();
|
self.start_time = current_time();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn post_exec(&mut self) -> Result<(), AflError> {
|
fn post_exec(&mut self) -> Result<(), Error> {
|
||||||
self.last_runtime = Some(current_time() - self.start_time);
|
self.last_runtime = Some(current_time() - self.start_time);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use crate::{
|
|||||||
observers::ObserversTuple,
|
observers::ObserversTuple,
|
||||||
state::State,
|
state::State,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A stage is one step in the fuzzing process.
|
/// A stage is one step in the fuzzing process.
|
||||||
@ -36,7 +36,7 @@ where
|
|||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
corpus_idx: usize,
|
corpus_idx: usize,
|
||||||
) -> Result<(), AflError>;
|
) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StagesTuple<C, E, EM, FT, I, OC, OFT, OT, R>
|
pub trait StagesTuple<C, E, EM, FT, I, OC, OFT, OT, R>
|
||||||
@ -58,7 +58,7 @@ where
|
|||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
corpus_idx: usize,
|
corpus_idx: usize,
|
||||||
) -> Result<(), AflError>;
|
) -> Result<(), Error>;
|
||||||
fn for_each(&self, f: fn(&dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>));
|
fn for_each(&self, f: fn(&dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>));
|
||||||
fn for_each_mut(&mut self, f: fn(&mut dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>));
|
fn for_each_mut(&mut self, f: fn(&mut dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>));
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ where
|
|||||||
_state: &mut State<C, FT, I, OC, OFT, R>,
|
_state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
_manager: &mut EM,
|
_manager: &mut EM,
|
||||||
_corpus_idx: usize,
|
_corpus_idx: usize,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn for_each(&self, _f: fn(&dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>)) {}
|
fn for_each(&self, _f: fn(&dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>)) {}
|
||||||
@ -111,7 +111,7 @@ where
|
|||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
corpus_idx: usize,
|
corpus_idx: usize,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
self.0.perform(rand, executor, state, manager, corpus_idx)?;
|
self.0.perform(rand, executor, state, manager, corpus_idx)?;
|
||||||
self.1
|
self.1
|
||||||
.perform_all(rand, executor, state, manager, corpus_idx)
|
.perform_all(rand, executor, state, manager, corpus_idx)
|
||||||
|
@ -11,7 +11,7 @@ use crate::{
|
|||||||
stages::Stage,
|
stages::Stage,
|
||||||
state::{HasCorpus, State},
|
state::{HasCorpus, State},
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO multi mutators stage
|
// TODO multi mutators stage
|
||||||
@ -54,7 +54,7 @@ where
|
|||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
corpus_idx: usize,
|
corpus_idx: usize,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
let num = self.iterations(rand);
|
let num = self.iterations(rand);
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
let mut input_mut = state
|
let mut input_mut = state
|
||||||
@ -142,7 +142,7 @@ where
|
|||||||
state: &mut State<C, FT, I, OC, OFT, R>,
|
state: &mut State<C, FT, I, OC, OFT, R>,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
corpus_idx: usize,
|
corpus_idx: usize,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
self.perform_mutational(rand, executor, state, manager, corpus_idx)
|
self.perform_mutational(rand, executor, state, manager, corpus_idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use crate::{
|
|||||||
inputs::Input,
|
inputs::Input,
|
||||||
observers::ObserversTuple,
|
observers::ObserversTuple,
|
||||||
utils::{current_milliseconds, Rand},
|
utils::{current_milliseconds, Rand},
|
||||||
AflError,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@ -99,7 +99,7 @@ where
|
|||||||
executor: &mut E,
|
executor: &mut E,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
in_dir: &Path,
|
in_dir: &Path,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<BytesInput, R>,
|
C: Corpus<BytesInput, R>,
|
||||||
E: Executor<BytesInput> + HasObservers<OT>,
|
E: Executor<BytesInput> + HasObservers<OT>,
|
||||||
@ -141,7 +141,7 @@ where
|
|||||||
executor: &mut E,
|
executor: &mut E,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
in_dirs: &[PathBuf],
|
in_dirs: &[PathBuf],
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
C: Corpus<BytesInput, R>,
|
C: Corpus<BytesInput, R>,
|
||||||
E: Executor<BytesInput> + HasObservers<OT>,
|
E: Executor<BytesInput> + HasObservers<OT>,
|
||||||
@ -268,7 +268,7 @@ where
|
|||||||
input: &I,
|
input: &I,
|
||||||
observers: &OT,
|
observers: &OT,
|
||||||
exit_kind: ExitKind,
|
exit_kind: ExitKind,
|
||||||
) -> Result<u32, AflError>
|
) -> Result<u32, Error>
|
||||||
where
|
where
|
||||||
OT: ObserversTuple,
|
OT: ObserversTuple,
|
||||||
{
|
{
|
||||||
@ -283,7 +283,7 @@ where
|
|||||||
input: &I,
|
input: &I,
|
||||||
executor: &mut E,
|
executor: &mut E,
|
||||||
event_mgr: &mut EM,
|
event_mgr: &mut EM,
|
||||||
) -> Result<(u32, u32), AflError>
|
) -> Result<(u32, u32), Error>
|
||||||
where
|
where
|
||||||
E: Executor<I> + HasObservers<OT>,
|
E: Executor<I> + HasObservers<OT>,
|
||||||
OT: ObserversTuple,
|
OT: ObserversTuple,
|
||||||
@ -311,14 +311,14 @@ where
|
|||||||
|
|
||||||
/// Resets all current feedbacks
|
/// Resets all current feedbacks
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn discard_input(&mut self, input: &I) -> Result<(), AflError> {
|
pub fn discard_input(&mut self, input: &I) -> Result<(), Error> {
|
||||||
// TODO: This could probably be automatic in the feedback somehow?
|
// TODO: This could probably be automatic in the feedback somehow?
|
||||||
self.feedbacks_mut().discard_metadata_all(&input)
|
self.feedbacks_mut().discard_metadata_all(&input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new testcase, appending the metadata from each feedback
|
/// Creates a new testcase, appending the metadata from each feedback
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn input_to_testcase(&mut self, input: I, fitness: u32) -> Result<Testcase<I>, AflError> {
|
pub fn input_to_testcase(&mut self, input: I, fitness: u32) -> Result<Testcase<I>, Error> {
|
||||||
let mut testcase = Testcase::new(input);
|
let mut testcase = Testcase::new(input);
|
||||||
testcase.set_fitness(fitness);
|
testcase.set_fitness(fitness);
|
||||||
self.feedbacks_mut().append_metadata_all(&mut testcase)?;
|
self.feedbacks_mut().append_metadata_all(&mut testcase)?;
|
||||||
@ -331,7 +331,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
input: I,
|
input: I,
|
||||||
fitness: u32,
|
fitness: u32,
|
||||||
) -> Result<Option<Testcase<I>>, AflError> {
|
) -> Result<Option<Testcase<I>>, Error> {
|
||||||
if fitness > 0 {
|
if fitness > 0 {
|
||||||
Ok(Some(self.input_to_testcase(input, fitness)?))
|
Ok(Some(self.input_to_testcase(input, fitness)?))
|
||||||
} else {
|
} else {
|
||||||
@ -342,7 +342,7 @@ where
|
|||||||
|
|
||||||
/// Adds this input to the corpus, if it's intersting
|
/// Adds this input to the corpus, if it's intersting
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_if_interesting(&mut self, input: I, fitness: u32) -> Result<Option<usize>, AflError>
|
pub fn add_if_interesting(&mut self, input: I, fitness: u32) -> Result<Option<usize>, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
{
|
{
|
||||||
@ -357,7 +357,7 @@ where
|
|||||||
|
|
||||||
/// Adds this input to the objective corpus, if it's an objective
|
/// Adds this input to the objective corpus, if it's an objective
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_if_objective(&mut self, input: I, fitness: u32) -> Result<Option<usize>, AflError>
|
pub fn add_if_objective(&mut self, input: I, fitness: u32) -> Result<Option<usize>, Error>
|
||||||
where
|
where
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
{
|
{
|
||||||
@ -378,7 +378,7 @@ where
|
|||||||
input: I,
|
input: I,
|
||||||
executor: &mut E,
|
executor: &mut E,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
) -> Result<u32, AflError>
|
) -> Result<u32, Error>
|
||||||
where
|
where
|
||||||
E: Executor<I> + HasObservers<OT>,
|
E: Executor<I> + HasObservers<OT>,
|
||||||
OT: ObserversTuple,
|
OT: ObserversTuple,
|
||||||
@ -420,7 +420,7 @@ where
|
|||||||
generator: &mut G,
|
generator: &mut G,
|
||||||
manager: &mut EM,
|
manager: &mut EM,
|
||||||
num: usize,
|
num: usize,
|
||||||
) -> Result<(), AflError>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
G: Generator<I, R>,
|
G: Generator<I, R>,
|
||||||
C: Corpus<I, R>,
|
C: Corpus<I, R>,
|
||||||
|
@ -5,7 +5,7 @@ use std::{path::PathBuf};
|
|||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
|
|
||||||
use afl::{
|
use afl::{
|
||||||
bolts::{tuples::tuple_list, shmem::AflShmem},
|
bolts::{tuples::tuple_list, shmem::UnixShMem},
|
||||||
corpus::{Corpus, InMemoryCorpus},
|
corpus::{Corpus, InMemoryCorpus},
|
||||||
events::setup_restarting_mgr,
|
events::setup_restarting_mgr,
|
||||||
events::{SimpleStats},
|
events::{SimpleStats},
|
||||||
@ -17,7 +17,7 @@ use afl::{
|
|||||||
stages::mutational::StdMutationalStage,
|
stages::mutational::StdMutationalStage,
|
||||||
state::{HasCorpus, State},
|
state::{HasCorpus, State},
|
||||||
utils::StdRand,
|
utils::StdRand,
|
||||||
AflError, Fuzzer, StdFuzzer,
|
Error, Fuzzer, StdFuzzer,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The name of the coverage map observer, to find it again in the observer list
|
/// The name of the coverage map observer, to find it again in the observer list
|
||||||
@ -53,7 +53,7 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The actual fuzzer
|
/// The actual fuzzer
|
||||||
fn fuzz(input: Option<Vec<PathBuf>>, broker_port: u16) -> Result<(), AflError> {
|
fn fuzz(input: Option<Vec<PathBuf>>, broker_port: u16) -> Result<(), Error> {
|
||||||
let mut rand = StdRand::new(0);
|
let mut rand = StdRand::new(0);
|
||||||
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
||||||
let stats = SimpleStats::new(|s| println!("{}", s));
|
let stats = SimpleStats::new(|s| println!("{}", s));
|
||||||
@ -64,7 +64,7 @@ fn fuzz(input: Option<Vec<PathBuf>>, broker_port: u16) -> Result<(), AflError> {
|
|||||||
|
|
||||||
// The restarting state will spawn the same process again as child, then restartet it each time it crashes.
|
// The restarting state will spawn the same process again as child, then restartet it each time it crashes.
|
||||||
let (state_opt, mut restarting_mgr) =
|
let (state_opt, mut restarting_mgr) =
|
||||||
setup_restarting_mgr::<_, _, _, _, AflShmem, _>(stats, broker_port).expect("Failed to setup the restarter".into());
|
setup_restarting_mgr::<_, _, _, _, UnixShMem, _>(stats, broker_port).expect("Failed to setup the restarter".into());
|
||||||
|
|
||||||
let edges_observer =
|
let edges_observer =
|
||||||
StdMapObserver::new_from_ptr(&NAME_COV_MAP, unsafe { &mut __lafl_edges_map[0] as *mut u8 }, __lafl_max_edges_size as usize);
|
StdMapObserver::new_from_ptr(&NAME_COV_MAP, unsafe { &mut __lafl_edges_map[0] as *mut u8 }, __lafl_max_edges_size as usize);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use afl::{
|
use afl::{
|
||||||
bolts::{serdeany::RegistryBuilder, shmem::AflShmem, tuples::tuple_list},
|
bolts::{serdeany::RegistryBuilder, shmem::UnixShMem, tuples::tuple_list},
|
||||||
corpus::{Corpus, InMemoryCorpus, OnDiskCorpus},
|
corpus::{Corpus, InMemoryCorpus, OnDiskCorpus},
|
||||||
events::setup_restarting_mgr,
|
events::setup_restarting_mgr,
|
||||||
executors::{inprocess::InProcessExecutor, Executor, ExitKind},
|
executors::{inprocess::InProcessExecutor, Executor, ExitKind},
|
||||||
@ -17,7 +17,7 @@ use afl::{
|
|||||||
state::{HasCorpus, HasMetadata, State},
|
state::{HasCorpus, HasMetadata, State},
|
||||||
stats::SimpleStats,
|
stats::SimpleStats,
|
||||||
utils::StdRand,
|
utils::StdRand,
|
||||||
AflError, Fuzzer, StdFuzzer,
|
Error, Fuzzer, StdFuzzer,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The name of the coverage map observer, to find it again in the observer list
|
/// The name of the coverage map observer, to find it again in the observer list
|
||||||
@ -72,14 +72,14 @@ fn fuzz(
|
|||||||
corpus_dirs: Vec<PathBuf>,
|
corpus_dirs: Vec<PathBuf>,
|
||||||
objective_dir: PathBuf,
|
objective_dir: PathBuf,
|
||||||
broker_port: u16,
|
broker_port: u16,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), Error> {
|
||||||
let mut rand = StdRand::new(0);
|
let mut rand = StdRand::new(0);
|
||||||
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
||||||
let stats = SimpleStats::new(|s| println!("{}", s));
|
let stats = SimpleStats::new(|s| println!("{}", s));
|
||||||
|
|
||||||
// The restarting state will spawn the same process again as child, then restarted it each time it crashes.
|
// The restarting state will spawn the same process again as child, then restarted it each time it crashes.
|
||||||
let (state, mut restarting_mgr) =
|
let (state, mut restarting_mgr) =
|
||||||
setup_restarting_mgr::<_, _, _, _, _, _, AflShmem, _>(stats, broker_port)
|
setup_restarting_mgr::<_, _, _, _, _, _, UnixShMem, _>(stats, broker_port)
|
||||||
.expect("Failed to setup the restarter".into());
|
.expect("Failed to setup the restarter".into());
|
||||||
|
|
||||||
// Create an observation channel using the coverage map
|
// Create an observation channel using the coverage map
|
||||||
|
Loading…
x
Reference in New Issue
Block a user