impl serdeany macro
This commit is contained in:
parent
58f8788a68
commit
1575a3994b
@ -4,7 +4,7 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use libafl::{
|
||||
bolts::{serdeany::RegistryBuilder, shmem::UnixShMem, tuples::tuple_list},
|
||||
bolts::{shmem::UnixShMem, tuples::tuple_list},
|
||||
corpus::{Corpus, InMemoryCorpus, OnDiskCorpus},
|
||||
events::setup_restarting_mgr,
|
||||
executors::{inprocess::InProcessExecutor, Executor, ExitKind},
|
||||
@ -52,8 +52,8 @@ where
|
||||
/// The main fn, parsing parameters, and starting the fuzzer
|
||||
pub fn main() {
|
||||
// Registry the metadata types used in this fuzzer
|
||||
RegistryBuilder::register::<TokensMetadata>();
|
||||
RegistryBuilder::finalize();
|
||||
// Needed only on no_std
|
||||
//RegistryBuilder::register::<TokensMetadata>();
|
||||
|
||||
println!(
|
||||
"Workdir: {:?}",
|
||||
|
@ -50,6 +50,7 @@ erased-serde = "0.3.12"
|
||||
postcard = { version = "0.5.1", features = ["alloc"] } # no_std compatible serde serialization fromat
|
||||
static_assertions = "1.1.0"
|
||||
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
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use alloc::boxed::Box;
|
||||
use core::any::{Any, TypeId};
|
||||
|
||||
#[cfg(fature = "anymap_debug")]
|
||||
#[cfg(feature = "anymap_debug")]
|
||||
use serde_json;
|
||||
|
||||
// yolo
|
||||
@ -499,3 +499,25 @@ macro_rules! create_serde_registry_for_trait {
|
||||
|
||||
create_serde_registry_for_trait!(serdeany_registry, crate::bolts::serdeany::SerdeAny);
|
||||
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 OBSERVERS_PTR: *const c_void = ptr::null();
|
||||
/// 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();
|
||||
|
||||
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),
|
||||
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
|
||||
std::process::exit(1);
|
||||
|
@ -8,6 +8,8 @@ Welcome to libAFL
|
||||
extern crate alloc;
|
||||
#[macro_use]
|
||||
extern crate static_assertions;
|
||||
#[macro_use]
|
||||
extern crate ctor;
|
||||
|
||||
pub mod bolts;
|
||||
pub mod corpus;
|
||||
|
@ -2,7 +2,6 @@
|
||||
//! They may be inserted as part of mutations during fuzzing.
|
||||
|
||||
use crate::{
|
||||
bolts::serdeany::SerdeAny,
|
||||
inputs::{HasBytesVec, Input},
|
||||
mutators::*,
|
||||
utils::Rand,
|
||||
@ -21,15 +20,7 @@ pub struct TokensMetadata {
|
||||
tokens: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl SerdeAny for TokensMetadata {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
crate::impl_serdeany!(TokensMetadata);
|
||||
|
||||
impl TokensMetadata {
|
||||
pub fn new(tokens: Vec<Vec<u8>>) -> Self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user