Skip to content

fix(native): find procedures by the secondary names exact lookup accepts - #8520

Merged
kaoru0822-kitauji merged 3 commits into
mainfrom
fix/8330-procedure-search-aliases
Nov 1, 2026
Merged

kaoru0822-kitauji merged 3 commits into
mainfrom
fix/8330-procedure-search-aliases

Conversation

@kaoru0822-kitauji

@kaoru0822-kitauji kaoru0822-kitauji commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

What broke: search_procedures matched only primary names, so a Kuna alias (versioned-symbol or generated sub_ name) or a Ghidra label at a function entry that procedure_address resolves returned [], and trace_feature silently found no procedure.
Fix: Kuna and the Ghidra bridge now search the same names their exact lookup accepts. Each procedure still appears once under its primary name, and an optional matched_aliases field lists the secondary names that matched. The Ghidra analysis profile records the new search semantics.
Risk: Low to medium. The output field is additive and list_procedures is unchanged. The Java bridge change was syntax-checked but not compiled or run here; CI's bridge job compiles it. Ghidra snapshots under the old profile are no longer replayed.

Summary

Fixes #8330.

Before this change, exact lookup accepted secondary names but procedure search did not. Kuna's #index indexes name and aliases, but #procedureList filtered on name only. Ghidra's resolveProcedure checks every symbol at a function's exact entry, but the bridge search matched only the primary inventory value. The search contract says it covers every analyzed procedure name, so a negative search could hide a name that procedure_address accepts. Both consumers of search, trace_feature and rea search/rea trace, inherited the gap.

Search now matches the primary name plus every secondary name exact lookup accepts. A matching procedure is returned once, with its primary name as value, and matched_aliases lists the distinct secondary spellings that matched. When an alias is shared by two entries, both entries are returned, each with its own primary name and address. Aliases never become rows of their own, and list_procedures output is unchanged.

Problem and expected behavior

Smallest trigger (from the issue): a Kuna inventory row {name: "audit_v1", aliases: ["audit_transform", "sub_1334"]}. procedure_address("sub_1334") returned 0x1334, but search_procedures("sub_1334") returned []. On Ghidra the same happened with an imported non-primary label at the entry (audit_primary at the entry of audit_alias). The broken invariant: a name exact lookup accepts must be findable by the search that the not-found message points callers to.

New behavior (fake-Kuna MCP, executed):

search_procedures {"pattern":"audit_transform"} →
[{"address":"0x1334","value":"audit_v1","matched_aliases":["audit_transform"]},
 {"address":"0x133a","value":"audit_v2","matched_aliases":["audit_transform"]}]

Change and scope

  • Shared row rule (domain): matchProcedureNames in src/domain/analysisSearch.ts takes a primary-named row, the provider's secondary names and a predicate. It returns the row once, with distinct matching secondary names (never the primary spelling) in matched_aliases, or nothing. addressedValueSchema gains the optional matched_aliases (min 1). Through that schema, the field reaches trace_feature matches, native-inventory view field selection and output schemas without separate handling.
  • Kuna: #procedureList uses the helper over entry.name and entry.aliases, the same fields #index uses for exact lookup. Regex runs once per distinct spelling in the existing worker. Mach-O data-entry omission and its limitation apply as before.
  • Ghidra: one bridge method, matchProcedureNames, now defines the names that select a procedure: the primary name and every other symbol at its exact entry, in leaf or namespace-qualified spelling (labels inside the body stay excluded). Both resolveProcedure (exact equality) and procedure search (the query matcher) use it, so they cannot drift; the lookup set is unchanged. Matching secondary symbols are reported by their qualified names, sorted, as matched_aliases. Because a leaf ends its qualified spelling, the host's Unicode literal pass stays exact over the reported names. For case-insensitive literals, the host-side Unicode folding pass (filterGhidraLiteralCandidates) now applies the same helper to the bridge's candidate aliases. The bridge result schema accepts the field for search_procedures only. procedure_search: "primary-and-exact-entry-symbol-names-v1" is added to the shared Ghidra profile, so snapshots of alias-blind results cannot replay (raw-profile digest test updated).
  • Hopper and IDA report one name per address, so they need no change.
  • Not included: listing every alias in list_procedures; promoting interior or data labels to procedures; Kuna's own missing source names (Kuna fix(process): handle launcher exit races and retain CommonJS regressions #1357); a cache for Ghidra entry-symbol lookups (see gaps).

