Skip to content

armgit / rea

Public Imported from GitHub
0

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

test(firmware): bind owned producers and exercise real limits

morluto3ba194263143
diff --git a/tests/boundary/firmware/firmwareIntegration.test.ts b/tests/boundary/firmware/firmwareIntegration.test.ts
index 3e7953da5..eb3ebd8d4 100644
--- a/tests/boundary/firmware/firmwareIntegration.test.ts
+++ b/tests/boundary/firmware/firmwareIntegration.test.ts
@@ -99,6 +99,11 @@ it("binds region observations to exact bytes and preserves provider-reported unc
const normalized = firmwareResultSchemas.inspect_firmware_regions.parse(
result.value.normalized_result,
);
+ expect(normalized.engine).toMatchObject({
+ name: "binwalk",
+ version: "3.1.0",
+ executable_path: fixture.commands.binwalk,
+ });
expect(normalized.regions[0]).toMatchObject({
offset: 2,
reported_size: 4,
@@ -145,6 +150,11 @@ it("extracts a selected interval with verified file identity and parent-byte lin
const normalized = firmwareResultSchemas.extract_firmware.parse(
result.value.normalized_result,
);
+ expect(normalized.engine).toMatchObject({
+ name: "unblob",
+ version: "26.6.4",
+ executable_path: fixture.commands.unblob,
+ });
expect(normalized.selection).toMatchObject({ offset: 2, length: 4 });
expect(normalized.files[0]).toMatchObject({
relative_path: "rootfs/config",
diff --git a/tests/fixtures/firmware/producer.mjs b/tests/fixtures/firmware/producer.mjs
index 338c746b9..02a8fc68c 100644
--- a/tests/fixtures/firmware/producer.mjs
+++ b/tests/fixtures/firmware/producer.mjs
@@ -9,9 +9,13 @@ import {
symlink,
} from "node:fs/promises";
import { join } from "node:path";
-const args = process.argv.slice(2);
+const engine = process.argv[2];
+if (engine !== "binwalk" && engine !== "unblob")
+ throw new Error(
+ "Firmware fixture requires an explicit binwalk or unblob engine",
+ );
+const args = process.argv.slice(3);
const mode = process.env.REA_FIRMWARE_FIXTURE_MODE;
-const engine = process.env.REA_FIRMWARE_FIXTURE_ENGINE;
const banner = process.env.REA_FIRMWARE_FIXTURE_VERSION;
if (args.includes("--version")) {
console.log(
diff --git a/tests/fixtures/firmware/provider.ts b/tests/fixtures/firmware/provider.ts
index 5b73226c5..82b23170e 100644
--- a/tests/fixtures/firmware/provider.ts
+++ b/tests/fixtures/firmware/provider.ts
@@ -1,6 +1,6 @@
import { join } from "node:path";
import { fileURLToPath } from "node:url";
-import { access, rm, writeFile } from "node:fs/promises";
+import { access, writeFile } from "node:fs/promises";
import { expect, onTestFinished } from "vitest";
import { createFirmwareAnalysisProvider } from "../../../src/composition/firmware.js";
import { FirmwareAnalysisService } from "../../../src/application/firmware/FirmwareAnalysisService.js";
@@ -8,12 +8,29 @@ import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.
import { cleanupOwnedProcessGroup } from "../../../src/process/ProcessOwnership.js";
import { createTestTempDirectory } from "../temporaryDirectory.js";
-/** Exercise real subprocess ownership with synthetic pinned producer representations. */
+/** Exercise the real limiter and process ownership with synthetic pinned reports. */
export const firmwareFixture = async (mode = "normal", banner?: string) => {
const root = await createTestTempDirectory("rea-firmware-test-");
const path = join(root, "input.bin");
await writeFile(path, Buffer.from("fixture-input-data"));
- onTestFinished(() => rm(root, { recursive: true, force: true }));
+ const commands = {
+ binwalk: join(root, "binwalk"),
+ unblob: join(root, "unblob"),
+ };
+ for (const engine of ["binwalk", "unblob"] as const) {
+ const invocation = [
+ process.execPath,
+ // Keep the synthetic JS producer within the real engines' address-space ceiling.
+ "--jitless",
+ fileURLToPath(new URL("./producer.mjs", import.meta.url)),
+ engine,
+ ]
+ .map((argument) => `'${argument.replaceAll("'", "'\\''")}'`)
+ .join(" ");
+ await writeFile(commands[engine], `#!/bin/sh\nexec ${invocation} "$@"\n`, {
+ mode: 0o700,
+ });
+ }
const launches: {
cwd: string | undefined;
pid: number | undefined;
@@ -23,33 +40,13 @@ export const firmwareFixture = async (mode = "normal", banner?: string) => {
const provider = createFirmwareAnalysisProvider(
{
...process.env,
- REA_BINWALK_COMMAND: "/usr/bin/true",
- REA_UNBLOB_COMMAND: process.execPath,
+ REA_BINWALK_COMMAND: commands.binwalk,
+ REA_UNBLOB_COMMAND: commands.unblob,
+ REA_FIRMWARE_FIXTURE_MODE: mode,
+ ...(banner === undefined ? {} : { REA_FIRMWARE_FIXTURE_VERSION: banner }),
},
async (options) => {
- const start = options.arguments.indexOf("--") + 2;
- const args = options.arguments.slice(start);
- const engine =
- options.arguments[start - 1]?.endsWith("/true") === true
- ? "binwalk"
- : "unblob";
- const spawned = await spawnOwnedProviderProcess({
- ...options,
- command: process.execPath,
- expectedCommand: process.execPath,
- arguments: [
- fileURLToPath(new URL("./producer.mjs", import.meta.url)),
- ...args,
- ],
- env: {
- ...options.env,
- REA_FIRMWARE_FIXTURE_MODE: mode,
- REA_FIRMWARE_FIXTURE_ENGINE: engine,
- ...(banner === undefined
- ? {}
- : { REA_FIRMWARE_FIXTURE_VERSION: banner }),
- },
- });
+ const spawned = await spawnOwnedProviderProcess(options);
launches.push({
cwd: options.cwd,
pid: spawned.process.pid,
@@ -86,6 +83,7 @@ export const firmwareFixture = async (mode = "normal", banner?: string) => {
output: join(root, "output"),
root,
launches,
+ commands,
close,
restoreCleanup: () => {
cleanupUnverified = false;