How fkie-cad/snafuzz works
1. Top-level shape
SNAFUzz is split into two operational paths: a snapshot-creation path and a snapshot-fuzzing path. The same binary (snafuzz.exe) can boot a live Windows system, capture a snapshot, reload it later, or start directly from an existing .snapshot / .dmp state for fuzzing.
2. Main entry and configuration
src/main.c is the orchestration point. Runtime behavior is controlled by src/options.c, and the build is intentionally a single-translation-unit model where a selected target file is included into main.c. That makes the fuzzing harness and the core engine compile together, while target-specific logic remains swappable.
3. State ingestion and snapshot formats
The input state can come from several sources: a live VM snapshot, a Windows kernel dump (.dmp), or a virtual disk image (.vhdx, .qcow2, raw disk variants). The repository has dedicated loaders/parsers for these formats in src/snapshot.c, src/parse_dmp.c, src/vhdx.c, src/qcow2.c, and src/raw_disk.c. This is the boundary where “real machine state” becomes emulator state.
4. Execution backends
There are two host-side execution backends: src/hyperv.c for Windows Hypervisor Platform and src/kvm.c for Linux/KVM. They provide the low-level VM control path used in snapshot mode and during bootstrapping. The README’s Linux path is clearly secondary; the Windows/WHP path is the primary and best-tested deployment.
5. Guest platform emulation
Booting Windows requires a partial platform emulation layer: src/uefi_bios.c provides an incomplete UEFI firmware, and src/vmbus.c plus the device modules emulate the minimal virtual hardware Windows expects. The device set is intentionally small: framebuffer, SCSI disk, PS/2 keyboard, and HID mouse. This is enough to get Windows into a debuggable, snapshot-able state.
6. CPU, memory, and JIT core
The deterministic emulator is the heart of fuzzing mode. src/jit.c lifts guest x64 instructions one basic block at a time and executes them through a host-side JIT. CPU register state is represented explicitly in src/cpu_state.c, while src/memory_unit.c manages guest physical memory, dirty-page tracking, and guest-virtual translation caching. This is the main performance and determinism boundary.
7. Instruction semantics and low-level helpers
Instruction decoding/execution is split across helpers like src/instruction_helpers.c, src/instruction_table.h, src/interrupts.c, src/apic.c, src/hooks.c, and src/core_target_helpers.c. These modules fill in the architectural details that the JIT delegates to: interrupt delivery, APIC behavior, instruction-specific helper logic, and target hooks.
8. Debugger and symbolization
src/debugger.c implements the built-in WinDbg-style debugger used both during boot/snapshot creation and during crash analysis. Breakpoints can be hit from either the hypervisor or the JIT and are funneled into one debugger handler. Symbol resolution is backed by src/pdb.c, with module enumeration from src/loaded_module.c using PsLoadedModuleList and the user-mode loader list. PDBs are fetched on demand from Microsoft’s public symbol server.
9. Fuzzing loop and feedback
Fuzzing mode repeatedly executes target inputs from a snapshot, monitors crashes, records coverage, mutates inputs, and resets back to the snapshot after a configurable number of cases or instructions. src/coverage.c collects instruction, branch, and compare coverage; crash artifacts are written to crashes/; coverage snapshots go to coverage/. The design is explicitly deterministic so crashes can be reproduced and minimized exactly.
10. Target-specific boundary
Target behavior is not hardcoded into the engine. Instead, targets implement three functions described in src/target_specific_code_api.h: initialization, input generation, and input execution. The repo includes examples for kernel fuzzing (hevd.c, kernel_snapshot.c) and user-mode fuzzing (HeaderParser.c, user_snapshot.c). src/default_target.c is the generic harness used for simple kernel IOCTL-style or user-input-style targets.
11. Bootstrapping and snapshot preparation
src/preboot_initialization.c and related initialization code prepare the VM before it enters the fuzzable state. In practice, snapshot creation is a workflow: boot Windows, load or prepare the target, break into the debugger, and serialize the resulting state. This is how the system bridges “normal OS boot” and “repeatable fuzzing state.”
12. Repo outputs and auxiliary tooling
The symbols/, coverage/, and crashes/ directories are runtime artifacts rather than source modules. scripts/ColorHitInstructions.java is an analysis aid for visualizing coverage in Ghidra. The images/ folder documents the operational flow but does not affect runtime architecture.
13. Important architectural boundary
The main boundary to capture in a diagram is: host-controlled orchestration on one side, and guest Windows state execution on the other. Host code manages snapshots, JIT, devices, debugging, coverage, and crash capture; target-specific code lives at the edge and only supplies “how to set up input” and “how to drive the target.” That separation is what makes the system reusable across kernel and user-mode targets.
Main entry points: main.c Main · target_specific_code_api.h Target API · jit.c JIT · snapshot.c Snapshot
Components 32
Orchestration
Top-level entrypoint, options, and snapshot workflow control.
- Main · Single orchestration entrypoint that selects snapshot creation, reload, or fuzzing mode.
src/main.c - Options · Parses runtime flags and mode selection.
src/options.c - Preboot Init · Prepares the VM before it enters a debuggable or fuzzable state.
src/preboot_initialization.c
State Ingestion
Loaders and parsers that turn external machine state into emulator state.
- Snapshot · Top-level snapshot workflow that bridges live machine state and replayable emulator state.
src/snapshot.c - DMP Parser · Loads Windows kernel dumps as initial state.
src/parse_dmp.c - VHDX Loader · Reads VHDX-backed disk state.
src/vhdx.c - QCOW2 Loader · Reads QCOW2-backed disk state.
src/qcow2.c - Raw Disk · Handles raw disk variants used as boot media.
src/raw_disk.c
Execution Backends
Host-side virtualization control paths.
Guest Emulation
Partial platform and device emulation needed to boot Windows.
Core Emulator
Deterministic CPU, memory, and instruction execution engine.
- JIT · Lifts and executes guest x64 basic blocks deterministically.
src/jit.c - CPU State · Explicit guest register and processor state representation.
src/cpu_state.c - Memory Unit · Guest physical memory, dirty tracking, and translation cache.
src/memory_unit.c - Instr Helpers · Instruction-specific helper logic and architectural fill-ins.
src/instruction_helpers.c - Interrupts · Interrupt delivery and architectural exception flow.
src/interrupts.c
Debugging
Debugger, symbols, and module discovery.
- Debugger · WinDbg-style debugger used for breakpoints, boot inspection, and crash analysis.
src/debugger.c - PDB · Resolves symbols via downloaded program database files.
src/pdb.c - Modules · Enumerates loaded kernel and user modules for symbolization.
src/loaded_module.c - Coverage · Collects instruction, branch, and compare coverage for fuzzing feedback.
src/coverage.c
Targets
Target-specific harnesses and the generic target API.
- Target API · Defines initialization, input generation, and execution hooks for targets.
src/target_specific_code_api.h - Default Target · Generic harness for simple kernel or user-input style targets.
src/default_target.c - HEVD · Example kernel fuzzing target implementation.
hevd.c - Kernel Snapshot · Kernel-target snapshot preparation and replay harness.
kernel_snapshot.c - Header Parser · Example user-mode fuzzing target implementation.
HeaderParser.c - User Snapshot · User-target snapshot preparation and replay harness.
user_snapshot.c
Artifacts
Runtime output directories and analysis aids.
- Crashes · Runtime crash artifacts written by fuzzing runs.
crashes - Coverage Dir · Stored coverage snapshots and outputs.
coverage - Symbols Dir · Fetched and cached symbol files.
symbols
Connections 31
- Main → Options: reads · Main selects runtime mode and configuration from parsed options.
- Main → Preboot Init: boots · Main drives VM preparation before snapshotting or fuzzing.
- Main → Snapshot: orchestrates · Main enters snapshot creation or replay through the snapshot boundary.
- Snapshot → DMP Parser: loads · Snapshot state can originate from kernel dumps.
- Snapshot → VHDX Loader: loads · Snapshot state can originate from VHDX disk images.
- Snapshot → QCOW2 Loader: loads · Snapshot state can originate from QCOW2 disk images.
- Snapshot → Raw Disk: loads · Snapshot state can originate from raw disk variants.
- Main → Hyper-V: uses · Primary host execution path on Windows.
- Main → KVM: uses · Secondary host execution path on Linux.
- Hyper-V → UEFI BIOS: boots · Hyper-V path starts Windows through firmware emulation.
- KVM → UEFI BIOS: boots · KVM path also relies on firmware emulation when booting.
- UEFI BIOS → VMBus: initializes · Firmware hands off into the minimal virtual platform.
- VMBus → Disk: provisions · VMBus-mediated devices include the boot disk.
- VMBus → Display: provisions · VMBus-mediated devices include framebuffer/display support.
- Main → JIT: executes · Fuzzing mode runs guest code through the JIT engine.
- JIT → CPU State: reads/writes · JIT operates over explicit guest CPU state.
- JIT → Memory Unit: uses · JIT fetches and stores through the guest memory model.
- JIT → Instr Helpers: delegates · Instruction-specific behavior is delegated to helper logic.
- JIT → Interrupts: delegates · Architectural interrupts and exceptions are handled separately.
- Debugger → PDB: resolves · Debugger uses PDBs for symbolized crash analysis.
- Debugger → Modules: enumerates · Debugger consults loaded modules for symbol lookup.
- Coverage → Coverage Dir: writes · Coverage feedback is persisted to the coverage output directory.
- Debugger → Crashes: writes · Crash findings are materialized as artifacts.
- PDB → Symbols Dir: caches · Downloaded symbols are stored locally for reuse.
- Target API → Default Target: implements · Generic target harness follows the target API contract.
- Target API → HEVD: implements · Kernel target example follows the target API contract.
- Target API → Kernel Snapshot: supports · Kernel snapshot harness sits at the target boundary.
- Target API → Header Parser: implements · User-mode target example follows the target API contract.
- Target API → User Snapshot: supports · User snapshot harness sits at the target boundary.
- Main → Target API: loads target · Single-translation-unit build pulls one selected target into the binary.
- Coverage → JIT: observes · Coverage is collected from executed blocks and comparisons.