Identify BSP (Board Support Package) functions in stripped microcontroller firmware by the memory-mapped I/O registers they touch, rather than by code-byte signatures.
Unlike byte-signature tools such as IDA's FLIRT or Ghidra's FunctionID — which
depend on the exact compiler and options used to build the firmware — mmiomapper
fingerprints a function by the hardware registers it reads, writes and
read-modify-writes. Because a BSP function must access the registers of the
peripheral it drives, this fingerprint survives recompilation, optimisation,
stripping, and even a change of driver library (HAL, LL, bare-metal).
Developed as part of a Bachelor thesis at HEIG-VD with the Cyberdefence Campus. Status: research prototype (see Status).
The engine runs on top of Ghidra (via PyGhidra) in three stages:
- Extract — walk each function's P-code, track values symbolically, and record
every
LOAD/STOREto a peripheral address as a(register, mode)access. The CMSIS-SVD file of the target chip resolves raw addresses to names (USART.CR1,RCC.APB2ENR). Architecture-independent and non-speculative (no value is ever guessed, so there are no false positives). - Learn — run the extractor on a firmware you compiled yourself with symbols
to build a reference database of
name -> signaturepairs. Several reference firmwares (HAL, LL, bare-metal, different chips) can be accumulated into one database to recognise more functions. - Identify — extract the signature of each unknown function in a stripped firmware and match it against the database. A confident match yields the function name; otherwise the function is still classified by role (e.g. "Init UART"), inferred purely from the registers and access modes.
- Ghidra 12.x, launched with PyGhidra (CPython 3)
- Python 3.13+
- A CMSIS-SVD file for the target microcontroller (a few are bundled in
data/svd/)
The engine itself has no third-party runtime dependency (SVD parsing uses the standard library).
pip install -e . # or: pip install -e ".[dev]" for the test extraThe command-line tools drive the engine head-less against a Ghidra project that already contains the imported, analysed program.
python scripts/build_db.py \
--project-loc /path/to/ghidra_projects --project-name my_project \
--program /reference.elf \
--svd data/svd/STM32F103.svd --chip-family STM32F1 \
--source hal-f1 --out data/signatures/STM32F1.jsonAccumulate more references into the same database with --append:
python scripts/build_db.py ... --program /reference_ll.elf \
--source ll-f1 --append data/signatures/STM32F1.json \
--out data/signatures/STM32F1.jsonpython scripts/annotate.py \
--project-loc /path/to/ghidra_projects --project-name my_project \
--program /unknown_stripped.bin \
--svd data/svd/STM32L100.svd \
--db data/signatures/STM32L1.jsonThis prints, per function, the inferred role, the best-matching reference name and a
confidence score, e.g. 0x08006e5c -> Config horloge (HAL_RCC_ClockConfig, 0.67).
Add --rename to write the names back into the Ghidra program.
The reverse of annotate.py: given a reference function (e.g. HAL_RCC_ClockConfig),
list the best-matching addresses in the target.
python scripts/search.py \
--project-loc /path/to/ghidra_projects --project-name my_project \
--program /unknown_stripped.bin \
--svd data/svd/STM32L100.svd --db data/signatures/STM32L1.json \
--function HAL_RCC_ClockConfig # omit to search every reference functionOutput: HAL_RCC_ClockConfig Config horloge -> 0x08006E5C (0.69), 0x0800262C (0.69), ...
python scripts/classify_run.py \
--project-loc /path/to/ghidra_projects --project-name my_project \
--program /unknown_stripped.bin --svd data/svd/STM32L100.svdGhidra must be started with PyGhidra (CPython 3) for .py scripts to run. Then:
- In the Script Manager, Manage Script Directories → add this repo's
ghidra_scripts/. - Open and analyse the target program.
- Run
run_mmiomapper.py. It asks for the CMSIS-SVD file for the chip (e.g. one fromdata/svd/) and, optionally, a reference database (data/signatures/*.json). It then, for each function, prints the identified BSP role / name and the MMIO accesses with their decoded write bit-fields (e.g.RCC.APB2ENR (USART1EN)) to the Console window, reports the run time, and offers to annotate the program: every function gets a comment, and the confident reference matches (score >= 0.6) are renamed. Lower-confidence guesses are shown marked(?)but keep theirFUN_name, to avoid asserting a misleading name.
(Open the Console window if you don't see the output. The console also shows a summary pop-up with the function count and elapsed time.)
mmiomapper/ Python package — the analysis library
peripherals.py PeripheralMap: address -> PERIPH.REG resolution
svd.py CMSIS-SVD loader (single file or merged), builds a PeripheralMap
parser.py Hybrid Low/High P-code MMIO signature extractor (the engine)
signatures.py Signature database: build, accumulate, role labels, IDF stats
scoring.py Similarity scoring (IDF-weighted cosine + sequence) and matching
classify.py Unsupervised role classifier (RMW = config) used as a fallback
scripts/ Tool entry points (build a DB, annotate, search, classify, run head-less)
ghidra_scripts/ Driver to run the engine from the Ghidra GUI Script Manager
experiments/ Validation/measurement scripts for the thesis (not the tool)
tests/ Pure-Python unit tests (no Ghidra needed)
data/svd/ Bundled CMSIS-SVD files
data/signatures/ Reference signature databases
The analysis logic is covered by pure-Python unit tests that need neither Ghidra nor a target firmware:
pytest tests/Research prototype. The extraction engine and the identification pipeline (database, scoring, role classification) are implemented and validated on STM32 firmware across optimisation levels, compilers (GCC/Clang) and driver implementations (HAL/LL/bare). Cross-architecture validation (RISC-V, AVR) and broader reference coverage are planned. This is not a final release.
To be defined.