Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(setup): preserve consent and startup target kind

morlutoa67054f81500
diff --git a/src/application/BinarySession.ts b/src/application/BinarySession.ts
index 00ad421df..5fc8ae2e3 100644
--- a/src/application/BinarySession.ts
+++ b/src/application/BinarySession.ts
@@ -38,11 +38,19 @@ export class BinarySession implements HopperToolPort {
*/
open(
path: string,
- options: { readonly signal?: AbortSignal } = {},
+ options: {
+ readonly signal?: AbortSignal;
+ readonly targetKind?: BinaryTarget["kind"];
+ } = {},
): Promise<Result<BinaryTarget, HopperError>> {
return this.#serialize(async () => {
if (isAborted(options.signal)) return err(new HopperCancelledError());
- const parsed = await parseBinaryTarget(path);
+ const parsed = await parseBinaryTarget(
+ path,
+ process.cwd(),
+ process.arch,
+ options.targetKind,
+ );
if (!parsed.ok) return parsed;
if (isAborted(options.signal)) return err(new HopperCancelledError());
if (this.#active?.target.path === parsed.value.path)
diff --git a/src/application/Setup.ts b/src/application/Setup.ts
index 4204b6867..c36f22f38 100644
--- a/src/application/Setup.ts
+++ b/src/application/Setup.ts
@@ -98,6 +98,7 @@ export const runSetup = async (
actions.push("installed_homebrew");
}
if ((await host.hopperPath()) === undefined) {
+ if (!yes) return fail("Re-run with --yes to install Hopper.");
if (!(await host.installHopper()))
return fail(
"Hopper installation was interrupted; resolve the system prompt and re-run setup.",
diff --git a/src/domain/binaryTarget.ts b/src/domain/binaryTarget.ts
index 09aeb6dbd..00839e15f 100644
--- a/src/domain/binaryTarget.ts
+++ b/src/domain/binaryTarget.ts
@@ -30,12 +30,16 @@ export const parseBinaryTarget = async (
input: string,
cwd = process.cwd(),
hostArchitecture: NodeJS.Architecture = process.arch,
+ targetKind?: BinaryTarget["kind"],
): Promise<Result<BinaryTarget, BinaryTargetError>> => {
const candidate = isAbsolute(input) ? input : resolve(cwd, input);
try {
await access(candidate, constants.R_OK);
const path = await realpath(candidate);
- if (path.toLowerCase().endsWith(".hop"))
+ if (
+ targetKind === "database" ||
+ (targetKind === undefined && path.toLowerCase().endsWith(".hop"))
+ )
return ok({ path, kind: "database", format: "hopper", loaderArgs: [] });
const handle = await open(path, "r");
let bytes: Buffer;
diff --git a/src/main.ts b/src/main.ts
index e11c52a65..62e54f1d3 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -26,7 +26,9 @@ export const run = async (): Promise<number> => {
const session = createBinarySession(config.value);
if (config.value.hopperTargetPath !== undefined) {
- const opened = await session.open(config.value.hopperTargetPath);
+ const opened = await session.open(config.value.hopperTargetPath, {
+ targetKind: config.value.hopperTargetKind,
+ });
if (!opened.ok) {
await session.close();
process.stderr.write(`${opened.error._tag}: ${opened.error.message}\n`);
diff --git a/tests/binaryTarget.test.ts b/tests/binaryTarget.test.ts
index ad82098ee..a9c2d7819 100644
--- a/tests/binaryTarget.test.ts
+++ b/tests/binaryTarget.test.ts
@@ -74,6 +74,22 @@ describe("binary target I/O", () => {
expect((await parseBinaryTarget("text", directory)).ok).toBe(false);
expect((await parseBinaryTarget("missing", directory)).ok).toBe(false);
});
+
+ it("honors an explicit database kind without relying on the file suffix", async () => {
+ directory = await mkdtemp(join(tmpdir(), "rea-target-"));
+ await writeFile(join(directory, "saved-analysis"), "database");
+ const result = await parseBinaryTarget(
+ "saved-analysis",
+ directory,
+ "arm64",
+ "database",
+ );
+ expect(result.ok && result.value).toMatchObject({
+ kind: "database",
+ format: "hopper",
+ loaderArgs: [],
+ });
+ });
});
const elf = (class_: number, endian: number, machine: number): Buffer => {
diff --git a/tests/runtime.test.ts b/tests/runtime.test.ts
index 33af40ad1..151b77f7d 100644
--- a/tests/runtime.test.ts
+++ b/tests/runtime.test.ts
@@ -44,4 +44,29 @@ describe("production stdio runtime", () => {
}
expect(stderr).toBe("");
});
+
+ it("honors the configured kind for an initial database target", async () => {
+ const transport = new StdioClientTransport({
+ command: process.execPath,
+ args: [mainPath],
+ cwd: process.cwd(),
+ env: {
+ PATH: process.env.PATH ?? "",
+ HOPPER_LAUNCHER_PATH: process.execPath,
+ HOPPER_TARGET_PATH: new URL(import.meta.url).pathname,
+ HOPPER_TARGET_KIND: "database",
+ HOPPER_LOADER_ARGS_JSON: JSON.stringify([fixturePath]),
+ },
+ stderr: "pipe",
+ });
+ const client = new Client({ name: "database-runtime", version: "1.0.0" });
+
+ try {
+ await client.connect(transport);
+ expect((await client.listTools()).tools).toHaveLength(42);
+ } finally {
+ await client.close();
+ await transport.close();
+ }
+ });
});
diff --git a/tests/setup.test.ts b/tests/setup.test.ts
index e1df79cc5..da55b5a1a 100644
--- a/tests/setup.test.ts
+++ b/tests/setup.test.ts
@@ -84,6 +84,15 @@ describe("setup workflow", () => {
expect(result.remediation).toContain("--yes");
});
+ it("requires --yes before installing Hopper", async () => {
+ const host = new FakeSetupHost();
+ host.brew = true;
+ const result = await runSetup(false, host);
+ expect(result.status).toBe("needs_human");
+ expect(host.hopperInstalls).toBe(0);
+ expect(result.remediation).toContain("--yes");
+ });
+
it("accepts existing Homebrew and manually installed Hopper", async () => {
const host = new FakeSetupHost();
host.brew = true;