| Crates.io | libafl-fandango-pyo3 |
| lib.rs | libafl-fandango-pyo3 |
| version | 0.3.0 |
| created_at | 2025-09-18 13:14:12.057643+00 |
| updated_at | 2025-12-22 11:55:24.760453+00 |
| description | A library for running Fandango as in LibAFL using PyO3 |
| homepage | |
| repository | https://github.com/riesentoaster/libafl-fandango-pyo3 |
| max_upload_size | |
| id | 1844698 |
| size | 87,378 |
This will allow you to run Fandango as a LibAFL Generator, Mutator, Stage, or Executor.
It works by internally calling a python script using the PyO3 interpreter. That script is expected to implement three functions. Here is the default implementation, but you can provide your own (using FandangoPythonModule::with_custom_python_interface):
import os
from typing import Any
from fandango import Fandango
class FandangoWrapper:
def __init__(self, fan_file: str, kwargs: dict[str, Any]):
with open(fan_file) as f:
self.fan = Fandango(f, **kwargs)
self.generator = self.fan.generate_solutions()
def setup(fan_file: str, kwargs: dict[str, Any]) -> FandangoWrapper:
return FandangoWrapper(fan_file, kwargs)
def next_input(wrapper: FandangoWrapper) -> bytes:
return bytes(next(wrapper.generator))
def parse_input(wrapper: FandangoWrapper, input: bytes) -> int:
return len(list(wrapper.fan.parse(input)))
Look at the example for how to use the Rust interface to run Fandango. Run it using the following:
cargo run --example run_fandango --release -- --fandango-file examples/even_numbers.fan
There are four ways of running libafl_fandango_pyo3 in LibAFL: As a generator, as a pseudo-mutator, as a stage with post-mutators, and as an executor.
There are four example fuzzers: baby_fuzzer_generator, baby_fuzzer_mutator, baby_fuzzer_stage, and baby_fuzzer_differential. The target for all four is an in-process function that parses the input to a string and then a number and checks if it is even. For the first three, it will consider any number that does not fit into 128 bits as a crash and thus produce a list of crashes after some time (in the crashes directory). They can be run with the following:
cargo run --example baby_fuzzer_generator --release
cargo run --example baby_fuzzer_mutator --release
cargo run --example baby_fuzzer_stage --release
cargo run --example baby_fuzzer_differential --release
For some reason, PyO3 struggles with matching the python interpreter to the one used in the shell – specifically when it comes to imports of dependencies. You may need to manually set the python path environment variable:
export PYTHONPATH=$(echo .venv/lib/python*/site-packages)