Repository navigation
FID PR2: FNV-1a64 FidHashQuad hasher - #97
Merged
Merged
Conversation
Port the pure FID hashing core, byte-exact to Ghidra's
MessageDigestFidHasher / FNV1a64MessageDigest. Mechanism only — no
pass/DB/option/engine wiring (PR3/PR4), so nothing here is reachable from a
decompilation and the parity oracles are structurally untouched.
New kuna-analysis/src/s1_fid/:
- hash.rs — Fnv1a64 (offset basis 0xcbf29ce484222325, prime 0x100000001b3;
update_byte/bytes/i32 [4 bytes big-endian]; digest_long resets to
basis) + FidHasher + FidHashQuad. FidHasher::hash ports the
per-instruction loop line-for-line: skippers BEFORE the call count
(codeUnitIndex -= 1; continue), the 4-way scalar rule in order
(relocation / whole-operand-address / large-non-whole /
small-usable), the full hash never sees a scalar value (only the
0xfeeddead placeholder), registers into both, then update_i32 the
operand subhashes, then mask buf[i] &= fixed_mask[i] and feed the
masked bytes to BOTH digests AFTER the operand writes (the critical
interleave). Magic verbatim; wrapping_* everywhere; extents < 4 ->
None. Relocation check consumed as a RelocationQuery trait.
- extent.rs — FunctionBodyFunctionExtentGenerator analog: the [entry,
next_function_after(entry)) address-contiguous clip (the
s1_noreturn_disc idiom); clip rule split out pure-testable.
- skipper.rs— InstructionSkipper trait + X86InstructionSkipper (17 NOP patterns
copied byte-for-byte); non-x86 = empty set, never skips.
Fidelity gate: FNV-1a64 validated against the canonical published FNV test
vectors (external authority); FidHashQuad gated by a hand-computed quad on a
5-instruction synthetic extent vs an independent in-test reference loop, plus
self-consistency + targeted invariants. The Ghidra-validated golden-vector gate
(design §7.1) is a documented follow-up: the ~/github/ghidra checkout has no
built distribution, so a (function -> FidHashQuad) dump needs a gradle build out
of scope for PR2 (PR3, which builds a real lib.o fixture, is the natural place).
Gates: make test 675/675 PARITY OK; make test-stages 205/205 PARITY OK;
make rust-test green; the new s1_fid unit gate RAN (19 passed, 0 ignored).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The second PR of the FID (Function-ID fingerprinting) port — the pure hashing core. Mechanism only: no pass / DB / option / engine wiring (that is PR3/PR4). Because nothing here is reachable from a decompilation, this PR structurally cannot perturb the parity oracles. Builds on PR1's
Sleigh::instruction_maskaccessor (#94). Whole-feature plan:docs/fid-design.md.The algorithm (byte-exact port of
MessageDigestFidHasher/FNV1a64MessageDigest)A one-bit divergence makes every hash miss silently, so the constants and the per-instruction loop order are reproduced verbatim. Three new pure modules under
kuna-analysis/src/s1_fid/:hash.rs—Fnv1a64(offset basis0xcbf29ce484222325, prime0x100000001b3;update_byte/update_bytes;update_i32= 4 bytes big-endian viaAbstractMessageDigest.update(int);digest_longresets to basis) +FidHasher+FidHashQuad { code_unit_size:i16, full_hash:u64, specific_addl_size:u8, specific_hash:u64 }.FidHasher::hashports the per-instruction loop line-for-line:code_unit_index -= 1; continueon skip — matching the Java order);is_call;full_u = spec_u = (ii+1)*7777, then the 4-way scalar rule in order (relocation / whole-operand-address / large-non-whole / small-usable) — the full hash NEVER sees a scalar value, only the0xfeeddeadplaceholder; registers mix(off+7654321)*98777into both; address objects are value-suppressed placeholders into both; thenfull.update_i32(full_u); spec.update_i32(spec_u);buf[i] &= fixed_mask[i]and feed the masked bytes to BOTH digests after that instruction's operandupdate_i32writes.0xfeeddead, 7777, 1234567, 67999, 7654321, 98777, 0xa5, 4, 127);wrapping_*everywhere (Java two's-complement overflow is observable, incl. the(int) valtruncation); extents< 4code units →None; empty/absent mask → Ghidra's NPE arm (fill0xa5). The relocation check is consumed as aRelocationQuerytrait (pure-core testable; PR4 supplies theelf_reloc.rs-backed adapter).extent.rs— theFunctionBodyFunctionExtentGeneratoranalog: the address-contiguous[entry, next_function_after(entry))clip over the flatinstructions()map (thes1_noreturn_discidiom). LOSS (documented): address-contiguous, not flow-reachable — same approximations1_noreturn_discaccepts.skipper.rs—InstructionSkippertrait +X86InstructionSkipper(17 NOP patterns copied byte-for-byte); non-x86 = empty skipper set → never skips.Fidelity gate (honest accounting)
FNV-1a64 is validated against an external authority — the unit gate asserts the canonical published FNV-1a64 test vectors (
""→ offset basis,a/b/c,foobar,hello), independently cross-checked against the reference algorithm, not mere self-consistency. The fullFidHashQuadis gated by a hand-computed quad on a 5-instruction synthetic extent (register / small-usable-scalar / large-suppressed / whole-operand-address / no-operand + a call), asserted against an independent in-test reference reimplementation of the loop, plus self-consistency across two builds of the hasher and targeted invariants (code_unit_size = count − calls; a relocation suppresses the scalar inspecific_countand changes only the specific hash, never the full hash).Caveat — the Ghidra-validated golden-vector gate (design §7.1) is a documented follow-up. The
~/github/ghidracheckout has the FID sources but no built distribution (build/distempty, no.classfiles), so dumping(function → FidHashQuad)vectors needs a multi-GB gradle build out of scope for PR2 — the design doc explicitly anticipates this fallback. PR3 (which builds a reallib.ofixture) is the natural place to add the Ghidra dump once a built Ghidra is available.Sample FidHashQuad (the in-tree gate's 5-instruction sequence)
A 5-instruction x86-64 extent —
push rbp/mov rbp,rsp(registers) /add eax,0x10(small usable scalar, counts) /mov eax,0x12345678(whole-operand scalar, counts) /call rel32(whole-operand address scalar, suppressed; is_call) — hashes to a quad withcode_unit_size = 5 − 1 call = 4,specific_addl_size = 2(two usable scalars), andfull_hash ≠ specific_hash(scalars folded only into the specific hash). The exactu64s are asserted inhash::tests::hand_computed_quad_matches_referenceagainst the independent reference loop.Gate results
make test— 675/675 PARITY OKmake test-stages— 205/205 PARITY OK (raised by the concurrent worker)make rust-test— green; the news1_fidunit gate RAN: 19 passed, 0 ignored (10hash, 5skipper, 4extent)Increment 53 in
docs/analysis-port-log.md. Next: PR3 (the.fidDB format +kuna fid buildgenerator), then PR4 (theFidPass+instruction_mask→InsnFingerprintassembly + rename/commit +--option fidsurface + the stripped-binary re-identification e2e test).🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb