[GH-ISSUE #2300] [Feature] Show one function's pseudocode from several decompiler providers in one call #764

Open
opened 2026-10-15 18:28:06 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @coygeek on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/2300

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

REA integrates three deep providers (Hopper, Ghidra, IDA), but a session binds exactly one. open_binary.provider_id "selects one deep provider ... the binding remains stable until close or an explicit switch" (src/contracts/sessionToolContracts.ts), and BinarySession owns a single active target whose switch "tears down the active provider client" (src/application/binary/BinarySession.ts). procedure_pseudo_code, batch_decompile and analyze_function take no provider argument, and the CLI's --provider accepts one provider ID or auto.

compare_functions accepts analyze_function Evidence from two different providers, but then returns the pseudocode and assembly dimensions as unknown with null digests and only character counts ("Exact text comparison requires one provider identity."), so the texts are not in its result (src/domain/functionComparisonDimensions.ts). It has no CLI command.

To read one function's pseudocode from two providers today, an MCP user opens with provider A, runs analyze_function, re-opens with provider B (which discards the binding to A and imports the target again), runs analyze_function, and lines the dossiers up by hand. A CLI user runs rea decompile PATH PROC --provider A --json and again with --provider B. Nothing checks that both providers resolved the same function, and nothing keeps the outputs together with their provenance.

Use cases

  • Check a doubtful decompilation (switch recovery, types, no-return cuts, calling convention) in a second engine before relying on it.
  • Let an agent cite which provider produced which reading when the providers disagree, instead of silently trusting one.
  • Keep the analyst's current provider binding while taking a quick second opinion.

Desired outcome and success criteria

One CLI command and one MCP call take a target, one procedure selector and two or more provider IDs, and return one entry per provider in request order. Each entry has the provider's identity, version and analysis profile; the entry address and name it resolved; its pseudocode text exactly as produced, or null; its own limitations; and ok or a typed error. The result never ranks the texts or claims they are equivalent.

Success criteria:

  • On a host with two working providers, one call on a fixture returns pseudocode for the same named function from each, with per-provider provenance.
  • An unconfigured or unsupported provider yields an entry with the existing provider-selection rejection code (not_configured, target_format_unsupported and so on), and the other providers' output is still returned. Timeouts and failures report their original reason and do not discard the other entries.
  • When REA cannot show that the resolved entries are the same function (provider addresses are provider-normalized and image bases can differ), function agreement is reported as unknown or mismatched, never assumed.
  • In MCP, binary_session shows the same target, provider binding and run after the call. No provider process started for the comparison survives completion or cancellation.
  • Per-provider Evidence plus derived combined Evidence that cites the target SHA-256 and links each entry; it round-trips through export_evidence_bundle and import_evidence_bundle.
  • Catalog, CLI help and docs/native-investigation.md document the operation. Adapter tests cover success, partial failure, unavailable providers and cancellation, and one real-toolchain run with two real providers covers the success path.

Expected interaction with targets

Read existing files or captured data

Target and scope details (optional)

Local native binaries that REA's existing deep providers already accept. Each requested provider runs as a local subprocess or attached engine, as open_binary already does, and reads the target statically; nothing executes the target. This adds no new provider and uses no network service. Running several providers in one call raises resource use and adds provider lifecycles, so the bounds on concurrency, deadlines and cleanup need maintainer review.

Verification available so far

Idea only; I need help defining checks

Verification details (optional)

Claims above were checked against REA main source and docs at aeee5074d1 (6.4.0). No prototype was run against real providers.

Alternatives considered

  • Extend compare_functions to return both texts when providers differ. This is small, but it still needs two provider runs and a switch or a second session first, so it does not give a one-call result. It could complement this feature.
  • Let one session bind several providers and add provider_id to procedure_pseudo_code and batch_decompile. This is more flexible but breaks the documented one-immutable-provider session contract and is much larger.
  • Document the existing switch-and-reopen sequence as the supported workflow. This needs no code but discards the active binding, repeats the import, and leaves alignment and same-function checks to the agent.

Possible direction

A provider-neutral comparison operation that opens short-lived, comparison-only provider sessions for the requested providers, separate from the bound session. It would reuse the existing pseudocode path and provider-selection rejection codes per provider, and derive one Evidence record linking the per-provider records. Concurrency (sequential or bounded) is open. Non-goals: new providers (Kuna is #1957), semantic or line-level alignment, ranking, and address normalization across builds (#1947, PRs #2124 and #2088).

References

Originally created by @coygeek on GitHub (Oct 12, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/2300 ### Before submitting - [x] I searched the open and closed issues and pull requests for a related proposal. - [x] I understand the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope) must be reviewed before integration; open questions are welcome here. - [x] This request does not include credentials, private samples, or sensitive target data. ### Area Native analysis or decompilation ### Current limitation REA integrates three deep providers (Hopper, Ghidra, IDA), but a session binds exactly one. `open_binary.provider_id` "selects one deep provider ... the binding remains stable until close or an explicit switch" ([src/contracts/sessionToolContracts.ts](https://github.com/morluto/rea/blob/main/src/contracts/sessionToolContracts.ts)), and `BinarySession` owns a single active target whose switch "tears down the active provider client" ([src/application/binary/BinarySession.ts](https://github.com/morluto/rea/blob/main/src/application/binary/BinarySession.ts)). `procedure_pseudo_code`, `batch_decompile` and `analyze_function` take no provider argument, and the CLI's `--provider` accepts one provider ID or `auto`. `compare_functions` accepts `analyze_function` Evidence from two different providers, but then returns the `pseudocode` and `assembly` dimensions as `unknown` with null digests and only character counts ("Exact text comparison requires one provider identity."), so the texts are not in its result ([src/domain/functionComparisonDimensions.ts](https://github.com/morluto/rea/blob/main/src/domain/functionComparisonDimensions.ts)). It has no CLI command. To read one function's pseudocode from two providers today, an MCP user opens with provider A, runs `analyze_function`, re-opens with provider B (which discards the binding to A and imports the target again), runs `analyze_function`, and lines the dossiers up by hand. A CLI user runs `rea decompile PATH PROC --provider A --json` and again with `--provider B`. Nothing checks that both providers resolved the same function, and nothing keeps the outputs together with their provenance. ### Use cases - Check a doubtful decompilation (switch recovery, types, no-return cuts, calling convention) in a second engine before relying on it. - Let an agent cite which provider produced which reading when the providers disagree, instead of silently trusting one. - Keep the analyst's current provider binding while taking a quick second opinion. ### Desired outcome and success criteria One CLI command and one MCP call take a target, one procedure selector and two or more provider IDs, and return one entry per provider in request order. Each entry has the provider's identity, version and analysis profile; the entry address and name it resolved; its pseudocode text exactly as produced, or `null`; its own limitations; and `ok` or a typed error. The result never ranks the texts or claims they are equivalent. Success criteria: - On a host with two working providers, one call on a fixture returns pseudocode for the same named function from each, with per-provider provenance. - An unconfigured or unsupported provider yields an entry with the existing provider-selection rejection code (`not_configured`, `target_format_unsupported` and so on), and the other providers' output is still returned. Timeouts and failures report their original reason and do not discard the other entries. - When REA cannot show that the resolved entries are the same function (provider addresses are provider-normalized and image bases can differ), function agreement is reported as `unknown` or mismatched, never assumed. - In MCP, `binary_session` shows the same target, provider binding and run after the call. No provider process started for the comparison survives completion or cancellation. - Per-provider Evidence plus derived combined Evidence that cites the target SHA-256 and links each entry; it round-trips through `export_evidence_bundle` and `import_evidence_bundle`. - Catalog, CLI help and docs/native-investigation.md document the operation. Adapter tests cover success, partial failure, unavailable providers and cancellation, and one real-toolchain run with two real providers covers the success path. ### Expected interaction with targets Read existing files or captured data ### Target and scope details (optional) Local native binaries that REA's existing deep providers already accept. Each requested provider runs as a local subprocess or attached engine, as `open_binary` already does, and reads the target statically; nothing executes the target. This adds no new provider and uses no network service. Running several providers in one call raises resource use and adds provider lifecycles, so the bounds on concurrency, deadlines and cleanup need maintainer review. ### Verification available so far Idea only; I need help defining checks ### Verification details (optional) Claims above were checked against REA `main` source and docs at aeee5074d124414239b6dd440dc79c26bcbd58a4 (6.4.0). No prototype was run against real providers. ### Alternatives considered - Extend `compare_functions` to return both texts when providers differ. This is small, but it still needs two provider runs and a switch or a second session first, so it does not give a one-call result. It could complement this feature. - Let one session bind several providers and add `provider_id` to `procedure_pseudo_code` and `batch_decompile`. This is more flexible but breaks the documented one-immutable-provider session contract and is much larger. - Document the existing switch-and-reopen sequence as the supported workflow. This needs no code but discards the active binding, repeats the import, and leaves alignment and same-function checks to the agent. ### Possible direction A provider-neutral comparison operation that opens short-lived, comparison-only provider sessions for the requested providers, separate from the bound session. It would reuse the existing pseudocode path and provider-selection rejection codes per provider, and derive one Evidence record linking the per-provider records. Concurrency (sequential or bounded) is open. Non-goals: new providers (Kuna is #1957), semantic or line-level alignment, ranking, and address normalization across builds (#1947, PRs #2124 and #2088). ### References - #2258 and gap 6 in the follow-up comment: https://github.com/morluto/rea/issues/2258#issuecomment-6130226337 - Prior art: [decompiler-explorer/decompiler-explorer](https://github.com/decompiler-explorer/decompiler-explorer) (MIT, the code behind dogbolt.org). It records each decompiler's name, version and revision, and stores for each binary and decompiler either an output or an error, plus analysis time. - #26 (closed) evaluated Ghidra, IDA, Binary Ninja, Rizin and LIEF as providers. #37 (closed) asked for "multiple providers in one investigation" and shipped `compare_functions`. #20 (closed) introduced provider-neutral sessions. - Related, distinct: #1947 (address-normalized text for same-provider comparisons), #2222 (`compare_functions` call coverage). - [docs/mcp-contracts.md](https://github.com/morluto/rea/blob/main/docs/mcp-contracts.md) (one immutable provider per deep open), [docs/ghidra-provider.md](https://github.com/morluto/rea/blob/main/docs/ghidra-provider.md) (cross-provider text is never treated as equal or unequal), [docs/tool-design.md](https://github.com/morluto/rea/blob/main/docs/tool-design.md) (when to compose a workflow).
Author
Owner

@matbrgz commented on GitHub (Oct 12, 2026):

Design & Architectural Boundary Notes

While comparing pseudocode across multiple decompilers (e.g. Hopper vs Ghidra vs IDA) on the same function is highly valuable for reverse engineering fidelity:

  1. Session Boundary Invariant: A BinarySession is designed to own exactly one active provider bridge at a time to prevent port/process contention, excessive RAM overhead (running multiple decompiler engines simultaneously), and state pollution.
  2. Recommended Composition Pattern: Rather than mutating BinarySession into a multi-provider orchestrator, cross-provider comparison is best achieved at the application/workflow or agent layer:
    • Perform independent sessions or query cached Evidence dossiers for the target function produced under each respective provider.
    • Use compare_functions or a dedicated synthesis helper over retained Evidence.
<!-- gh-comment-id:6134280005 --> @matbrgz commented on GitHub (Oct 12, 2026): ### Design & Architectural Boundary Notes While comparing pseudocode across multiple decompilers (e.g. Hopper vs Ghidra vs IDA) on the same function is highly valuable for reverse engineering fidelity: 1. **Session Boundary Invariant:** A `BinarySession` is designed to own exactly one active provider bridge at a time to prevent port/process contention, excessive RAM overhead (running multiple decompiler engines simultaneously), and state pollution. 2. **Recommended Composition Pattern:** Rather than mutating `BinarySession` into a multi-provider orchestrator, cross-provider comparison is best achieved at the application/workflow or agent layer: - Perform independent sessions or query cached `Evidence` dossiers for the target function produced under each respective provider. - Use `compare_functions` or a dedicated synthesis helper over retained Evidence.
Author
Owner

@morluto commented on GitHub (Oct 30, 2026):

Real-provider follow-up on PR #8187 branch, macOS arm64, the same self-built unexecuted Mach-O, Ghidra 12.1.4 and Kuna 1.986:

  1. In one MCP connection, open_binary with Ghidra and analyze_function with summary retained the complete _evaluate dossier. Explicitly opening the same target with Kuna and analyzing _evaluate retained a second dossier; the first reference still resolved after the switch.
  2. compare_functions accepted both retained references. Both providers reported the same name and 0x100000430 in this fixture, but REA correctly returned ambiguous function identity and all eight dimensions unknown: in particular, the providers do not establish a common coordinate commitment or stable Kuna symbol origin, and their text is not a cross-provider invariant.
  3. Exporting the session Evidence bundle preserved both source dossiers and comparison; after close_binary cleared session records, comparison by those IDs failed with actionable evidence_integrity_mismatch. Importing the bundle restored the same comparison Evidence ID. In a fresh MCP server, get_evidence_bundle summary discovered both dossiers and two inspect_analysis_view native-pseudocode pages retrieved each provider's actual text with parent references, coverage and limitations, without reopening a provider.

This refines the original limitation: the current workflow can keep the observations together and recover both texts from retained or bundled Evidence, but it takes a provider switch, two analyses and separate views. A direct composition over already-retained dossiers may therefore be a smaller complementary design than always starting multiple engines; an acquisition workflow would still need separate provider lifecycles, partial failures, cancellation and preservation of the caller's existing binding. Matching names or numeric addresses alone should not be promoted into a cross-provider correspondence. The selected fixture and reported addresses do not establish other mappings or behavioral equivalence. No autonomous agent-selection or performance measurement was performed. Related: #8173.

<!-- gh-comment-id:6533934108 --> @morluto commented on GitHub (Oct 30, 2026): Real-provider follow-up on PR #8187 branch, macOS arm64, the same self-built unexecuted Mach-O, Ghidra 12.1.4 and Kuna 1.986: 1. In one MCP connection, `open_binary` with Ghidra and `analyze_function` with summary retained the complete `_evaluate` dossier. Explicitly opening the same target with Kuna and analyzing `_evaluate` retained a second dossier; the first reference still resolved after the switch. 2. `compare_functions` accepted both retained references. Both providers reported the same name and `0x100000430` in this fixture, but REA correctly returned ambiguous function identity and all eight dimensions unknown: in particular, the providers do not establish a common coordinate commitment or stable Kuna symbol origin, and their text is not a cross-provider invariant. 3. Exporting the session Evidence bundle preserved both source dossiers and comparison; after `close_binary` cleared session records, comparison by those IDs failed with actionable `evidence_integrity_mismatch`. Importing the bundle restored the same comparison Evidence ID. In a fresh MCP server, `get_evidence_bundle` summary discovered both dossiers and two `inspect_analysis_view` native-pseudocode pages retrieved each provider's actual text with parent references, coverage and limitations, without reopening a provider. This refines the original limitation: the current workflow **can** keep the observations together and recover both texts from retained or bundled Evidence, but it takes a provider switch, two analyses and separate views. A direct composition over already-retained dossiers may therefore be a smaller complementary design than always starting multiple engines; an acquisition workflow would still need separate provider lifecycles, partial failures, cancellation and preservation of the caller's existing binding. Matching names or numeric addresses alone should not be promoted into a cross-provider correspondence. The selected fixture and reported addresses do not establish other mappings or behavioral equivalence. No autonomous agent-selection or performance measurement was performed. Related: #8173.
Author
Owner

@morluto commented on GitHub (Oct 31, 2026):

Real cross-provider disagreement and existing manual corroboration

On current REA a989c0e, real Ghidra 12.1.4 and Kuna 1.986 analyzed an explicitly selected, source-built x86-64 ELF containing audit_select. The function has one unconditional write and a conditional return. Kuna rendered a second write on one return path; Ghidra rendered one. Independent instruction listing and REA's Ghidra inspect_native_instruction show the single MOV write at 0x101377 followed by a conditional move and return. Direct Kuna and an ordinary non-IFUNC reduction reproduce the upstream issue Kuna #1355.

The existing MCP workflow can retain both observations: open Ghidra, take an analyze_function summary, explicitly switch to Kuna and take its summary, then use each parent ID with inspect_analysis_view for pseudocode and assembly. Exporting the bundle, closing, and importing in a fresh target-free server reproduced all four normalized views exactly. compare_functions kept identity ambiguous and both text dimensions unknown; it did not attempt to flag the semantic discrepancy, consistent with its contract. The caller can manually inspect the differing pseudocode and instruction Evidence; this is not an automated verdict that one provider is correct.

Coordinates matter even for the same file: the format export reported ELF value 0x1370, Kuna's entry was 0x1370, and Ghidra's was 0x101370. Ghidra address_to_file_offset returned 0x370; independent ELF load headers map the source value to that file offset on this fixture. Kuna's assembly also included a trailing NOP outside Ghidra's displayed function body, so matching entry coordinates does not automatically establish equal extents. Those observations support a manual same-artifact handoff here, not general cross-provider correspondence.

This is a concrete example for the second-opinion task and its Evidence/coordinate tradeoffs, not a request to rank outputs or assert text equality. A provider switch can retire edited session state (#8289); the test made no edits. Fixture and exported bundle hashes stayed unchanged, no target was executed, and no autonomous agent or performance trial was run.

<!-- gh-comment-id:6545462727 --> @morluto commented on GitHub (Oct 31, 2026): ### Real cross-provider disagreement and existing manual corroboration On current REA `a989c0e`, real Ghidra 12.1.4 and Kuna 1.986 analyzed an explicitly selected, source-built x86-64 ELF containing `audit_select`. The function has one unconditional write and a conditional return. Kuna rendered a second write on one return path; Ghidra rendered one. Independent instruction listing and REA's Ghidra `inspect_native_instruction` show the single `MOV` write at `0x101377` followed by a conditional move and return. Direct Kuna and an ordinary non-IFUNC reduction reproduce the upstream issue [Kuna #1355](https://github.com/Noelo-Lab/kuna/issues/1355). The existing MCP workflow can retain both observations: open Ghidra, take an `analyze_function` summary, explicitly switch to Kuna and take its summary, then use each parent ID with `inspect_analysis_view` for pseudocode and assembly. Exporting the bundle, closing, and importing in a fresh target-free server reproduced all four normalized views exactly. `compare_functions` kept identity ambiguous and both text dimensions unknown; it did not attempt to flag the semantic discrepancy, consistent with its contract. The caller can manually inspect the differing pseudocode and instruction Evidence; this is not an automated verdict that one provider is correct. Coordinates matter even for the same file: the format export reported ELF value `0x1370`, Kuna's entry was `0x1370`, and Ghidra's was `0x101370`. Ghidra `address_to_file_offset` returned `0x370`; independent ELF load headers map the source value to that file offset on this fixture. Kuna's assembly also included a trailing NOP outside Ghidra's displayed function body, so matching entry coordinates does not automatically establish equal extents. Those observations support a manual same-artifact handoff here, not general cross-provider correspondence. This is a concrete example for the second-opinion task and its Evidence/coordinate tradeoffs, not a request to rank outputs or assert text equality. A provider switch can retire edited session state (#8289); the test made no edits. Fixture and exported bundle hashes stayed unchanged, no target was executed, and no autonomous agent or performance trial was run.
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#764
No description provided.