#13292

[Feature] Eliminate Ghidra search_strings non-ASCII flood/heap bloat and bound large-binary string search operations

Openmorlutoopened 4d ago

Before submitting

Area

Native / Decompiler Providers: Ghidra & IDA search_strings Scaling (bridge/ghidra/, src/ghidra/, src/ida/)

Current limitation

User report (Windows Unreal Engine game): calling search_strings({ "pattern": "warfare/storage/read-write" }) (default mode: "literal", case_sensitive: false) hung for 2+ hours with no response.

Alongside the IDA predicate-pushdown fix in PR #13291 (IdaProtocolValues.ts / IdaOperationRunner.ts), source analysis identified remaining architectural bottlenecks across Ghidra and IDA on large game binaries (millions of DefinedData / localized UI strings):

1. Ghidra literalCandidateMatcher floods every non-ASCII string across IPC (bridge/ghidra/ReaGhidraBridge.java:5601-5608, src/ghidra/GhidraProviderClient.ts:1184-1201)

  • On default case_sensitive: false literal search, GhidraClient.ts:499 sends literal_ascii_candidate (lowercased ASCII).
  • In ReaGhidraBridge.java:5604-5607:
    if (value.chars().anyMatch(character -> character > 127)) return true;
  • Any string containing any non-ASCII character (localized menus, CJK/Cyrillic/accented asset paths, copyright symbols, Unreal telemetry/editor text — often hundreds of thousands of strings in Unreal games) matches unconditionally as a false-positive candidate, gets serialized across the bridge socket, Zod-validated in GhidraProviderClient, retained in rawResult (line 1195) / EvidenceLedger, and re-filtered in Node (filterGhidraLiteralCandidates).

2. Ghidra strings() eager per-string Gson heap amplification & comparator serialization (bridge/ghidra/ReaGhidraBridge.java:2732-2762, 5314-5325, 5881-5884, src/ghidra/GhidraJavaLaunch.ts:145)

  • First invocation of strings() walks every defined datum in currentProgram.getListing().getDefinedData(true) (line 2737) and allocates a 3-field Gson JsonObject (encoding, termination, byte_length) per string under the default -Xmx2G headless JVM (GhidraJavaLaunch.ts:145).
  • Sorting via INVENTORY_ORDER (line 5884) invokes GSON.toJson(item.facts) on comparator evaluations, and resultItem() (line 5319) calls item.facts.deepCopy(). On multi-million-string Unreal binaries, this amplifies heap retention and triggers prolonged Stop-The-World GC thrashing under 2 GiB -Xmx.

3. Unbounded / slow pagination and missing operation deadlines on large string inventories

  • Ghidra (src/ghidra/GhidraClient.ts:477-515 -> GhidraClientWire.ts:123, 162): search_strings passes timeoutMs: undefined, so a GC-thrashing or multi-million-item scan in Java never times out cleanly with actionable recovery.
  • IDA (src/ida/IdaOperationRunner.ts:313-342, src/ida/IdaConfiguration.ts:29, src/ida/IdaHexRaysProtocol.ts:124): strings() hardcodes limit: 100 (line 329), resetting DEFAULT_IDA_REQUEST_TIMEOUT_MS (300 s) on each 100-item page without an operation-wide deadline or MCP progress ticks, while runHexRaysQuery (IdaHexRaysProtocol.ts:124) re-transmits the full hexrays_queries.py source per page request. This still affects list_strings, mode: "regex", and non-ASCII case_sensitive: false searches (where find_regex enumerates unbounded candidates).

Use cases

  • Searching literal asset/config/storage paths ("warfare/storage/read-write") or symbols inside multi-hundred-MB Windows PE/PDB Unreal Engine games in Ghidra or IDA without multi-hour stalls.
  • Failing fast with explicit deadline & recovery guidance (such as GHIDRA_HEADLESS_MAXMEM, search_bytes, or narrower patterns) rather than silently hanging.

Desired outcome and success criteria

