rea-agents 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -32
- package/bridge/ghidra/ReaGhidraBridge.java +96 -11
- package/dist/application/ArtifactExtraction.js +1 -1
- package/dist/application/ArtifactInventory/classify.js +42 -0
- package/dist/application/ArtifactInventory/hash.js +43 -0
- package/dist/application/ArtifactInventory/reader.js +41 -0
- package/dist/application/ArtifactInventory/scanCanonical.js +155 -0
- package/dist/application/ArtifactInventory/scanReader.js +124 -0
- package/dist/application/ArtifactInventory/types.js +10 -0
- package/dist/application/ArtifactInventory.js +9 -351
- package/dist/application/AuthorizedArtifactInventory.js +2 -2
- package/dist/application/BinarySession.js +47 -270
- package/dist/application/BinarySessionExecution.js +28 -0
- package/dist/application/BinarySessionOpen.js +39 -0
- package/dist/application/BinarySessionRecords.js +149 -0
- package/dist/application/BinarySessionStatus.js +75 -0
- package/dist/application/CapabilityInventory.js +24 -2
- package/dist/application/ClientRegistrationStatus.js +1 -1
- package/dist/application/CrossVersionInventory.js +8 -2
- package/dist/application/CrossVersionInvestigation.js +1 -23
- package/dist/application/CrossVersionInvestigationCollections.js +23 -0
- package/dist/application/DirectAnalysis.js +47 -44
- package/dist/application/Doctor.js +156 -238
- package/dist/application/DoctorDiagnostics.js +180 -0
- package/dist/application/ElectronBoundaryAnalysis.js +23 -7
- package/dist/application/ElectronBoundaryGraphWindows.js +32 -8
- package/dist/application/EnhancedToolPagination.js +22 -0
- package/dist/application/EnhancedToolTypes.js +4 -0
- package/dist/application/EnhancedTools.js +20 -37
- package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
- package/dist/application/InvestigationWorkspaceStore.js +24 -10
- package/dist/application/JavaScriptArtifactAnalysis.js +45 -6
- package/dist/application/JavaScriptArtifactFiles.js +6 -2
- package/dist/application/JavaScriptArtifactGraphBuilder.js +23 -1
- package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
- package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
- package/dist/application/JavaScriptArtifactGraphFindings.js +54 -8
- package/dist/application/JavaScriptArtifactGraphStructure.js +29 -101
- package/dist/application/JavaScriptArtifactPathResolution.js +269 -0
- package/dist/application/JavaScriptArtifactReconstruction.js +1 -1
- package/dist/application/JavaScriptJsonModules.js +39 -0
- package/dist/application/JavaScriptModuleRelationships.js +262 -0
- package/dist/application/JavaScriptReplayPermission.js +16 -0
- package/dist/application/JavaScriptReplayService.js +182 -156
- package/dist/application/LinuxHopper.js +10 -0
- package/dist/application/MacHopper.js +22 -11
- package/dist/application/NodeRuntimeCharacterizationService.js +196 -0
- package/dist/application/PermissionAuthority.js +106 -63
- package/dist/application/ProcessCaptureCapability.js +1 -1
- package/dist/application/ProcessCapturePermission.js +13 -0
- package/dist/application/ProcessCli.js +2 -12
- package/dist/application/ProcessHarness.js +1 -1
- package/dist/application/ProjectPermissionStore.js +48 -9
- package/dist/application/RealHopperAssertions.js +76 -0
- package/dist/application/ReconstructionCoverageService.js +69 -0
- package/dist/application/ReconstructionCoverageWorkspaceStore.js +31 -0
- package/dist/application/RuntimeExecutableDiagnostics.js +172 -0
- package/dist/application/Setup.js +147 -259
- package/dist/application/SetupClientConfiguration.js +220 -0
- package/dist/application/SetupClients.js +24 -2
- package/dist/application/SetupPlan.js +123 -12
- package/dist/application/SetupSkill.js +26 -12
- package/dist/application/SupportedClients.js +1 -0
- package/dist/application/Uninstall.js +6 -3
- package/dist/application/WindowsCapabilities.js +86 -0
- package/dist/artifacts/AsarArtifactReader.js +11 -0
- package/dist/browser/BrowserProcessStartup.js +88 -0
- package/dist/browser/CdpCaptureDocuments.js +12 -8
- package/dist/browser/CdpCaptureEventBodyShapes.js +75 -0
- package/dist/browser/CdpCaptureEventHandlers.js +336 -0
- package/dist/browser/CdpCaptureEventHelpers.js +71 -0
- package/dist/browser/CdpCaptureEventState.js +1 -0
- package/dist/browser/CdpCaptureEventTypes.js +1 -0
- package/dist/browser/CdpCaptureEvents.js +29 -496
- package/dist/browser/CdpObservationSession.js +51 -8
- package/dist/browser/CdpPageCapture.js +12 -133
- package/dist/browser/CdpPageCaptureScripts.js +97 -0
- package/dist/browser/CdpPageCaptureWorkers.js +46 -0
- package/dist/browser/CdpWebMcpDiscovery.js +38 -14
- package/dist/browser/PngVisualDiff.js +9 -2
- package/dist/catalogIdentity.js +4 -0
- package/dist/cli/artifactCommands.js +82 -0
- package/dist/cli/coreAnalysisCommands.js +232 -0
- package/dist/cli/managedCommands.js +397 -0
- package/dist/cli/managedProjectGraphCommand.js +24 -0
- package/dist/cli/options.js +9 -0
- package/dist/cli/setupCommands.js +108 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utilityCommands.js +122 -0
- package/dist/cli.js +10 -768
- package/dist/cliApplicationCommands.js +118 -4
- package/dist/cliBrowserAdvancedCommands.js +73 -16
- package/dist/cliBrowserCommands.js +39 -115
- package/dist/cliCommandNames.js +4 -0
- package/dist/cliElectronCommands.js +33 -62
- package/dist/cliEvidenceCommands.js +13 -2
- package/dist/cliInvestigationCommands.js +53 -10
- package/dist/cliObservationOptions.js +137 -0
- package/dist/cliPolicyCommands.js +80 -46
- package/dist/cliSetup.js +289 -0
- package/dist/config/environment.js +107 -0
- package/dist/config/parseConfig.js +228 -0
- package/dist/config/parsers.js +68 -0
- package/dist/config/permissions.js +30 -0
- package/dist/config/types.js +1 -0
- package/dist/config.js +1 -375
- package/dist/contracts/applicationToolContracts.js +134 -0
- package/dist/contracts/managedToolContracts.js +1 -1
- package/dist/contracts/managedWorkflowToolContracts.js +3 -3
- package/dist/contracts/providerSelection.js +2 -0
- package/dist/contracts/toolContracts.js +2 -2
- package/dist/contracts/toolEffects.js +14 -0
- package/dist/contracts/toolOutputSchemaGroups.js +232 -0
- package/dist/contracts/toolOutputSchemaPrimitives.js +327 -0
- package/dist/contracts/toolOutputSchemas.js +2 -550
- package/dist/domain/analysisErrorPresentation.js +234 -0
- package/dist/domain/analysisErrorProjection.js +284 -0
- package/dist/domain/artifactComparison.js +34 -15
- package/dist/domain/binaryTarget.js +87 -37
- package/dist/domain/browserObservation.js +1 -285
- package/dist/domain/browserObservationSchemas.js +286 -0
- package/dist/domain/electronStaticAnalysisBrowser.js +14 -2
- package/dist/domain/errors.js +4 -486
- package/dist/domain/functionComparison.js +4 -165
- package/dist/domain/functionComparisonDimensions.js +164 -0
- package/dist/domain/javascriptApplicationVersionItems.js +18 -6
- package/dist/domain/javascriptApplicationVersionKeys.js +8 -8
- package/dist/domain/javascriptExportInstrumentation.js +97 -0
- package/dist/domain/javascriptFeatureTraversal.js +19 -7
- package/dist/domain/javascriptRuntimeStaticCandidates.js +3 -1
- package/dist/domain/javascriptSemanticAnalysis.js +386 -0
- package/dist/domain/javascriptSemanticIr.js +30 -0
- package/dist/domain/javascriptSemanticProjection.js +366 -0
- package/dist/domain/javascriptSemanticState.js +40 -0
- package/dist/domain/javascriptSemanticTraversal.js +22 -0
- package/dist/domain/javascriptSemanticValues.js +352 -0
- package/dist/domain/javascriptStaticAnalysis.js +5 -221
- package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +71 -2
- package/dist/domain/knownPageCoverage.js +21 -0
- package/dist/domain/managedApplicationGraph.js +14 -364
- package/dist/domain/managedApplicationGraphCoverage.js +170 -0
- package/dist/domain/managedApplicationGraphNodeCoverage.js +6 -0
- package/dist/domain/managedApplicationGraphNodes.js +336 -0
- package/dist/domain/managedArtifact.js +16 -8
- package/dist/domain/managedMemberComparison.js +37 -391
- package/dist/domain/managedMemberComparisonCoverage.js +72 -0
- package/dist/domain/managedMemberComparisonMatch.js +356 -0
- package/dist/domain/managedNativeVerification.js +27 -389
- package/dist/domain/managedNativeVerificationMatch.js +272 -0
- package/dist/domain/managedNativeVerificationSchemas.js +141 -0
- package/dist/domain/managedReconstruction.js +82 -69
- package/dist/domain/managedRuntimeCorrelation.js +12 -3
- package/dist/domain/nodeRuntimeCharacterization.js +66 -0
- package/dist/domain/permissionPolicy.js +2 -0
- package/dist/domain/reconstructionCoverage.js +387 -0
- package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
- package/dist/domain/reconstructionVerificationSchemas.js +8 -0
- package/dist/domain/runtimeCharacterization.js +85 -0
- package/dist/domain/webBundleAnalyzer.js +3 -409
- package/dist/domain/webBundleAnalyzerAst.js +77 -0
- package/dist/domain/webBundleAnalyzerInspection.js +307 -0
- package/dist/domain/webBundleAnalyzerResult.js +120 -0
- package/dist/dotnet/ManagedArtifactInspector.js +50 -29
- package/dist/dotnet/ManagedMemberInspector.js +51 -785
- package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
- package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
- package/dist/dotnet/ManagedMemberRows.js +120 -0
- package/dist/dotnet/ManagedMetadataInventory.js +42 -306
- package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
- package/dist/dotnet/ManagedMetadataLayout.js +48 -111
- package/dist/dotnet/ManagedMetadataRowSizes.js +54 -0
- package/dist/dotnet/ManagedMethodBodyReader.js +143 -0
- package/dist/dotnet/ManagedNativeBoundaryHelpers.js +311 -0
- package/dist/dotnet/ManagedNativeBoundaryInspector.js +102 -350
- package/dist/dotnet/ManagedPeReader.js +59 -28
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraClient.js +76 -91
- package/dist/ghidra/GhidraClientStartup.js +29 -0
- package/dist/ghidra/GhidraClientWire.js +34 -0
- package/dist/ghidra/GhidraDefaults.js +1 -1
- package/dist/ghidra/GhidraDiagnostics.js +6 -1
- package/dist/ghidra/GhidraInstallation.js +20 -15
- package/dist/ghidra/GhidraLauncher.js +93 -29
- package/dist/ghidra/GhidraProvider.js +61 -161
- package/dist/ghidra/GhidraProviderCapabilities.js +173 -0
- package/dist/ghidra/GhidraSessionValues.js +2 -0
- package/dist/ghidra/GhidraSocketConnection.js +44 -7
- package/dist/ghidra/GhidraTargetSnapshot.js +30 -0
- package/dist/ghidra/GhidraTransport.js +71 -0
- package/dist/identity.js +3 -2
- package/dist/main/messages.js +5 -0
- package/dist/main/reload.js +49 -0
- package/dist/main/shutdown.js +25 -0
- package/dist/main/startup.js +14 -0
- package/dist/main/state.js +26 -0
- package/dist/main/transport.js +61 -0
- package/dist/main/types.js +1 -0
- package/dist/main.js +35 -146
- package/dist/process/PrivateRuntimeRoot.js +3 -2
- package/dist/process/ProcessOwnership.js +35 -0
- package/dist/process/ProviderProcess.js +2 -0
- package/dist/replay/JavaScriptReplayWorker.js +64 -50
- package/dist/replay/LinuxJavaScriptReplayRunner.js +173 -390
- package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
- package/dist/replay/ReplayOutcome.js +95 -0
- package/dist/replay/ReplayProcessLifecycle.js +71 -0
- package/dist/server/ProcessCaptureElicitation.js +157 -0
- package/dist/server/createServer.js +119 -54
- package/dist/server/registerApplicationTools/characterization.js +57 -0
- package/dist/server/registerApplicationTools/compareVersions.js +34 -0
- package/dist/server/registerApplicationTools/controlledReplay.js +38 -0
- package/dist/server/registerApplicationTools/coverage.js +84 -0
- package/dist/server/registerApplicationTools/helpers.js +42 -0
- package/dist/server/registerApplicationTools/traceFeature.js +26 -0
- package/dist/server/registerApplicationTools/types.js +1 -0
- package/dist/server/registerApplicationTools.js +10 -112
- package/dist/server/registerBrowserTools.js +59 -83
- package/dist/server/registerElectronTools.js +31 -46
- package/dist/server/registerEnhancedTools.js +34 -42
- package/dist/server/registerEvidenceResources.js +54 -0
- package/dist/server/registerInvestigationTools/helpers.js +74 -0
- package/dist/server/registerInvestigationTools/types.js +1 -0
- package/dist/server/registerInvestigationTools.js +83 -116
- package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +65 -0
- package/dist/server/registerManagedWorkflowTools/contract.js +8 -0
- package/dist/server/registerManagedWorkflowTools/evidence.js +43 -0
- package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +39 -0
- package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +39 -0
- package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +52 -0
- package/dist/server/registerManagedWorkflowTools/types.js +1 -0
- package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +75 -0
- package/dist/server/registerManagedWorkflowTools.js +10 -274
- package/dist/server/registerOfficialTools.js +73 -59
- package/dist/server/registerSessionRecordTools.js +137 -0
- package/dist/server/registerSessionStatusTool.js +2 -1
- package/dist/server/registerSessionTools.js +60 -164
- package/dist/server/sessionAvailabilityPolicy.js +10 -0
- package/dist/server/toolRegistrationOptions.js +101 -3
- package/dist/server/toolResult.js +5 -0
- package/package.json +10 -11
- package/skills/{rea-analysis → reverse-engineer-anything}/SKILL.md +20 -7
- package/scripts/prepare-node-pty.mjs +0 -35
- package/scripts/rebuild-native.mjs +0 -22
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
See a feature in an app that you want in your own product? Give the app to your agent—even without its source code. With REA, the agent can investigate the feature, explain how it works, show its evidence, and build a version adapted to your stack and requirements.
|
|
32
32
|
|
|
33
|
-
REA gives agents one consistent way to investigate software. Today that includes deep native analysis and function dossiers through Hopper or bring-your-own Ghidra on Linux, execution-free managed PE/CLI triage
|
|
33
|
+
REA gives agents one consistent way to investigate software. Today that includes deep native analysis and function dossiers through Hopper or bring-your-own Ghidra on Linux, plus an experimental Windows x64 Ghidra P0 for approved native PE applications; execution-free managed PE/CLI triage; reproducible Evidence v2 records; controlled process capture; passive website and Electron observation; bounded JavaScript/source-map reconstruction; and a versioned domain graph for connecting JavaScript application layers without confusing static inference with runtime observation. The longer-term toolkit extends the same agent workflow to APIs, protocols, mobile artifacts, firmware, richer runtime behavior, and differences between versions.
|
|
34
34
|
|
|
35
35
|
Reverse engineering normally makes the operator choose a tool, learn its API, move evidence between programs, and decide what to inspect next. REA gives that work to the agent through commands, skills, structured results, and repeatable investigation workflows.
|
|
36
36
|
|
|
@@ -85,17 +85,41 @@ REA shows how it reached its conclusions. It does not claim to recover original
|
|
|
85
85
|
|
|
86
86
|
## Quick start
|
|
87
87
|
|
|
88
|
-
###
|
|
88
|
+
### Run setup — recommended
|
|
89
89
|
|
|
90
90
|
```bash
|
|
91
|
-
|
|
92
|
-
rea setup
|
|
91
|
+
npx rea-agents setup
|
|
93
92
|
```
|
|
94
93
|
|
|
95
|
-
|
|
94
|
+
The npm package-runner prompt, when shown, approves downloading REA for this
|
|
95
|
+
invocation; it does not approve any setup changes. The REA wizard separately
|
|
96
|
+
shows its complete plan and asks before applying it. Setup does not update
|
|
97
|
+
Homebrew, Node.js, or npm. `npx rea-agents setup` opens with the work it
|
|
98
|
+
enables: investigate local apps from an agent, recover evidence through a
|
|
99
|
+
deep-analysis provider, and reuse REA's guided workflow. It summarizes the
|
|
100
|
+
detected agents, then asks which independent capabilities to set up: coding-agent
|
|
101
|
+
access through MCP, the shared investigation skill, and—when needed—the Hopper
|
|
102
|
+
provider. Nothing is preselected. Choosing MCP access opens a second empty
|
|
103
|
+
checklist for the specific detected agents that should receive a registration.
|
|
104
|
+
|
|
105
|
+
REA keeps the journey inline so its history remains in the terminal. Selecting
|
|
106
|
+
a capability does not select every detected target or authorize a change.
|
|
107
|
+
Before anything changes, REA validates existing configuration, prints exact
|
|
108
|
+
paths and external effects, and asks for final approval with **No** as the
|
|
109
|
+
default. The screen keeps the available keys visible while you choose; Ctrl-C
|
|
110
|
+
and declining leave the system unchanged.
|
|
96
111
|
|
|
97
112
|
REA detects Claude Code, Claude Desktop, Codex, Cursor, Gemini CLI, Windsurf, and Devin. It configures the first six when detected; Devin is reported but left unchanged because it has no documented local MCP configuration boundary. Registrations are additive, backup-first, and read back after writing. You can safely rerun setup.
|
|
98
113
|
|
|
114
|
+
Use `rea setup --dry-run` to inspect the plan, repeat `--client` to select exact
|
|
115
|
+
agents, and `--accessible` for sequential vertical prompts. Machine output
|
|
116
|
+
remains available through `--json`; prompt UI and progress go to stderr.
|
|
117
|
+
|
|
118
|
+
After a successful setup, REA reports the capabilities now ready to use and a
|
|
119
|
+
concrete next step, such as restarting a configured agent before asking it to
|
|
120
|
+
investigate an application. It does not claim an integration or provider is
|
|
121
|
+
ready unless setup and its final diagnostic check verified it.
|
|
122
|
+
|
|
99
123
|
An optional curl wrapper installs the same CLI package and starts setup only when a terminal is available:
|
|
100
124
|
|
|
101
125
|
```bash
|
|
@@ -117,9 +141,9 @@ Review the setup plan, approve it if appropriate, then describe the app or featu
|
|
|
117
141
|
### From Terminal — no installation
|
|
118
142
|
|
|
119
143
|
```bash
|
|
120
|
-
npx
|
|
121
|
-
npx -y rea-agents doctor
|
|
122
|
-
npx -y rea-agents analyze /Applications/Notes.app
|
|
144
|
+
npx rea-agents setup
|
|
145
|
+
npx -y rea-agents@latest doctor
|
|
146
|
+
npx -y rea-agents@latest analyze /Applications/Notes.app
|
|
123
147
|
```
|
|
124
148
|
|
|
125
149
|
Review the setup plan before confirming it. Restart a configured agent so it loads REA.
|
|
@@ -146,10 +170,16 @@ an unrelated global package.
|
|
|
146
170
|
|
|
147
171
|
Choose either the no-install commands or the global installation. You do not need both.
|
|
148
172
|
|
|
173
|
+
`npm install rea-agents` without `--global` installs `rea` only into the
|
|
174
|
+
current project's `node_modules/.bin`; it does not add `rea` to your shell
|
|
175
|
+
`PATH`. Use the `npx` commands above for one-off runs or `--global` when you
|
|
176
|
+
want a shell-visible `rea` command.
|
|
177
|
+
|
|
149
178
|
### Requirements
|
|
150
179
|
|
|
151
180
|
- macOS 12 or newer
|
|
152
181
|
- Ubuntu 24.04+, Fedora 41+, or 64-bit Arch Linux
|
|
182
|
+
- Windows x64 for the experimental, Ghidra-only native PE P0 boundary
|
|
153
183
|
- Node.js 22.19+ or 24.11+ (including newer releases)
|
|
154
184
|
- npm; REA does not require or install a particular npm version
|
|
155
185
|
|
|
@@ -158,7 +188,7 @@ Deep binary operations use [Hopper](https://www.hopperapp.com/), a separate desk
|
|
|
158
188
|
If something is not working, run:
|
|
159
189
|
|
|
160
190
|
```bash
|
|
161
|
-
npx -y rea-agents doctor
|
|
191
|
+
npx -y rea-agents@latest doctor
|
|
162
192
|
```
|
|
163
193
|
|
|
164
194
|
`rea doctor --json` is read-only and distinguishes unsupported hosts, missing dependencies, a missing local analysis engine, configuration drift, and healthy checks. Paid-license activation is optional: on Linux, REA runs the supported Hopper demo build on a private Xvfb display and selects Hopper's offered demo mode for each analysis session.
|
|
@@ -188,7 +218,7 @@ REA defaults `HOPPER_LAUNCHER_PATH` to `/Applications/Hopper Disassembler.app/Co
|
|
|
188
218
|
|
|
189
219
|
### Ghidra read-only analysis provider
|
|
190
220
|
|
|
191
|
-
The
|
|
221
|
+
The Ghidra adapter supports the exact official Ghidra 12.1.2 release with a 64-bit full JDK 21 on Linux x64. It also provides an experimental Windows x64 P0 limited to approved native x86-64 PE applications. Download and extract those projects yourself, then configure absolute paths:
|
|
192
222
|
|
|
193
223
|
```bash
|
|
194
224
|
export GHIDRA_INSTALL_DIR=/absolute/path/to/ghidra_12.1.2_PUBLIC
|
|
@@ -200,7 +230,9 @@ rea providers --json
|
|
|
200
230
|
|
|
201
231
|
Doctor distinguishes missing configuration, a bad installation root, the wrong Ghidra or Java version, a JRE without `javac`, a missing `support/analyzeHeadless`, and an unsupported platform or architecture. Approved setup only copies the verified non-secret paths into detected MCP registrations; it does not modify the Ghidra installation or install/download Ghidra or Java.
|
|
202
232
|
|
|
203
|
-
|
|
233
|
+
On Windows, set the same variables in PowerShell and run `rea doctor --json`; automated `rea setup` and Hopper installation remain unavailable. The P0 target boundary rejects DLLs, managed PE files, non-x86-64 images, mutable/hostile inputs, and non-PE formats. See the [Windows Ghidra P0 operations guide](docs/windows-ghidra-p0.md) for registration, exact limitations, CI evidence, and acceptance gates.
|
|
234
|
+
|
|
235
|
+
REA loads its packaged Java `HeadlessScript` with `-scriptPath`, copies and digest-verifies the target in an ephemeral runtime, enables `-readOnly` and `-deleteProject`, caps auto-analysis at 300 seconds with two CPUs and a 2 GiB Java heap, and authenticates every request. Linux uses a mode-0600 Unix socket. Windows P0 uses token-authenticated IPv4 loopback and a token-free endpoint record because Node path-based IPC does not connect to Java AF_UNIX sockets on Windows. The bridge verifies Ghidra's imported-byte SHA-256 before serving any operation.
|
|
204
236
|
|
|
205
237
|
The Ghidra adapter declares 18 direct and enhanced operations. Its ten inventory operations are `list_documents`, `list_procedures`, `list_strings`, `list_names`, `list_segments`, `address_name`, `procedure_address`, `resolve_containing_procedure`, `search_procedures`, and `search_strings`. It also admits `procedure_info`, `procedure_pseudo_code`, `procedure_assembly`, `procedure_callers`, `procedure_callees`, `procedure_references`, `xrefs`, and `analyze_function`. These capabilities enable the shared Swift/Objective-C inventory workflows, `binary_overview`, `batch_decompile`, `get_call_graph`, `find_xrefs_to_name`, `trace_feature`, and complete function dossiers. Default-space addresses are lowercase `0x` hexadecimal. Other spaces, including `EXTERNAL`, use `<percent-encoded-space>:0x<hex>`. Symbol results identify primary, dynamic, external, type, and source facts; procedures distinguish external functions and thunks; strings identify charset, missing-terminator state, byte length, and value truncation; memory-block ends are exclusive and permissions come directly from Ghidra.
|
|
206
238
|
|
|
@@ -208,6 +240,8 @@ The bridge serves operations only after auto-analysis completes. Each Program ow
|
|
|
208
240
|
|
|
209
241
|
`npm run verify:ghidra` compiles source-owned x86-64 debug and stripped ELF, AArch64 ELF, x86-64 PE, and x86-64 Mach-O fixtures. Against real Ghidra 12.1.2 it validates every admitted operation, direct and indirect calls, imports/exports/thunks, typed references, strings/xrefs, multi-block CFG, cancellation, deadlines, concurrency, malformed inputs, and complete process/project cleanup. Set `REA_CC`, `REA_CLANG`, or `REA_LLD_LINK` only when the corresponding compiler command is not on `PATH`.
|
|
210
242
|
|
|
243
|
+
`npm run verify:ghidra:windows` uses a deterministic source-owned native x86-64 PE application and requires all 18 operations, target/snapshot/import digest linkage, authenticated loopback transport, and cleanup on a controlled Windows x64 Ghidra 12.1.2 runner. This proof does not establish Job Object ownership, private DACLs, or reparse-point-safe authority.
|
|
244
|
+
|
|
211
245
|
To remove only REA-owned MCP registrations and the managed skill:
|
|
212
246
|
|
|
213
247
|
```bash
|
|
@@ -331,14 +365,14 @@ REA handles the app analysis in steps 1–5. The agent performs step 6 with its
|
|
|
331
365
|
| Managed PE/CLI | 8 | PE/CLI identity, metadata members, CIL hashes, P/Invoke/native-boundary declarations and verification, application-graph projection, decompiler reconstruction import, token remapping, runtime-correlation plans, and version comparison |
|
|
332
366
|
| Browser observation | 8 | exact-origin CDP capture, bundle and source-map analysis, WebMCP discovery, session timelines, capture diff, and visual evidence |
|
|
333
367
|
| Electron analysis | 4 | passive root-confined observation, bounded static application mapping, and evidence-backed static/runtime reconciliation |
|
|
334
|
-
| Application workflows |
|
|
368
|
+
| Application workflows | 7 | bounded cross-layer traces, unique-only version matching, approved Linux-isolated extracted-module replay, managed-runtime characterization, and reconstruction coverage closure |
|
|
335
369
|
| Workspace and observation | 18 | target lifecycle, Evidence v2 bundles, process/artifact/function comparison, evidence-linked residual-unknown lifecycle |
|
|
336
370
|
|
|
337
371
|
The public interface describes what the agent is trying to learn. Providers decide how to answer. macOS utilities handle common semantic inspection without launching Hopper; Hopper handles deeper native analysis; the process harness implements controlled behavioral capture.
|
|
338
372
|
|
|
339
373
|
## Current status
|
|
340
374
|
|
|
341
|
-
REA is already useful for native application, browser, and Electron investigation on supported macOS and Linux hosts:
|
|
375
|
+
REA is already useful for native application, browser, and Electron investigation on supported macOS and Linux hosts, plus the bounded Windows Ghidra P0 described above:
|
|
342
376
|
|
|
343
377
|
- Open Mach-O, ELF, PE, `.app`, ZIP, APK, IPA, ASAR, plist, JavaScript, source-map, and generic analysis-database targets; Hopper remains the only adapter that accepts legacy `.hop` databases.
|
|
344
378
|
- Discover deep-analysis candidates without starting them, choose deterministically, and retain one immutable provider/profile binding until an explicit switch or close; provider failures never trigger transparent fallback.
|
|
@@ -348,7 +382,11 @@ REA is already useful for native application, browser, and Electron investigatio
|
|
|
348
382
|
- Reconstruct bounded static package, entrypoint, Webpack/Rspack module, import, worker, endpoint, storage, source-map, BrowserWindow, preload, contextBridge, IPC, utility-process, and native-add-on structure from an approved local directory or ASAR through `analyze_javascript_application` or `rea analyze-javascript-application`. The AST-only [application service](docs/javascript-artifact-reconstruction.md) never executes bootstrap code, pairs only unique exact literal IPC channels, and reports dynamic or ambiguous channels as unresolved.
|
|
349
383
|
- Reconcile that static graph with existing passive web or Electron Evidence through `reconcile_javascript_runtime` or `rea reconcile-javascript-runtime`. Exact captured bytes outrank caller-declared file/URL mappings; target, frame, script, worker, cache, and asset ambiguity stays explicit, source-map authority stays separate, and a module resident in an observed bundle is never reported as executed. See [JavaScript static/runtime reconciliation](docs/javascript-runtime-reconciliation.md).
|
|
350
384
|
- Trace a literal route, string, API, IPC channel, module, or native export through authenticated application Evidence with explicit traversal bounds, then hand exact native artifact digests and requested exports to retained Ghidra or Hopper Evidence without automatic provider switching. Compare application versions using unique-only digest, source-map, structural, and semantic tiers; duplicate, incomplete, and truncated matches stay unknown. See [cross-layer JavaScript application workflows](docs/javascript-application-workflows.md).
|
|
351
|
-
- Classify PE/CLI managed artifacts with `inspect_managed_artifact` / `rea inspect-managed-artifact`, inspect bounded metadata members, signatures,
|
|
385
|
+
- Classify PE/CLI managed artifacts with `inspect_managed_artifact` / `rea inspect-managed-artifact`, inspect bounded metadata members, signatures, raw CIL hashes, limited decoded-instruction-tuple v1 hashes, separately reported exception regions, call edges, and field-access anchors with `inspect_managed_members` / `rea inspect-managed-members`, inventory declared ModuleRef/ImplMap/PInvoke and non-IL method boundary indicators with `inspect_managed_native_boundaries` / `rea inspect-managed-native-boundaries`, then compare two authenticated member observations with `compare_managed_members` / `rea compare-managed-members`. `verify_managed_native_boundaries` / `rea verify-managed-native-boundaries` checks managed P/Invoke declarations against authenticated native export or function Evidence while keeping verified, inferred, contradicted, and unresolved states distinct. The comparison treats build-local tokens as build-local and uses unique decoded-CIL/signature and structural method-shape tiers, never names alone; the v1 tuple hash does not itself resolve tokens or fully commit control flow. `project_managed_application_graph` / `rea project-managed-application-graph` projects authenticated managed artifact/member/native-boundary Evidence into the existing application graph for cross-layer feature tracing. `import_managed_reconstruction` / `rea import-managed-reconstruction` admits user-supplied decompiler C#/IL/pseudocode as analyst inference only after exact artifact SHA-256, MVID, signature, and the shipped v1 decoded-IL commitment match. Separately, `plan_managed_runtime_correlation` / `rea plan-managed-runtime-correlation` can admit a default-disabled, permission-gated runtime-correlation plan locked to the same build evidence. These paths never load the assembly, resolve CLR dependencies, execute target code, run a decompiler, or translate managed tokens into native addresses; full normalized-CIL v2 semantics, native-body bridge mapping, and an actual runtime executor remain future managed-code contracts.
|
|
386
|
+
- Configure `REA_ILSPY_CMD_PATH=/absolute/path/to/ilspycmd` only when you want
|
|
387
|
+
doctor and `verify:managed` to inspect a bring-your-own ILSpy command as a
|
|
388
|
+
real reconstruction oracle. REA does not install ILSpy and does not treat
|
|
389
|
+
decompiler text as canonical metadata or CIL observation.
|
|
352
390
|
- Traverse content-addressed artifact graphs without extraction; on macOS, read-only DMG traversal additionally requires `native_mount_approved: true` and `REA_ARTIFACT_NATIVE_MOUNT_ENABLED=true`. Materialize only approved occurrences into absent output roots.
|
|
353
391
|
- Build bounded function dossiers with pseudocode, assembly, CFG edges, comments, calls, references, strings, and names.
|
|
354
392
|
- Search and trace features across symbols, strings, metadata, references, and call paths.
|
|
@@ -423,7 +461,7 @@ Setup detects Claude Code, Claude Desktop, Codex, Cursor, Gemini CLI, Windsurf,
|
|
|
423
461
|
"mcpServers": {
|
|
424
462
|
"rea": {
|
|
425
463
|
"command": "npx",
|
|
426
|
-
"args": ["-y", "rea-agents", "mcp"]
|
|
464
|
+
"args": ["-y", "rea-agents@latest", "mcp"]
|
|
427
465
|
}
|
|
428
466
|
}
|
|
429
467
|
}
|
|
@@ -464,20 +502,20 @@ The CLI and MCP server use the same application workflows and evidence contracts
|
|
|
464
502
|
The agent workflow above is the easiest way to use REA. For a one-off overview from the Terminal:
|
|
465
503
|
|
|
466
504
|
```bash
|
|
467
|
-
npx -y rea-agents analyze /Applications/Notes.app
|
|
468
|
-
npx -y rea-agents inspect /Applications/Notes.app
|
|
469
|
-
npx -y rea-agents inspect /Applications/Notes.app --detail detailed --limit 20
|
|
470
|
-
npx -y rea-agents search /Applications/Notes.app "offline"
|
|
471
|
-
npx -y rea-agents function /Applications/Notes.app 0x1000
|
|
472
|
-
npx -y rea-agents xrefs /Applications/Notes.app 0x1000
|
|
473
|
-
npx -y rea-agents trace /Applications/Notes.app "offline"
|
|
474
|
-
npx -y rea-agents compare /absolute/path/to/left-evidence.json /absolute/path/to/right-evidence.json
|
|
475
|
-
npx -y rea-agents investigate-versions /path/to/v1 /path/to/v2 /absolute/path/to/evidence/releases.json --yes
|
|
476
|
-
npx -y rea-agents capabilities
|
|
477
|
-
npx -y rea-agents providers
|
|
505
|
+
npx -y rea-agents@latest analyze /Applications/Notes.app
|
|
506
|
+
npx -y rea-agents@latest inspect /Applications/Notes.app
|
|
507
|
+
npx -y rea-agents@latest inspect /Applications/Notes.app --detail detailed --limit 20
|
|
508
|
+
npx -y rea-agents@latest search /Applications/Notes.app "offline"
|
|
509
|
+
npx -y rea-agents@latest function /Applications/Notes.app 0x1000
|
|
510
|
+
npx -y rea-agents@latest xrefs /Applications/Notes.app 0x1000
|
|
511
|
+
npx -y rea-agents@latest trace /Applications/Notes.app "offline"
|
|
512
|
+
npx -y rea-agents@latest compare /absolute/path/to/left-evidence.json /absolute/path/to/right-evidence.json
|
|
513
|
+
npx -y rea-agents@latest investigate-versions /path/to/v1 /path/to/v2 /absolute/path/to/evidence/releases.json --yes
|
|
514
|
+
npx -y rea-agents@latest capabilities
|
|
515
|
+
npx -y rea-agents@latest providers
|
|
478
516
|
```
|
|
479
517
|
|
|
480
|
-
Run `npx -y rea-agents --help` for direct decompilation, bounded search and
|
|
518
|
+
Run `npx -y rea-agents@latest --help` for direct decompilation, bounded search and
|
|
481
519
|
other options. `analyze` and `inspect` share the same overview workflow;
|
|
482
520
|
`function`, `xrefs`, and `trace` return the same Evidence v2 envelopes as MCP.
|
|
483
521
|
|
|
@@ -566,6 +604,10 @@ environment allowlist in `REA_PROCESS_ALLOWED_ENV_JSON`. Because the current PTY
|
|
|
566
604
|
adapter uses host networking, it also requires
|
|
567
605
|
`REA_PROCESS_ALLOW_EXTERNAL_NETWORK=true`.
|
|
568
606
|
|
|
607
|
+
Set `REA_PROCESS_CAPTURE_AUTO_GRANT=false` to configure those process-capture
|
|
608
|
+
limits as a ceiling without implicitly granting them. This mode remains
|
|
609
|
+
fail-closed until a narrower grant is established.
|
|
610
|
+
|
|
569
611
|
Capture a scenario or compare two saved Process Capture v4 Evidence records:
|
|
570
612
|
|
|
571
613
|
```bash
|
|
@@ -579,18 +621,22 @@ first terminal, interaction, exit, filesystem, protocol, process, or shim
|
|
|
579
621
|
divergence. See [Process Capture v4](docs/process-capture.md) for scenario
|
|
580
622
|
fields, command-shim replay, checkpoint triggers, limits, and safety behavior.
|
|
581
623
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
624
|
+
REA installs a prebuilt PTY backend for supported macOS, Linux, and Windows
|
|
625
|
+
architectures. If the capability check reports that the backend is unavailable,
|
|
626
|
+
reinstall REA for the current platform and architecture.
|
|
585
627
|
|
|
586
628
|
ASAR inventory verifies Electron integrity metadata for both archive entries
|
|
587
629
|
and `.asar.unpacked` companion files. Integrity failures identify the logical
|
|
588
630
|
path, declared and calculated SHA-256 values, and whether the entry was
|
|
589
|
-
unpacked; REA does not silently accept the mismatched artifact.
|
|
631
|
+
unpacked; REA does not silently accept the mismatched artifact. If a supplied
|
|
632
|
+
ASAR declares unpacked companion bytes that are absent from the local artifact
|
|
633
|
+
set, REA keeps that occurrence as `unavailable` and continues analyzing the
|
|
634
|
+
embedded JavaScript instead of treating the missing native/resource bytes as
|
|
635
|
+
verified or absent.
|
|
590
636
|
|
|
591
637
|
## Security model
|
|
592
638
|
|
|
593
|
-
REA does not provide a hosted analysis service. Hopper and Ghidra bridge communication uses authenticated private local sockets. Dynamic capabilities are disabled by default and require both operator policy and explicit per-call approval. Shipped providers, passive observers, and Process Capture are not security sandboxes: providers and launched targets run with the current user's permissions. Extracted JavaScript replay is a distinct Linux-only capability that fails closed unless Bubblewrap namespaces, architecture-checked seccomp, private runtime mounts, and delegated cgroup limits are available; it never inherits browser, Electron, or Process Capture authority. See [ADR-0002](docs/adr/0002-controlled-replay-authority-and-sandbox.md). Report vulnerabilities through the private process in [SECURITY.md](SECURITY.md).
|
|
639
|
+
REA does not provide a hosted analysis service. Hopper and Linux Ghidra bridge communication uses authenticated private local sockets. Windows Ghidra P0 uses authenticated IPv4 loopback but does not claim named-pipe DACL or hostile-local-user isolation. Dynamic capabilities are disabled by default and require both operator policy and explicit per-call approval. Shipped providers, passive observers, and Process Capture are not security sandboxes: providers and launched targets run with the current user's permissions. Extracted JavaScript replay is a distinct Linux-only capability that fails closed unless Bubblewrap namespaces, architecture-checked seccomp, private runtime mounts, and delegated cgroup limits are available; it never inherits browser, Electron, or Process Capture authority. See [ADR-0002](docs/adr/0002-controlled-replay-authority-and-sandbox.md). Report vulnerabilities through the private process in [SECURITY.md](SECURITY.md).
|
|
594
640
|
|
|
595
641
|
## FAQ
|
|
596
642
|
|
|
@@ -7,15 +7,20 @@ import java.io.ByteArrayOutputStream;
|
|
|
7
7
|
import java.io.IOException;
|
|
8
8
|
import java.io.Reader;
|
|
9
9
|
import java.math.BigInteger;
|
|
10
|
+
import java.net.InetAddress;
|
|
11
|
+
import java.net.InetSocketAddress;
|
|
10
12
|
import java.net.StandardProtocolFamily;
|
|
11
13
|
import java.net.UnixDomainSocketAddress;
|
|
12
14
|
import java.nio.channels.Channels;
|
|
13
15
|
import java.nio.channels.ServerSocketChannel;
|
|
14
16
|
import java.nio.channels.SocketChannel;
|
|
15
17
|
import java.nio.charset.StandardCharsets;
|
|
18
|
+
import java.nio.file.AtomicMoveNotSupportedException;
|
|
16
19
|
import java.nio.file.Files;
|
|
17
20
|
import java.nio.file.LinkOption;
|
|
18
21
|
import java.nio.file.Path;
|
|
22
|
+
import java.nio.file.StandardCopyOption;
|
|
23
|
+
import java.nio.file.StandardOpenOption;
|
|
19
24
|
import java.nio.file.attribute.PosixFilePermissions;
|
|
20
25
|
import java.security.MessageDigest;
|
|
21
26
|
import java.util.ArrayList;
|
|
@@ -67,7 +72,7 @@ import ghidra.program.model.symbol.Symbol;
|
|
|
67
72
|
import ghidra.program.model.symbol.SymbolIterator;
|
|
68
73
|
|
|
69
74
|
public final class ReaGhidraBridge extends HeadlessScript {
|
|
70
|
-
private static final int BRIDGE_VERSION =
|
|
75
|
+
private static final int BRIDGE_VERSION = 4;
|
|
71
76
|
private static final int MAX_DESCRIPTOR_BYTES = 16 * 1024;
|
|
72
77
|
private static final int MAX_REQUEST_CHARACTERS = 256 * 1024;
|
|
73
78
|
private static final int MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
@@ -85,9 +90,11 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
85
90
|
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
|
|
86
91
|
private static final Set<String> DESCRIPTOR_KEYS = Set.of(
|
|
87
92
|
"schema_version",
|
|
88
|
-
"
|
|
93
|
+
"transport",
|
|
94
|
+
"endpoint_path",
|
|
89
95
|
"token",
|
|
90
96
|
"run_id",
|
|
97
|
+
"target_sha256",
|
|
91
98
|
"provider_version",
|
|
92
99
|
"profile_digest"
|
|
93
100
|
);
|
|
@@ -143,6 +150,16 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
143
150
|
if (!Application.getApplicationVersion().equals(descriptor.providerVersion)) {
|
|
144
151
|
throw new IllegalStateException("Ghidra provider version does not match the session");
|
|
145
152
|
}
|
|
153
|
+
String importedSha256 = currentProgram.getExecutableSHA256();
|
|
154
|
+
if (importedSha256 == null ||
|
|
155
|
+
!constantTimeEquals(
|
|
156
|
+
importedSha256.toLowerCase(Locale.ROOT),
|
|
157
|
+
descriptor.targetSha256
|
|
158
|
+
)) {
|
|
159
|
+
throw new IllegalStateException(
|
|
160
|
+
"Ghidra imported-byte digest does not match the admitted target"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
146
163
|
try {
|
|
147
164
|
initializeDecompiler();
|
|
148
165
|
serve(descriptor);
|
|
@@ -156,22 +173,77 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
156
173
|
}
|
|
157
174
|
|
|
158
175
|
private void serve(SessionDescriptor descriptor) throws Exception {
|
|
159
|
-
|
|
176
|
+
if (descriptor.transport.equals("unix-socket")) {
|
|
177
|
+
serveUnixSocket(descriptor);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (descriptor.transport.equals("authenticated-loopback-tcp")) {
|
|
181
|
+
serveLoopbackTcp(descriptor);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
throw new IllegalArgumentException("REA bridge transport is invalid");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private void serveUnixSocket(SessionDescriptor descriptor) throws Exception {
|
|
188
|
+
Path socketPath = Path.of(descriptor.endpointPath);
|
|
160
189
|
Files.deleteIfExists(socketPath);
|
|
161
190
|
try (ServerSocketChannel server = ServerSocketChannel.open(StandardProtocolFamily.UNIX)) {
|
|
162
191
|
server.bind(UnixDomainSocketAddress.of(socketPath));
|
|
163
192
|
Files.setPosixFilePermissions(socketPath, PosixFilePermissions.fromString("rw-------"));
|
|
164
|
-
|
|
165
|
-
BufferedReader reader = new BufferedReader(Channels.newReader(client, StandardCharsets.UTF_8));
|
|
166
|
-
BufferedWriter writer = new BufferedWriter(Channels.newWriter(client, StandardCharsets.UTF_8))) {
|
|
167
|
-
serveClient(descriptor, reader, writer);
|
|
168
|
-
}
|
|
193
|
+
acceptClient(server, descriptor);
|
|
169
194
|
}
|
|
170
195
|
finally {
|
|
171
196
|
Files.deleteIfExists(socketPath);
|
|
172
197
|
}
|
|
173
198
|
}
|
|
174
199
|
|
|
200
|
+
private void serveLoopbackTcp(SessionDescriptor descriptor) throws Exception {
|
|
201
|
+
Path endpointPath = Path.of(descriptor.endpointPath);
|
|
202
|
+
Path pendingPath = endpointPath.resolveSibling(endpointPath.getFileName() + ".pending");
|
|
203
|
+
Files.deleteIfExists(endpointPath);
|
|
204
|
+
Files.deleteIfExists(pendingPath);
|
|
205
|
+
try (ServerSocketChannel server = ServerSocketChannel.open()) {
|
|
206
|
+
server.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0));
|
|
207
|
+
InetSocketAddress address = (InetSocketAddress) server.getLocalAddress();
|
|
208
|
+
JsonObject endpoint = new JsonObject();
|
|
209
|
+
endpoint.addProperty("schema_version", 1);
|
|
210
|
+
endpoint.addProperty("host", "127.0.0.1");
|
|
211
|
+
endpoint.addProperty("port", address.getPort());
|
|
212
|
+
Files.writeString(
|
|
213
|
+
pendingPath,
|
|
214
|
+
GSON.toJson(endpoint) + "\n",
|
|
215
|
+
StandardCharsets.UTF_8,
|
|
216
|
+
StandardOpenOption.CREATE_NEW,
|
|
217
|
+
StandardOpenOption.WRITE
|
|
218
|
+
);
|
|
219
|
+
try {
|
|
220
|
+
Files.move(pendingPath, endpointPath, StandardCopyOption.ATOMIC_MOVE);
|
|
221
|
+
}
|
|
222
|
+
catch (AtomicMoveNotSupportedException exception) {
|
|
223
|
+
Files.move(pendingPath, endpointPath);
|
|
224
|
+
}
|
|
225
|
+
acceptClient(server, descriptor);
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
Files.deleteIfExists(pendingPath);
|
|
229
|
+
Files.deleteIfExists(endpointPath);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private void acceptClient(
|
|
234
|
+
ServerSocketChannel server,
|
|
235
|
+
SessionDescriptor descriptor) throws Exception {
|
|
236
|
+
try (SocketChannel client = server.accept();
|
|
237
|
+
BufferedReader reader = new BufferedReader(
|
|
238
|
+
Channels.newReader(client, StandardCharsets.UTF_8)
|
|
239
|
+
);
|
|
240
|
+
BufferedWriter writer = new BufferedWriter(
|
|
241
|
+
Channels.newWriter(client, StandardCharsets.UTF_8)
|
|
242
|
+
)) {
|
|
243
|
+
serveClient(descriptor, reader, writer);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
175
247
|
private void serveClient(
|
|
176
248
|
SessionDescriptor descriptor,
|
|
177
249
|
BufferedReader reader,
|
|
@@ -270,6 +342,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
270
342
|
"default_address_space",
|
|
271
343
|
currentProgram.getAddressFactory().getDefaultAddressSpace().getName()
|
|
272
344
|
);
|
|
345
|
+
target.addProperty("sha256", descriptor.targetSha256);
|
|
273
346
|
|
|
274
347
|
JsonObject result = new JsonObject();
|
|
275
348
|
result.addProperty("name", "REA Ghidra bridge");
|
|
@@ -1586,13 +1659,15 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
1586
1659
|
JsonParser.parseString(Files.readString(path, StandardCharsets.UTF_8)),
|
|
1587
1660
|
DESCRIPTOR_KEYS
|
|
1588
1661
|
);
|
|
1589
|
-
if (requireInteger(object, "schema_version") !=
|
|
1662
|
+
if (requireInteger(object, "schema_version") != 2) {
|
|
1590
1663
|
throw new IllegalArgumentException("REA session descriptor version is invalid");
|
|
1591
1664
|
}
|
|
1592
1665
|
return new SessionDescriptor(
|
|
1593
|
-
requireString(object, "
|
|
1666
|
+
requireString(object, "transport"),
|
|
1667
|
+
requireString(object, "endpoint_path"),
|
|
1594
1668
|
requireString(object, "token"),
|
|
1595
1669
|
requireString(object, "run_id"),
|
|
1670
|
+
requireSha256(object, "target_sha256"),
|
|
1596
1671
|
requireString(object, "provider_version"),
|
|
1597
1672
|
requireString(object, "profile_digest")
|
|
1598
1673
|
);
|
|
@@ -1662,6 +1737,14 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
1662
1737
|
return result;
|
|
1663
1738
|
}
|
|
1664
1739
|
|
|
1740
|
+
private static String requireSha256(JsonObject object, String name) {
|
|
1741
|
+
String value = requireString(object, name);
|
|
1742
|
+
if (!value.matches("[a-f0-9]{64}")) {
|
|
1743
|
+
throw new IllegalArgumentException(name + " must be lowercase SHA-256");
|
|
1744
|
+
}
|
|
1745
|
+
return value;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1665
1748
|
private static int requireInteger(JsonObject object, String name) {
|
|
1666
1749
|
JsonElement value = object.get(name);
|
|
1667
1750
|
if (value == null || !value.isJsonPrimitive() || !value.getAsJsonPrimitive().isNumber()) {
|
|
@@ -1795,9 +1878,11 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|
|
1795
1878
|
private record InstructionScan(List<Instruction> instructions, boolean truncated) {}
|
|
1796
1879
|
private record TruncatedValue(String value, boolean truncated) {}
|
|
1797
1880
|
private record SessionDescriptor(
|
|
1798
|
-
String
|
|
1881
|
+
String transport,
|
|
1882
|
+
String endpointPath,
|
|
1799
1883
|
String token,
|
|
1800
1884
|
String runId,
|
|
1885
|
+
String targetSha256,
|
|
1801
1886
|
String providerVersion,
|
|
1802
1887
|
String profileDigest
|
|
1803
1888
|
) {}
|
|
@@ -113,7 +113,7 @@ const createExtractionResult = (input, inventory, selected, extracted) => {
|
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
115
|
const loadInventory = async (path, limits, selectedIds, signal) => {
|
|
116
|
-
const snapshot = await scanArtifactInventory(path, limits, signal);
|
|
116
|
+
const snapshot = await scanArtifactInventory(path, limits, { signal });
|
|
117
117
|
const occurrences = new Map();
|
|
118
118
|
const neededNodes = new Set();
|
|
119
119
|
collectOccurrences(snapshot.occurrences, selectedIds, occurrences, neededNodes);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { classifyArtifactPath } from "../ArtifactGraphConstruction.js";
|
|
3
|
+
const classifyContainerExtension = (path) => {
|
|
4
|
+
const lower = path.toLowerCase();
|
|
5
|
+
for (const format of ["asar", "ipa", "apk", "zip", "dmg", "pkg"])
|
|
6
|
+
if (lower.endsWith(`.${format}`))
|
|
7
|
+
return format;
|
|
8
|
+
return undefined;
|
|
9
|
+
};
|
|
10
|
+
export const classifyRoot = async (path, directory) => {
|
|
11
|
+
if (directory)
|
|
12
|
+
return "directory";
|
|
13
|
+
const extensionFormat = classifyContainerExtension(path);
|
|
14
|
+
if (extensionFormat !== undefined)
|
|
15
|
+
return extensionFormat;
|
|
16
|
+
const handle = await open(path, "r");
|
|
17
|
+
try {
|
|
18
|
+
const magic = Buffer.alloc(4);
|
|
19
|
+
const observed = await handle.read(magic, 0, magic.length, 0);
|
|
20
|
+
if (observed.bytesRead === 4 &&
|
|
21
|
+
magic[0] === 0x50 &&
|
|
22
|
+
magic[1] === 0x4b &&
|
|
23
|
+
[0x03, 0x05, 0x07].includes(magic[2] ?? -1) &&
|
|
24
|
+
[0x04, 0x06, 0x08].includes(magic[3] ?? -1))
|
|
25
|
+
return "zip";
|
|
26
|
+
if (observed.bytesRead === 4) {
|
|
27
|
+
const header = magic.readUInt32BE(0);
|
|
28
|
+
if ([0xcafebabe, 0xbebafeca, 0xcafebabf, 0xbfbafeca].includes(header))
|
|
29
|
+
return "mach-o-universal";
|
|
30
|
+
if ([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe].includes(header))
|
|
31
|
+
return "mach-o";
|
|
32
|
+
if (magic.equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46])))
|
|
33
|
+
return "elf";
|
|
34
|
+
}
|
|
35
|
+
if (observed.bytesRead >= 2 && magic[0] === 0x4d && magic[1] === 0x5a)
|
|
36
|
+
return "pe";
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
await handle.close();
|
|
40
|
+
}
|
|
41
|
+
return classifyArtifactPath(path).format;
|
|
42
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { ArtifactReaderFailure, } from "../../artifacts/ArtifactReader.js";
|
|
3
|
+
import { streamChunkToBuffer } from "../../artifacts/StreamBytes.js";
|
|
4
|
+
export const abortIfNeeded = (signal) => {
|
|
5
|
+
if (signal?.aborted === true)
|
|
6
|
+
throw new ArtifactReaderFailure("cancelled", "Artifact inventory cancelled");
|
|
7
|
+
};
|
|
8
|
+
export const preflightEntry = (entry, limits) => {
|
|
9
|
+
if (entry.declaredSize !== null && entry.declaredSize > limits.maxEntryBytes)
|
|
10
|
+
throw new ArtifactReaderFailure("limit", `Entry exceeds byte limit: ${entry.path}`);
|
|
11
|
+
if (entry.declaredSize !== null &&
|
|
12
|
+
entry.compressedSize !== null &&
|
|
13
|
+
entry.compressedSize === 0 &&
|
|
14
|
+
entry.declaredSize > 0)
|
|
15
|
+
throw new ArtifactReaderFailure("limit", `Invalid compression ratio: ${entry.path}`);
|
|
16
|
+
if (entry.declaredSize !== null &&
|
|
17
|
+
entry.compressedSize !== null &&
|
|
18
|
+
entry.compressedSize > 0 &&
|
|
19
|
+
entry.declaredSize / entry.compressedSize > limits.maxCompressionRatio)
|
|
20
|
+
throw new ArtifactReaderFailure("limit", `Compression ratio exceeds limit: ${entry.path}`);
|
|
21
|
+
};
|
|
22
|
+
export const hashReadable = async (stream, maximum, signal) => {
|
|
23
|
+
const hash = createHash("sha256");
|
|
24
|
+
const prefixes = [];
|
|
25
|
+
let prefixBytes = 0;
|
|
26
|
+
let bytes = 0;
|
|
27
|
+
for await (const raw of stream) {
|
|
28
|
+
abortIfNeeded(signal);
|
|
29
|
+
const chunk = streamChunkToBuffer(raw);
|
|
30
|
+
bytes += chunk.length;
|
|
31
|
+
if (bytes > maximum) {
|
|
32
|
+
stream.destroy();
|
|
33
|
+
throw new ArtifactReaderFailure("limit", "Observed entry bytes exceed limit");
|
|
34
|
+
}
|
|
35
|
+
hash.update(chunk);
|
|
36
|
+
if (prefixBytes < 16) {
|
|
37
|
+
const selected = chunk.subarray(0, 16 - prefixBytes);
|
|
38
|
+
prefixes.push(selected);
|
|
39
|
+
prefixBytes += selected.length;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { sha256: hash.digest("hex"), bytes, prefix: Buffer.concat(prefixes) };
|
|
43
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AsarArtifactReader } from "../../artifacts/AsarArtifactReader.js";
|
|
2
|
+
import { ArtifactReaderFailure, } from "../../artifacts/ArtifactReader.js";
|
|
3
|
+
import { DirectoryArtifactReader } from "../../artifacts/DirectoryArtifactReader.js";
|
|
4
|
+
import { MachOSliceArtifactReader } from "../../artifacts/MachOSliceArtifactReader.js";
|
|
5
|
+
import { NativeDmgArtifactReader } from "../../artifacts/NativeDmgArtifactReader.js";
|
|
6
|
+
import { ZipArtifactReader } from "../../artifacts/ZipArtifactReader.js";
|
|
7
|
+
export const createReader = async (path, format, nativeMount, signal) => {
|
|
8
|
+
switch (format) {
|
|
9
|
+
case "directory":
|
|
10
|
+
return new DirectoryArtifactReader(path);
|
|
11
|
+
case "zip":
|
|
12
|
+
case "ipa":
|
|
13
|
+
case "apk":
|
|
14
|
+
return new ZipArtifactReader(path, format);
|
|
15
|
+
case "asar":
|
|
16
|
+
return new AsarArtifactReader(path);
|
|
17
|
+
case "mach-o-universal":
|
|
18
|
+
return process.platform === "darwin"
|
|
19
|
+
? new MachOSliceArtifactReader(path)
|
|
20
|
+
: undefined;
|
|
21
|
+
case "dmg":
|
|
22
|
+
if (!nativeMount.nativeMountApproved)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (!nativeMount.nativeMountEnabled)
|
|
25
|
+
throw new ArtifactReaderFailure("unavailable", "Native DMG mounting is disabled by operator policy");
|
|
26
|
+
return NativeDmgArtifactReader.create(path, signal);
|
|
27
|
+
default:
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const inventoryLimitations = (format, reader) => {
|
|
32
|
+
if (reader !== undefined)
|
|
33
|
+
return [];
|
|
34
|
+
if (format === "dmg" || format === "pkg")
|
|
35
|
+
return [
|
|
36
|
+
`${format.toUpperCase()} root hash is observed; child inventory requires an approved native macOS adapter.`,
|
|
37
|
+
];
|
|
38
|
+
if (format === "mach-o-universal" && process.platform !== "darwin")
|
|
39
|
+
return ["Universal Mach-O slices require the native macOS lipo adapter."];
|
|
40
|
+
return ["Artifact has no child container entries."];
|
|
41
|
+
};
|