#13355

[Feature] Avoid eager full-inventory materialization, duplicate leaf/qualified literal matching, and monolithic JsonArray replies in ReaGhidraBridge

Openmorlutoopened 3d ago

Before submitting

  • I searched the open and closed issues and pull requests for a related proposal.
  • I understand the contribution scope must be reviewed before integration; open questions are welcome here.
  • This request does not include credentials, private samples, or sensitive target data.

Area

Native analysis or decompilation

Current limitation

Source inspection of bridge/ghidra/ReaGhidraBridge.java on origin/main (d0929f9aa2) identifies three remaining scaling bottlenecks in Ghidra search and inventory construction (source-derived; not benchmarked in live Ghidra here):

  1. Duplicate leaf + qualified literal matching in spellingMatches (bridge/ghidra/ReaGhidraBridge.java:2753-2756): matcher.matches(qualified) || (!leaf.equals(qualified) && matcher.matches(leaf)) runs the matcher twice on every non-matching qualified symbol. While the comment notes a leaf is a suffix of the qualified spelling for literal searches, non-matching literal searches still re-run matcher.matches(leaf) when matcher.matches(qualified) returned false (unless a regex uses start anchors or qualified delimiters).
  2. Unbounded in-memory JsonArray construction during search (bridge/ghidra/ReaGhidraBridge.java:2696-2724): builds a single full JsonArray items holding every matching JsonObject (including facts and matched_aliases) in Java heap and serializes one monolithic NDJSON response line, amplifying peak heap in the Ghidra JVM and in Node's NDJSON parser on broad queries.
  3. Eager full-table materialization and sorting in names(), procedures(), and strings() (bridge/ghidra/ReaGhidraBridge.java:2758-2880): iterates the entire symbol/function/defined-data tables, constructs sorted immutable lists (symbolFacts, aliases, charset names) up front even for a single selective query or name lookup before procedureNameIndex is populated.

Use cases

Large binaries (e.g., stripped mobile libraries, C++ binaries with deep namespace hierarchies, firmware images) queried via search_procedures, search_strings, list_procedures, or list_strings under bounded Ghidra JVM heap.

Desired outcome and success criteria

  • Skip redundant matcher.matches(leaf) checks when !matcher.matches(qualified) is already decisive (e.g., all unanchored literal searches, and regexes without ^ / \A / \b boundary sensitivity on the namespace separator).
  • Bound or stream large inventory/search replies across the Ghidra Unix socket (while preserving exact deterministic sort order, matched_aliases, and truncation/error semantics).
  • Avoid eagerly materializing full names()/procedures()/strings() lists with full symbolFacts when serving targeted operations.

Expected interaction with targets

  • Read existing files or captured data

Verification available so far

  • Idea only; I need help defining checks

Verification details (optional)

Source-derived analysis at d0929f9aa2. Live JVM heap and wall-clock impact on large Ghidra programs remain unmeasured.

Alternatives considered

  • Merged PRs #13305 and #13310 indexed procedureNameIndex / symbolTable.getSymbols(name) and parallelized language catalog checks, and #13278 / #13292 / #13299 track symbol-table lookup indexing, non-ASCII string search flood mitigation, and workflow scale bounds. None address spellingMatches double matching on misses, monolithic JsonArray search replies, or eager names()/procedures()/strings() fact materialization.

Possible direction

  • Add a boolean needsLeafCheck flag on ValueMatcher (false for substring/literal matchers since leaf is always a substring of qualified — wait: preserve leaf.equals(qualified) exact edge cases and anchored/separator regexes).
  • Stream chunked NDJSON or cursor-bounded pages from ReaGhidraBridge.search(...) / list commands, and defer alias/symbolFacts object creation until a row matches or is requested.

References

  • Related issues/PRs: #13278, #13292, #13299, merged PRs #13305, #13310

Activity

0

No activity yet.