diff --git a/Cargo.toml b/Cargo.toml index 8973fa815d..9b384235b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,8 @@ debug = true [workspace] members = [ "libafl", + "libafl_derive", #example fuzzers "fuzzers/libfuzzer_libpng", -] \ No newline at end of file +] diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index 38a94a54a1..7c7f9f5e00 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -30,10 +30,11 @@ harness = false #debug = true [features] -default = ["std", "anymapdbg"] +default = ["std", "anymapdbg", "derive"] std = [] # print, sharedmap, ... support runtime = [] # a runtime for clang inmem-executor -anymapdbg = [] # uses serde_json to Debug the anymap trait. Disable for smaller footprint. +anymapdbg = ["serde_json"] # uses serde_json to Debug the anymap trait. Disable for smaller footprint. +derive = ["libafl_derive"] # provide derive(SerdeAny) macro. [[example]] name = "llmp_test" @@ -49,8 +50,9 @@ serde = { version = "1.0", default-features = false, features = ["alloc"] } # se 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" +ctor = "*" +libafl_derive = { version = "*", optional = true, path = "../libafl_derive" } +serde_json = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } # an easy way to debug print SerdeAnyMap #TODO: for llmp brotli = { version = "3.3.0", default-features = false } # brotli compression [target.'cfg(unix)'.dependencies] diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index 13146be934..01fb47a3f9 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -12,6 +12,15 @@ extern crate static_assertions; #[macro_use] extern crate ctor; +// Re-export derive(SerdeAny) +#[cfg(feature = "libafl_derive")] +#[allow(unused_imports)] +#[macro_use] +extern crate libafl_derive; +#[cfg(feature = "libafl_derive")] +#[doc(hidden)] +pub use libafl_derive::*; + pub mod bolts; pub mod corpus; pub mod events; diff --git a/libafl_derive/Cargo.toml b/libafl_derive/Cargo.toml new file mode 100644 index 0000000000..5f9cb2861a --- /dev/null +++ b/libafl_derive/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "libafl_derive" +version = "0.1.0" +authors = ["Andrea Fioraldi "] +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] +syn = { version = "1", features = ["full", "extra-traits"] } +quote = "1" diff --git a/libafl_derive/src/lib.rs b/libafl_derive/src/lib.rs new file mode 100644 index 0000000000..066ad9b9e1 --- /dev/null +++ b/libafl_derive/src/lib.rs @@ -0,0 +1,12 @@ +extern crate proc_macro; +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input, DeriveInput}; + +#[proc_macro_derive(SerdeAny)] +pub fn libafl_serdeany_derive(input: TokenStream) -> TokenStream { + let name = parse_macro_input!(input as DeriveInput).ident; + TokenStream::from(quote! { + libafl::impl_serdeany!(#name); + }) +}