Applying DDIA principles (exact character-folding pushdown, compact primitive storage views before serialization, and bounded operation deadlines):

  1. Exact Unicode simple-fold pushdown in ReaGhidraBridge.literalCandidateMatcher:
    • Exhaustively checked against ECMAScript /iu across all 1,114,112 Unicode code points: only U+017F (ſ -> s) and U+212A (K -> k) fold into ASCII [a-z] under simple case folding.
    • Instead of if (value.chars().anyMatch(c -> c > 127)) return true;, match asciiPattern via zero-allocation case/fold scanning (A-Z -> a-z, '\u017f' -> 's', '\u212a' -> 'k') inside Java directly (preserving non-ASCII candidate passthrough only if literal_ascii_candidate was null for non-ASCII patterns, or validating parity cleanly with GhidraLiteralSearch.ts).
  2. Compact StringFacts record in ReaGhidraBridge.java:
    • Replace per-string eager JsonObject facts + GSON.toJson(item.facts) comparator + deepCopy() with a lightweight primitive representation (String charset, boolean missingNull, int byteLength) that materializes JSON only for matched rows in resultItem().
  3. Bounded search_strings / list_strings deadlines, progress reporting & larger IDA pages:
    • Bound full-inventory string searches cleanly with configurable timeouts / MCP progress notifications and support larger / configurable find_regex page sizes (and session-resident helper upload or larger batching in IdaHexRaysProtocol.ts / IdaOperationRunner.ts).

Expected interaction with targets

  • Read existing files or captured data (local binary analysis under existing Ghidra/IDA session boundaries).

Target and scope details

  • Covers bridge/ghidra/ReaGhidraBridge.java, src/ghidra/GhidraClient.ts, src/ghidra/GhidraLiteralSearch.ts, src/ida/IdaOperationRunner.ts, src/ida/IdaHexRaysProtocol.ts.
  • Preserves ECMAScript Unicode simple case-folding semantics, deterministic INVENTORY_ORDER sorting, and fail-closed timeout/cleanup behavior.

Verification available so far

  • Source code analysis across Ghidra & IDA search pipelines.
  • Exhaustive Node v24.22.1 check of all 1,114,112 Unicode code points confirming only U+017F (ſ) and U+212A (K) fold to ASCII under /iu.
  • Local npm run verify:ghidra:bridge-sources requires GHIDRA_INSTALL_DIR (blocked in offline sandbox without Ghidra >=12.2 installation).

Verification details

Requires real-provider validation with:

  • npm run verify:ghidra:bridge-sources
  • npm run verify:ghidra
  • npm run verify:ida
  • Plus bridge unit parity tests against GhidraLiteralSearch.test.ts and IdaHexRaysProtocol.test.ts / test_hexrays_queries.py.

Alternatives considered

  • Adding an LRU result cache in Node: does not fix the first cold scan (which is what hangs for 2+ hours on an Unreal game) nor reduce Java heap pressure / IPC flooding.

Possible direction

  1. Update literalCandidateMatcher in ReaGhidraBridge.java:5601-5608 to fold A-Z, \u017f, \u212a inline against asciiPattern instead of returning true for all char > 127.
  2. Replace eager JsonObject per string in ReaGhidraBridge.strings() (line 2749) with compact fields and skip GSON.toJson inside INVENTORY_ORDER.
  3. Add explicit operation deadline & MCP progress ticks on search_strings / list_strings for Ghidra and multi-page IDA scans.

References

  • Related PR & issues: #13291, #13276, #13278
  • bridge/ghidra/ReaGhidraBridge.java:2584-2635, 2732-2762, 5314-5325, 5601-5608, 5881-5884
  • src/ghidra/GhidraLiteralSearch.ts:15-76
  • src/ghidra/GhidraJavaLaunch.ts:145
  • src/ghidra/GhidraClient.ts:477-515
  • src/ghidra/GhidraClientWire.ts:123, 162
  • src/ida/IdaOperationRunner.ts:313-342
  • src/ida/IdaHexRaysProtocol.ts:103-130

Activity

0

No activity yet.