#13284

[Feature] Single-pass tshark pipelines in PCAP, streaming snapshots and pooled workers in SQLite, and single-pass indexing in IL2CPP/WABT

Openmorlutoopened 4d ago

Before submitting

  • I searched for existing feature requests.
  • I read CONTRIBUTING.md so the request fits REA's local-only scope.

Area

Format Providers: PCAP, SQLite, IL2CPP Binary Registration & WABT (src/pcap/, src/sqlite/, src/il2cpp/, src/wasm/)

Current limitation

Source-derived findings across four binary/format providers:

  1. Redundant second tshark pass & before/after 64 MiB tool executable re-hashing in PCAP (src/pcap/PcapProvider.ts:322-370, 415-432, 1137-1190, src/pcap/PcapSnapshot.ts:171-240):
    • PcapProvider.#run calls this.readToolIdentity (line 322), which reads and hashes up to 64 MiB of the Wireshark binary (tshark / capinfos) both before (line 366) and after (line 417) every single command invocation (version, capinfos, primary tshark, and secondary tshark).
    • On inspect_pcap_capture, after running the full packet tshark pass, lines 1152-1174 launch a second full tshark -r snapshot.path -T json ... -Y "dns || mdns || llmnr" -x -J "frame dns mdns llmnr" pass over the entire capture file instead of extracting required fields in one streaming pass.
    • PcapSnapshot.ts:174-199 copies captures in 64 KiB JS chunks rather than using larger buffered transfers or APFS/Linux CoW clones (when digest is already computed or verified in one stream).
  2. Whole-file buffering + cold worker per SQLite inspection (src/sqlite/SqliteDatabaseProvider.ts:277-302, src/sqlite/SqliteDatabaseSnapshot.ts:380-413):
    • Every inspect_sqlite_database call reads the entire SQLite DB (and -wal if present) into a JS Buffer via readMember (SqliteDatabaseSnapshot.ts:381), writes it out to database.snapshot (line 386), and spawns a cold worker process (SqliteDatabaseProvider.ts:286) even for small read-only inventory / short row_limit queries.
  3. Remaining O(N) full-binary pointer-struct scan in IL2CPP (src/il2cpp/Il2cppBinaryRegistration.ts:217-231, 354-380):
    • While PR #13272 optimizes ripRelativeReferences and arm64PageReferences executable scans, findCodeRegistration (lines 354-380) still walks every 8-byte aligned offset across all container mappings calling readUInt32 and readSlot per 8-byte slot before checking relocation overlays/mappings.
  4. Triple WABT subprocess chain + O(N²) S-expression re-splitting (src/wasm/WabtArtifactProvider.ts:265-305, 604-608, src/wasm/WabtInterface.ts:81-125, 285-320):
    • WabtArtifactProvider executes three separate subprocesses sequentially (wasm-validate, wasm-objdump, wasm2wat; lines 604-608), and WabtInterface.ts parses WAT declarations by repeatedly invoking splitParts(form) per form, type, parameter, and export (lines 87, 94, 96, 286, 290) while retaining full wat_form strings (line 312).

Use cases

  • Analyzing multi-hundred-MB .pcapng captures with inspect_pcap_capture.
  • Interactive multi-page browsing (row_offset/row_limit) of large SQLite databases with inspect_sqlite_database.
  • Analyzing 100+ MB libil2cpp.so / GameAssembly.dll or multi-megabyte .wasm modules.

Desired outcome and success criteria

Applying DDIA principles (single-pass streaming, OS-level file snapshots / streaming copy, single-pass parsing & indexing):

  1. PCAP: Combine DNS/mDNS/LLMNR hex/frame extraction with the primary tshark stream (or use tshark -T ek / field projection in a single streaming pass) and rely on verified open-file/executable stat+descriptor identity across commands in the same run rather than hashing the 64 MiB tshark binary up to 8 times per capture inspection.
  2. SQLite: Stream database/WAL files directly to database.snapshot without holding the entire multi-hundred-MB DB in Node heap Buffer, and evaluate a reusable isolated read-only worker across read queries.
  3. IL2CPP: Build a fast raw-byte/slot filter on !loaded && little mappings in findCodeRegistration's primary struct loop (lines 354-380, matching PR #13272's executable-scan design and checking alignment/expected modules.length word directly via byte/u32 checks before BigInt slot arithmetic).
  4. WABT: Parse core WASM binary sections directly for export/import/type interfaces or tokenize WAT once via a single-pass structural lexer instead of per-node splitParts() calls.

Expected interaction with targets

  • Read existing files or captured data (local .pcap/.sqlite/ELF/Mach-O/PE/.wasm files and private snapshots).

Target and scope details

  • Covers src/pcap/, src/sqlite/, src/il2cpp/, and src/wasm/.
  • Preserves all WABT diagnostic limits, SQLite consistency/WAL admission invariants, PCAP capinfos/tshark count cross-checks, and IL2CPP unknown/unresolved relocation semantics.

Verification available so far

  • Source code analysis of REA only.

Verification details

Requires validation with:

  • npm run verify:pcap
  • npm run verify:il2cpp:metadata
  • npm run verify:wasm:artifact, npm run verify:wasm:interface-comparison, npm run verify:wasm:package
  • SQLite boundary suites (tests/boundary/sqlite/).

Alternatives considered

  • Adding result caches in front of PcapProvider or WabtArtifactProvider: leaves cold single-file runs paying 2× tshark passes and 8× binary hashing; unifying passes and streaming snapshots helps cold calls immediately.

Possible direction

  1. Stream SqliteDatabaseSnapshot copy-and-hash (readArtifactFileChunks -> Transform sha256 -> WriteStream) instead of allocating captured.bytes in JS heap.
  2. Extend PR #13272's raw-slice count pre-filter to findCodeRegistration lines 356-362 (with relocation overlay fallback).
  3. Replace repeated splitParts() calls in WabtInterface.ts with a cursor-based S-expression tokenizer.

References

  • Follow-up to PR #13272 (IL2CPP executable scan) and PR #13274 (SQLite decoders & short-page truncation)
  • src/pcap/PcapProvider.ts:322-432, 1137-1190
  • src/pcap/PcapSnapshot.ts:171-240
  • src/sqlite/SqliteDatabaseProvider.ts:275-305
  • src/sqlite/SqliteDatabaseSnapshot.ts:380-413
  • src/il2cpp/Il2cppBinaryRegistration.ts:217-231, 347-380
  • src/wasm/WabtArtifactProvider.ts:265-305, 604-608
  • src/wasm/WabtInterface.ts:81-125, 285-320

Activity

0

No activity yet.