#13301

[Design] Shared-memory RegexMatcher, Frida RPC deadlines and filtering, faceted Pwntools/Pwndbg, and Android/SQLite pagination

Openmorlutoopened 4d ago

Before submitting

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

Decision needed

Should REA redesign four cross-cutting resource/contract bottlenecks that hit hard limits on large inputs:

  1. Streaming / zero-copy SharedArrayBuffer RegexMatcher (src/process/RegexMatcher.ts) so matching 1M+ strings (IDA/Hopper/Kuna) does not clone the full string[] inventory via workerData into a 128 MiB worker heap and fail with ERR_WORKER_OUT_OF_MEMORY,
  2. Per-RPC timeouts, abort teardown, and process filtering in Frida (src/frida/FridaInstrumentationManager.ts, src/contracts/fridaToolContracts.ts) so hung enumerateDevices/enumerateProcesses/addRemoteDevice/attach/spawn/script.load() calls cannot stall indefinitely holding #sessionQueues locks,
  3. Faceted/paginated inspect_binary_layout and bounded inspect_recorded_crash in Pwntools/Pwndbg (bridge/pwntools/layout_impl.py, recorded_crash_impl.py, bridge/pwndbg/core_context.py) so large ELFs do not dump 100k+ symbols/relocations + Unicorn PLT emulation unconditionally, and
  4. Pagination (offset/limit) and cursor-based reads for Android JADX (search_android_classes, trace_android_references, scoped inspect_android_jni_bindings) and SQLite keyset paging + session reuse?

Context and evidence

  1. Regex Worker OOM (src/process/RegexMatcher.ts:635-645):
    • Every regex search spawns a cold Worker with default maxOldGenerationSizeMb: 128 and passes the entire values: readonly string[] inventory via structured-cloned workerData. At 1M+ strings (typical on Windows Unreal Engine or large macOS/Linux binaries), structured-cloning into a 128 MiB V8 old-gen heap fails with ERR_WORKER_OUT_OF_MEMORY before testing the regex, and callers cannot push down offset/limit.
  2. Frida untimed RPCs & lock contention (src/frida/FridaInstrumentationManager.ts:190, 256, 341, 347, 356):
    • Calls such as manager.enumerateDevices(), device.enumerateProcesses(), device.getProcessByPid(), device.spawn(), device.attach(), createScript(), and script.load() await Frida promises without timeouts or abort races, and list_frida_processes lacks query/offset/limit filters. A stalled attach or script load blocks #sessionQueues, preventing close/unload cleanup.
  3. Pwntools / Pwndbg unbounded dumps & Unicorn PLT emulation (bridge/pwntools/layout_impl.py:240-332):
    • inspect_binary_layout unconditionally emits every SHT_SYMTAB/SHT_DYNSYM symbol (with base64 names), every SHT_REL/SHT_RELA/SHT_RELR relocation, and unconditionally evaluates image.got/image.plt (triggering Unicorn emulation across PLT stubs), exceeding output_bytes/RLIMIT_AS on large ELFs. Similarly, inspect_recorded_crash embeds raw base64 note descriptor blobs unconditionally and bridge/pwndbg/core_context.py returns unpaged vmmap entries.
  4. SQLite OFFSET O(N²) paging (src/sqlite/SqliteDatabaseInspection.ts:1002-1044) & Android JADX unpaged class/ref dumps:
    • readRows in SQLite runs NOT INDEXED ... LIMIT ? OFFSET ?, causing O(offset) scans on every page alongside per-page up-to-256 MiB snapshot copying (SqliteDatabaseSnapshot.ts).
    • search_android_classes and trace_android_references lack offset/limit pushdown (fetching all pages / limit: 2_147_483_647), and inspect_android_jni_bindings materializes all declarations/candidates even when filtered to a single class/method.

Expected interaction with targets

  • Read existing files or captured data (static inspection of binaries/APKs/SQLite/core dumps; note Frida attaches/spawns target processes under existing Frida tool scope).

Boundary details (optional)

  • RegexMatcher must keep exact worker isolation (crash/timeout/OOM containment) and deterministic index ordering (indices), while cleanly aborting in-flight matches on timeout or AbortSignal.
  • Any Frida timeout/cancellation wrapper must clean up or detach half-opened remote/device/session handles explicitly without leaking orphan locks in #sessionQueues.
  • Any faceted/paged contracts in Pwntools/Android/SQLite must report explicit completeness/truncation (status: "partial", truncated: true, next cursor/offset).

Options and tradeoffs

  • RegexMatcher: Reuse a warm worker (respawned on timeout/OOM/error) paired with chunked message streaming or a single SharedArrayBuffer UTF-8 string arena + Uint32Array offset table, plus offset/limit early-stop support.
  • Frida: Add configurable operation deadline + AbortSignal racing around device/spawn/attach/load RPCs with explicit session detach recovery, plus query/offset/limit on list_frida_processes.
  • Pwntools / Android / SQLite: Add opt-in/paged facets (symbols, relocations, include_plt_emulation) on inspect_binary_layout, add offset/limit on search_android_classes & trace_android_references, and add keyset pagination (WHERE rowid > ?) + short-lived verified snapshot reuse across SQLite pages.

Verification available so far

  • Idea only; I need help defining checks

Success criteria and open questions

  • Should inspect_binary_layout omit unbounded symbols/relocations and Unicorn PLT emulation by default behind explicit facets/limits, or keep full defaults with pagination parameters?
  • For RegexMatcher, is chunked IPC streaming or a SharedArrayBuffer string arena preferred under Node's worker_threads resource limits?
  • What default RPC timeout best fits interactive attach/spawn/enumerateProcesses in FridaInstrumentationManager?

References

  • Related issues: #13283, #13284
  • src/process/RegexMatcher.ts:575-744
  • src/frida/FridaInstrumentationManager.ts:182-375
  • bridge/pwntools/layout_impl.py:240-332
  • src/sqlite/SqliteDatabaseInspection.ts:1002-1044

Activity

0

No activity yet.