Unicorn mode allows you to fuzz binary code snippets using the Unicorn Engine. This is ideal for fuzzing specific functions or code segments that can’t be built with afl-cc or used in QEMU mode.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AFLplusplus/AFLplusplus/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Unicorn mode provides AFL++ instrumentation for binary code running in the Unicorn emulator. You can fuzz black-box, closed-source binary snippets with full control over memory layout and execution state. Performance: Significant penalty compared to native AFL++ (but better than no fuzzing!) Language Support: Python, C, Rust harnesses Original Authors:- Nathan Voss (original implementation)
- Dominik Maier (AFL++ port)
- Andrea Fioraldi (CompareCoverage, NeverZero)
- Ziqiao Kong (current maintainer)
Building Unicorn Mode
Requirements for Fuzzing
To effectively use Unicorn mode, you need:- Binary code to be fuzzed
- Memory map knowledge and good starting state
- Seed corpus folder with sample inputs
- Follow AFL++ guidance on creating quality corpora
- Quality of results depends on seed quality
- Unicornafl-based test harness (in Rust, C, or Python) that:
- Adds memory map regions
- Loads binary code into memory
- Calls
uc.afl_fuzz()oruc.afl_start_forkserver - Loads and validates fuzzer input from command-line file
- Checks input constraints (size, invalid bytes, etc.) in the place_input handler
- Sets up registers and memory state
- Emulates the target code from start to finish
- Crashes on errors by throwing a signal (SIGSEGV, SIGKILL, SIGABORT, etc.)
Basic Usage
Once your harness is ready, run afl-fuzz with the-U flag:
Example Harnesses
Several examples are provided in thesamples/ directory:
Available Examples
| Example | Language | Description |
|---|---|---|
c | C | Simple C bindings usage |
compcov_x64 | Python | Using CompareCoverage to traverse hard-to-reach blocks |
persistent | C | Persistent mode for maximum speed with state reset |
python_simple | Python | Simple Python example |
speedtest/c | C | Performance comparison harness |
speedtest/python | Python | Python performance benchmark |
speedtest/rust | Rust | Rust performance benchmark |
Running Examples
Most harnesses include:- Well-documented source code
afl-fuzzcommand line examplesmake fuzzMakefile targets- Pre-built targets (where applicable)
Configuration Options
CompareCoverage
Enable sub-instruction instrumentation similar to laf-intel:Advanced Resources
Framework Integration
For advanced emulation scenarios, consider:Documentation and Tutorials
Read the comprehensive documentation inunicorn_mode/unicornafl/docs for:
- Updating Unicorn versions
- Advanced configuration
- Troubleshooting
Helper Scripts
Thehelper_scripts/ directory contains utilities to:
- Dump context from running processes
- Load saved context
- Hook heap allocations
Installation Details
The build script:- Builds unicornafl and Python bindings
- Installs them system-wide (leaves existing Unicorn installations untouched)
- Builds C/C++ bindings in:
unicorn_mode/lib(libraries)unicorn_mode/include(headers)
Creating a Harness
Basic Structure (Python)
Basic Structure (C)
Best Practices
Limitations
- Performance: Slower than native instrumentation or QEMU mode
- Setup Complexity: Requires detailed understanding of target’s memory layout and execution state
- Full System Emulation: Not suitable for targets requiring complex OS interactions (consider Nyx mode instead)
When to Use Unicorn Mode
Unicorn mode is ideal when:- You need to fuzz specific binary functions or code snippets
- You want fine-grained control over execution environment
- The target can’t be easily built with afl-cc
- QEMU mode doesn’t provide sufficient control
- You’re fuzzing embedded firmware or specific CPU architectures

