impl serdeany macro
This commit is contained in:
parent
58f8788a68
commit
1575a3994b
@ -4,7 +4,7 @@
|
|||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use libafl::{
|
use libafl::{
|
||||||
bolts::{serdeany::RegistryBuilder, shmem::UnixShMem, tuples::tuple_list},
|
bolts::{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},
|
||||||
@ -52,8 +52,8 @@ where
|
|||||||
/// The main fn, parsing parameters, and starting the fuzzer
|
/// The main fn, parsing parameters, and starting the fuzzer
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
// Registry the metadata types used in this fuzzer
|
// Registry the metadata types used in this fuzzer
|
||||||
RegistryBuilder::register::<TokensMetadata>();
|
// Needed only on no_std
|
||||||
RegistryBuilder::finalize();
|
//RegistryBuilder::register::<TokensMetadata>();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Workdir: {:?}",
|
"Workdir: {:?}",
|
||||||
|
@ -50,6 +50,7 @@ erased-serde = "0.3.12"
|
|||||||
postcard = { version = "0.5.1", features = ["alloc"] } # no_std compatible serde serialization fromat
|
postcard = { version = "0.5.1", features = ["alloc"] } # no_std compatible serde serialization fromat
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
serde_json = { version = "1.0", default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap
|
serde_json = { version = "1.0", default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap
|
||||||
|
ctor = "0.1.3"
|
||||||
#TODO: for llmp brotli = { version = "3.3.0", default-features = false } # brotli compression
|
#TODO: for llmp brotli = { version = "3.3.0", default-features = false } # brotli compression
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use core::any::{Any, TypeId};
|
use core::any::{Any, TypeId};
|
||||||
|
|
||||||
#[cfg(fature = "anymap_debug")]
|
#[cfg(feature = "anymap_debug")]
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
// yolo
|
// yolo
|
||||||
@ -499,3 +499,25 @@ macro_rules! create_serde_registry_for_trait {
|
|||||||
|
|
||||||
create_serde_registry_for_trait!(serdeany_registry, crate::bolts::serdeany::SerdeAny);
|
create_serde_registry_for_trait!(serdeany_registry, crate::bolts::serdeany::SerdeAny);
|
||||||
pub use serdeany_registry::*;
|
pub use serdeany_registry::*;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! impl_serdeany {
|
||||||
|
($struct_name:ident) => {
|
||||||
|
impl crate::bolts::serdeany::SerdeAny for $struct_name {
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[ctor]
|
||||||
|
fn $struct_name() {
|
||||||
|
crate::bolts::serdeany::RegistryBuilder::register::<$struct_name>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -239,7 +239,7 @@ pub mod unix_signals {
|
|||||||
static mut EVENT_MGR_PTR: *mut c_void = ptr::null_mut();
|
static mut EVENT_MGR_PTR: *mut c_void = ptr::null_mut();
|
||||||
static mut OBSERVERS_PTR: *const c_void = ptr::null();
|
static mut OBSERVERS_PTR: *const c_void = ptr::null();
|
||||||
/// The (unsafe) pointer to the current inmem input, for the current run.
|
/// The (unsafe) pointer to the current inmem input, for the current run.
|
||||||
/// This is neede for certain non-rust side effects, as well as unix signal handling.
|
/// This is needed for certain non-rust side effects, as well as unix signal handling.
|
||||||
static mut CURRENT_INPUT_PTR: *const c_void = ptr::null();
|
static mut CURRENT_INPUT_PTR: *const c_void = ptr::null();
|
||||||
|
|
||||||
pub unsafe extern "C" fn libaflrs_executor_inmem_handle_crash<C, EM, FT, I, OC, OFT, OT, R>(
|
pub unsafe extern "C" fn libaflrs_executor_inmem_handle_crash<C, EM, FT, I, OC, OFT, OT, R>(
|
||||||
@ -267,6 +267,15 @@ pub mod unix_signals {
|
|||||||
Ok(maps) => println!("maps:\n{}", maps),
|
Ok(maps) => println!("maps:\n{}", maps),
|
||||||
Err(e) => println!("Couldn't load mappings: {:?}", e),
|
Err(e) => println!("Couldn't load mappings: {:?}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
{
|
||||||
|
println!("Type QUIT to restart the child");
|
||||||
|
let mut line = String::new();
|
||||||
|
while line.trim() != "QUIT" {
|
||||||
|
std::io::stdin().read_line(&mut line).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO tell the parent to not restart
|
// TODO tell the parent to not restart
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
@ -8,6 +8,8 @@ Welcome to libAFL
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate ctor;
|
||||||
|
|
||||||
pub mod bolts;
|
pub mod bolts;
|
||||||
pub mod corpus;
|
pub mod corpus;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
//! They may be inserted as part of mutations during fuzzing.
|
//! They may be inserted as part of mutations during fuzzing.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bolts::serdeany::SerdeAny,
|
|
||||||
inputs::{HasBytesVec, Input},
|
inputs::{HasBytesVec, Input},
|
||||||
mutators::*,
|
mutators::*,
|
||||||
utils::Rand,
|
utils::Rand,
|
||||||
@ -21,15 +20,7 @@ pub struct TokensMetadata {
|
|||||||
tokens: Vec<Vec<u8>>,
|
tokens: Vec<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SerdeAny for TokensMetadata {
|
crate::impl_serdeany!(TokensMetadata);
|
||||||
fn as_any(&self) -> &dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TokensMetadata {
|
impl TokensMetadata {
|
||||||
pub fn new(tokens: Vec<Vec<u8>>) -> Self {
|
pub fn new(tokens: Vec<Vec<u8>>) -> Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user