libafl_derive proc macro crate

This commit is contained in:
Andrea Fioraldi 2021-03-01 14:11:37 +01:00
parent 868d408799
commit f18af45d09
5 changed files with 41 additions and 5 deletions

View File

@ -8,6 +8,7 @@ debug = true
[workspace]
members = [
"libafl",
"libafl_derive",
#example fuzzers
"fuzzers/libfuzzer_libpng",

View File

@ -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]

View File

@ -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;

12
libafl_derive/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "libafl_derive"
version = "0.1.0"
authors = ["Andrea Fioraldi <andreafioraldi@gmail.com>"]
edition = "2018"
[lib]
proc-macro = true
[dependencies]
syn = { version = "1", features = ["full", "extra-traits"] }
quote = "1"

12
libafl_derive/src/lib.rs Normal file
View File

@ -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);
})
}