Contribution scope: an ordinary fix within existing boundaries, so no maintainer scope decision applies.

Contract and boundary impact

  • Semantic owner and earliest changed stage: each provider owns its name inventory: Kuna KunaInventoryFunction.{name,aliases}, and the Ghidra bridge's entry symbols. The domain owns the search row rule and its schema. Consumers (trace_feature, CLI search/trace, the native-inventory view) parse the same rows and do no matching of their own.
  • Contribution scope fit and linked maintainer decision: an existing read-only search contract; not applicable.
  • CLI and MCP/tool-catalog contract: the search_procedures description now names secondary-name matching and matched_aliases. The output schema gains one optional string-array field, which also appears in trace_feature procedure matches.
  • Provider, bridge, target-format, or platform compatibility: Kuna (ELF/Mach-O) and Ghidra bridge search. Hopper and IDA are unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: rows keep the address and primary value; the matching spelling is recorded. The Ghidra profile digest changes, so earlier search snapshots are not replayed.
  • Target selection, authority, upstream behavior, and cleanup details: no change; read-only.
  • Generated metadata, package, or installation impact: the tool description and output schema in the generated catalogs change. No committed generated files changed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/providers/kuna/kunaAliasSearchMcp.test.ts: public MCP with fake Kuna. Covers shared and unique aliases; literal, regex and case-sensitive negative; a primary-only control; primary plus alias; an alias repeating the primary; a negative control; the unchanged listing; exact lookup (unique resolves, shared stays ambiguous with both addresses); summary detail plus the native-inventory fields:["matched_aliases"] page; trace_feature by alias (match plus xref, with Kuna's unavailable containment kept explicit) and a primary-name control; and a Mach-O data entry sharing an alias with a code entry (data omitted with its limitation).
    • tests/boundary/cli/procedureAliasSearchCli.test.ts: built CLI rea search --kind procedures --mode regex and rea trace by alias.
    • tests/boundary/mcp/ghidraInventoryMcp.test.ts: Ghidra MCP with an injected bridge. Covers bridge matched_aliases passthrough and the profile key; the Unicode folding pass dropping non-matching candidate aliases and rows while keeping ASCII matches (raw bridge output retained); rejection of an empty matched_aliases; and namespaced names matched by leaf spelling (ns::audit_alias alias, alpha::same primary) through regex and the folding pass. The injected tests pin the host contract only; the Java matching is exercised by the real lanes.
    • scripts/lib/real-ghidra-entry-aliases.mjs (real-Ghidra lane, not run here): literal and anchored-regex search by the fixture's secondary entry label, listing unchanged, trace_feature by that label, and the interior-label control.
    • scripts/lib/real-ghidra-namespace-annotations.mjs (real-Ghidra lane, not run here): leaf regex ^same$ returns each demangled <ns>::same once, matching lookup's existing ambiguity report.
  • Base reproduction: with the src/ changes stashed, all 4 new Kuna/Ghidra MCP tests fail (expected [] to deeply equal [...], and so on); with the fix they pass.
  • Remaining proof gaps: no real Kuna, Ghidra or Java on this host. The Java change was parsed with java-parser (syntax only), not compiled; the CI ghidra-bridge-sources job compiles it. Ghidra search now does one symbol-table lookup per procedure (the same per-procedure work resolveProcedure already does on each name lookup). That cost is source-derived and unmeasured.

Boundary regressions covered: identity (one row per entry, same-address and shared-alias entries), omission (Mach-O data), unknown or partial status (unavailable containment preserved in the trace), malformed producer output (empty alias list), and projection (summary and view field selection). Lifecycle: not applicable, since search ownership and cancellation paths are unchanged (the existing regex worker and monitor.checkCancelled() are reused).

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • vitest new Kuna MCP (3), Ghidra MCP file (9) and CLI (1) tests: pass. The 4 original new MCP tests fail on base.

  • After the leaf-spelling review fix: 39 related files (Ghidra MCP, evidence and routing, Kuna alias MCP, alias CLI, src/ghidra): 1055 pass. check:fast and format:check pass. Java was re-parsed with java-parser (syntax only).

  • 61 related boundary files (all 39 Kuna boundary files, Ghidra/trace/inventory-view/schema MCP files, CLI selector/coverage, snapshot replay, Ghidra client, Hopper regex, IDA containment): 651 pass, 2 fail. Both failures are in kunaInstallationLifetime.test.ts (installation hash-close accounting, expected 3 to be 2) and also fail on unmodified aa48d494e on this Node 26 host; they are unrelated.

  • 65 related source and composition files (src/ghidra, src/contracts, analysis search/view, snapshot cache, capability inventory, Hopper regex, IDA client, binary session): 1540 pass.

  • npm run check:fast: pass. npm run format:check: pass.

  • Docs: generate-product-catalog and its --check, generate-error-schema --check, and readmeConsistency.test.ts: pass. The full npm run docs:check/metadata:check could not run locally: the verifier source loader's stripTypeScriptTypes({mode:"transform"}) is rejected by Node 26.5 on unmodified scripts. That is a local toolchain limit; CI uses Node 24.22.1.

  • Fake-Kuna in-process timing, 50,000 entries with 2 aliases each, median of 5 warm runs. This is one host's measurement, not a real-Kuna benchmark:

    Search Base Fix
    literal, no match 0.6 ms 3.6 ms
    regex matching all 50,000 primaries (identical output) 53.7 ms 63.7 ms

    Responses are unchanged when no alias matches.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Previously valid calls are accepted unchanged. Searches can now return rows that exact lookup already accepted, and those rows carry the new optional field.
  • Real Hopper/Ghidra, browser, or OS coverage: none run. Kuna and Ghidra behavior here comes from simulated or injected providers. The real-Ghidra entry-alias lane was extended but not executed.
  • Package or release metadata impact: the tool description and output schema change. The Ghidra analysis-profile digest changes, so earlier Ghidra snapshots miss.
  • Security, privacy, process, or containment review: read-only search with no new processes, files or network access.

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

search_procedures matched only each procedure's primary name, while exact
lookup also accepts Kuna inventory aliases (versioned-symbol and generated
sub_ names) and Ghidra symbols at an exact function entry. A search for a
name procedure_address resolves returned nothing, and trace_feature
silently missed the procedure.

Both providers now match the same names their exact lookup accepts. A
procedure still appears once under its primary name; the optional
matched_aliases field lists the secondary names that matched, so aliases
never become procedures of their own and list_procedures is unchanged.
The shared domain helper owns that row rule for Kuna and for the Ghidra
host-side Unicode folding pass. The Ghidra analysis profile records the
new search semantics so older snapshots cannot replay alias-blind results.

Fixes #8330

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added bug Something isn't working track:bugs Small-bug loop track PRs labels Nov 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T16:01:08.989517Z 0139ca2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no blocking defect was found in the changed search paths.

Summary

Procedure search now covers the secondary names that exact lookup accepts in Kuna and Ghidra. Results keep each procedure’s primary name and report matching secondary names in matched_aliases.

  • Kuna searches find procedures by their primary names and aliases.
  • Ghidra searches procedures by their primary names and exact-entry symbols.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Query["Procedure search query"] --> Kuna["Kuna: primary name and aliases"]
  Query --> Ghidra["Ghidra: shared entry-name matcher"]
  Exact["Ghidra exact lookup"] --> Ghidra
  Kuna --> Row["One primary-named row with matching aliases"]
  Ghidra --> Row
  Row --> Trace["Feature trace"]
  Row --> View["Native inventory views"]
Loading

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
procedure_address accepts each entry symbol's leaf or namespace-qualified
spelling, but procedure search tested only qualified names, so a regex
such as ^audit_alias$ missed a secondary symbol ns::audit_alias (and ^same$
missed a primary alpha::same) that exact lookup selects.

Lookup and search now share one bridge definition of the names that select
a procedure, so they cannot drift. Matching secondary symbols are still
reported by their qualified names; because a leaf ends its qualified
spelling, the host's Unicode literal pass stays exact over those names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…arch-aliases

Recompute the raw-binary profile digests for the merged shared policy, which
commits both the relocation-symbol load-image revision and procedure search.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji
kaoru0822-kitauji merged commit 44b6384 into main Nov 1, 2026
49 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/8330-procedure-search-aliases branch November 1, 2026 16:53
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 1, 2026
main moved the real-toolchain lanes section from docs/testing.md to
docs/testing-lanes.md. docs/testing.md takes main's version, the
verify:ghidra:cortex-m paragraph moves to the same place in
docs/testing-lanes.md, and the raw-binary guide links there.

main's load-image observation (morluto#8531) and procedure search (morluto#8520)
revisions change every Ghidra profile digest. With this branch's own
bridge and shared semantics, the merged tree keeps every earlier pin,
so the move is main's alone. The legacy pins take main's own digests at
d3ab0fa, which the merged branch matches for all five loads; the
variant digest is re-pinned. The compatibility test accepts the two new
revisions beside instruction_status and still requires the rest of the
saved profile.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 1, 2026
main's load-image observation (morluto#8531) and procedure search (morluto#8520)
revisions change every Ghidra profile, so this branch's pins move again:
morluto#7951's raw digests and its pre-morluto#7823 snapshot comparison, which now
also sets aside the two revisions, Q10's digests outside the M-profile
ELF lane, and morluto#8464's RISC-V images without an overlap. With this
branch's earlier bridge and shared semantics, every earlier pin holds,
so the move is main's alone. The legacy raw comment now says that these
pins include Change 2's revision, as Q10's does.
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 1, 2026
main's load-image observation (morluto#8531) and procedure search (morluto#8520)
revisions change every Ghidra profile digest, so the profiles of images
without an overlap move with main. With this branch's own bridge and
shared semantics, the merged tree keeps the earlier pins, so the move is
main's alone. Both pins take main's own digests at d3ab0fa, which the
merged branch matches.
coyoteXujie pushed a commit to coyoteXujie/rea that referenced this pull request Nov 2, 2026
…pts (morluto#8520)

* fix(native): find procedures by the secondary names exact lookup accepts

search_procedures matched only each procedure's primary name, while exact
lookup also accepts Kuna inventory aliases (versioned-symbol and generated
sub_ names) and Ghidra symbols at an exact function entry. A search for a
name procedure_address resolves returned nothing, and trace_feature
silently missed the procedure.

Both providers now match the same names their exact lookup accepts. A
procedure still appears once under its primary name; the optional
matched_aliases field lists the secondary names that matched, so aliases
never become procedures of their own and list_procedures is unchanged.
The shared domain helper owns that row rule for Kuna and for the Ghidra
host-side Unicode folding pass. The Ghidra analysis profile records the
new search semantics so older snapshots cannot replay alias-blind results.

Fixes morluto#8330

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ghidra): match leaf spellings of procedure names in search

procedure_address accepts each entry symbol's leaf or namespace-qualified
spelling, but procedure search tested only qualified names, so a regex
such as ^audit_alias$ missed a secondary symbol ns::audit_alias (and ^same$
missed a primary alpha::same) that exact lookup selects.

Lookup and search now share one bridge definition of the names that select
a procedure, so they cannot drift. Matching secondary symbols are still
reported by their qualified names; because a leaf ends its qualified
spelling, the host's Unicode literal pass stays exact over those names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working track:bugs Small-bug loop track PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Procedure search omits secondary names accepted by exact lookup

2 participants