Skip to content

FID PR4: gated --option fid matching pass (stripped FUN_* -> kuna_crc32) - #101

Merged
mahaloz merged 1 commit into
mainfrom
fid-pass
Jun 26, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fid-pass

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

THE PAYOFF — the stripped-binary re-identification

PR1-PR3 built the FID mechanism (the Sleigh::instruction_mask accessor, the byte-exact FNV-1a64 FidHasher/FidHashQuad, the kuna-native .fid database + kuna fid build generator). PR4 wires it into a default-off Listing/xref consumer pass that re-identifies a function in a STRIPPED binary purely by its instruction-stream fingerprint — the one capability unique to FID.

Before / after (the only thing FID does)

On the stripped, statically-linked, -no-pie x86-64 fixture tests/fixtures/fid/prog (kuna_crc32 pinned at VMA 0x4017c0):

run symbol @ 0x4017c0 rendered body
--option fid off (default) sub_4017c0 uint4 sub_4017c0(uint1 *a0,uint4 a1) { ... 0xedb88320 ... }
--option listing on --option fid on + kuna_fid_db=tests/fixtures/fid/lib.fid kuna_crc32 uint4 kuna_crc32(uint1 *a0,uint4 a1) { ... 0xedb88320 ... }

The binary is strip --strip-all'd (NO symbol table), so the function is the engine placeholder sub_4017c0 by default — proving the name is not a leftover symbol. With FID on it is renamed to kuna_crc32, recovered by a full-hash match against the vendored lib.fid (built by kuna fid build over the un-stripped lib.o). Same function, same body (the CRC-32 loop with the magic 0xedb88320), only the name changes. Only FID could do this.

The verify_fid e2e proves the transition two ways — the symbol-table name at 0x4017c0 (the rename ground truth) and the rendered C — and ran (not skipped).

