[PR #7041] feat(binary-ninja-headless): add owned headless Binary Ninja provider #7600

Open
opened 2026-11-03 13:39:02 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7041
Author: @ihabontop
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: feat/binary-ninja-headless


📝 Commits (1)

  • d4deddf feat(binary-ninja-headless): add owned headless Binary Ninja provider

📊 Changes

30 files changed (+5300 additions, -12 deletions)

View changed files

➕ bridge/binaryninja/rea_binaryninja_bridge.py (+858 -0)
➕ bridge/binaryninja/test_rea_binaryninja_bridge.py (+389 -0)
📝 docs/.vitepress/config.ts (+4 -0)
📝 docs/architecture.mermaid (+7 -0)
➕ docs/binaryninja-headless-provider.md (+90 -0)
📝 docs/index.md (+1 -1)
📝 docs/installation.md (+7 -7)
📝 docs/mcp-contracts.md (+1 -0)
📝 docs/testing.md (+37 -0)
📝 package.json (+2 -1)
📝 scripts/lib/catalog-builders.mjs (+9 -0)
📝 scripts/lib/catalog-core.mjs (+2 -0)
📝 scripts/lib/module-boundaries.mjs (+1 -0)
📝 scripts/lib/test-projects.mjs (+1 -1)
➕ src/binaryNinjaHeadless/BinaryNinjaHeadlessBridgeProcess.ts (+464 -0)
➕ src/binaryNinjaHeadless/BinaryNinjaHeadlessInstallation.ts (+184 -0)
➕ src/binaryNinjaHeadless/BinaryNinjaHeadlessOperationRunner.ts (+483 -0)
➕ src/binaryNinjaHeadless/BinaryNinjaHeadlessProtocolValues.ts (+455 -0)
➕ src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.test.ts (+327 -0)
➕ src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.ts (+288 -0)

...and 10 more files

📄 Description

Summary

Adds binary-ninja-headless, a deep-analysis provider that starts an owned headless Binary Ninja Python interpreter, loads the admitted file read-only after verifying its Raw-view digest, waits for default auto-analysis, and serves REA's native analysis operations from that BinaryView. Refs #1551. Draft for the maintainer scope decision CONTRIBUTING requires for a new provider; it does not ask for integration yet.

It complements the attached GUI MCP adapter proposed in #5794: that adapter reads a file the analyst already opened in the GUI; this provider needs no GUI and reproduces analysis from the file alone, but requires a Binary Ninja license edition that permits headless use.

Problem and expected behavior

Binary Ninja users with a headless-capable license cannot point REA at Binary Ninja without keeping a GUI open. With this change, --provider binary-ninja-headless (or REA_ANALYSIS_PROVIDER / open_binary.provider_id) serves decompile, function, analyze, search, trace and the underlying native operations from an owned, digest-bound headless analysis, with the same Evidence and limitation reporting as the other providers.

Change and scope

  • src/binaryNinjaHeadless/: capabilities (identity, operations, limitations, effects), filesystem-only installation discovery, protocol values with zod schemas and projections to the shared REA shapes, an owned bridge process (NDJSON over stdio on spawnOwnedProviderProcess + ProviderProcessSupervisor, reply-size budget, startup deadline, cancellation stops the interpreter), an operation runner, a serial session client, and the AnalysisProviderCandidate.
  • bridge/binaryninja/rea_binaryninja_bridge.py: the Python side; one BinaryView per process, Binary Ninja log on stderr, requests validated and answered with stable error codes.
  • Configuration: BINARY_NINJA_INSTALL_DIR, REA_BINARY_NINJA_PYTHON, REA_BINARY_NINJA_STARTUP_TIMEOUT_MS (additive, optional).
  • Composition: registered in src/composition/binary.ts; catalog, module-boundary and test-project wiring.
  • Intentionally not included: list_segments (segment contract provenance is Hopper/Ghidra only), list_names, procedure_references, read_bytes, doctor integration, a real-provider verifier lane, engine-version commitment in the profile. These are listed in the guide as next steps.
  • Existing providers are unchanged.

Contribution scope: new provider; maintainer scope decision requested in #1551 (pending). No target execution, injection, mutation or protection recovery.

Contract and boundary impact

  • Semantic owner and earliest changed stage: new provider adapter src/binaryNinjaHeadless/ and bridge; application and contract layers unchanged.
  • Contribution scope fit and linked maintainer decision: pending in #1551.
  • CLI and MCP/tool-catalog contract: no new tools or schemas; the provider catalog gains one provider entry.
  • Provider, bridge, target-format, or platform compatibility: Binary Ninja 6.0 headless API; PE, ELF and thin Mach-O executables on x86, x86_64, arm, arm64, mips, powerpc, riscv; Windows bundled interpreter by default, explicit interpreter elsewhere.
  • Evidence, artifact, provenance, or reconstruction contract: observations carry cachePolicy: live, Binary Ninja provenance strings in body/classification/locals, reference kinds reported as unavailable with the observed category, and relationship coverage unknown (callers) / partial-or-complete (callees).
  • Target selection, authority, upstream behavior, and cleanup details: REA owns the interpreter process; Binary Ninja writes only its own user directory; close releases the view and stops the process; failed startups are not cached.
  • Generated metadata, package, or installation impact: package.json#files ships the bridge script; test:python runs its unit test; no installer changes.

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: src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.test.ts (availability, target support, profile binding), src/binaryNinjaHeadless/BinaryNinjaHeadlessSessionClient.test.ts (launch contract, projections against functionDossierSchema and instruction windows, caller mistakes, startup failure attribution, deadline, cancellation, protocol faults, reply bounds, close) with tests/fixtures/fakeBinaryNinjaBridge.mjs; bridge/binaryninja/test_rea_binaryninja_bridge.py with a fake binaryninja module.

  • Base reproduction or other evidence: real-engine run recorded in docs/testing.md#binary-ninja-headless-lane (Windows 11 x64, Binary Ninja 6.0.10905, where.exe).

  • User-visible CLI/MCP output: rea decompile 'C:\Windows\System32\where.exe' --procedure __wmainCRTStartup --provider binary-ninja-headless --json returns Pseudo C Evidence with provider binary-ninja-headless, profile mode owned-headless, and raw engine facts (core_version 6.0.10905).

  • Remaining proof gaps: MCP parity, Linux and macOS hosts, ELF and Mach-O targets, other Binary Ninja releases and license editions, cancellation against the real engine, token/CPU/memory measurements.

  • 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

  • npm run check:fast — passed (typecheck and lint, 2 tasks successful).
  • npm run test:local -- src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.test.ts src/binaryNinjaHeadless/BinaryNinjaHeadlessSessionClient.test.ts src/config.test.ts — 111 tests passed.
  • python -m unittest bridge/binaryninja/test_rea_binaryninja_bridge.py (CPython 3.14) — 10 tests passed.
  • Production CLI against real Binary Ninja 6.0.10905 on Windows 11 x64 with where.exe: decompile, function --detail complete, analyze, search --pattern 'cannot be run', trace --query 'cannot be run' — all exit 0; every output parsed against the built Evidence schema and its output contract; dossier parsed against functionDossierSchema.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; all settings are new and optional.
  • Real Hopper/Ghidra, browser, or OS coverage: existing providers untouched; real Binary Ninja coverage limited to one Windows host.
  • Package or release metadata impact: one new packaged bridge script; one provider catalog entry.
  • Security, privacy, process, or containment review: the interpreter runs with the current user's permissions under REA's owned-process supervision, user plugins and settings disabled, no network use by REA; Binary Ninja's own license and user directory behavior is unchanged.

Author readiness

Human owner: @ihabontop

  • 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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/7041 **Author:** [@ihabontop](https://github.com/ihabontop) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/binary-ninja-headless` --- ### 📝 Commits (1) - [`d4deddf`](https://github.com/morluto/rea/commit/d4deddf8a38de83919373084680806fa0f3281b4) feat(binary-ninja-headless): add owned headless Binary Ninja provider ### 📊 Changes **30 files changed** (+5300 additions, -12 deletions) <details> <summary>View changed files</summary> ➕ `bridge/binaryninja/rea_binaryninja_bridge.py` (+858 -0) ➕ `bridge/binaryninja/test_rea_binaryninja_bridge.py` (+389 -0) 📝 `docs/.vitepress/config.ts` (+4 -0) 📝 `docs/architecture.mermaid` (+7 -0) ➕ `docs/binaryninja-headless-provider.md` (+90 -0) 📝 `docs/index.md` (+1 -1) 📝 `docs/installation.md` (+7 -7) 📝 `docs/mcp-contracts.md` (+1 -0) 📝 `docs/testing.md` (+37 -0) 📝 `package.json` (+2 -1) 📝 `scripts/lib/catalog-builders.mjs` (+9 -0) 📝 `scripts/lib/catalog-core.mjs` (+2 -0) 📝 `scripts/lib/module-boundaries.mjs` (+1 -0) 📝 `scripts/lib/test-projects.mjs` (+1 -1) ➕ `src/binaryNinjaHeadless/BinaryNinjaHeadlessBridgeProcess.ts` (+464 -0) ➕ `src/binaryNinjaHeadless/BinaryNinjaHeadlessInstallation.ts` (+184 -0) ➕ `src/binaryNinjaHeadless/BinaryNinjaHeadlessOperationRunner.ts` (+483 -0) ➕ `src/binaryNinjaHeadless/BinaryNinjaHeadlessProtocolValues.ts` (+455 -0) ➕ `src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.test.ts` (+327 -0) ➕ `src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.ts` (+288 -0) _...and 10 more files_ </details> ### 📄 Description ## Summary Adds `binary-ninja-headless`, a deep-analysis provider that starts an owned headless Binary Ninja Python interpreter, loads the admitted file read-only after verifying its Raw-view digest, waits for default auto-analysis, and serves REA's native analysis operations from that BinaryView. Refs #1551. Draft for the maintainer scope decision CONTRIBUTING requires for a new provider; it does not ask for integration yet. It complements the attached GUI MCP adapter proposed in #5794: that adapter reads a file the analyst already opened in the GUI; this provider needs no GUI and reproduces analysis from the file alone, but requires a Binary Ninja license edition that permits headless use. ## Problem and expected behavior Binary Ninja users with a headless-capable license cannot point REA at Binary Ninja without keeping a GUI open. With this change, `--provider binary-ninja-headless` (or `REA_ANALYSIS_PROVIDER` / `open_binary.provider_id`) serves `decompile`, `function`, `analyze`, `search`, `trace` and the underlying native operations from an owned, digest-bound headless analysis, with the same Evidence and limitation reporting as the other providers. ## Change and scope - `src/binaryNinjaHeadless/`: capabilities (identity, operations, limitations, effects), filesystem-only installation discovery, protocol values with zod schemas and projections to the shared REA shapes, an owned bridge process (NDJSON over stdio on `spawnOwnedProviderProcess` + `ProviderProcessSupervisor`, reply-size budget, startup deadline, cancellation stops the interpreter), an operation runner, a serial session client, and the `AnalysisProviderCandidate`. - `bridge/binaryninja/rea_binaryninja_bridge.py`: the Python side; one BinaryView per process, Binary Ninja log on stderr, requests validated and answered with stable error codes. - Configuration: `BINARY_NINJA_INSTALL_DIR`, `REA_BINARY_NINJA_PYTHON`, `REA_BINARY_NINJA_STARTUP_TIMEOUT_MS` (additive, optional). - Composition: registered in `src/composition/binary.ts`; catalog, module-boundary and test-project wiring. - Intentionally not included: `list_segments` (segment contract provenance is Hopper/Ghidra only), `list_names`, `procedure_references`, `read_bytes`, doctor integration, a real-provider verifier lane, engine-version commitment in the profile. These are listed in the guide as next steps. - Existing providers are unchanged. Contribution scope: new provider; maintainer scope decision requested in #1551 (pending). No target execution, injection, mutation or protection recovery. ## Contract and boundary impact - Semantic owner and earliest changed stage: new provider adapter `src/binaryNinjaHeadless/` and bridge; application and contract layers unchanged. - Contribution scope fit and linked maintainer decision: pending in #1551. - CLI and MCP/tool-catalog contract: no new tools or schemas; the provider catalog gains one provider entry. - Provider, bridge, target-format, or platform compatibility: Binary Ninja 6.0 headless API; PE, ELF and thin Mach-O executables on x86, x86_64, arm, arm64, mips, powerpc, riscv; Windows bundled interpreter by default, explicit interpreter elsewhere. - Evidence, artifact, provenance, or reconstruction contract: observations carry `cachePolicy: live`, Binary Ninja provenance strings in body/classification/locals, reference kinds reported as unavailable with the observed category, and relationship coverage unknown (callers) / partial-or-complete (callees). - Target selection, authority, upstream behavior, and cleanup details: REA owns the interpreter process; Binary Ninja writes only its own user directory; close releases the view and stops the process; failed startups are not cached. - Generated metadata, package, or installation impact: `package.json#files` ships the bridge script; `test:python` runs its unit test; no installer changes. Expected effects: - [x] Read existing files or captured data. - [x] 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: `src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.test.ts` (availability, target support, profile binding), `src/binaryNinjaHeadless/BinaryNinjaHeadlessSessionClient.test.ts` (launch contract, projections against `functionDossierSchema` and instruction windows, caller mistakes, startup failure attribution, deadline, cancellation, protocol faults, reply bounds, close) with `tests/fixtures/fakeBinaryNinjaBridge.mjs`; `bridge/binaryninja/test_rea_binaryninja_bridge.py` with a fake `binaryninja` module. - Base reproduction or other evidence: real-engine run recorded in `docs/testing.md#binary-ninja-headless-lane` (Windows 11 x64, Binary Ninja 6.0.10905, `where.exe`). - User-visible CLI/MCP output: `rea decompile 'C:\Windows\System32\where.exe' --procedure __wmainCRTStartup --provider binary-ninja-headless --json` returns Pseudo C Evidence with provider `binary-ninja-headless`, profile mode `owned-headless`, and raw engine facts (`core_version` 6.0.10905). - Remaining proof gaps: MCP parity, Linux and macOS hosts, ELF and Mach-O targets, other Binary Ninja releases and license editions, cancellation against the real engine, token/CPU/memory measurements. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run check:fast` — passed (typecheck and lint, 2 tasks successful). - `npm run test:local -- src/binaryNinjaHeadless/BinaryNinjaHeadlessProvider.test.ts src/binaryNinjaHeadless/BinaryNinjaHeadlessSessionClient.test.ts src/config.test.ts` — 111 tests passed. - `python -m unittest bridge/binaryninja/test_rea_binaryninja_bridge.py` (CPython 3.14) — 10 tests passed. - Production CLI against real Binary Ninja 6.0.10905 on Windows 11 x64 with `where.exe`: `decompile`, `function --detail complete`, `analyze`, `search --pattern 'cannot be run'`, `trace --query 'cannot be run'` — all exit 0; every output parsed against the built Evidence schema and its output contract; dossier parsed against `functionDossierSchema`. ## Compatibility, safety, and release - Breaking changes or migration steps: none; all settings are new and optional. - Real Hopper/Ghidra, browser, or OS coverage: existing providers untouched; real Binary Ninja coverage limited to one Windows host. - Package or release metadata impact: one new packaged bridge script; one provider catalog entry. - Security, privacy, process, or containment review: the interpreter runs with the current user's permissions under REA's owned-process supervision, user plugins and settings disabled, no network use by REA; Binary Ninja's own license and user directory behavior is unchanged. ## Author readiness Human owner: @ihabontop - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] 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`. - [x] 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7600
No description provided.