### Build and run sample fuzzing with afl-fuzz Source: https://github.com/aflplusplus/unicornafl/blob/main/Readme.md Build the sample harness and start fuzzing with afl-fuzz. The -c 0 flag enables cmplog integration, which finds the crash instantly. ```bash cargo build --example sample --release # assume AFL++ is installed afl-fuzz -i ./input -o ./output-8 -b 1 -g 8 -G 8 -V 60 -c 0 -- ./target/release/examples/sample @@ true ``` -------------------------------- ### Build unicornafl with cargo Source: https://github.com/aflplusplus/unicornafl/blob/main/Readme.md Clone the repository and build the release version with cargo. This builds the core library and the sample harness. ```bash git clone https://github.com/AFLplusplus/unicornafl cd unicornafl cargo build --release ``` -------------------------------- ### Build Python bindings with maturin Source: https://github.com/aflplusplus/unicornafl/blob/main/Readme.md Build the Python bindings using maturin. This is required until wheels are released. ```bash maturin build --release ``` -------------------------------- ### Sample target assembly Source: https://github.com/aflplusplus/unicornafl/blob/main/Readme.md The target assembly for the sample harness. The harness stops at any 'xor rax, rax' instruction; if rax equals 0x114514, an unmapped read error occurs and is captured as a crash. ```assembly mov rax, rdx; cmp rax, 0x114514; je die; xor rax, rax; die: mov rax, [rax]; xor rax, rax; ``` -------------------------------- ### Example usage of afl_fuzz Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Example harness that calls unicornafl::afl_fuzz with a Unicorn instance, no input file (fuzzing mode), a callback that returns true, exit addresses 0x4001000 and 0x4002000, and persistent_iters Some(1). On error, prints an error message. ```rust // Creating uc // Other setup ... if let Err(err) = unicornafl::afl_fuzz( uc, None, |uc, input, persistent_round| { // Custom logics here, use uc.reg_write() or uc.mem_write(), for instance. true }, vec![0x4001000, 0x4002000], Some(1), ) { eprintln!("Unexpected happened! {err:?}"); } ``` -------------------------------- ### uc_afl_fuzz Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/c-usage.md Simplified API to start fuzzing with UnicornAFL. It takes a pre-created Unicorn instance, an input file path, callbacks for placing input and validating crashes, exit points, and other configuration parameters. ```APIDOC ## uc_afl_fuzz ### Description Simplified API to start fuzzing with UnicornAFL. It takes a pre-created Unicorn instance, an input file path, callbacks for placing input and validating crashes, exit points, and other configuration parameters. ### Function Signature ```c uc_afl_ret uc_afl_fuzz(uc_engine* uc, char* input_file, uc_afl_cb_place_input_t place_input_callback, uint64_t* exits, size_t exit_count, uc_afl_cb_validate_crash_t validate_crash_callback, bool always_validate, uint32_t persistent_iters, void* data); ``` ### Parameters - **uc** (uc_engine*) - Required - A unicorn instance created in advance. - **input_file** (char*) - Required - Path to input file. Pass NULL for fuzzing mode; seed directory is passed to afl-fuzz instead. For standalone mode, input is taken from this file. - **place_input_callback** (uc_afl_cb_place_input_t) - Required - Callback to place received input into Unicorn's memory space. Takes five arguments: pointer to unicorn instance, pointer to input buffer, input buffer length, persistent round, and custom data. Returns bool indicating if input is acceptable. - **exits** (uint64_t*) - Required - Array of exit points for Unicorn. - **exit_count** (size_t) - Required - Number of exit points. - **validate_crash_callback** (uc_afl_cb_validate_crash_t) - Required - Callback invoked when an error occurs during execution. Takes six arguments: pointer to unicorn instance, error value, input buffer pointer, input buffer length, persistent round, and custom data. Returns bool; if false, the round is not treated as a crash. - **always_validate** (bool) - Required - If true, validate_crash_callback is invoked even if no errors occur. - **persistent_iters** (uint32_t) - Required - Number of times to execute the harness persistently before forking. Pass 1 to always fork, 0 to never fork. - **data** (void*) - Required - Custom data passed to callbacks. ### Return Value - **uc_afl_ret** - Returns UC_AFL_RET_OK on success; otherwise indicates unexpected fuzzing issues. ``` -------------------------------- ### uc_afl_fuzz_custom Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/c-usage.md Advanced API for fuzzing with a custom execution callback. Similar to uc_afl_fuzz but allows you to control how each execution round is started via the fuzz_callback. ```APIDOC ## uc_afl_fuzz_custom ### Description Advanced API for fuzzing with a custom execution callback. Similar to uc_afl_fuzz but allows you to control how each execution round is started via the fuzz_callback. ### Function Signature ```c uc_afl_ret uc_afl_fuzz_custom(uc_engine* uc, char* input_file, uc_afl_cb_place_input_t place_input_callback, uc_afl_fuzz_cb_t fuzz_callbck, uc_afl_cb_validate_crash_t validate_crash_callback, bool always_validate, uint32_t persistent_iters, void* data); ``` ### Parameters - **uc** (uc_engine*) - Required - A unicorn instance created in advance. - **input_file** (char*) - Required - Path to input file. Pass NULL for fuzzing mode; seed directory is passed to afl-fuzz instead. For standalone mode, input is taken from this file. - **place_input_callback** (uc_afl_cb_place_input_t) - Required - Callback to place received input into Unicorn's memory space. Takes five arguments: pointer to unicorn instance, pointer to input buffer, input buffer length, persistent round, and custom data. Returns bool indicating if input is acceptable. - **fuzz_callbck** (uc_afl_fuzz_cb_t) - Required - Callback to start one execution round. When this function stops, UnicornAFL knows the round has ended. By default, UnicornAFL uses uc_emu_start(). - **validate_crash_callback** (uc_afl_cb_validate_crash_t) - Required - Callback invoked when an error occurs during execution. Takes six arguments: pointer to unicorn instance, error value, input buffer pointer, input buffer length, persistent round, and custom data. Returns bool; if false, the round is not treated as a crash. - **always_validate** (bool) - Required - If true, validate_crash_callback is invoked even if no errors occur. - **persistent_iters** (uint32_t) - Required - Number of times to execute the harness persistently before forking. Pass 1 to always fork, 0 to never fork. - **data** (void*) - Required - Custom data passed to callbacks. ### Return Value - **uc_afl_ret** - Returns UC_AFL_RET_OK on success; otherwise indicates unexpected fuzzing issues. ``` -------------------------------- ### Custom hook implementation and usage of afl_fuzz_custom Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Example showing how to define a custom UnicornAflExecutorHook and pass it to afl_fuzz_custom. The hook implements place_input (required) and optionally validate_crash and fuzz. The main function calls afl_fuzz_custom with the hook, exit addresses, and persistent iterations. ```rust use unicornafl::UnicornAflExecutorHook; struct MyOwnExecutorHook { my_data: usize } impl UnicornAflExecutorHook for MyOwnExecutorHook { fn place_input( &mut self, uc: &mut Unicorn<'a, UnicornFuzzData>, input: &[u8], persistent_round: u64, ) -> bool { // Custom logics here, use uc.reg_write() or uc.mem_write(), for instance. true } // I don't need to implement `validate_crash` and `fuzz`. } fn main() { // Creating uc // Other setup ... if let Err(err) = unicornafl::afl_fuzz_custom( uc, None, MyOwnExecutorHook { my_data: 0 }, vec![0x4001000, 0x4002000], false, Some(1), ) { eprintln!("Unexpected happened! {err:?}"); } } ``` -------------------------------- ### Add unicornafl dependency to Cargo.toml Source: https://github.com/aflplusplus/unicornafl/blob/main/Readme.md Add this line to your Cargo.toml to use unicornafl as a Rust library. The 'main' branch is used because unicorn is not yet released. ```toml unicornafl = { git = "https://github.com/AFLplusplus/unicornafl", branch = "main" } ``` -------------------------------- ### uc_afl_fuzz_custom advanced API signature Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/python-usage.md Advanced fuzzing entry point. Same as uc_afl_fuzz but adds a fuzzing_callback that starts each execution round; when it stops, the round ends. By default UnicornAFL uses uc_emu_start(). ```python def uc_afl_fuzz_custom(uc: Uc, input_file: str, place_input_callback: Callable, fuzzing_callback: Callable, validate_crash_callback: Callable = None, always_validate: bool = False, persistent_iters: int = 1, data: Any = None): ... ``` -------------------------------- ### Build with env_logger feature for debugging Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/c-usage.md Compile the repository with the env_logger feature to enable logging. This is required before running with RUST_LOG=trace. ```shell cargo build --release --features env_logger ``` -------------------------------- ### Build UnicornAFL from source Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/c-usage.md Clone the repository and build with Cargo, enabling the bindings feature. Requires Unicorn dependencies and Rust 1.87.0 or later. ```shell git clone --depth 1 https://github.com/AFLplusplus/unicornafl && cd unicornafl cargo build --release --features bindings ``` -------------------------------- ### Initialize env_logger in main function Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Add this to your main function to enable logging. Run with RUST_LOG=trace (and AFL_DEBUG=1 if using afl-fuzz) to see debug logs. ```rust fn main() { env_logger::init(); // ... } ``` -------------------------------- ### Run afl-fuzz with UnicornAFL (static link) Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/fuzzing.md Use this command when your harness is built with Rust or C/C++ statically linked against libunicornafl.a. The -U option is not needed in this case. ```shell afl-fuzz \ -i input \ -o output \ -- \ ./your-harness --and-your-own-harness-options ``` -------------------------------- ### Create Unicorn instance with UnicornFuzzData::default() Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Sets up a Unicorn instance for fuzzing with UnicornAFL, using default shared fuzzing data. The target must be manually set up in the Unicorn memory space. ```rust use unicornafl::UnicornFuzzData; // Set up arch, mode, and some shared fuzzing data. let mut uc = Unicorn::new_with_data(Arch::X86, Mode::MODE_64, UnicornFuzzData::default()); ``` -------------------------------- ### Run afl-fuzz with UnicornAFL (dynamic link) Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/fuzzing.md Use this command when your harness is built with Python or C/C++ dynamically linked against libunicornafl.so. The -U option specifies legacy Unicorn mode. ```shell afl-fuzz \ -U \ -i input \ -o output \ -- \ ./your-harness --and-your-own-harness-options ``` -------------------------------- ### Build UnicornAFL with cargo and maturin Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/python-usage.md Clone the repository and build the Python wheel. Requires Unicorn dependencies, stable Rust 1.87.0+, and maturin. The resulting wheel is in ./target/wheels. ```shell git clone --depth 1 https://github.com/AFLplusplus/unicornafl && cd unicornafl cargo build --release maturin build --release ``` -------------------------------- ### uc_afl_fuzz simplified API signature Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/python-usage.md Simplified fuzzing entry point. Takes a pre-created Unicorn instance, input file path (or None for fuzzing mode), a callback to place input into memory, exit addresses, and optional crash validation and persistence settings. Returns UcAflError or UC_AFL_RET_OK. ```python def uc_afl_fuzz(uc: Uc, input_file: str, place_input_callback: Callable, exits: List[int], validate_crash_callback: Callable = None, always_validate: bool = False, persistent_iters: int = 1, data: Any = None): ... ``` -------------------------------- ### Optimize release profile in Cargo.toml Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Add this to your Cargo.toml to enable link-time optimization and reduce codegen units for a faster, more optimized binary. Compile time may increase significantly. ```toml [profile.release] lto = true codegen-units = 1 ``` -------------------------------- ### Simplified API signature for afl_fuzz Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Shows the function signature of unicornafl::afl_fuzz. The lifetime marker can be ignored in most cases. Parameters include a Unicorn instance, an optional input file path, a callback to place input, exit addresses, and persistent iteration count. ```rust fn afl_fuzz<'a, D: 'a>( uc: Unicorn<'a, UnicornFuzzData>, input_file: Option, place_input_cb: impl FnMut(&mut Unicorn<'a, UnicornFuzzData>, &[u8], u64) -> bool + 'a, exits: Vec, persistent_iters: Option, ) -> Result<(), uc_afl_ret>; ``` -------------------------------- ### Create Unicorn instance with custom user data and code hook Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Defines a custom data structure for shared fuzzing data, creates a Unicorn instance with it, and adds a code hook that increments a counter. Note that get_data_mut() requires an Rc check and may decrease performance. ```rust use unicornafl::UnicornFuzzData; struct MyFuzzData { hook_call_count: usize } let mut uc = Unicorn::new_with_data( Arch::X86, Mode::MODE_64, UnicornFuzzData::new( MyFuzzData { hook_call_count: 0 } ) ); uc.add_code_hook(/* ... */, |uc, _, _| { let my_fuzz_data = &mut uc.get_data_mut().user_data; my_fuzz_data.hook_call_count += 1; }).unwrap(); ``` -------------------------------- ### uc_afl_fuzz Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/python-usage.md Simplified API for fuzzing a Unicorn emulated target. It takes an input file, a callback to place input into memory, and exit points, and runs the fuzzing loop. ```APIDOC ## uc_afl_fuzz ### Description Simplified API for fuzzing a Unicorn emulated target. It takes an input file, a callback to place input into memory, and exit points, and runs the fuzzing loop. ### Method Function call ### Signature ```python def uc_afl_fuzz(uc: Uc, input_file: str, place_input_callback: Callable, exits: List[int], validate_crash_callback: Callable = None, always_validate: bool = False, persistent_iters: int = 1, data: Any = None): ... ``` ### Parameters - **uc** (Uc) - Required - A unicorn instance created in advance. - **input_file** (str) - Required - Path to input file. Pass `None` for fuzzing mode; the input seed directory should be passed to `afl-fuzz` instead. For standalone mode, UnicornAFL takes input using this argument. - **place_input_callback** (Callable) - Required - Callback to place received input into Unicorn's memory space. Takes four arguments: pointer to unicorn instance, input buffer, persistent round, and custom data. Returns a Bool indicating whether the input is acceptable. - **exits** (List[int]) - Required - Exit points for Unicorn. When the Unicorn instance reaches one of these addresses, UnicornAFL switches to next round. - **validate_crash_callback** (Callable) - Optional - Callback for when an error is encountered during execution. Takes five arguments: pointer to unicorn instance, error value, input buffer, persistent round, and custom data. Returns a Bool; if `False`, the AFL++ main executable will not treat this round as crash. - **always_validate** (bool) - Optional - Whether `validate_crash_callback` will be invoked even if Unicorn does not face errors during execution. - **persistent_iters** (int) - Optional - How many times the harness should be executed persistently until the parent forks another child. Pass `1` to always exit and fork; pass `0` to never exit or fork unless the process crashes. - **data** (Any) - Optional - Custom data passed to each callback. ### Return Value Returns a `UcAflError` or value `UC_AFL_RET_OK`. If not `UC_AFL_RET_OK`, unexpected things happened during fuzzing. ``` -------------------------------- ### uc_afl_fuzz function signature Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/c-usage.md Simplified API for fuzzing with UnicornAFL. Takes a Unicorn instance, input file, callbacks, exit points, and persistence settings. Returns a uc_afl_ret indicating success or failure. ```c uc_afl_ret uc_afl_fuzz(uc_engine* uc, char* input_file, uc_afl_cb_place_input_t place_input_callback, uint64_t* exits, size_t exit_count, uc_afl_cb_validate_crash_t validate_crash_callback, bool always_validate, uint32_t persistent_iters, void* data); ``` -------------------------------- ### uc_afl_fuzz_custom Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/python-usage.md Advanced API for fuzzing with a custom fuzzing callback. It allows you to control the execution of each round by providing a custom callback instead of using the default `uc_emu_start()`. ```APIDOC ## uc_afl_fuzz_custom ### Description Advanced API for fuzzing with a custom fuzzing callback. It allows you to control the execution of each round by providing a custom callback instead of using the default `uc_emu_start()`. ### Method Function call ### Signature ```python def uc_afl_fuzz_custom(uc: Uc, input_file: str, place_input_callback: Callable, fuzzing_callback: Callable, validate_crash_callback: Callable = None, always_validate: bool = False, persistent_iters: int = 1, data: Any = None): ... ``` ### Parameters - **uc** (Uc) - Required - A unicorn instance created in advance. - **input_file** (str) - Required - Path to input file. Pass `None` for fuzzing mode; the input seed directory should be passed to `afl-fuzz` instead. For standalone mode, UnicornAFL takes input using this argument. - **place_input_callback** (Callable) - Required - Callback to place received input into Unicorn's memory space. Takes four arguments: pointer to unicorn instance, input buffer, persistent round, and custom data. Returns a Bool indicating whether the input is acceptable. - **fuzzing_callback** (Callable) - Required - Callback to start one execution round. When this function stops, UnicornAFL knows the round has ended. By default, UnicornAFL uses `uc_emu_start()`. - **validate_crash_callback** (Callable) - Optional - Callback for when an error is encountered during execution. Takes five arguments: pointer to unicorn instance, error value, input buffer, persistent round, and custom data. Returns a Bool; if `False`, the AFL++ main executable will not treat this round as crash. - **always_validate** (bool) - Optional - Whether `validate_crash_callback` will be invoked even if Unicorn does not face errors during execution. - **persistent_iters** (int) - Optional - How many times the harness should be executed persistently until the parent forks another child. Pass `1` to always exit and fork; pass `0` to never exit or fork unless the process crashes. - **data** (Any) - Optional - Custom data passed to each callback. ### Return Value Returns a `UcAflError` or value `UC_AFL_RET_OK`. If not `UC_AFL_RET_OK`, unexpected things happened during fuzzing. ``` -------------------------------- ### afl_fuzz Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md The simplified fuzzing API for UnicornAFL. It takes a Unicorn instance, an optional input file, a callback to place input into memory, exit points, and a persistent iteration count, returning a Result indicating success or failure. ```APIDOC ## Function: afl_fuzz ### Description Simplified fuzzing API for UnicornAFL. It sets up the fuzzing loop with a Unicorn instance, input handling, and exit conditions. ### Signature ```rust fn afl_fuzz<'a, D: 'a>( uc: Unicorn<'a, UnicornFuzzData>, input_file: Option, place_input_cb: impl FnMut(&mut Unicorn<'a, UnicornFuzzData>, &[u8], u64) -> bool + 'a, exits: Vec, persistent_iters: Option, ) -> Result<(), uc_afl_ret>; ``` ### Parameters - **uc** (Unicorn) - Required - A Unicorn instance created in advance. - **input_file** (Option) - Required - Path to input file for standalone mode; pass `None` for fuzzing mode. - **place_input_cb** (closure) - Required - Callback to place input into Unicorn's memory. Takes mutable Unicorn reference, input buffer, and persistent round; returns bool indicating if input is acceptable. - **exits** (Vec) - Required - Exit addresses for Unicorn; when reached, UnicornAFL switches to next round. - **persistent_iters** (Option) - Required - Number of persistent iterations before forking; `Some(1)` for always forking, `None` for never forking. ### Return Value - **Result<(), uc_afl_ret>** - Ok on success, Err on unexpected fuzzing issues. ### Example ```rust // Creating uc // Other setup ... if let Err(err) = unicornafl::afl_fuzz( uc, None, |uc, input, persistent_round| { // Custom logics here, use uc.reg_write() or uc.mem_write(), for instance. true }, vec![0x4001000, 0x4002000], Some(1), ) { eprintln!("Unexpected happened! {err:?}"); } ``` ``` -------------------------------- ### uc_afl_fuzz_custom function signature Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/c-usage.md Advanced API that allows a custom fuzz callback to control each execution round. Other arguments are the same as uc_afl_fuzz. ```c uc_afl_ret uc_afl_fuzz_custom(uc_engine* uc, char* input_file, uc_afl_cb_place_input_t place_input_callback, uc_afl_fuzz_cb_t fuzz_callbck, uc_afl_cb_validate_crash_t validate_crash_callback, bool always_validate, uint32_t persistent_iters, void* data); ``` -------------------------------- ### Function signature for afl_fuzz_custom Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Signature of the advanced fuzzing API. It takes a Unicorn instance with fuzz data, an optional input file, a user-defined hook, exit addresses, a validation flag, and an optional persistent iteration count. Returns a Result with uc_afl_ret. ```rust fn afl_fuzz_custom<'a, D: 'a>( uc: Unicorn<'a, UnicornFuzzData>, input_file: Option, callbacks: impl UnicornAflExecutorHook<'a, D>, exits: Vec, always_validate: bool, persistent_iters: Option, ) -> Result<(), uc_afl_ret>; ``` -------------------------------- ### UnicornAflExecutorHook trait methods Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Trait that users implement to customize fuzzing behavior. It includes required place_input and optional validate_crash and fuzz methods. ```APIDOC ## [RUST] UnicornAflExecutorHook trait ### Description Trait that users implement to customize fuzzing behavior. It includes required place_input and optional validate_crash and fuzz methods. ### Methods #### place_input ##### Description Required method to place input into the emulator. Called for each fuzzing iteration. ##### Parameters - **&mut self** - Required - Mutable reference to the hook structure. - **uc** (&mut Unicorn<'a, UnicornFuzzData>) - Required - The Unicorn instance. - **input** (&[u8]) - Required - The input bytes to place. - **persistent_round** (u64) - Required - The current persistent round number. ##### Returns - **bool** - Returns true if input placement succeeded, false otherwise. #### validate_crash ##### Description Optional method to validate whether a crash is a true positive. Called when Unicorn encounters exceptions or when always_validate is true. ##### Parameters - **&mut self** - Required - Mutable reference to the hook structure. - (Additional parameters not specified in source) ##### Returns - **bool** - Returns false to indicate the crash is a false positive; otherwise true. #### fuzz ##### Description Optional method to start one execution round. When this function stops, the round is considered ended. Default implementation uses uc.emu_start(). ##### Parameters - **&mut self** - Required - Mutable reference to the hook structure. - (Additional parameters not specified in source) ##### Returns - (Not specified in source) ### Notes - All methods take `&mut self`, allowing shared data across persistent rounds. - Data stored in the hook is not preserved across process forks after max persistent rounds; save data after `afl_fuzz_custom` ends. ``` -------------------------------- ### unicornafl::afl_fuzz_custom Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Advanced fuzzing entry point that allows custom input placement, crash validation, and execution control via a user-defined hook. It requires a callbacks structure implementing UnicornAflExecutorHook and an always_validate flag. ```APIDOC ## [RUST] unicornafl::afl_fuzz_custom ### Description Advanced fuzzing entry point that allows custom input placement, crash validation, and execution control via a user-defined hook. It requires a callbacks structure implementing UnicornAflExecutorHook and an always_validate flag. ### Method Rust function call ### Endpoint `unicornafl::afl_fuzz_custom` ### Parameters #### Function Arguments - **uc** (Unicorn<'a, UnicornFuzzData>) - Required - The Unicorn instance with fuzz data. - **input_file** (Option) - Required - Optional path to input file. - **callbacks** (impl UnicornAflExecutorHook<'a, D>) - Required - User-defined hook implementing the executor hook trait. - **exits** (Vec) - Required - List of exit addresses. - **always_validate** (bool) - Required - If true, always invoke validate_crash callback. - **persistent_iters** (Option) - Required - Number of persistent iterations, if any. ### Request Example ```rust use unicornafl::UnicornAflExecutorHook; struct MyOwnExecutorHook { my_data: usize } impl UnicornAflExecutorHook for MyOwnExecutorHook { fn place_input( &mut self, uc: &mut Unicorn<'a, UnicornFuzzData>, input: &[u8], persistent_round: u64, ) -> bool { // Custom logics here, use uc.reg_write() or uc.mem_write(), for instance. true } // I don't need to implement `validate_crash` and `fuzz`. } fn main() { // Creating uc // Other setup ... if let Err(err) = unicornafl::afl_fuzz_custom( uc, None, MyOwnExecutorHook { my_data: 0 }, vec![0x4001000, 0x4002000], false, Some(1), ) { eprintln!("Unexpected happened! {err:?}"); } } ``` ### Response #### Success Response - **Ok(())** - Returns Ok(()) on success. #### Error Response - **Err(uc_afl_ret)** - Returns an error of type uc_afl_ret on failure. ### Notes - The `callbacks` parameter must implement the `UnicornAflExecutorHook` trait. - The `always_validate` flag forces validation of crashes even without exceptions. - The `persistent_iters` parameter controls the number of persistent rounds; after reaching the max, the process exits and a new one is forked. ``` -------------------------------- ### Override Unicorn dependency in Cargo.toml Source: https://github.com/aflplusplus/unicornafl/blob/main/docs/rust-usage.md Use this to point UnicornAFL to your own version of Unicorn, either via a local path or a git fork. Older Unicorn versions may not work due to reliance on newest APIs. ```toml [patch.'https://github.com/unicorn-engine/unicorn'] unicorn-engine = { path = "/my/own/path/to/local/unicorn" } # or unicorn-engine = { git = "http://my/own/unicorn/fork" } ```