Skip to content

cli: default AIF on for non-x86-64 decompile-all — recover stripped ARM Cortex-M functions (crazyflie 1430→2700) - #172

Merged
mahaloz merged 1 commit into
mainfrom
feat/arm-aif-discovery
Jul 14, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/arm-aif-discovery

Conversation

@mahaloz

@mahaloz mahaloz commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

The #1 cause of kuna losing to angr on the decbench O0 benchmark is stripped ARM Cortex-M firmware discovery — kuna failed to discover ~3,600 Thumb functions angr finds (75% of the angr-beats-kuna gap; kuna produces no output on 35% of O0 functions, almost all ARM). kuna already leads on x86 structuring, so this is what drags the overall score down.

Root cause

funcstart_patterns (DIV-20) only seeds a candidate when a matching epilogue prepattern (Ghidra <patternpairs>) sits immediately before it. So ~70% of a firmware's functions — preceded by literal pools/data/padding, living in call-graph components reachable only via indirect calls / function-pointer tables (87% of the missed have no direct-call edge) — are never seeded, and recursive descent (direct CALL/BL only) structurally can't reach them.

Fix — the mechanism was already ported, just disabled

kuna already ports Ghidra's Aggressive Instruction Finder (aif): it gap-walks the undefined regions, gating each candidate on a prologue-fingerprint histogram + check_valid_subroutine, bridging the disconnected components. Its results were computed but dropped behind the default-off analysis_aif flag. This injects --option aif on for non-x86-64 on the decompile-all surface (beside the funcstart_patterns/listing DIV-20 injections), unless the caller names it.

Impact (measured)

binary before after angr
crazyflie cf2.elf 1,430 2,700 (45%→82% of angr's set) 2,781
betaflight STM32F405 ~1,830 4,783 4,249
libopencm3 cdcacm 69 82 of 87 GT —

Extra non-ground-truth functions are harmless to the GED benchmark (scored per ground-truth function, matched by name).

Scope / safety

Driver policy only — engine default (analysis_aif = false), console/subprocess path, and x86-64 are untouched (AIF stays off for x86-64, so every datatest is byte-identical). make test 675/675, make test-stages 261/261, make rust-test 0 failures (+ a new arm_decompile_all_defaults_aif_on test).

Stage 2 (follow-up) adds angr-style raw unpaired Thumb-prologue seeding for the dense-binary residual (betaflight still misses ~483 GT PUSH-prologue functions).

🤖 Generated with Claude Code

https://claude.ai/code/session_018DV2MXxQAAWK7xLPBmsq9J

…RM Cortex-M functions

The #1 cause of kuna losing to angr on the decbench O0 benchmark is stripped ARM
Cortex-M firmware: kuna failed to DISCOVER ~3,600 Thumb functions angr finds (75% of the
angr-beats-kuna gap; kuna produces no output on 35% of O0 functions, almost all ARM). kuna
already leads on x86 structuring — the ARM discovery failures are what drag it down.

## Root cause
`funcstart_patterns` (DIV-20) only seeds a candidate when a matching EPILOGUE prepattern
(Ghidra <patternpairs>) sits immediately before it, so ~70% of a firmware's functions —
those preceded by literal pools / data / padding and living in call-graph components
reachable only through indirect calls / function-pointer tables (87% of the missed have NO
direct-call edge) — are never seeded, and the recursive-descent walk (direct CALL/BL only)
structurally cannot reach them.

## Fix (the mechanism was already ported, just disabled)
kuna already ports Ghidra's Aggressive Instruction Finder (`aif`,
ArmAggressiveInstructionFinderAnalyzer): it gap-walks the UNDEFINED regions the walk left
uncovered, gating each candidate on a prologue-fingerprint histogram learned from the
already-discovered functions + check_valid_subroutine, so it bridges the disconnected
components. Its results were computed but DROPPED behind the default-off `analysis_aif` flag.
This injects `--option aif on` for non-x86-64 on the `decompile-all` surface (beside the
funcstart_patterns/listing injections, DIV-20), unless the caller names it.

## Impact (measured)
- crazyflie cf2.elf: 1430 -> 2700 functions (45% -> 82% of angr's discovered set)
- betaflight STM32F405: ~1830 -> 4783 functions
- libopencm3 cdcacm: -> 82 of 87 ground-truth
Extra non-ground-truth functions are harmless to the GED benchmark (scored per ground-truth
function, matched by name); strictly more coverage = strictly better.

## Scope / safety
Driver policy only — the engine default (`analysis_aif = false`), the console/subprocess
path, and x86-64 are untouched (AIF stays OFF for x86-64, so every datatest is byte-identical).
make test 675/675 PARITY OK, make test-stages 261/261, make rust-test 0 failures (+ a new
arm_decompile_all_defaults_aif_on wiring/non-destructive test).

A follow-up (Stage 2) adds angr-style raw unpaired Thumb-prologue seeding to close the
dense-binary residual (betaflight still misses ~483 GT functions with a PUSH prologue).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018DV2MXxQAAWK7xLPBmsq9J
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant