Skip to main content

Crate libafl_derive

Crate libafl_derive 

Source
Expand description

Derives for LibAFL

§LibAFL_derive: Derive Macros for LibAFL

LibAFL logo

The libafl_derive crate offers derive macros, such as #[derive(SerdeAny)].

§Available Derive Macros

§#[derive(SerdeAny)]

This macro implements the SerdeAny trait for a type. This is necessary to store the type in a SerdeAnyMap, a key component for type-safe storage of different data types in LibAFL.

Usage:

use libafl_derive::SerdeAny;
use serde::{Serialize, Deserialize};

#[derive(SerdeAny, Serialize, Deserialize)]
struct MyStruct {
    // ...
}

§#[derive(Display)]

This macro implements the core::fmt::Display trait for a struct. It generates a Display implementation that concatenates the string representations of all fields, separated by spaces.

Special Handling:

  • Option<T>: If the value is Some(inner), the inner value is displayed. If it is None, nothing is displayed.
  • Vec<T>: The elements of the vector are displayed, each separated by a space.

Example:

use libafl_derive::Display;
use std::fmt::Display;

#[derive(Display)]
struct MyStruct {
    foo: String,
    bar: Option<u32>,
    baz: Vec<i32>,
}

let instance = MyStruct {
    foo: "hello".to_string(),
    bar: Some(42),
    baz: vec![1, 2, 3],
};
// The following will print: " hello 42 1 2 3"
println!("{}", instance);

§The LibAFL Project

The LibAFL project is part of AFLplusplus and maintained by

§Contributing

For bugs, feel free to open issues or contact us directly. Thank you for your support. <3

Even though we will gladly assist you in finishing up your PR, try to

  • keep all the crates compiling with stable rust (hide the eventual non-stable code under cfgs.)
  • run cargo nightly fmt on your code before pushing
  • check the output of cargo clippy --all or ./clippy.sh
  • run cargo build --no-default-features to check for no_std compatibility (and possibly add #[cfg(feature = "std")]) to hide parts of your code.

Some parts in this list may sound hard, but don’t be afraid to open a PR if you cannot fix them by yourself. We will gladly assist.

§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies under more restrictive licenses, such as GPL or AGPL, can be enabled using the respective feature in each crate when it is present, such as the 'agpl' feature of the libafl crate.

Derive Macros§

Display
A derive macro to implement Display
SerdeAny
Derive macro to implement SerdeAny, to use a type in a SerdeAnyMap