Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(pwntools): preserve actionable provider admission errors

morluto5b3400d5d945
diff --git a/docs/cli.md b/docs/cli.md
index 5b075fe37..407e5d3f0 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -152,9 +152,13 @@ overrides it. In MCP, pass `provider_id` to `open_binary`:
The selected provider remains bound to the session until an explicit switch
or close. Provider failures are returned with their original reason. For an
`ambiguous` selection error, choose from `details.candidate_ids`; for
-`provider_unavailable`, run `rea doctor --provider ID --json` to diagnose the
-selected engine. See [task readiness](installation.md#check-readiness-for-your-task)
-and [provider selection](mcp-contracts.md#identity-and-discovery).
+`provider_unavailable`, follow `message`, `remediation.action`, and the original
+reasons in `details.rejections`. For Hopper, Ghidra, IDA, and JADX, run
+`rea doctor --provider ID --json` to diagnose the selected engine. Other adapters,
+such as `pwntools-elf`, report their configuration requirements directly and are
+not accepted by `doctor --provider`. See
+[task readiness](installation.md#check-readiness-for-your-task) and
+[provider selection](mcp-contracts.md#identity-and-discovery).
The session reports work still in progress through `analysis_activity`.
A client timeout can end its wait while the provider continues analyzing.
diff --git a/src/domain/providerSelectionError.ts b/src/domain/providerSelectionError.ts
index e6520848f..fb7a262c3 100644
--- a/src/domain/providerSelectionError.ts
+++ b/src/domain/providerSelectionError.ts
@@ -23,6 +23,7 @@ export interface ProviderSelectionRejection {
/** Complete typed context for one failed deep-provider selection. */
export interface ProviderSelectionErrorOptions {
readonly capturedOutput?: AnalysisCapturedOutput;
+ readonly userMessage?: string;
readonly operation?: string;
readonly reason: ProviderSelectionFailureReason;
readonly requestedProviderId: string;
@@ -56,7 +57,8 @@ export class ProviderSelectionError extends AnalysisError {
...rejection,
diagnostics: structuredClone(rejection.diagnostics),
}));
- this.userMessage = providerSelectionUserMessage(options);
+ this.userMessage =
+ options.userMessage ?? providerSelectionUserMessage(options);
}
}
diff --git a/src/native/pwntools/PwntoolsFailures.ts b/src/native/pwntools/PwntoolsFailures.ts
index e36ae9503..17e3a8296 100644
--- a/src/native/pwntools/PwntoolsFailures.ts
+++ b/src/native/pwntools/PwntoolsFailures.ts
@@ -265,6 +265,7 @@ export const pwntoolsUnavailable = (
): ProviderSelectionError =>
new ProviderSelectionError({
...(capturedOutput === undefined ? {} : { capturedOutput }),
+ userMessage: reason,
operation: context.operation,
reason: "provider_unavailable",
requestedProviderId: context.providerId,
diff --git a/tests/process-global/pwntoolsCliRemediation.test.ts b/tests/process-global/pwntoolsCliRemediation.test.ts
new file mode 100644
index 000000000..c764166a3
--- /dev/null
+++ b/tests/process-global/pwntoolsCliRemediation.test.ts
@@ -0,0 +1,115 @@
+import { writeFile } from "node:fs/promises";
+import { afterEach, beforeEach, expect, it, onTestFinished, vi } from "vitest";
+
+import { createCli } from "../../src/cli.js";
+import * as composition from "../../src/composition/binaryDiagnostics.js";
+import { BinaryLayoutService } from "../../src/application/binaryDiagnostics/BinaryLayoutService.js";
+import { RecordedCrashService } from "../../src/application/binaryDiagnostics/RecordedCrashService.js";
+import { PwntoolsLayoutProvider } from "../../src/native/pwntools/PwntoolsLayoutProvider.js";
+import { PwntoolsRecordedCrashProvider } from "../../src/native/pwntools/PwntoolsRecordedCrashProvider.js";
+import {
+ createTestWorkspace,
+ removeTestWorkspace,
+} from "../support/workspace/workspaceFixture.js";
+
+const platform = Object.getOwnPropertyDescriptor(process, "platform");
+const architecture = Object.getOwnPropertyDescriptor(process, "arch");
+const exitCode = process.exitCode;
+
+beforeEach(() => {
+ // Exercise configuration admission on this host without starting Python.
+ Object.defineProperty(process, "platform", { value: "linux" });
+ Object.defineProperty(process, "arch", { value: "x64" });
+});
+afterEach(() => {
+ if (platform !== undefined)
+ Object.defineProperty(process, "platform", platform);
+ if (architecture !== undefined)
+ Object.defineProperty(process, "arch", architecture);
+ process.exitCode = exitCode;
+ vi.restoreAllMocks();
+});
+
+it
+ .skipIf(process.platform === "win32")
+ .each(["inspect-binary-layout", "inspect-recorded-crash"] as const)(
+ "reports actionable configuration failures through %s",
+ async (command) => {
+ const workspace = await createTestWorkspace("rea-pwntools-remediation-");
+ onTestFinished(() => removeTestWorkspace(workspace.root));
+ const nonExecutable = workspace.path("python-no-execute");
+ await writeFile(nonExecutable, "not executable", { mode: 0o600 });
+ const missing = workspace.path("missing-python");
+ const configurations = [
+ {
+ environment: {},
+ message: "Set REA_PWNTOOLS_PYTHON",
+ key: "REA_PWNTOOLS_PYTHON",
+ },
+ {
+ environment: { REA_PWNTOOLS_PYTHON: workspace.root },
+ message: "not a directory",
+ key: "REA_PWNTOOLS_PYTHON",
+ },
+ {
+ environment: { REA_PWNTOOLS_PYTHON: missing },
+ message: "ENOENT",
+ key: "REA_PWNTOOLS_PYTHON",
+ },
+ {
+ environment: { REA_PWNTOOLS_PYTHON: nonExecutable },
+ message: "EACCES",
+ key: "REA_PWNTOOLS_PYTHON",
+ },
+ {
+ environment: {
+ REA_PWNTOOLS_PYTHON: process.execPath,
+ REA_PWNTOOLS_MAX_INPUT_BYTES: "0",
+ },
+ message: "REA_PWNTOOLS_MAX_INPUT_BYTES",
+ key: "REA_PWNTOOLS_MAX_INPUT_BYTES",
+ },
+ ];
+ for (const { environment, message, key } of configurations) {
+ if (command === "inspect-binary-layout")
+ vi.spyOn(composition, "createBinaryLayoutService").mockReturnValue(
+ new BinaryLayoutService(new PwntoolsLayoutProvider(environment)),
+ );
+ else
+ vi.spyOn(composition, "createRecordedCrashService").mockReturnValue(
+ new RecordedCrashService(
+ new PwntoolsRecordedCrashProvider(environment),
+ ),
+ );
+ let stdout = "";
+ process.exitCode = 0;
+ await createCli({}).serve(
+ [command, workspace.path("selected.elf"), "--json"],
+ {
+ env: {},
+ stdout: (text) => {
+ stdout += text;
+ },
+ exit: () => undefined,
+ },
+ );
+ const output: unknown = JSON.parse(stdout);
+ expect(output).toMatchObject({
+ code: "provider_unavailable",
+ message: expect.stringContaining(message),
+ remediation: { action: expect.stringContaining(message) },
+ details: {
+ requested_provider_id: "pwntools-elf",
+ rejections: [
+ {
+ reason: expect.stringContaining(message),
+ diagnostics: { configuration_key: key },
+ },
+ ],
+ },
+ });
+ expect(stdout).not.toContain("rea doctor");
+ expect(process.exitCode).toBe(1);
+ }
+ },
+);