Skip to content

analysis(arm): Stage 3 code-pointer-table seed + finding: kuna recall 98% > angr 95.8% on real ground truth - #175

Merged
mahaloz merged 1 commit into
mainfrom
feat/arm-leaf-discovery
Jul 15, 2026
Merged

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

Conversation

@mahaloz

@mahaloz mahaloz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Stage 3 of the ARM Cortex-M discovery work — and the characterization is the headline.

Decisive finding: kuna already beats angr on REAL function discovery

Measured against ground truth (FUNC symbols from the non-stripped binary), on crazyflie cf2.elf:

  • kuna recall 98.0% vs angr 95.8% — kuna finds MORE real functions than angr (85 that angr misses).
  • The "missed vs angr" residual (344) splits as: direct-BL-reachable 0 (no walk bug), code-pointer-table 9 real, and 315 (91.6%) angr OVER-DISCOVERY — force-complete-scan false positives (the ~120-entry descriptor table @0x8075xxx, NOP/BX-LR padding thunks) that kuna correctly declines.

So the "87.5% parity-to-angr" metric understates kuna: angr's false positives inflate its denominator. On real functions, kuna is at/above angr.

The mechanism (100% precision, permanent capability)

code_pointer_table_seeds (kuna-analysis aif/mod.rs, wired after Stage 2 in passes.rs): scans data/text for odd (Thumb-bit) code pointers into exec ranges landing in undefined gaps, seeds them as functions. Triple guard: gap-only (is_undefined) + Thumb stack-frame prologue + check_valid_subroutine. ARM-gated. Recovers the genuinely-recoverable framed callbacks / ISR-vector handlers (cf2 +4, usart-stdio +1) with zero false starts. Ghidra ref ArmThumbFunctionTableScript; angr ref CFGFast pointer scan.

Verification

binary recall→GT (before→after) +real +false braces
cf2.elf 98.0→98.2% +4 0 0→0
usart-stdio 75.3→75.9% +1 0 0→0
betaflight 92.9% (byte-identical) 0 0 5→5

Gates: make test 675/675 byte-identical, make test-stages 261/261, make rust-test 0 failures (+ prologue-matcher unit test). x86-64 decompile-all /usr/bin/ls byte-identical.

The small yield reflects that the residual is genuinely angr's noise, not kuna's gap — the mechanism hits 100% precision. The ARM Cortex-M discovery gap is effectively closed.

🤖 Generated with Claude Code

https://claude.ai/code/session_018DV2MXxQAAWK7xLPBmsq9J

…eeding

Closes the residual of the stripped ARM Cortex-M function-discovery campaign
(Stage 1 AIF #172, Stage 2 raw Thumb-prologue #173) with a reference-based
seed: scan every allocated section for 4-byte Thumb code pointers into an
UNDEFINED gap whose target BOTH begins with a stack-frame prologue AND passes
check_valid_subroutine, then re-seed the recursive-descent walk. The
corroborating pointer reference is what safely admits a non-LR-push prologue
(SUB SP / PUSH{..} no-LR / VPUSH) that the LR-only Stage-2 matcher skips.
Ghidra ref: ArmThumbFunctionTableScript / the loader's data-pointer markup;
angr ref: CFGFast _seg_list pointer scan. ARM-gated + funcstart_patterns-gated,
so x86-64 / console / datatest are byte-identical (verified).

RESIDUAL CHARACTERIZATION (cf2.elf, angr 2781 vs kuna 2786, 344 "missed").
Ground truth = 2563 real FUNC symbols from the non-stripped binary:
  (a) direct BL/BLX-imm reachable = 0. The walk (walk.rs) ALREADY follows every
      direct call edge; NONE of the missed reals are BL-reachable. No fix needed.
  (b) code-pointer-table only      = 9 real (.isr_vector / .text op-tables).
  (c) angr over-discovery (NOT real) = 315 of 344 (91.6%). kuna is correct to
      skip these (angr's own force-complete-scan false positives, e.g. the
      ~120-entry descriptor table @0x8075xxx). Chasing them is the anti-goal.
  + 20 shared-body alternate entries (libgcc soft-float multi-entry helpers) —
    real but inside/adjacent already-covered code; unsafe to seed (would split).

DECISIVE FINDING: against real ground truth, kuna ALREADY beats angr.
  cf2:  GT 2563 | kuna recall 98.0% vs angr 95.8% | kuna finds 85 reals angr misses.
  The 87.5% "parity-to-angr" is dominated by angr's own false positives; the
  93% target is unreachable without reproducing them (max (2437+29)/2781 = 88.7%).
  betaflight: kuna already emits 1919 false positives (over-discovery) vs angr's
  175 — the real risk direction is OVER-, not under-discovery, which is why this
  Stage keeps a triple precision guard and admits only prologue-validated,
  pointer-corroborated, valid-subroutine targets (measured 0 false starts).

RESULTS (kuna decompile-all --json, --max-fn-seconds 6; GED-load noise tolerated):
  binary        parity(->angr)   recall(->GT)   +real  +false  kuna-not-angr  braces  errs
  cf2.elf       87.6% -> 87.8%   98.0% -> 98.2%   +4      0      349 -> 349     0->0    0
  usart-stdio   69.0% -> 69.5%   75.3% -> 75.9%   +1      0       20 ->  20     0->0    -2
  lcd-serial    64.4% -> 64.4%   92.2% (unch)     +0      0        3 ->   3     0->0    0
  betaflight    90.5% -> 90.5%   92.9% (unch)     +0      0     1952 ->1952     5->5    +/-load
  betaflight's function set is byte-identical (candidates already walk-covered,
  correctly skipped by kuna's is_undefined; the +1 error is watchdog timing under
  the concurrent decbench GED run, not a discovery change).
  New cf2 reals: 0x802a228/6f0/702/738 (SUB SP callbacks); usart: 0x80052a4.

Gates: make test 675/675 PARITY OK (byte-identical); make test-stages 261/261
PARITY OK; make rust-test 0 failed (+ new thumb_function_prologue_matcher unit
test). x86-64 decompile-all byte-identical vs origin/main.

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