How firmwire/firmwire works
FirmWire is a two-part system: a Python host framework that models and drives modem firmware, and a separate C “modkit” tree that is compiled into target-side helpers/fuzzers for specific baseband families.
1. Entry point and packaging
- firmwire.py is the top-level CLI entry point.
- The firmwire/ package contains the runtime framework; README.md positions it as a full-system analysis platform for Samsung and MediaTek baseband firmware.
2. Workspace and configuration boundary
- firmwire/workspace.py is the project-level state manager: it likely ties together firmware images, vendor selection, paths, and analysis artifacts.
- firmwire/vendor/ holds vendor-specific data and is the main boundary where generic framework code becomes device-family aware.
3. Firmware ingestion and address layout
- firmwire/loader.py loads firmware images into the analysis environment.
- firmwire/memory_map.py describes how firmware is placed and accessed in memory, which is central for symbol resolution, MMIO modeling, and debugger-style reasoning.
4. Emulation orchestration
- firmwire/emulator/firmwire.py is the core runtime coordinator.
- Supporting modules split responsibilities: init.py for bootstrapping, snapshot.py for saved/restored state, guestlogs.py for collecting guest output, and patterndb.py for matching/recognizing recurring firmware behaviors.
5. Hardware modeling layer
- firmwire/hw/ contains the synthetic hardware that the firmware interacts with.
- soc.py defines SoC-level composition, peripheral.py provides the base peripheral abstraction, and fifo.py/glink.py model communication channels used by modem software.
- This is the main boundary between guest firmware execution and host-side simulation.
6. Analysis and symbol utilities
- firmwire/util/ provides cross-cutting helpers: logging, parameter handling, symbol lookup, port management, hex formatting, and ARM stack unwinding.
- util/panda.py suggests integration helpers for a PANDA/QEMU-style execution backend, which is likely the low-level execution engine beneath the Python orchestration.
7. Modkit: target-side support code
- modkit/ is a separate build tree with its own Makefiles and README.
- It contains C runtimes, task abstractions, AFL-style fuzzing hooks, and firmware-facing helpers for two families: modkit/mtk and modkit/shannon.
8. Protocol- and vendor-specific fuzzing
- Under each modkit family are example fuzzers such as LTE RRC, GSM MM/SM, and test payloads.
- These are not host-side tests; they are firmware-adjacent programs that exercise modem logic through the modkit runtime and communication primitives.
9. Data flow through the system
- Typical flow is: CLI → workspace/vendor selection → firmware loading/memory mapping → emulator initialization → synthetic SoC/peripheral handling → guest execution → logs/snapshots/pattern matches.
- The modkit side feeds inputs into that execution environment, often through channels like GLINK/FIFO or family-specific task abstractions.
10. Tooling and reproducibility
- Dockerfile, requirements.txt, and GitHub Actions workflow indicate the repo is meant to be built and tested reproducibly.
- tests/test_vendor_basic.py is a lightweight guard around vendor configuration/selection rather than a broad functional test suite.
For an architecture diagram, the most important boundaries are: host Python framework vs. target-side C modkit, generic framework vs. vendor-specific extensions, and firmware execution vs. modeled hardware/peripheral interfaces.
Main entry points: firmwire.py Emulator · soc.py SoC · workspace.py Workspace · modkit.c MTK modkit
Components 22
Python host
Runtime framework that loads, emulates, and observes modem firmware.
- firmwire.py · Top-level command-line entry point.
firmwire.py - Workspace · Tracks firmware selection, paths, and analysis state.
firmwire/workspace.py - Loader · Ingests firmware images into the analysis environment.
firmwire/loader.py - Memory map · Defines firmware placement and address translation.
firmwire/memory_map.py - Emulator · Coordinates boot, execution, and runtime services.
firmwire/emulator/firmwire.py - Init · Bootstraps emulator setup and guest start conditions.
firmwire/emulator/init.py - Snapshot · Captures and restores emulator state.
firmwire/emulator/snapshot.py - Guest logs · Collects guest-side output and traces.
firmwire/emulator/guestlogs.py - Pattern DB · Matches recurring firmware behaviors and signatures.
firmwire/emulator/patterndb.py - SoC · Composes the synthetic system presented to firmware.
firmwire/hw/soc.py - Peripheral · Base abstraction for modeled devices.
firmwire/hw/peripheral.py - FIFO · Models queued communication paths used by modem software.
firmwire/hw/fifo.py - GLINK · Models GLINK-style interprocessor communication.
firmwire/hw/glink.py - Utilities · Cross-cutting helpers for symbols, ports, logging, and analysis.
firmwire/util/__init__.py - PANDA bridge · Integration helpers for the execution backend.
firmwire/util/panda.py - Vendor data · Device-family-specific extensions and configuration.
firmwire/vendor
Target modkit
C build tree compiled into firmware-adjacent helpers and fuzzers.
- Modkit · Separate target-side support tree for firmware-facing helpers and fuzzers.
modkit/README.md - MTK modkit · MediaTek-specific support code and fuzzers.
modkit/mtk/modkit.c - Shannon modkit · Shannon-specific support code and fuzzers.
modkit/shannon/modkit.c - MTK fuzzers · Example firmware-adjacent inputs such as LTE RRC and message injection.
modkit/mtk/fuzzers/lte_rrc.c - Shannon fuzzers · Example firmware-adjacent fuzzers for GSM and LTE protocols.
modkit/shannon/fuzzers/gsm_mm.c
Tooling
Packaging and reproducibility boundary.
- Build files · Reproducible build and container setup.
Dockerfile
Connections 24
- firmwire.py → Workspace: selects · CLI drives workspace selection and analysis context.
- Workspace → Vendor data: uses · Workspace binds vendor-specific configuration.
- Workspace → Loader: loads · Workspace initiates firmware ingestion.
- Loader → Memory map: lays out · Loaded firmware is mapped into modeled memory.
- Memory map → Emulator: feeds · Address layout is consumed by the emulator runtime.
- Emulator → Init: boots · Core runtime delegates startup sequencing.
- Emulator → Snapshot: persists · Runtime can save and restore state.
- Emulator → Guest logs: captures · Runtime collects guest output.
- Emulator → Pattern DB: matches · Runtime consults pattern recognition during execution.
- Emulator → SoC: runs on · Firmware executes against the modeled SoC.
- SoC → Peripheral: composes · SoC is built from peripheral abstractions.
- SoC → FIFO: connects · SoC exposes queued communication channels.
- SoC → GLINK: connects · SoC exposes GLINK-style channels.
- Peripheral → Emulator: serves · Peripherals mediate guest/host interaction.
- Utilities → PANDA bridge: integrates · Utility layer includes backend-specific glue.
- firmwire.py → Utilities: uses · CLI and runtime rely on shared helpers.
- Modkit → MTK modkit: contains · Modkit splits into family-specific builds.
- Modkit → Shannon modkit: contains · Modkit splits into family-specific builds.
- MTK modkit → MTK fuzzers: ships · MTK tree includes example fuzzers and payloads.
- Shannon modkit → Shannon fuzzers: ships · Shannon tree includes example fuzzers and payloads.
- MTK modkit → Emulator: inputs · Target-side code feeds data into the host execution environment.
- Shannon modkit → Emulator: inputs · Target-side code feeds data into the host execution environment.
- Build files → firmwire.py: packages · Container and dependency setup support the host framework.
- Build files → Modkit: builds · Tooling supports reproducible modkit builds.