ghidra
Use when analyzing raw firmware images (ARM/Thumb embedded), dumped flash, or binaries without symbols - importing at a custom base address, seeding function discovery, and dumping decompiled output + xrefs for offline study via Ghidra headless.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- ghidra
- triggers
- [ "user", "model" ]
- description
- Use when analyzing raw firmware images (ARM/Thumb embedded), dumped flash, or binaries without symbols - importing at a custom base address, seeding function discovery, and dumping decompiled output + xrefs for offline study via Ghidra headless.
- allowed-tools
- [ "read", "exec", "write", "edit" ]
03 SKILL.md 正文
Ghidra headless firmware RE
Validated on Ghidra 12.1.4 + OpenJDK 25, Windows. Target: nRF52810 Cortex-M4 Thumb app slice (Minew ESL tag), but applies to any raw bin.
When
- Raw firmware
.bin(no ELF headers, no symbols) needs decompilation. - Need repeatable dumps of decompiled functions + xrefs to answer "who calls X", "what reads offset Y in ctx".
- Capstone-level disasm is not enough (literal-pool indirection, computed refs, argument tracking).
Install / locate
- Ghidra has no winget package. Download the release zip from GitHub
NationalSecurityAgency/ghidra, extract somewhere stable, e.g.tools/ghidra. - Needs JDK 17+ on PATH.
- Headless binary:
<ghidra>/support/analyzeHeadless.bat(Windows) /analyzeHeadless(Linux).
Hard-won facts (do not relearn)
- Ghidra 12 has no Jython.
.pypost-scripts fail with "Ghidra was not started with PyGhidra". Write analysis scripts in Java (GhidraScriptsubclass) - they run directly. - Raw import needs manual context. A bare app-slice
.binhas no vector table, so auto-analysis finds ~zero functions. You must:- Import with explicit base address (e.g. app at
0x19000after bootloader). - Set Thumb mode:
setRegisterValue/ context registerTMode=1on the whole image range before disassembly. - Seed known function addresses, or auto-analysis stays blind.
- Import with explicit base address (e.g. app at
- Linear sweep
disassemble()per halfword is too slow (flow analysis per call). Instead: generate a seed list from Capstone BL/B.W targets (one pass in Python over the bin) plus known entry points, then let Ghidra'sdisassembleexpand by control flow. ~213 seeds -> full coverage in seconds. - RAM matters. Create the RAM memory block (e.g.
0x20000000-0x2003ffff) or the decompiler cannot resolveldrinto ctx structures. CatchMemoryConflictException- the block may already exist. - Match the binary to the dump. Decompiled addresses are meaningless across firmware versions. Record which
.binproduced whichgh_dump.txt; re-scan constants (e.g.movw #0xca01) in the SAME file. - Ghidra misreads
ldr/strliteral-pool pairs as arrays.DAT_0001f334looked like a 10-u32 table but was{fn_ptr, param}pairs - verify suspicious "tables" by dumping raw bytes and checking for Thumb function pointers (odd addresses into code). analyzeHeadless <projdir> <projname> -import <bin> -processor <lang> -cspec <c> -postScript <script> [args] -scriptPath <dir>- processor for Cortex-M4 Thumb LE:ARM:LE:32:v7(v8 for M33+).
Workflow that worked
support\analyzeHeadless.bat ghproj esl -import fw.bin ^
-processor ARM:LE:32:v7 -postScript GhDump.java -scriptPath . -deleteProject
Script skeleton (Java):
setRegisterValueTMode=1 over[imgStart, imgStart+len).- Add RAM block via
getMemory().createInitializedBlock("ram", toAddr(0x20000000), size, (byte)0, monitor, false)(orcreateUninitializedBlock). - Read seed addresses from
seeds.txt(capstone-generated BL targets),disassemble(addr)each. - For each target function:
getFunctionAt,DecompInterface.openProgram,decompileFunction(fn, 60, monitor), printgetDecompiledFunction().getC(). - Print xrefs:
getReferencesTo(addr)/getReferencesFrom. - Print
cmp/movwsites matching interesting immediates.
Capstone seed generator (python):
from capstone import *
data = open('fw.bin','rb').read(); base = 0x19000
md = Cs(CS_ARCH_ARM, CS_MODE_THUMB | CS_MODE_LITTLE_ENDIAN)
seeds = set()
for off in range(0, len(data)-4, 2):
for i in md.disasm(data[off:off+4], base+off, 2):
if i.mnemonic in ('bl','blx','b','b.w') and i.op_str.startswith('#0x'):
t = int(i.op_str[1:],16)
if base <= t < base+len(data): seeds.add(t)
open('seeds.txt','w').write('\n'.join(hex(s) for s in sorted(seeds)))
Analysis recipes that paid off
- Find a message consumer: producers
FUN_x(msg_id, sub, buf, len)are easy; consumers live in other tasks. Grep disasm forcmp rX, #<msgid>clusters - the real dispatcher compares several IDs in one function. Do not trust the firstmovs r0,#id(that is a producer). - Follow ctx offsets, not names: pick a struct offset (e.g.
ctx+0x118), grep all disasm touching it - that is how you find readers/writers when there are no xrefs (literal pools). - Odd-value table entries:
0x196f5in a "param table" = Thumb func ptr (low bit). Dump code there; tinymovs r0,#N; bx lrgetters reveal the slot is a callback column, not data. - Distinguish "committed" vs "rendered" on hardware: protocol ack != visual effect. Correlate each hypothesis test with a physical observation (flash, LED, pixels) before recording conclusions.
Outputs to keep
gh_dump.txt: decompiled functions + xrefs + cmp-site index, checked next to the.binit came from.seeds.txt: reproducible function seed list.- Project notes doc: dispatcher table, msg-type map, ctx offsets, hardware-confirmed behaviors vs hypotheses. Date each section; mark superseded interpretations instead of deleting them.
Cascade
binary-triage: cheap static triage first; Ghidra is the escalation.re-binary: managed RE via rea-ops when its engine covers the artifact.firmware-probe: extraction (binwalk/EMBA) before RE.
04 同仓库更多 Skills
montador-de-ideias
Use when assembling, expanding, or elevating a raw project idea or initial prompt into an ultra-detailed, first-principles dossier and compiled master prompt with journalistic OSINT market research, Tech Lead and Staff Architect justifications, atomic and modular hardening/optimization, and high-impact contact surfaces.
git-github-adaptive-engineering
Use when any task touches git history, GitHub issues/PRs/releases/CI, repo governance, or branch and merge decisions. Runs the Fase Zero situational-awareness battery, picks one of five delivery flows via the adaptive decision engine, and enforces commit/PR information-density standards. Orchestrates the gh, git-workflows, github-actions, pr, and debug/finish skills.
adaptive-agenda-calendar-routine-engine
Use when planning or executing work across hours, days, weeks, or sprints. Turns the calendar into a strict time-blocked agenda (HH:MM-HH:MM blocks carrying a routine profile, expected inputs, and a handoff output artifact), runs the 5-stage cognitive flow (Radar and Hunt -> Triage plus Steve Jobs conception -> workbench manifest -> >=32-cycle loop -> Close plus Open-Minded Scrum), and unfolds macro calendar milestones into micro agenda blocks through extensions/gcal/wrapper.py.
demo
Use when demonstrating a skill in a fixture project.
duplicate-skill
Use when testing duplicate skill name detection.
duplicate-skill
Use when testing duplicate skill name detection.