Wiring (each piece a verified clone of the noreturn_disc consumer)

  • s1_fid/mod.rs — FidPass (id "fid", S1): inert without the Listing AND without a configured DB (kuna_fid_db env var, mirroring the loader's kuna_i386_pie_plt). Over each listing.functions() entry it builds the [entry,next) extent (PR2's extent::calculate_extent), fingerprints each instruction via the SAME build::fingerprint_from_mask projection the generator uses (driving Sleigh::instruction_mask), hashes with FidHasher, queries db.find_by_full_hash, and pick_unique_name (emit a name ONLY when the bucket collapses to one name — never guess on a tie). Registered in listing_consumer_passes().
  • pass.rs — FidMatch { addr, name } + AnalysisOutput.fid_names + the merge line.
  • engine.rs — the new FID rename commit arm (after the no-return arm): resolve the function by ADDRESS (find_function_across_scopes), then — ONLY behind the label gate is_generic_placeholder_name (sub_/func_/FUN_/LAB_, never a real .symtab/DWARF name) — Database::rename_symbol + register_symbol. The SymFact path is an idempotent-add and would no-op on an existing function, so the rename is the one net-new piece of plumbing. + "fid" => arch.analysis_fid gate.
  • Option surface (cloned from noreturn_disc): architecture.rs field/default/reset/set_kuna_option arm; options.rs KUNA_OPTION_NAMES; stages.toml [[settable]] fid block (default="off", change_kind="analysis-enablement"); settable count 60 → 61 (kuna_stages/tests.rs count + comma + PASS_GATES suppressed set, catalog_bytecompat.rs, kuna-catalog.xml Stage reorg #5/Fix test stages #9 max 61→62); regenerated stage_catalog.json + docs/assertions.md.
  • DB path from the kuna_fid_db env var (a real --fidb <path> flag is deferred). The stripped tests/fixtures/fid/prog is vendored (recipe + the pinned VMA in the fixture README).

Speed

The FID-on decompile of kuna_crc32 (load function + decompile + print C) is ~6.5 ms wall; the default (FID-off) path builds no Listing and runs no consumer. The FID hash is a single per-function decode-pass + FNV stream, on an opt-in, real-ELF-only path — no impact on the default pipeline (FID never runs by default).

Parity

Real-ELF-path-only + default-off ⇒ the XML datatest path never builds a Listing and never runs the FID consumer, so the 675/158 oracles are structurally untouched.

Gates

  • make test — 675/675 PARITY OK
  • make test-stages — 222/222 PARITY OK (the KUNA-CATALOG Stage reorg #5/Fix test stages #9 use_when/change_kind max bumped 61→62; the catalog <script> emits the full catalog + one returnpair single-row, so the count is settables+1)
  • make rust-test — green (exit 0, 0 failures) incl. the new verify_fid e2e (2 tests) + the regenerated catalog tests + the SLEIGH .sla content-parity
  • kuna catalog --check — catalog OK

See docs/analysis-port-log.md Increment 56 + docs/rust-port/losses.md LOSS-251 (kuna ships the FID mechanism + its own .fid DB, not Ghidra's datasets; .fidbf interop deferred; extent [entry,next)-approximated).

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

THE PAYOFF for the FID port: wire the FID mechanism (PR1's
Sleigh::instruction_mask, PR2's byte-exact FNV-1a64 hasher, PR3's
.fid DB + generator) into a default-off Listing/xref consumer that
re-identifies a function in a STRIPPED binary purely by its
instruction-stream fingerprint.

Before/after on the stripped, static, -no-pie x86-64 fixture
tests/fixtures/fid/prog (kuna_crc32 @ 0x4017c0):

  --option fid off (default)            -> sub_4017c0
  --option listing on --option fid on   -> kuna_crc32
    (+ kuna_fid_db=tests/fixtures/fid/lib.fid)

The binary is stripped (no symbol table), so the function is the
engine placeholder sub_4017c0 by default; FID renames it to
kuna_crc32 by a full-hash match against the vendored lib.fid. Same
body (the CRC-32 loop, 0xedb88320), only the name changes.

Wiring (each piece a clone of the noreturn_disc consumer):
- s1_fid/mod.rs FidPass (id "fid", S1): inert without the Listing
  AND without a configured DB (kuna_fid_db env var). Hashes each
  listing.functions() entry over the [entry,next) extent via the
  same build::fingerprint_from_mask projection the generator uses;
  pick_unique_name emits a name only when the full-hash bucket
  collapses to one name (never guesses on a tie).
- pass.rs FidMatch + AnalysisOutput.fid_names + merge.
- engine.rs FID rename commit arm (after the no-return arm): resolve
  by address, rename only behind the is_generic_placeholder_name
  label gate (sub_/func_/FUN_/LAB_, never a real .symtab/DWARF name)
  + the "fid" => analysis_fid gate.
- Option surface: architecture.rs field/default/reset/set_kuna_option,
  options.rs KUNA_OPTION_NAMES, stages.toml [[settable]] fid block,
  settable count 60 -> 61 (tests.rs count/comma/PASS_GATES,
  catalog_bytecompat.rs, kuna-catalog.xml #5/#9 max 61->62),
  regenerated stage_catalog.json + docs/assertions.md.
- DB path from the kuna_fid_db env var (a --fidb flag is deferred).

Real-ELF-path-only + default-off => the XML datatest path never
builds a Listing or runs FID, so the 675/158 oracles are
structurally untouched.

Gates: make test 675/675 PARITY OK; make test-stages 222/222 PARITY
OK; make rust-test green incl. the new verify_fid e2e (2 tests, ran
not skipped); kuna catalog --check catalog OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
@mahaloz
mahaloz merged commit ed94dac into main Jun 26, 2026
mahaloz added a commit that referenced this pull request Jun 26, 2026
…post-rebase

After rebasing onto main (FID PR4 #101 brought settables to 61), the combined
tree has 62 settables; the console 'stage catalog' + 'stage catalog returnpair'
emits 63 use_when / change_kind entries (62 + returnpair double-count), so bump
the KUNA-CATALOG #5/#9 max from 62 to 63.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz added a commit that referenced this pull request Jun 26, 2026
Reconcile the taildup feature with main after the FID PRs (#97-#101) and
switchmultipred (#102) landed:

- ElementId: taildup collided with switchsharedcase (both 4106 on the merged
  tree). Renumbered taildup -> 4108 (next free above ifelseflatten's 4107).
- Count unions (taildup +1 settable, switchmultipred +1, fid +1 vs merge-base):
  settable 60 -> 63, surface stays 97 (taildup adds no surface row),
  corpus files 151 -> 153, universalaction leaves -> 264 (252 C++ + 5 kuna),
  bytecompat fixture 63, stages.toml header counts.
- kuna-catalog.xml provenance: source_decompiler angr 22, structure-recovery 12
  (+taildup), opt-in-tool 11 (+switchmultipred), use_when/change_kind max 64
  (settables + returnpair double-count in `stage catalog`).
- Regenerated docs/assertions.md (no change) and docs/baseline-stages.json
  (230 passing keys).

Gates: catalog --check OK; make test PARITY OK 675/675 (baseline.json untouched);
make test-stages PARITY OK 230/230; make rust-test green.
@mahaloz
mahaloz deleted the fid-pass branch July 29, 2026 08:01
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