Merge main and preserve iNES evidence format boundaries
This commit is contained in:
@@ -39,6 +39,47 @@ export function superclass() {
|
||||
new B().v.x = 2;
|
||||
return shared.x;
|
||||
}
|
||||
export function arrayReceiver() {
|
||||
const arr = [{ x: 1, get self() { return this; } }];
|
||||
arr[0].self.x = 2;
|
||||
return arr[0].x;
|
||||
}
|
||||
export function nestedArrayReceiver() {
|
||||
const outer = { arr: [{ x: 1, get self() { return this; } }] };
|
||||
outer.arr[0].self.x = 2;
|
||||
return outer.arr[0].x;
|
||||
}
|
||||
export function assignedReceiver() {
|
||||
let box;
|
||||
box = { x: 1, get self() { return this; } };
|
||||
box.self.x = 2;
|
||||
return box.x;
|
||||
}
|
||||
export function savedArrayReceiver() {
|
||||
const arr = [{ x: 1, get self() { return this; } }];
|
||||
const saved = arr[0].self;
|
||||
saved.x = 2;
|
||||
return arr[0].x;
|
||||
}
|
||||
export function arrayReadOnly() {
|
||||
const arr = [{ x: 1, get self() { return this; } }];
|
||||
const saved = arr[0].self;
|
||||
return arr[0].x;
|
||||
}
|
||||
export function replacementKeepsOldObject() {
|
||||
const old = { x: 1 };
|
||||
let box = old;
|
||||
box = { x: 1, old: box, get self() { return this; } };
|
||||
box.self.x = 2;
|
||||
return old.x;
|
||||
}
|
||||
export function replacementMutatesCapturedObject() {
|
||||
const old = { x: 1 };
|
||||
let box = old;
|
||||
box = { old: box, get self() { return this; } };
|
||||
box.self.old.x = 2;
|
||||
return old.x;
|
||||
}
|
||||
export function untouched() {
|
||||
const box = { x: 1, y: 1, get self() { return this; } };
|
||||
box.self.y = 2;
|
||||
@@ -66,13 +107,20 @@ export function untouched() {
|
||||
const { graph } = z
|
||||
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
|
||||
.parse(document).normalized_result;
|
||||
for (const name of [
|
||||
"self",
|
||||
"property",
|
||||
"privateField",
|
||||
"superclass",
|
||||
"untouched",
|
||||
]) {
|
||||
for (const [name, status] of [
|
||||
["self", "unknown"],
|
||||
["property", "unknown"],
|
||||
["privateField", "unknown"],
|
||||
["superclass", "unknown"],
|
||||
["arrayReceiver", "unknown"],
|
||||
["nestedArrayReceiver", "unknown"],
|
||||
["assignedReceiver", "unknown"],
|
||||
["savedArrayReceiver", "unknown"],
|
||||
["arrayReadOnly", "literal"],
|
||||
["replacementKeepsOldObject", "literal"],
|
||||
["replacementMutatesCapturedObject", "unknown"],
|
||||
["untouched", "literal"],
|
||||
] as const) {
|
||||
const projection = graph.nodes
|
||||
.flatMap(({ observations }) => observations)
|
||||
.find(
|
||||
@@ -82,7 +130,16 @@ export function untouched() {
|
||||
);
|
||||
expect(projection, name).toBeDefined();
|
||||
expect(projection?.properties.static_return_shapes).toMatchObject([
|
||||
{ value_status: name === "untouched" ? "literal" : "unknown" },
|
||||
{
|
||||
value_status: status,
|
||||
fields: [
|
||||
{
|
||||
path: "",
|
||||
state: status,
|
||||
...(status === "literal" ? { value: 1 } : {}),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -141,6 +141,13 @@ cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
).toBe("node_modules/fi%xture/actual.cjs");
|
||||
|
||||
const { graph } = await analyzeJavaScriptDirectory(surface, cli, root);
|
||||
expect(graph.coverage.status).toBe("complete");
|
||||
const requireFileUrl = graph.edges.find(
|
||||
({ properties }) =>
|
||||
properties.module_link_kind === "require" &&
|
||||
properties.specifier === "file:///src/uri-dep.cjs",
|
||||
);
|
||||
expect(requireFileUrl?.evidence.limitations.length).toBeGreaterThan(0);
|
||||
const imports = graph.edges.filter(
|
||||
({ properties }) => properties.module_link_kind === "require",
|
||||
);
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Uint8ArrayReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import {
|
||||
CPU,
|
||||
fatImage,
|
||||
machoImage,
|
||||
} from "../../src/artifacts/apple/MachoImage.fixture.js";
|
||||
import { artifactInventoryResultSchema } from "../../src/domain/artifactGraph.js";
|
||||
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
|
||||
cliTest.for(["jar", "zip"])(
|
||||
"distinguishes JVM classes from universal Mach-O files in %s inventory",
|
||||
async (extension, { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-class-inventory-");
|
||||
const path = join(root, `mixed.${extension}`);
|
||||
// The large class can hold the entire 65-entry table suggested by its
|
||||
// version bytes. Checking only the table length does not distinguish it.
|
||||
const classes = [
|
||||
["Hello.class", javaClass()],
|
||||
["Big.class", javaClass("x".repeat(4_000))],
|
||||
["renamed.bin", javaClass()],
|
||||
] as const;
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
for (const [name, bytes] of classes)
|
||||
await writer.add(name, new Uint8ArrayReader(bytes));
|
||||
const nativePaths: string[] = [];
|
||||
for (const wide of [false, true]) {
|
||||
for (const littleEndian of [false, true]) {
|
||||
const name = `fat${wide ? 64 : 32}-${littleEndian ? "le" : "be"}`;
|
||||
nativePaths.push(name);
|
||||
await writer.add(
|
||||
name,
|
||||
new Uint8ArrayReader(
|
||||
fatImage(
|
||||
[{ cpu: CPU.arm64, bytes: machoImage({ cpu: CPU.arm64 }) }],
|
||||
wide,
|
||||
littleEndian,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const reply = await cli.run({
|
||||
arguments: ["inspect-artifact", path, "--json"],
|
||||
});
|
||||
expect(reply.exitCode, reply.stdout + reply.stderr).toBe(0);
|
||||
const inspection = artifactInspectionResultSchema.parse(
|
||||
parseEvidence(reply.json).normalized_result,
|
||||
);
|
||||
const inventory = artifactInventoryResultSchema.parse(
|
||||
inspection.substeps[0]?.evidence.normalized_result,
|
||||
);
|
||||
for (const name of nativePaths) {
|
||||
expect(inventory.occurrences).toContainEqual(
|
||||
expect.objectContaining({
|
||||
logical_path: name,
|
||||
artifact_kind: "executable",
|
||||
artifact_format: "mach-o-universal",
|
||||
limitations: [],
|
||||
}),
|
||||
);
|
||||
}
|
||||
for (const [name, bytes] of classes) {
|
||||
const occurrence = inventory.occurrences.find(
|
||||
(item) => item.logical_path === name,
|
||||
);
|
||||
expect(occurrence).toBeDefined();
|
||||
expect.soft(occurrence?.artifact_kind, name).not.toBe("executable");
|
||||
expect.soft(occurrence?.artifact_format, name).not.toMatch(/^mach-o/u);
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
const node = inventory.nodes.find((item) => item.sha256 === sha256);
|
||||
expect(node).toBeDefined();
|
||||
expect.soft(node?.format, name).not.toMatch(/^mach-o/u);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
/** Minimal valid Java 21 class, with an optional unused UTF-8 constant. */
|
||||
const javaClass = (extra?: string): Buffer => {
|
||||
const utf8 = (value: string): Buffer => {
|
||||
const text = Buffer.from(value);
|
||||
const header = Buffer.alloc(3);
|
||||
header[0] = 1;
|
||||
header.writeUInt16BE(text.length, 1);
|
||||
return Buffer.concat([header, text]);
|
||||
};
|
||||
const constants = [
|
||||
Buffer.from([7, 0, 2]),
|
||||
utf8("Hello"),
|
||||
Buffer.from([7, 0, 4]),
|
||||
utf8("java/lang/Object"),
|
||||
...(extra === undefined ? [] : [utf8(extra)]),
|
||||
];
|
||||
const header = Buffer.from("cafebabe000000410000", "hex");
|
||||
header.writeUInt16BE(constants.length + 1, 8);
|
||||
return Buffer.concat([
|
||||
header,
|
||||
...constants,
|
||||
Buffer.from("0021000100030000000000000000", "hex"),
|
||||
]);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { dirname, join } from "node:path";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { expect } from "vitest";
|
||||
@@ -8,6 +8,111 @@ import { z } from "zod";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest.for([
|
||||
{
|
||||
label: "blank defaults",
|
||||
harness: "",
|
||||
agents: " \t ",
|
||||
dshRoot: "home/.dsh",
|
||||
agentsRoot: "home/.agents",
|
||||
},
|
||||
{
|
||||
label: "tilde roots",
|
||||
harness: "~/selected harness",
|
||||
agents: "~\\shared agents",
|
||||
dshRoot: "home/selected harness",
|
||||
agentsRoot: "home/shared agents",
|
||||
},
|
||||
{
|
||||
label: "relative roots",
|
||||
harness: "./selected harness",
|
||||
agents: "../shared agents",
|
||||
dshRoot: "workspace/selected harness",
|
||||
agentsRoot: "shared agents",
|
||||
},
|
||||
])(
|
||||
"DSH CLI uses Harness path semantics through setup, doctor and uninstall for $label",
|
||||
async ({ harness, agents, dshRoot, agentsRoot }, { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-dsh-paths-");
|
||||
const home = join(root, "home");
|
||||
const cwd = join(root, "workspace");
|
||||
const config = join(root, dshRoot, "cordis.patch.yml");
|
||||
const skillRoot = join(
|
||||
root,
|
||||
agentsRoot,
|
||||
"skills",
|
||||
"reverse-engineer-anything",
|
||||
);
|
||||
const skill = join(skillRoot, "SKILL.md");
|
||||
await mkdir(home);
|
||||
await mkdir(cwd);
|
||||
await mkdir(dirname(config), { recursive: true });
|
||||
const original =
|
||||
"# caller patch\n- insert: [{id: caller, name: caller-plugin}]\n";
|
||||
await writeFile(config, original);
|
||||
const run = (args: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: [...args, "--json"],
|
||||
cwd,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
DSH_HOME: harness,
|
||||
DSH_AGENTS_HOME: agents,
|
||||
},
|
||||
});
|
||||
const planned = await run(["setup", "--client", "dsh", "--dry-run"]);
|
||||
expect(planned.exitCode).toBe(0);
|
||||
expect(planned.json).toMatchObject({
|
||||
status: "planned",
|
||||
appliedActions: [],
|
||||
plannedActions: expect.arrayContaining([
|
||||
expect.objectContaining({ id: "configure_client:dsh", target: config }),
|
||||
expect.objectContaining({ kind: "install_skill", target: skillRoot }),
|
||||
]),
|
||||
});
|
||||
expect(await readFile(config, "utf8")).toBe(original);
|
||||
await expect(readFile(skill)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
const configured = await run(["setup", "--client", "dsh", "--yes"]);
|
||||
expect(configured.exitCode).toBe(0);
|
||||
expect(configured.json).toMatchObject({
|
||||
status: "ready",
|
||||
clients: { dsh: { status: "configured" } },
|
||||
});
|
||||
const text = await readFile(config, "utf8");
|
||||
expect(text).toContain("# caller patch");
|
||||
expect(text).toContain("rea-mcp");
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
expect(await readFile(skill, "utf8")).toContain(
|
||||
"name: reverse-engineer-anything",
|
||||
);
|
||||
const doctor = await run(["doctor", "--client", "dsh", "--skill"]);
|
||||
expect(doctor.exitCode).toBe(0);
|
||||
expect(doctor.json).toMatchObject({ healthy: true });
|
||||
const repeated = await run(["setup", "--client", "dsh", "--yes"]);
|
||||
expect(repeated.exitCode).toBe(0);
|
||||
expect(repeated.json).toMatchObject({
|
||||
status: "ready",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
});
|
||||
expect(await readFile(config, "utf8")).toBe(text);
|
||||
const removed = await run(["uninstall"]);
|
||||
expect(removed.exitCode).toBe(0);
|
||||
expect(removed.json).toMatchObject({
|
||||
status: "complete",
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({ name: "dsh", status: "removed" }),
|
||||
]),
|
||||
});
|
||||
expect(parse(await readFile(config, "utf8"))).toEqual([
|
||||
{ insert: [{ id: "caller", name: "caller-plugin" }] },
|
||||
]);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
await expect(readFile(skill)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"DSH CLI previews, approves, repairs, launches MCP, repeats and uninstalls while preserving caller YAML",
|
||||
async ({ cli }) => {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { open } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { PwntoolsLayoutProvider } from "../../../src/native/pwntools/PwntoolsLayoutProvider.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const unsupportedHost = process.platform !== "linux" || process.arch !== "x64";
|
||||
const DEFAULT_INPUT_BYTES = 33_554_432;
|
||||
// One byte above the shipped bound, so the admission decision is the only
|
||||
// difference between the first two cases.
|
||||
const ARTIFACT_BYTES = DEFAULT_INPUT_BYTES + 1;
|
||||
|
||||
/** Sparse regular file just larger than the shipped input bound. */
|
||||
const oversizedArtifact = async (): Promise<string> => {
|
||||
const root = await createTestTempDirectory("rea-pwntools-input-bound-");
|
||||
const path = join(root, "recorded-core");
|
||||
const handle = await open(path, "w");
|
||||
await handle.truncate(ARTIFACT_BYTES);
|
||||
await handle.close();
|
||||
return path;
|
||||
};
|
||||
|
||||
/** One admission attempt, reported as the projected caller-visible failure. */
|
||||
const inspect = async (override?: string) => {
|
||||
const path = await oversizedArtifact();
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{
|
||||
REA_PWNTOOLS_PYTHON: process.execPath,
|
||||
...(override === undefined
|
||||
? {}
|
||||
: { REA_PWNTOOLS_MAX_INPUT_BYTES: override }),
|
||||
},
|
||||
async (spawn) =>
|
||||
spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: ["-e", "process.stdout.write('no reply')"],
|
||||
}),
|
||||
);
|
||||
onTestFinished(async () => {
|
||||
await provider.close();
|
||||
});
|
||||
const result = await provider.inspect({ path });
|
||||
if (result.ok) throw new Error("Expected the bounded decoder to fail");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
return { projected, text: JSON.stringify(projected) };
|
||||
};
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"refuses an artifact above the shipped bound when no override is set",
|
||||
async () => {
|
||||
const { projected, text } = await inspect();
|
||||
expect(projected.code).toBe("invalid_request");
|
||||
expect(text).toContain(
|
||||
`Selected artifact exceeds ${String(DEFAULT_INPUT_BYTES)} bytes`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"admits the same artifact once the override widens the bound",
|
||||
async () => {
|
||||
const { projected, text } = await inspect(String(ARTIFACT_BYTES));
|
||||
// Admission passed, so the only remaining failure is that the owned decoder
|
||||
// never wrote a reply, which also proves the process really ran.
|
||||
expect(text).not.toContain("Selected artifact exceeds");
|
||||
expect(projected.code).toBe("unreadable_output");
|
||||
expect(text).toContain("no reply");
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"refuses an unusable override before reading the artifact",
|
||||
async () => {
|
||||
const { projected, text } = await inspect("0");
|
||||
expect(projected.code).toBe("provider_unavailable");
|
||||
expect(projected.details).toMatchObject({
|
||||
rejections: [
|
||||
{ diagnostics: { configuration_key: "REA_PWNTOOLS_MAX_INPUT_BYTES" } },
|
||||
],
|
||||
});
|
||||
expect(text).toContain("REA_PWNTOOLS_MAX_INPUT_BYTES must be a decimal");
|
||||
expect(text).not.toContain("Selected artifact exceeds");
|
||||
},
|
||||
);
|
||||
@@ -58,6 +58,95 @@ describe("CLI output argument boundary", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("unclosed CLI output filter slices", () => {
|
||||
it.each([
|
||||
"providers[",
|
||||
"providers[0,1].name[",
|
||||
"name,providers[",
|
||||
"][,]",
|
||||
"providers],name[0,1]",
|
||||
])("rejects %s before the filter parser runs", (filter) => {
|
||||
expect(
|
||||
validateCliOutputArguments([
|
||||
"providers",
|
||||
"--json",
|
||||
"--filter-output",
|
||||
filter,
|
||||
]),
|
||||
).toMatchObject({ ok: false, code: "INVALID_OUTPUT_FILTER" });
|
||||
});
|
||||
|
||||
it("preserves effective-filter and earlier flag-error precedence", () => {
|
||||
for (const arguments_ of [
|
||||
[
|
||||
"--filter-output",
|
||||
"providers[",
|
||||
"--filter-output",
|
||||
"capabilities[0,1].provider.id,open",
|
||||
],
|
||||
["--filter-output", "capabilities[-1,].provider.id"],
|
||||
["--filter-output", "capabilities[[0,1]"],
|
||||
["--format", "invalid", "--filter-output", "providers["],
|
||||
["--token-limit", "invalid", "--filter-output", "providers["],
|
||||
])
|
||||
expect(validateCliOutputArguments(arguments_)).toEqual({ ok: true });
|
||||
});
|
||||
|
||||
workspaceCliTest(
|
||||
"fails promptly across output formats without invoking the command",
|
||||
async ({ cli }) => {
|
||||
for (const format of ["json", "jsonl", "yaml", "toon", "md"]) {
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"analyze",
|
||||
"/absent/target",
|
||||
"--format",
|
||||
format,
|
||||
"--filter-output",
|
||||
"result[0,1].name[",
|
||||
],
|
||||
timeoutMs: 3000,
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.stdout).toContain("INVALID_OUTPUT_FILTER");
|
||||
expect(result.stdout).toContain("closing ]");
|
||||
expect(result.stderr).toBe("");
|
||||
}
|
||||
const splitPath = await cli.run({
|
||||
arguments: ["providers", "--json", "--filter-output", "][,]"],
|
||||
timeoutMs: 3000,
|
||||
});
|
||||
expect(splitPath.exitCode).toBe(1);
|
||||
expect(splitPath.json).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "INVALID_OUTPUT_FILTER" },
|
||||
});
|
||||
},
|
||||
CLI_INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
workspaceCliTest(
|
||||
"retains closed slices and multiple filter paths",
|
||||
async ({ cli }) => {
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"providers",
|
||||
"--json",
|
||||
"--filter-output",
|
||||
"capabilities[0,1].provider.id,open",
|
||||
],
|
||||
timeoutMs: 3000,
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.json).toEqual({
|
||||
capabilities: [{ provider: { id: expect.any(String) } }],
|
||||
open: false,
|
||||
});
|
||||
},
|
||||
CLI_INTEGRATION_TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
|
||||
describe("CLI output valued-flag parsing", () => {
|
||||
workspaceCliTest(
|
||||
"preserves complete JSON errors when native builtin flags follow unusual arguments",
|
||||
|
||||
@@ -180,14 +180,17 @@ describe("trace-dylib-resolution CLI", () => {
|
||||
// A root below a symlinked directory that points outside the bundle.
|
||||
const outside = await createTestTempDirectory("rea-dylib-outside-");
|
||||
await writeFiles(outside, { Tool: machoImage({}) });
|
||||
await symlink(outside, join(app, "Contents/Linked"));
|
||||
await symlink(outside, join(app, "Contents/Linked"), "dir");
|
||||
for (const [root, reason, message] of [
|
||||
["../outside", "invalid_format", "Use a normalized path"],
|
||||
["Contents/Info.plist", "invalid_value", "is not a Mach-O image"],
|
||||
[
|
||||
"Contents/Linked/Tool",
|
||||
"invalid_value",
|
||||
"resolves outside the analyzed root",
|
||||
// Windows link text is outside the POSIX dyld path representation.
|
||||
process.platform === "win32"
|
||||
? "is not a regular file in the analyzed root"
|
||||
: "resolves outside the analyzed root",
|
||||
],
|
||||
] as const) {
|
||||
await expectRootInputError(cli, { app, root, reason, message });
|
||||
@@ -378,7 +381,8 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
describe.skipIf(process.getuid?.() === 0)(
|
||||
// This permission fixture requires POSIX mode bits and a non-root caller.
|
||||
describe.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||||
"trace-dylib-resolution permissions",
|
||||
() => {
|
||||
cliTest(
|
||||
@@ -510,6 +514,8 @@ cliTest(
|
||||
app,
|
||||
"--root",
|
||||
"Contents/MacOS/App",
|
||||
"--architecture",
|
||||
"arm64e",
|
||||
"--json",
|
||||
],
|
||||
environment: ENVIRONMENT,
|
||||
@@ -518,9 +524,7 @@ cliTest(
|
||||
const trace = dylibResolutionResultSchema.parse(
|
||||
parseEvidence(result.json).normalized_result,
|
||||
);
|
||||
expect(
|
||||
trace.roots.filter(({ architecture }) => architecture === "arm64e"),
|
||||
).toHaveLength(2);
|
||||
expect(trace.roots).toHaveLength(2);
|
||||
const environments = trace.findings
|
||||
.filter(({ kind }) => kind === "dyld-environment-present")
|
||||
.map(({ explanation }) =>
|
||||
|
||||
@@ -561,3 +561,35 @@ describe("CLI result output surface", () => {
|
||||
});
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
describe("streamed CLI filtered selections", () => {
|
||||
it.each([
|
||||
["raw_result", "json", "null\n"],
|
||||
["raw_result", "jsonl", "null\n"],
|
||||
["nested.value", "json", '{"nested":{"value":null}}\n'],
|
||||
["missing", "json", "{}\n"],
|
||||
["count", "json", "0\n"],
|
||||
["enabled", "json", "false\n"],
|
||||
] as const)(
|
||||
"keeps the selected value of --filter-output %s in %s",
|
||||
async (filter, format, expected) => {
|
||||
const chunks: Buffer[] = [];
|
||||
const destination = new Writable({
|
||||
write(chunk: Buffer, _encoding, callback) {
|
||||
chunks.push(chunk);
|
||||
callback();
|
||||
},
|
||||
});
|
||||
const output = createCliResultOutput(
|
||||
["--format", format, "--filter-output", filter],
|
||||
destination,
|
||||
);
|
||||
if (output === undefined) throw new Error("Missing JSON output surface");
|
||||
await output.write(
|
||||
{ raw_result: null, nested: { value: null }, count: 0, enabled: false },
|
||||
{ command: "fixture", duration: "1ms", format },
|
||||
);
|
||||
expect(Buffer.concat(chunks).toString("utf8")).toBe(expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { copyFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { describe, expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
inspectMachoSchema,
|
||||
listArchitecturesSchema,
|
||||
} from "../../../src/domain/native/nativeInspection.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
@@ -34,27 +38,68 @@ const resultSchema = z.object({
|
||||
describe.skipIf(process.platform !== "darwin")(
|
||||
"native Mach-O CLI with echoed path text",
|
||||
() => {
|
||||
cliTest(
|
||||
"does not read load commands or symbols from the file name",
|
||||
async ({ cli }) => {
|
||||
const directory = await createTestTempDirectory("rea-macho-echo-");
|
||||
const inspect = async (name: string) => {
|
||||
const path = join(directory, name);
|
||||
await copyFile("/usr/bin/true", path);
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-macho", path, "--json"],
|
||||
environment,
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const { provenance: _provenance, ...facts } = resultSchema.parse(
|
||||
result.json,
|
||||
).normalized_result;
|
||||
return facts;
|
||||
};
|
||||
const forged = await inspect(FORGED_NAME);
|
||||
expect(forged).toEqual(await inspect("tool"));
|
||||
expect(JSON.stringify(forged)).not.toMatch(/forged|4242/u);
|
||||
},
|
||||
);
|
||||
const lipoName = "tool\narchitecture forged\n offset 123\n size 32";
|
||||
for (const [facts, command, filename] of [
|
||||
["load commands or symbols", "inspect-macho", FORGED_NAME],
|
||||
["FAT architecture records", "inspect-macho", lipoName],
|
||||
["FAT architecture inventory", "list-architectures", lipoName],
|
||||
["thin-file framing", "inspect-macho", "tool\nNon-fat file: forged"],
|
||||
] as const) {
|
||||
cliTest(
|
||||
`does not read ${facts} from the file name`,
|
||||
async ({ cli, processes }) => {
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-native-cli-echo-",
|
||||
);
|
||||
const fixture = join(directory, "fat-fixture");
|
||||
const compiled = await processes.run(
|
||||
"/usr/bin/xcrun",
|
||||
[
|
||||
"clang",
|
||||
"-arch",
|
||||
"arm64",
|
||||
"-arch",
|
||||
"x86_64",
|
||||
resolve("tests/conformance/c/fixture.c"),
|
||||
"-o",
|
||||
fixture,
|
||||
],
|
||||
{ timeoutMs: 30_000 },
|
||||
);
|
||||
expect(compiled.exitCode, compiled.stderr).toBe(0);
|
||||
const inspect = async (name: string) => {
|
||||
const path = join(directory, name);
|
||||
await copyFile(fixture, path);
|
||||
const result = await cli.run({
|
||||
arguments: [command, path, "--json"],
|
||||
environment,
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const { provenance: _provenance, ...facts } = resultSchema.parse(
|
||||
result.json,
|
||||
).normalized_result;
|
||||
return facts;
|
||||
};
|
||||
const ordinary = await inspect("tool");
|
||||
// Prove this comparison exercised FAT framing, independent of host binaries.
|
||||
const architectures =
|
||||
listArchitecturesSchema.shape.architectures.parse(
|
||||
ordinary.architectures,
|
||||
);
|
||||
expect(architectures.total).toBeGreaterThan(1);
|
||||
if (command === "inspect-macho") {
|
||||
const selected =
|
||||
inspectMachoSchema.shape.selected_architecture.parse(
|
||||
ordinary.selected_architecture,
|
||||
);
|
||||
expect(selected.container_file_offset).toBeGreaterThan(0);
|
||||
}
|
||||
const forged = await inspect(filename);
|
||||
expect(forged).toEqual(ordinary);
|
||||
expect(JSON.stringify(forged)).not.toMatch(/forged|4242/u);
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -38,6 +38,36 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"rejects a 6502 image crossing the 16-bit boundary before provider startup",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-6502-cli-overflow-");
|
||||
const path = join(root, "image.bin");
|
||||
await writeFile(path, Buffer.from("a92a60", "hex"));
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect",
|
||||
path,
|
||||
"--target-format",
|
||||
"raw-binary",
|
||||
"--architecture",
|
||||
"6502",
|
||||
"--entry-point",
|
||||
"0xffff",
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: { reason: expect.stringContaining("6502 address width") },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"rejects an unaligned AArch64 entry before provider startup",
|
||||
async ({ cli }) => {
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { describe, expect } from "vitest";
|
||||
|
||||
import { historicalSourceGraphSchema } from "../../../src/domain/referenceSourceGraph.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
// Reference-source reads require no-follow opens; Windows reports unsupported.
|
||||
describe.skipIf(process.platform === "win32")(
|
||||
"compiled reference-source directory imports",
|
||||
() => {
|
||||
cliTest(
|
||||
"resolves directory spellings without selecting similarly named files",
|
||||
async ({ cli }) => {
|
||||
const workspace = await createTestTempDirectory(
|
||||
"rea-reference-directory-imports-",
|
||||
);
|
||||
const root = join(workspace, "source");
|
||||
const imports = [
|
||||
["slash.cjs", "./lib/", "lib/index.js"],
|
||||
["dot.cjs", "./lib/.", "lib/index.js"],
|
||||
["self.cjs", ".", "index.js"],
|
||||
["self-slash.cjs", "./", "index.js"],
|
||||
["nested/parent.cjs", "..", "index.js"],
|
||||
["nested/parent-slash.cjs", "../", "index.js"],
|
||||
["direct.cjs", "./lib.js", "lib.js"],
|
||||
["fallback.cjs", "./fallback", "fallback/index.js"],
|
||||
["legacy-order.cjs", "./dep", "dep/index.js"],
|
||||
] as const;
|
||||
const unresolved = [
|
||||
["missing.cjs", "./missing/", "missing/"],
|
||||
["escape.cjs", "../outside/", "../outside/"],
|
||||
["main.ts", "./folder.js/.", "folder.js"],
|
||||
] as const;
|
||||
const files = new Map<string, string>([
|
||||
["index.js", 'module.exports = "root index";\n'],
|
||||
["lib/index.js", 'module.exports = "library index";\n'],
|
||||
["lib.js", 'module.exports = "sibling JavaScript file";\n'],
|
||||
["lib.ts", 'export const value = "sibling TypeScript file";\n'],
|
||||
["fallback/index.js", 'module.exports = "fallback index";\n'],
|
||||
["dep/index.js", 'module.exports = "existing index priority";\n'],
|
||||
["dep.cjs", 'module.exports = "later CommonJS candidate";\n'],
|
||||
[
|
||||
"folder.ts",
|
||||
'export const value = "emitted filename counterpart";\n',
|
||||
],
|
||||
["missing.js", 'module.exports = "not a directory";\n'],
|
||||
...[...imports, ...unresolved].map(
|
||||
([path, specifier]) =>
|
||||
[path, `require(${JSON.stringify(specifier)});\n`] as const,
|
||||
),
|
||||
]);
|
||||
await Promise.all(
|
||||
[...files].map(async ([path, contents]) => {
|
||||
const target = join(root, path);
|
||||
await mkdir(dirname(target), { recursive: true });
|
||||
await writeFile(target, contents);
|
||||
}),
|
||||
);
|
||||
const outside = join(workspace, "outside", "index.js");
|
||||
await mkdir(dirname(outside), { recursive: true });
|
||||
await writeFile(outside, 'module.exports = "outside import root";\n');
|
||||
|
||||
// Node's loader establishes each fixture's meaning independently.
|
||||
for (const [path, specifier, target] of imports)
|
||||
expect(createRequire(join(root, path)).resolve(specifier)).toBe(
|
||||
join(root, target),
|
||||
);
|
||||
expect(() =>
|
||||
createRequire(join(root, "missing.cjs")).resolve("./missing/"),
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
createRequire(join(root, "main.ts")).resolve("./folder.js/."),
|
||||
).toThrow();
|
||||
expect(
|
||||
createRequire(join(root, "escape.cjs")).resolve("../outside/"),
|
||||
).toBe(outside);
|
||||
|
||||
const result = await cli.run({
|
||||
arguments: ["import-reference-source", root, "--json"],
|
||||
environment: {
|
||||
HOME: workspace,
|
||||
XDG_CONFIG_HOME: workspace,
|
||||
XDG_CACHE_HOME: workspace,
|
||||
},
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const graph = historicalSourceGraphSchema.parse(result.json);
|
||||
expect(graph.parse_failures).toEqual([]);
|
||||
expect(graph.relationships).toHaveLength(
|
||||
imports.length + unresolved.length,
|
||||
);
|
||||
for (const [from, , to] of imports)
|
||||
expect.soft(graph.relationships, from).toContainEqual({
|
||||
from_path: from,
|
||||
to,
|
||||
kind: "requires",
|
||||
resolution: "internal",
|
||||
parse_state: "parsed",
|
||||
});
|
||||
for (const [from, , to] of unresolved)
|
||||
expect.soft(graph.relationships, from).toContainEqual({
|
||||
from_path: from,
|
||||
to,
|
||||
kind: "requires",
|
||||
resolution: "unresolved",
|
||||
parse_state: "parsed",
|
||||
});
|
||||
expect(
|
||||
graph.entries.some((entry) => entry.path.includes("outside")),
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1,3 +1,5 @@
|
||||
import { join } from "node:path";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { describe, expect } from "vitest";
|
||||
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
@@ -62,3 +64,42 @@ describe("scenario CLI schema diagnostics", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
for (const field of [
|
||||
"executable_path",
|
||||
"application_path",
|
||||
"application_root",
|
||||
] as const) {
|
||||
cliTest(`names the unresolved Electron ${field}`, async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-electron-path-");
|
||||
const missing = join(root, "missing");
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"capture-electron-scenario",
|
||||
JSON.stringify({
|
||||
executable_path: process.execPath,
|
||||
application_path: root,
|
||||
application_root: root,
|
||||
actions: [],
|
||||
[field]: missing,
|
||||
}),
|
||||
"--json",
|
||||
],
|
||||
environment: { REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: [field],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining("ENOENT"),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(result.json)).toContain(missing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -366,16 +366,11 @@ it("rejects overlapping ZIP member data ranges through artifact inventory", asyn
|
||||
bytes.writeUInt32LE(firstLocalOffset, second + 42);
|
||||
await writeFile(path, bytes);
|
||||
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
const result = await withArtifactClient(target.value, (client) =>
|
||||
client.execute("inventory_artifact", {}),
|
||||
await expectInventoryFailure(
|
||||
path,
|
||||
"format",
|
||||
"ZIP archive is malformed: Overlapping entry found",
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ArtifactOperationError", reason: "io" },
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves encrypted-member and corrupt-CRC observations", async () => {
|
||||
@@ -438,16 +433,11 @@ it("preserves encrypted-member and corrupt-CRC observations", async () => {
|
||||
bytes[dataOffset] = firstByte ^ 1;
|
||||
await writeFile(corruptPath, bytes);
|
||||
|
||||
const corruptTarget = await parseBinaryTarget(corruptPath);
|
||||
if (!corruptTarget.ok) throw corruptTarget.error;
|
||||
const corruptResult = await withArtifactClient(
|
||||
corruptTarget.value,
|
||||
(client) => client.execute("inventory_artifact", {}),
|
||||
await expectInventoryFailure(
|
||||
corruptPath,
|
||||
"format",
|
||||
"ZIP archive is malformed: Invalid compressed data",
|
||||
);
|
||||
expect(corruptResult).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ArtifactOperationError", reason: "io" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a truncated ZIP through artifact inventory", async () => {
|
||||
@@ -455,17 +445,51 @@ it("rejects a truncated ZIP through artifact inventory", async () => {
|
||||
const path = join(root, "truncated.zip");
|
||||
await writeFile(path, Buffer.from([0x50, 0x4b, 0x03, 0x04]));
|
||||
|
||||
await expectInventoryFailure(
|
||||
path,
|
||||
"format",
|
||||
"ZIP archive is malformed: File format is not recognized",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports an unsupported ZIP compression method as unavailable", async () => {
|
||||
const root = await createTestTempDirectory("rea-zip-method-");
|
||||
const path = join(root, "lzma.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("data.txt", new TextReader("member bytes"), { level: 0 });
|
||||
const bytes = Buffer.from(await writer.close());
|
||||
// Declare LZMA (14) in both headers; REA reads only stored and Deflate data.
|
||||
const localHeader = bytes.indexOf(Buffer.from([0x50, 0x4b, 0x03, 0x04]));
|
||||
const centralHeader = bytes.indexOf(Buffer.from([0x50, 0x4b, 0x01, 0x02]));
|
||||
if (localHeader < 0 || centralHeader < 0)
|
||||
throw new Error("Expected ZIP local and central headers");
|
||||
bytes.writeUInt16LE(14, localHeader + 8);
|
||||
bytes.writeUInt16LE(14, centralHeader + 10);
|
||||
await writeFile(path, bytes);
|
||||
|
||||
await expectInventoryFailure(
|
||||
path,
|
||||
"unavailable",
|
||||
"ZIP archive uses an unsupported feature: Compression method not supported",
|
||||
);
|
||||
});
|
||||
|
||||
/** Inventory one archive through the provider and expect a typed failure. */
|
||||
const expectInventoryFailure = async (
|
||||
path: string,
|
||||
reason: string,
|
||||
detail: string,
|
||||
): Promise<void> => {
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
const result = await withArtifactClient(target.value, (client) =>
|
||||
client.execute("inventory_artifact", {}),
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ArtifactOperationError", reason: "io" },
|
||||
error: { _tag: "ArtifactOperationError", reason, detail },
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const writeSingleEntryZip = async (
|
||||
path: string,
|
||||
|
||||
@@ -515,6 +515,10 @@ it.each([
|
||||
"src/windows/Example.ts",
|
||||
{ code: true, runtime: true, package: true, apple: false, evm: false },
|
||||
],
|
||||
[
|
||||
"src/domain/javascript/javascriptRuntimeStaticCandidates.ts",
|
||||
{ code: true, runtime: true, package: true, javascript_recovery: true },
|
||||
],
|
||||
["install.sh", { code: true, runtime: true, package: true, evm: false }],
|
||||
[
|
||||
".agents/skills/reverse-engineer-anything/SKILL.md",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { parseConfig } from "../../../src/config/parseConfig.js";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { symlink, writeFile } from "node:fs/promises";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
@@ -14,7 +14,7 @@ import type {
|
||||
import type { DirectAnalysisDependencies } from "../../../src/application/DirectAnalysisDependencies.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { err, ok } from "../../../src/domain/result.js";
|
||||
import {
|
||||
readAnalysisSnapshot,
|
||||
writeAnalysisSnapshot,
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
} from "../../fixtures/binarySession.js";
|
||||
import { BinarySession } from "../../../src/application/binary/BinarySession.js";
|
||||
import { OwnedStagedOutput } from "../../../src/filesystem/OwnedStagedOutput.js";
|
||||
import { ProviderAdapterError } from "../../../src/domain/providerAdapterError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
CAPABILITIES as GHIDRA_CAPABILITIES,
|
||||
@@ -396,7 +397,85 @@ describe("snapshot output cleanup lifecycle", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const verifyWindowsSnapshotAdmission = async (
|
||||
selectedPath: "direct" | "junction",
|
||||
): Promise<void> => {
|
||||
const fixture = await createSnapshotReplayFixture(
|
||||
"rea-direct-snapshot-junction-",
|
||||
);
|
||||
const rawPath = join(dirname(fixture.path), "image.bin");
|
||||
await writeFile(rawPath, Buffer.from("a92a60", "hex"));
|
||||
const linked = join(dirname(fixture.path), "linked");
|
||||
const linkedPath = join(linked, basename(rawPath));
|
||||
const identity = { ...GHIDRA_PROVIDER_IDENTITY, version: "12.1.4" };
|
||||
const profile = createAnalysisProfile(identity, {
|
||||
fixture: true,
|
||||
});
|
||||
const baseProvider = fixture.createProvider({
|
||||
identity,
|
||||
profile,
|
||||
supportedOperations: ["search_strings"],
|
||||
});
|
||||
let rejectAdmission = false;
|
||||
const provider: AnalysisProvider = {
|
||||
...baseProvider,
|
||||
createClient: (target, profile, context) => {
|
||||
const client = baseProvider.createClient(target, profile, context);
|
||||
return {
|
||||
...client,
|
||||
execute: (operation, parameters, options) =>
|
||||
rejectAdmission && operation === "search_strings"
|
||||
? Promise.resolve(
|
||||
err(new ProviderAdapterError("ghidra", operation)),
|
||||
)
|
||||
: client.execute(operation, parameters, options),
|
||||
};
|
||||
},
|
||||
};
|
||||
const dependencies = fixture.dependencies(provider);
|
||||
const arguments_ = { pattern: "fixture", document: "fixture" };
|
||||
const options = {
|
||||
snapshotPath: fixture.snapshotPath,
|
||||
formatHint: "raw-binary" as const,
|
||||
architecture: "6502" as const,
|
||||
entryPoint: "0x8001",
|
||||
};
|
||||
const first = await runDirectAnalysis(
|
||||
dependencies,
|
||||
rawPath,
|
||||
"search_strings",
|
||||
arguments_,
|
||||
options,
|
||||
);
|
||||
expect(first).toMatchObject({ operation: "search_strings" });
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
if (selectedPath === "junction")
|
||||
await symlink(dirname(fixture.path), linked, "junction");
|
||||
rejectAdmission = true;
|
||||
const second = await runDirectAnalysis(
|
||||
dependencies,
|
||||
selectedPath === "junction" ? linkedPath : rawPath,
|
||||
"search_strings",
|
||||
arguments_,
|
||||
options,
|
||||
);
|
||||
expect(second).toMatchObject({ error: "Analysis failed" });
|
||||
expect(fixture.starts).toHaveLength(2);
|
||||
expect(
|
||||
fixture.calls.filter((call) => call === "search_strings"),
|
||||
).toHaveLength(1);
|
||||
};
|
||||
|
||||
describe("direct analysis composed snapshot replay", () => {
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"does not replay a CLI snapshot through a Windows junction",
|
||||
() => verifyWindowsSnapshotAdmission("junction"),
|
||||
);
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"does not replay a CLI snapshot before native admission on a canonical path",
|
||||
() => verifyWindowsSnapshotAdmission("direct"),
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
tool: "search_strings",
|
||||
@@ -516,7 +595,7 @@ describe("Ghidra composed workflow snapshot replay", () => {
|
||||
{ tool: "inspect_native_api", arguments: { procedure: "0x1000" } },
|
||||
{ tool: "trace_feature", arguments: { query: "fixture" } },
|
||||
] as const)(
|
||||
"persists and replays $tool with production Ghidra capability policies",
|
||||
"persists $tool with production Ghidra capability policies",
|
||||
async ({ tool, arguments: parameters }) => {
|
||||
const fixture = await createSnapshotReplayFixture("rea-ghidra-workflow-");
|
||||
const profile = createAnalysisProfile(
|
||||
@@ -554,8 +633,14 @@ describe("Ghidra composed workflow snapshot replay", () => {
|
||||
{ snapshotPath: fixture.snapshotPath },
|
||||
);
|
||||
expect(replay).toEqual(first);
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
expect(fixture.calls).toEqual(initialCalls);
|
||||
if (process.platform === "win32") {
|
||||
// The first provider call in a new CLI session admits its source.
|
||||
expect(fixture.starts).toHaveLength(2);
|
||||
expect(fixture.calls.length).toBeGreaterThan(initialCalls.length);
|
||||
} else {
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
expect(fixture.calls).toEqual(initialCalls);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -37,28 +37,76 @@ const dshClient = (
|
||||
env: Parameters<typeof supportedClients>[2],
|
||||
platform: NodeJS.Platform = "linux",
|
||||
) =>
|
||||
supportedClients(join("/home/a"), platform, env).find(
|
||||
supportedClients(resolve("/home/a"), platform, env).find(
|
||||
({ name }) => name === "dsh",
|
||||
);
|
||||
|
||||
describe("DeepSeek Harness configuration paths", () => {
|
||||
it.each([
|
||||
[undefined, ".dsh", ".agents", "shared"],
|
||||
["", ".dsh", ".agents", "shared"],
|
||||
[" \t ", ".dsh", ".agents", "shared"],
|
||||
["~", "", "", "dsh"],
|
||||
["~/selected home", "selected home", "selected home", "dsh"],
|
||||
["~\\selected home", "selected home", "selected home", "dsh"],
|
||||
] as const)(
|
||||
"resolves Harness and agents roots for %j",
|
||||
(override, dshRoot, agentsRoot, client) => {
|
||||
const home = resolve("/home/a");
|
||||
const environment = { DSH_HOME: override, DSH_AGENTS_HOME: override };
|
||||
expect(
|
||||
supportedClients(home, process.platform, environment).find(
|
||||
({ name }) => name === "dsh",
|
||||
),
|
||||
).toMatchObject({
|
||||
configPath: join(home, dshRoot, "cordis.patch.yml"),
|
||||
markerPath: join(home, dshRoot),
|
||||
});
|
||||
expect(clientSkillDirectories(home, ["dsh"], environment)).toEqual([
|
||||
{ client, directory: join(home, agentsRoot, "skills") },
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["relative home", " literal home ", "~someone"])(
|
||||
"resolves a literal root %j relative to cwd without trimming it",
|
||||
(override) => {
|
||||
const home = resolve("/home/a");
|
||||
const root = resolve(override);
|
||||
const environment = { DSH_HOME: override, DSH_AGENTS_HOME: override };
|
||||
expect(
|
||||
supportedClients(home, process.platform, environment).find(
|
||||
({ name }) => name === "dsh",
|
||||
),
|
||||
).toMatchObject({
|
||||
configPath: join(root, "cordis.patch.yml"),
|
||||
markerPath: root,
|
||||
});
|
||||
expect(clientSkillDirectories(home, ["dsh"], environment)).toEqual([
|
||||
{ client: "dsh", directory: join(root, "skills") },
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves the home Cordis patch under the Harness home", () => {
|
||||
expect(dshClient({})).toEqual({
|
||||
name: "dsh",
|
||||
displayName: "DeepSeek Harness",
|
||||
configPath: join("/home/a", ".dsh", "cordis.patch.yml"),
|
||||
markerPath: join("/home/a", ".dsh"),
|
||||
configPath: resolve("/home/a", ".dsh", "cordis.patch.yml"),
|
||||
markerPath: resolve("/home/a", ".dsh"),
|
||||
format: "dsh",
|
||||
});
|
||||
// The home patch applies to every profile; DSH_HOME relocates it.
|
||||
expect(dshClient({ DSH_HOME: "/custom/harness" })?.configPath).toBe(
|
||||
join("/custom/harness", "cordis.patch.yml"),
|
||||
resolve("/custom/harness", "cordis.patch.yml"),
|
||||
);
|
||||
expect(
|
||||
clientSkillDirectories(join("/home/a"), ["dsh"], {
|
||||
DSH_AGENTS_HOME: "/custom/agents",
|
||||
}),
|
||||
).toEqual([{ client: "dsh", directory: join("/custom/agents", "skills") }]);
|
||||
).toEqual([
|
||||
{ client: "dsh", directory: resolve("/custom/agents", "skills") },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -87,3 +87,43 @@ it.each([
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("bounds the Java version probe and reports an over-budget probe as a failed Java check", async () => {
|
||||
const root = await createTestTempDirectory("rea-java-probe-bound-");
|
||||
const configuredHome = join(root, "selected-jdk");
|
||||
const installDir = join(root, "ghidra");
|
||||
await mkdir(join(installDir, "Ghidra"), { recursive: true });
|
||||
await writeFile(
|
||||
join(installDir, "Ghidra", "application.properties"),
|
||||
`application.version=${SUPPORTED_GHIDRA_VERSION}\napplication.java.min=17\n`,
|
||||
);
|
||||
// A chatty or hostile JVM that overruns the capture budget: spawnSync reports
|
||||
// ENOBUFS, which the probe already treats as a failed observation.
|
||||
mockSpawnSync.mockReturnValue({
|
||||
stdout: "",
|
||||
stderr: "java.version = 21.0.11\n",
|
||||
status: null,
|
||||
error: Object.assign(new Error("spawnSync /java ENOBUFS"), {
|
||||
code: "ENOBUFS",
|
||||
}),
|
||||
});
|
||||
|
||||
const inspection = inspectGhidraInstallation({
|
||||
environment: {},
|
||||
installDir,
|
||||
javaHome: configuredHome,
|
||||
});
|
||||
|
||||
const [, , options] = mockSpawnSync.mock.calls[0] as [
|
||||
string,
|
||||
readonly string[],
|
||||
{ readonly maxBuffer?: number },
|
||||
];
|
||||
expect(options.maxBuffer).toBe(1024 * 1024);
|
||||
expect(inspection.javaVersion).toBeNull();
|
||||
expect(inspection.javaHome).toBe(configuredHome);
|
||||
expect(inspection.checks.find(({ name }) => name === "java")).toMatchObject({
|
||||
status: "failed",
|
||||
code: "runtime_missing",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -237,6 +237,38 @@ mcp_servers:
|
||||
expect(await readFile(client.configPath, "utf8")).toBe(original);
|
||||
});
|
||||
|
||||
it("keeps unrelated numbers as written, including Discord IDs", async () => {
|
||||
const { home, client } = await hermesClient();
|
||||
// Hermes reads these exactly: two IDs one apart, an octal mode, a float.
|
||||
const original = `discord:
|
||||
free_response_channels:
|
||||
- 1187654321098765432
|
||||
channel_prompts:
|
||||
1187654321098765433: Build questions.
|
||||
1187654321098765434: Release questions.
|
||||
mode: 0600
|
||||
min_score: 0.0000001
|
||||
mcp_servers:
|
||||
other:
|
||||
command: other-server
|
||||
`;
|
||||
await writeFile(client.configPath, original);
|
||||
expect(
|
||||
(await configureClientConfiguration(client, {}, command)).status,
|
||||
).toBe("configured");
|
||||
const text = await readFile(client.configPath, "utf8");
|
||||
expect(text.startsWith(original)).toBe(true);
|
||||
expect(parseYaml(text, { intAsBigInt: true })).toMatchObject({
|
||||
mcp_servers: {
|
||||
rea: { command: command[0], args: command.slice(1), enabled: true },
|
||||
},
|
||||
});
|
||||
expect((await systemUninstallHost(home).removeClient(client)).status).toBe(
|
||||
"removed",
|
||||
);
|
||||
expect(await readFile(client.configPath, "utf8")).toBe(original);
|
||||
});
|
||||
|
||||
it("creates config.yaml when Hermes has no configuration yet", async () => {
|
||||
const { client } = await hermesClient();
|
||||
expect(
|
||||
|
||||
@@ -1060,6 +1060,142 @@ describe("NIBArchive UIKit event connections", () => {
|
||||
"UIRuntimeEventConnection",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports a runtime connection with no resolvable owner as an omission", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-ownerless-");
|
||||
const bundle = join(root, "Example.app");
|
||||
await mkdir(bundle, { recursive: true });
|
||||
// The connector is recognized by class, but carries no UISource reference,
|
||||
// so no connection can be projected from it.
|
||||
await writeFile(
|
||||
join(bundle, "Cell.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: [
|
||||
"UIProxyObject",
|
||||
"UIClassSwapper",
|
||||
"UIButton",
|
||||
"UIRuntimeEventConnection",
|
||||
"NSString",
|
||||
],
|
||||
objects: [
|
||||
{ classIndex: 0, values: { UIProxiedObjectIdentifier: { ref: 5 } } },
|
||||
{ classIndex: 1, values: { UIClassName: { ref: 6 } } },
|
||||
{ classIndex: 2, values: {} },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: { UIDestination: { ref: 1 }, UIEventMask: 64 },
|
||||
},
|
||||
{ classIndex: 2, values: {} },
|
||||
{ classIndex: 4, values: { "NS.bytes": "IBFilesOwner" } },
|
||||
{ classIndex: 4, values: { "NS.bytes": "BuildCell" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "e".repeat(64),
|
||||
});
|
||||
|
||||
expect(analysis.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
facet: "connections:Cell.nib",
|
||||
status: "partial",
|
||||
reason: "connection_unresolved",
|
||||
examined: 0,
|
||||
omitted: 1,
|
||||
}),
|
||||
);
|
||||
// The keyed-archive producer counts a recognized connector it cannot emit,
|
||||
// so this producer has to report the same document total for the same
|
||||
// connector rather than zero.
|
||||
expect(analysis.documents).toContainEqual(
|
||||
expect.objectContaining({
|
||||
relative_path: "Cell.nib",
|
||||
connection_count: 1,
|
||||
}),
|
||||
);
|
||||
expect(analysis.graph.truncated).toBe(true);
|
||||
expect(analysis.limitations).toContain(
|
||||
"Some recognized NIBArchive connectors declare no resolvable owner; they carry no connection evidence and are reported as omissions.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("NIBArchive ownerless connector accounting", () => {
|
||||
it("keeps a connection dropped by the limit reported as a limit", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-ownerless-limit-");
|
||||
const bundle = join(root, "Example.app");
|
||||
await mkdir(bundle, { recursive: true });
|
||||
// Two resolvable connectors and one ownerless connector with the limit
|
||||
// below the resolvable count, so this facet has both causes at once. Only a
|
||||
// higher limit recovers the dropped connection, so that is the reason the
|
||||
// caller needs, exactly as the keyed-archive producer reports it.
|
||||
await writeFile(
|
||||
join(bundle, "Cell.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: [
|
||||
"UIProxyObject",
|
||||
"UIClassSwapper",
|
||||
"UIButton",
|
||||
"UIRuntimeEventConnection",
|
||||
"NSString",
|
||||
],
|
||||
objects: [
|
||||
{ classIndex: 0, values: { UIProxiedObjectIdentifier: { ref: 5 } } },
|
||||
{ classIndex: 1, values: { UIClassName: { ref: 6 } } },
|
||||
{ classIndex: 2, values: {} },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: {
|
||||
UISource: { ref: 2 },
|
||||
UIDestination: { ref: 1 },
|
||||
UILabel: { ref: 7 },
|
||||
UIEventMask: 64,
|
||||
},
|
||||
},
|
||||
{ classIndex: 2, values: {} },
|
||||
{ classIndex: 4, values: { "NS.bytes": "IBFilesOwner" } },
|
||||
{ classIndex: 4, values: { "NS.bytes": "BuildCell" } },
|
||||
{ classIndex: 4, values: { "NS.bytes": "buildTapped:" } },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: {
|
||||
UISource: { ref: 4 },
|
||||
UIDestination: { ref: 1 },
|
||||
UILabel: { ref: 7 },
|
||||
},
|
||||
},
|
||||
{
|
||||
classIndex: 3,
|
||||
values: { UIDestination: { ref: 1 }, UIEventMask: 64 },
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "e".repeat(64),
|
||||
limits: { max_connections: 1 },
|
||||
});
|
||||
|
||||
expect(analysis.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
facet: "connections:Cell.nib",
|
||||
status: "partial",
|
||||
reason: "connection_limit_reached",
|
||||
examined: 1,
|
||||
omitted: 2,
|
||||
}),
|
||||
);
|
||||
expect(analysis.documents).toContainEqual(
|
||||
expect.objectContaining({
|
||||
relative_path: "Cell.nib",
|
||||
connection_count: 3,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// This exact file is already selected by the unchanged native Apple CI lane.
|
||||
|
||||
+3
-3
@@ -388,7 +388,7 @@ it("produces deterministic ASAR graphs with unpacked native linkage and complete
|
||||
await mkdir(source);
|
||||
await writeJavaScriptArtifactFixture(source);
|
||||
const archive = join(root, "app.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
|
||||
const first = await reconstructJavaScriptArtifact({
|
||||
input_path: archive,
|
||||
@@ -487,7 +487,7 @@ it("keeps ASAR analysis usable when unpacked native companion bytes are absent",
|
||||
await mkdir(source);
|
||||
await writeJavaScriptArtifactFixture(source);
|
||||
const archive = join(root, "app.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
await rm(join(`${archive}.unpacked`, "native", "addon.node"));
|
||||
|
||||
const snapshot = await scanArtifactInventory(archive);
|
||||
@@ -515,7 +515,7 @@ it("recurses into filesystem-backed ASAR containers without losing container-rel
|
||||
const resources = join(outer, "resources");
|
||||
await mkdir(resources, { recursive: true });
|
||||
await createPackageWithOptions(source, join(resources, "app.asar"), {
|
||||
unpack: "**/*.node",
|
||||
unpack: "*.node",
|
||||
});
|
||||
|
||||
const result = await reconstructJavaScriptArtifact({
|
||||
|
||||
@@ -444,73 +444,97 @@ describe("JavaScript application workflow error diagnostics", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const RUNTIME_PATH_CASES = [
|
||||
{
|
||||
name: "case-sensitive POSIX input root",
|
||||
root: null,
|
||||
path: "/applications/Example.app/Contents/Resources/app/renderer.js",
|
||||
status: "unknown",
|
||||
basis: "none",
|
||||
},
|
||||
{
|
||||
name: "case-sensitive POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/app/renderer.js",
|
||||
status: "unknown",
|
||||
basis: "none",
|
||||
},
|
||||
{
|
||||
name: "matching POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/App/renderer.js",
|
||||
status: "matched",
|
||||
basis: "operator-file-mapping",
|
||||
},
|
||||
{
|
||||
name: "case-insensitive Windows mapping root",
|
||||
root: String.raw`C:\runtime\App`,
|
||||
path: String.raw`c:\runtime\app\renderer.js`,
|
||||
status: "matched",
|
||||
basis: "operator-file-mapping",
|
||||
},
|
||||
] as const;
|
||||
|
||||
describe("JavaScript runtime reconciliation local paths", () => {
|
||||
it.each([
|
||||
{
|
||||
name: "case-sensitive POSIX input root",
|
||||
root: null,
|
||||
path: "/applications/Example.app/Contents/Resources/app/renderer.js",
|
||||
status: "unknown",
|
||||
},
|
||||
{
|
||||
name: "case-sensitive POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/app/renderer.js",
|
||||
status: "unknown",
|
||||
},
|
||||
{
|
||||
name: "matching POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/App/renderer.js",
|
||||
status: "matched",
|
||||
},
|
||||
{
|
||||
name: "case-insensitive Windows mapping root",
|
||||
root: String.raw`C:\runtime\App`,
|
||||
path: String.raw`c:\runtime\app\renderer.js`,
|
||||
status: "matched",
|
||||
},
|
||||
])("uses $name on every host", ({ root, path, status }) => {
|
||||
const base = JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE;
|
||||
const original = base.runtime_observations[0]!;
|
||||
const inspection = electronPageInspectionSchema.parse(
|
||||
original.normalized_result,
|
||||
);
|
||||
const runtime = createEvidence(undefined, original.provider, {
|
||||
predicateType: original.predicate_type,
|
||||
operation: original.operation,
|
||||
parameters: { ...original.parameters, include_script_sources: false },
|
||||
result: {
|
||||
...inspection,
|
||||
scripts: {
|
||||
...inspection.scripts,
|
||||
items: inspection.scripts.items.map((script) => ({
|
||||
...script,
|
||||
file_path: path,
|
||||
source: { included: false, reason: "not-requested" },
|
||||
})),
|
||||
it.each(RUNTIME_PATH_CASES)(
|
||||
"uses $name on every host",
|
||||
({ root, path, status, basis }) => {
|
||||
const base = JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE;
|
||||
const original = base.runtime_observations[0]!;
|
||||
const inspection = electronPageInspectionSchema.parse(
|
||||
original.normalized_result,
|
||||
);
|
||||
// Keep target and script coordinates consistent so an unrelated target
|
||||
// cannot activate the static layer after its script mapping was rejected.
|
||||
const runtime = createEvidence(undefined, original.provider, {
|
||||
predicateType: original.predicate_type,
|
||||
operation: original.operation,
|
||||
parameters: { ...original.parameters, include_script_sources: false },
|
||||
result: {
|
||||
...inspection,
|
||||
target: { ...inspection.target, file_path: path },
|
||||
scripts: {
|
||||
...inspection.scripts,
|
||||
items: inspection.scripts.items.map((script) => ({
|
||||
...script,
|
||||
file_path: path,
|
||||
source: { included: false, reason: "not-requested" },
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
confidence: original.confidence,
|
||||
authority: original.authority,
|
||||
});
|
||||
const reconciled = reconcileJavaScriptRuntimeEvidence({
|
||||
static_layers: base.static_layers.map((layer) => ({
|
||||
...layer,
|
||||
runtime_mappings: root === null ? [] : [{ kind: "file-root", root }],
|
||||
})),
|
||||
runtime_observations: [runtime],
|
||||
});
|
||||
if (!reconciled.ok) throw reconciled.error;
|
||||
const result = javascriptRuntimeReconciliationResultSchema.parse(
|
||||
reconciled.value.normalized_result,
|
||||
);
|
||||
expect(
|
||||
result.reconciliations.find(
|
||||
({ entity_kind }) => entity_kind === "script",
|
||||
),
|
||||
).toMatchObject({ status });
|
||||
});
|
||||
confidence: original.confidence,
|
||||
authority: original.authority,
|
||||
});
|
||||
const reconciled = reconcileJavaScriptRuntimeEvidence({
|
||||
static_layers: base.static_layers.map((layer) => ({
|
||||
...layer,
|
||||
runtime_mappings: root === null ? [] : [{ kind: "file-root", root }],
|
||||
})),
|
||||
runtime_observations: [runtime],
|
||||
});
|
||||
if (!reconciled.ok) throw reconciled.error;
|
||||
const result = javascriptRuntimeReconciliationResultSchema.parse(
|
||||
reconciled.value.normalized_result,
|
||||
);
|
||||
expect(
|
||||
result.reconciliations.find(
|
||||
({ entity_kind }) => entity_kind === "script",
|
||||
),
|
||||
).toMatchObject({ status, basis });
|
||||
expect(
|
||||
result.static_load_states.find(
|
||||
({ kind }) => kind === "javascript-asset",
|
||||
),
|
||||
).toMatchObject(
|
||||
status === "matched"
|
||||
? { status: "loaded", reason: "runtime-script-correspondence" }
|
||||
: { status: "unknown", reason: "layer-outside-runtime-scope" },
|
||||
);
|
||||
expect(result.static_layers[0]?.runtime_mappings).toEqual(
|
||||
root === null ? [] : [{ kind: "file-root", root, artifact_prefix: "" }],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves relative file mapping roots before deriving result Evidence", () => {
|
||||
const absoluteRoot = resolve(process.cwd(), "runtime-cache-fixture");
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import {
|
||||
mkdir,
|
||||
readFile,
|
||||
realpath,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
@@ -7,6 +13,37 @@ import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("raw-binary admission", () => {
|
||||
it("preserves the requested raw path for Windows reparse admission", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-linked-");
|
||||
const actual = join(directory, "actual");
|
||||
const linked = join(directory, "linked");
|
||||
await mkdir(actual);
|
||||
const bytes = Buffer.from("a90160", "hex");
|
||||
await writeFile(join(actual, "fixture.bin"), bytes);
|
||||
await symlink(
|
||||
actual,
|
||||
linked,
|
||||
process.platform === "win32" ? "junction" : "dir",
|
||||
);
|
||||
const requested = join(linked, "fixture.bin");
|
||||
const canonical = await realpath(requested);
|
||||
const target = await parseBinaryTarget("linked/fixture.bin", {
|
||||
cwd: directory,
|
||||
formatHint: "raw-binary",
|
||||
architecture: "6502",
|
||||
entryPoint: "0x8000",
|
||||
});
|
||||
expect(target).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
path: canonical,
|
||||
sourcePath: process.platform === "win32" ? requested : canonical,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
format: "raw-binary",
|
||||
architecture: "6502",
|
||||
},
|
||||
});
|
||||
});
|
||||
it("requires explicit architecture and entry even with a misleading suffix", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-target-");
|
||||
const path = join(directory, "fixture.js");
|
||||
|
||||
@@ -4,9 +4,35 @@ import { describe, expect, it } from "vitest";
|
||||
import { systemDoctorHost } from "../../../src/application/Doctor.js";
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { pe } from "../../../src/domain/binaryTarget.fixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("executable format refusal diagnostics", () => {
|
||||
it.each([
|
||||
[0x01a6, "0x01a6"],
|
||||
[0x0000, "0x0000"],
|
||||
[0xffff, "0xffff"],
|
||||
] as const)(
|
||||
"retains unsupported PE machine %i in the refusal",
|
||||
async (machine, expectedMachine) => {
|
||||
const directory = await createTestTempDirectory("rea-target-pe-machine-");
|
||||
const path = join(directory, "unsupported.exe");
|
||||
const bytes = pe(0x014c);
|
||||
bytes.writeUInt16LE(machine, 0x44);
|
||||
await writeFile(path, bytes);
|
||||
|
||||
const result = await parseBinaryTarget(path);
|
||||
if (result.ok) throw new Error("unsupported PE target was admitted");
|
||||
const reason = `unsupported PE architecture (COFF machine ${expectedMachine})`;
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "target_unavailable",
|
||||
category: "unsupported_target",
|
||||
message: `Cannot open artifact: ${reason}.`,
|
||||
details: { reason, constraint: "file_format_rejected" },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["NE", "LE", "LX"] as const)(
|
||||
"reports unsupported %s executables without path advice",
|
||||
async (signature) => {
|
||||
|
||||
@@ -471,3 +471,49 @@ it("exposes the target-free static JavaScript application workflow", async () =>
|
||||
const evidenceFor = (value: unknown) => {
|
||||
return parseEvidence(value);
|
||||
};
|
||||
|
||||
it("reports every unresolved Electron path without starting a provider", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-invalid-paths-");
|
||||
const capture = vi.fn();
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("must not start");
|
||||
});
|
||||
const server = createServer(
|
||||
{ kind: "session", session },
|
||||
{
|
||||
electronActiveObservation: {
|
||||
capture,
|
||||
identity: () => ({ id: "test", name: "test", version: "1" }),
|
||||
},
|
||||
},
|
||||
);
|
||||
const client = new Client({ name: "electron-path-test", version: "1" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server, session);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const fields = ["executable_path", "application_path", "application_root"];
|
||||
const result = await client.callTool({
|
||||
name: "capture_electron_scenario",
|
||||
arguments: {
|
||||
...Object.fromEntries(fields.map((field) => [field, join(root, field)])),
|
||||
actions: [],
|
||||
},
|
||||
});
|
||||
expect(result.isError).toBe(true);
|
||||
expect(parseMcpToolError(result)).toMatchObject({
|
||||
error: {
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: fields.map((field) => ({
|
||||
path: [field],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining("ENOENT"),
|
||||
})),
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(capture).not.toHaveBeenCalled();
|
||||
await client.ping();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import type { AnalysisOperationPort } from "../../../src/application/AnalysisProvider.js";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import { EnhancedTools } from "../../../src/application/EnhancedTools.js";
|
||||
import { AnalysisOutputError } from "../../../src/domain/analysisErrorCore.js";
|
||||
import { err, ok } from "../../../src/domain/result.js";
|
||||
|
||||
import { closeEnhancedToolResources, connect } from "./enhancedToolsHarness.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
const PROVIDER = {
|
||||
id: "fixture",
|
||||
name: "Fixture analysis provider",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
type Coverage = boolean | undefined;
|
||||
|
||||
interface Behavior {
|
||||
/** What the provider reports for the references of each match address. */
|
||||
readonly coverage?: Readonly<Record<string, Coverage>>;
|
||||
readonly limitations?: readonly string[];
|
||||
/** Also report the first string match as a procedure match. */
|
||||
readonly duplicateProcedure?: boolean;
|
||||
/** Fail the references read of this address. */
|
||||
readonly failXrefsOf?: string;
|
||||
readonly calls?: string[];
|
||||
}
|
||||
|
||||
const containing = (address: string) => ({
|
||||
query_address: address,
|
||||
found: false,
|
||||
procedure: null,
|
||||
reason: "not_in_procedure",
|
||||
});
|
||||
|
||||
/**
|
||||
* A provider with two string matches (0x10 and 0x11), each referenced from
|
||||
* one address (0x20 and 0x21).
|
||||
*/
|
||||
const provider = (behavior: Behavior = {}): AnalysisOperationPort => ({
|
||||
execute: async (name, arguments_) => {
|
||||
const address = String(arguments_.address);
|
||||
behavior.calls?.push(`${name}:${address}`);
|
||||
switch (name) {
|
||||
case "search_strings":
|
||||
return ok(
|
||||
createAnalysisExecution(
|
||||
[
|
||||
{ address: "0x10", value: "hello" },
|
||||
{ address: "0x11", value: "hello again" },
|
||||
],
|
||||
PROVIDER,
|
||||
),
|
||||
);
|
||||
case "search_procedures":
|
||||
return ok(
|
||||
createAnalysisExecution(
|
||||
behavior.duplicateProcedure === true
|
||||
? [{ address: "0x10", value: "hello" }]
|
||||
: [],
|
||||
PROVIDER,
|
||||
),
|
||||
);
|
||||
case "xrefs": {
|
||||
if (address === behavior.failXrefsOf)
|
||||
return err(new AnalysisOutputError("xrefs", "provider failed"));
|
||||
const reported = behavior.coverage?.[address];
|
||||
return ok(
|
||||
createAnalysisExecution(
|
||||
[address === "0x10" ? "0x20" : "0x21"],
|
||||
PROVIDER,
|
||||
{
|
||||
limitations: behavior.limitations ?? [],
|
||||
...(reported === undefined
|
||||
? {}
|
||||
: { referencesTruncated: reported }),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
case "resolve_containing_procedure":
|
||||
return ok(createAnalysisExecution(containing(address), PROVIDER));
|
||||
default:
|
||||
throw new Error(`Unexpected operation: ${name}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const expectedTrace = (
|
||||
residual: readonly string[],
|
||||
extraMatches: readonly object[] = [],
|
||||
) => ({
|
||||
query: "hello",
|
||||
search_mode: "literal",
|
||||
matches: [
|
||||
{ type: "string", address: "0x10", value: "hello" },
|
||||
{ type: "string", address: "0x11", value: "hello again" },
|
||||
...extraMatches,
|
||||
],
|
||||
references: [
|
||||
{
|
||||
target_address: "0x10",
|
||||
source_address: "0x20",
|
||||
containing_procedure: containing("0x20"),
|
||||
},
|
||||
{
|
||||
target_address: "0x11",
|
||||
source_address: "0x21",
|
||||
containing_procedure: containing("0x21"),
|
||||
},
|
||||
...extraMatches.map(() => ({
|
||||
target_address: "0x10",
|
||||
source_address: "0x20",
|
||||
containing_procedure: containing("0x20"),
|
||||
})),
|
||||
],
|
||||
truncated: residual.length > 0,
|
||||
residual_unknowns: residual,
|
||||
});
|
||||
|
||||
const unknownFor = (address: string) =>
|
||||
`References to ${address} were truncated by the provider; additional references may exist.`;
|
||||
|
||||
const trace = async (analysis: AnalysisOperationPort) => {
|
||||
const client = await connect(analysis);
|
||||
const result = await client.callTool({
|
||||
name: "trace_feature",
|
||||
arguments: { query: "hello" },
|
||||
});
|
||||
expect(result.isError).not.toBe(true);
|
||||
return result.structuredContent as { normalized_result: unknown };
|
||||
};
|
||||
|
||||
describe("trace_feature reference coverage", () => {
|
||||
it("marks the trace truncated for the target whose references the provider capped", async () => {
|
||||
const output = await trace(
|
||||
provider({ coverage: { "0x10": true, "0x11": false } }),
|
||||
);
|
||||
|
||||
expect(
|
||||
output.normalized_result,
|
||||
"the received references are kept and only the capped target is a residual unknown",
|
||||
).toEqual(expectedTrace([unknownFor("0x10")]));
|
||||
});
|
||||
|
||||
it("does not carry a truncation over to the next target that reports nothing", async () => {
|
||||
const output = await trace(provider({ coverage: { "0x10": true } }));
|
||||
|
||||
expect(output.normalized_result).toEqual(
|
||||
expectedTrace([unknownFor("0x10")]),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports a capped target once when it is matched twice", async () => {
|
||||
const output = await trace(
|
||||
provider({ coverage: { "0x10": true }, duplicateProcedure: true }),
|
||||
);
|
||||
|
||||
expect(output.normalized_result).toEqual(
|
||||
expectedTrace(
|
||||
[unknownFor("0x10")],
|
||||
[{ type: "procedure", address: "0x10", value: "hello" }],
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves the containing procedure of a repeated reference source once", async () => {
|
||||
const calls: string[] = [];
|
||||
const output = await trace(provider({ duplicateProcedure: true, calls }));
|
||||
|
||||
expect(
|
||||
calls.filter((call) => call.startsWith("resolve_containing_procedure:")),
|
||||
"the source 0x20 is referenced by two matches of the same address and resolved once",
|
||||
).toEqual([
|
||||
"resolve_containing_procedure:0x20",
|
||||
"resolve_containing_procedure:0x21",
|
||||
]);
|
||||
expect(
|
||||
output.normalized_result,
|
||||
"every reference is still reported with its containing procedure",
|
||||
).toEqual(
|
||||
expectedTrace(
|
||||
[],
|
||||
[{ type: "procedure", address: "0x10", value: "hello" }],
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the trace complete when the provider explicitly reports no cap", async () => {
|
||||
const output = await trace(
|
||||
provider({ coverage: { "0x10": false, "0x11": false } }),
|
||||
);
|
||||
|
||||
expect(output.normalized_result).toEqual(expectedTrace([]));
|
||||
});
|
||||
|
||||
it("does not change the trace of a provider that reports no coverage", async () => {
|
||||
const output = await trace(
|
||||
provider({
|
||||
limitations: ["Upstream xrefs_to capped results at 1000 references."],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(
|
||||
output.normalized_result,
|
||||
"a limitation text alone never truncates, and an absent field keeps the previous result",
|
||||
).toEqual(expectedTrace([]));
|
||||
});
|
||||
|
||||
it("never exposes the coverage field in the tool output", async () => {
|
||||
const output = await trace(
|
||||
provider({ coverage: { "0x10": true, "0x11": false } }),
|
||||
);
|
||||
|
||||
expect(JSON.stringify(output)).not.toMatch(
|
||||
/referencesTruncated|references_truncated/,
|
||||
);
|
||||
});
|
||||
|
||||
it("fails the trace when a references read fails and reads nothing further", async () => {
|
||||
const calls: string[] = [];
|
||||
const result = await new EnhancedTools(
|
||||
provider({ failXrefsOf: "0x10", calls }),
|
||||
).execute("trace_feature", { query: "hello" });
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(
|
||||
calls.filter((call) => call.startsWith("xrefs:")),
|
||||
"the next target is not read after the failure",
|
||||
).toEqual(["xrefs:0x10"]);
|
||||
});
|
||||
|
||||
it("stops without reading references when the trace is cancelled", async () => {
|
||||
const calls: string[] = [];
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const result = await new EnhancedTools(provider({ calls })).execute(
|
||||
"trace_feature",
|
||||
{ query: "hello" },
|
||||
controller.signal,
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
expect(calls.filter((call) => call.startsWith("xrefs:"))).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -10,7 +10,8 @@ import { createServer } from "../../../src/server/createServer.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import type { AnalysisProvider } from "../../../src/application/AnalysisProvider.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { ProviderAdapterError } from "../../../src/domain/providerAdapterError.js";
|
||||
import { err, ok } from "../../../src/domain/result.js";
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
import {
|
||||
createCacheProvider,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
} from "../../fixtures/binarySession.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { silentLogger } from "../../../src/logger.js";
|
||||
import { GHIDRA_PROVIDER_IDENTITY } from "../../../src/ghidra/GhidraProviderCapabilities.js";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
|
||||
const connect = async (
|
||||
@@ -50,29 +52,97 @@ const structured = (result: CallToolResult): Record<string, unknown> => {
|
||||
return z.record(z.string(), z.unknown()).parse(result.structuredContent);
|
||||
};
|
||||
|
||||
it("opens a headerless image when architecture and entry are supplied", async () => {
|
||||
const root = await createTestTempDirectory("rea-raw-mcp-");
|
||||
const path = join(root, "ecu.bin");
|
||||
await writeFile(path, Buffer.from("1eff2fe1", "hex"));
|
||||
const { client } = await connect();
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: {
|
||||
const withGhidraFixtureIdentity = (
|
||||
provider: AnalysisProvider,
|
||||
): AnalysisProvider => {
|
||||
const identity = { ...GHIDRA_PROVIDER_IDENTITY, version: "12.1.4" };
|
||||
const profile = createAnalysisProfile(identity, { fixture: true });
|
||||
return {
|
||||
...provider,
|
||||
identity: () => identity,
|
||||
capabilities: () =>
|
||||
provider.capabilities().map((capability) => ({
|
||||
...capability,
|
||||
provider: identity,
|
||||
})),
|
||||
resolveAnalysisProfile: () => Promise.resolve(ok({ profile })),
|
||||
createClient: (target, _profile, context) => {
|
||||
const client = provider.createClient(target, profile, context);
|
||||
return {
|
||||
...client,
|
||||
execute: async (operation, parameters, options) => {
|
||||
const result = await client.execute(operation, parameters, options);
|
||||
return result.ok
|
||||
? ok({
|
||||
...result.value,
|
||||
provider: identity,
|
||||
analysisProfile: profile,
|
||||
})
|
||||
: result;
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
it("keeps 6502 out of detected lifecycle output contracts", () => {
|
||||
const schema = toolContract("open_binary").outputSchema;
|
||||
const result = {
|
||||
path: "/fixture/image.bin",
|
||||
kind: "executable",
|
||||
sha256: "a".repeat(64),
|
||||
architecture: "6502",
|
||||
};
|
||||
expect(
|
||||
schema.safeParse({ result: { ...result, format: "pe" } }).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
schema.safeParse({
|
||||
result: { ...result, format: "raw-binary", entry_point: "0x8001" },
|
||||
}).success,
|
||||
).toBe(true);
|
||||
const validateAdvertised = new Ajv2020({ strict: false }).compile(
|
||||
z.toJSONSchema(schema),
|
||||
);
|
||||
expect(validateAdvertised({ result: { ...result, format: "pe" } })).toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
validateAdvertised({
|
||||
result: { ...result, format: "raw-binary", entry_point: "0x8001" },
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["arm", "0x08000000", "0x8000000", "1eff2fe1"],
|
||||
["6502", "0x008001", "0x8001", "a92a60"],
|
||||
])(
|
||||
"opens a headerless %s image when architecture and entry are supplied",
|
||||
async (architecture, entryPoint, canonical, bytes) => {
|
||||
const root = await createTestTempDirectory("rea-raw-mcp-");
|
||||
const path = join(root, "ecu.bin");
|
||||
await writeFile(path, Buffer.from(bytes, "hex"));
|
||||
const { client } = await connect();
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: {
|
||||
path,
|
||||
format: "raw-binary",
|
||||
architecture,
|
||||
entry_point: entryPoint,
|
||||
},
|
||||
});
|
||||
expect(opened.isError).not.toBe(true);
|
||||
expect(structured(opened).result).toMatchObject({
|
||||
path,
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entry_point: "0x08000000",
|
||||
},
|
||||
});
|
||||
expect(opened.isError).not.toBe(true);
|
||||
expect(structured(opened).result).toMatchObject({
|
||||
path,
|
||||
format: "raw-binary",
|
||||
kind: "executable",
|
||||
architecture: "arm",
|
||||
entry_point: "0x8000000",
|
||||
});
|
||||
});
|
||||
kind: "executable",
|
||||
architecture,
|
||||
entry_point: canonical,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects an unaligned AArch64 entry before selecting or starting a provider", async () => {
|
||||
const root = await createTestTempDirectory("rea-raw-mcp-alignment-");
|
||||
@@ -217,3 +287,118 @@ it("reuses a canonical raw entry and replaces the session when the entry changes
|
||||
expect(created).toEqual(["0x8000000", "0x9000000"]);
|
||||
expect(closed).toEqual(["0x8000000"]);
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"does not replay a saved read after switching to a Windows junction",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-raw-mcp-linked-reopen-");
|
||||
const actual = join(root, "actual");
|
||||
const linked = join(root, "linked");
|
||||
await mkdir(actual);
|
||||
const path = join(actual, "image.bin");
|
||||
await writeFile(path, Buffer.from("a92a60", "hex"));
|
||||
await symlink(actual, linked, "junction");
|
||||
const created: string[] = [];
|
||||
const executed: string[] = [];
|
||||
const fixture = createCacheProvider([]);
|
||||
const { client } = await connect(
|
||||
withGhidraFixtureIdentity({
|
||||
...fixture,
|
||||
createClient: (target) => {
|
||||
created.push(target.sourcePath ?? target.path);
|
||||
return {
|
||||
execute: (operation) => {
|
||||
if (operation === "address_name")
|
||||
executed.push(target.sourcePath ?? target.path);
|
||||
if (
|
||||
operation === "address_name" &&
|
||||
target.sourcePath === join(linked, "image.bin")
|
||||
)
|
||||
return Promise.resolve(
|
||||
err(new ProviderAdapterError("fixture", operation)),
|
||||
);
|
||||
return Promise.resolve(
|
||||
observed(operation === "address_name" ? "entry" : null),
|
||||
);
|
||||
},
|
||||
close: () => Promise.resolve(ok(null)),
|
||||
};
|
||||
},
|
||||
}),
|
||||
);
|
||||
const linkedPath = join(linked, "image.bin");
|
||||
for (const requested of [path, linkedPath]) {
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: {
|
||||
path: requested,
|
||||
format: "raw-binary",
|
||||
architecture: "6502",
|
||||
entry_point: "0x8001",
|
||||
},
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
||||
const address = await client.callTool({
|
||||
name: "address_name",
|
||||
arguments: { address: "0x8001", document: "image.bin" },
|
||||
});
|
||||
expect(address.isError === true, JSON.stringify(address)).toBe(
|
||||
requested === linkedPath,
|
||||
);
|
||||
}
|
||||
expect(created).toEqual([path, linkedPath]);
|
||||
expect(executed).toEqual([path, linkedPath]);
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"reuses saved reads after a fixture admits a noncanonical Windows path",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-raw-mcp-admitted-path-");
|
||||
const actual = join(root, "actual");
|
||||
const linked = join(root, "linked");
|
||||
await mkdir(actual);
|
||||
const path = join(actual, "image.bin");
|
||||
await writeFile(path, Buffer.from("a92a60", "hex"));
|
||||
await symlink(actual, linked, "junction");
|
||||
const calls: string[] = [];
|
||||
const fixture = createCacheProvider([]);
|
||||
// This fixture accepts the alias to isolate cache behavior after admission.
|
||||
// The real Ghidra verifier checks that a junction itself is rejected.
|
||||
const { client, session } = await connect(
|
||||
withGhidraFixtureIdentity({
|
||||
...fixture,
|
||||
createClient: () => ({
|
||||
execute: (operation) => {
|
||||
if (operation === "address_name") calls.push(operation);
|
||||
return Promise.resolve(
|
||||
observed(operation === "health" ? null : "entry"),
|
||||
);
|
||||
},
|
||||
close: () => Promise.resolve(ok(null)),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
const linkedPath = join(linked, "image.bin");
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: {
|
||||
path: linkedPath,
|
||||
format: "raw-binary",
|
||||
architecture: "6502",
|
||||
entry_point: "0x8001",
|
||||
},
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
||||
expect(session.activeTarget()?.sourcePath).toBe(linkedPath);
|
||||
expect(session.activeTarget()?.path).toBe(path);
|
||||
for (const _ of [0, 1]) {
|
||||
const address = await client.callTool({
|
||||
name: "address_name",
|
||||
arguments: { address: "0x8001", document: "image.bin" },
|
||||
});
|
||||
expect(address.isError, JSON.stringify(address)).not.toBe(true);
|
||||
}
|
||||
expect(calls).toEqual(["address_name"]);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -257,9 +257,11 @@ it.skipIf(process.platform === "win32").each(["cancelled", "timeout"] as const)(
|
||||
failures: [expect.objectContaining({ reason: "run-token-mismatch" })],
|
||||
});
|
||||
expect(failure.cleanupResult).toEqual(cleanup);
|
||||
expect(failure.resources).toEqual(
|
||||
expect.arrayContaining([request.runId]),
|
||||
);
|
||||
expect(failure.resources).toEqual([
|
||||
request.runId,
|
||||
`pid:${launched.ownership.leaderPid}`,
|
||||
`process-group:${launched.ownership.processGroupId}`,
|
||||
]);
|
||||
// An unresolved member does not grant authority to signal the shared group.
|
||||
const acquiredPid = launched.ownership.leaderPid;
|
||||
expect(() => process.kill(acquiredPid, 0)).not.toThrow();
|
||||
|
||||
@@ -28,6 +28,35 @@ const identitySchema = z.object({
|
||||
const itWithLinuxCaptureCapability =
|
||||
process.platform === "linux" ? itWithCaptureCapability : it.skip;
|
||||
|
||||
itWithCaptureCapability(
|
||||
"captures a POSIX PATH executable with a literal backslash in its basename",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-process-backslash-name-");
|
||||
const bin = join(root, "bin");
|
||||
await mkdir(bin);
|
||||
const command = "selected\\node";
|
||||
const selected = join(bin, command);
|
||||
await symlink(process.execPath, selected);
|
||||
const scenario = parseProcessScenario({
|
||||
executable: command,
|
||||
working_directory: root,
|
||||
environment: { PATH: bin },
|
||||
arguments: ["-e", 'process.stdout.write("selected executable")'],
|
||||
settle_ms: 100,
|
||||
});
|
||||
const result = await captureProcessScenario(scenario);
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.frames.map(({ data }) => data).join("")).toBe(
|
||||
"selected executable",
|
||||
);
|
||||
expect(result.value.exit).toMatchObject({ code: 0, reason: "exited" });
|
||||
expect(result.value.cleanup).toMatchObject({
|
||||
owned_process_group: "verified",
|
||||
temporary_root: "removed",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
itWithCaptureCapability(
|
||||
"preserves numeric reports and original normalized PTY text in Evidence",
|
||||
async () => {
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { access, chmod, readFile, stat } from "node:fs/promises";
|
||||
import {
|
||||
access,
|
||||
chmod,
|
||||
mkdir,
|
||||
readFile,
|
||||
stat,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join, posix, win32 } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
@@ -479,6 +486,66 @@ describe("Ghidra Windows launcher", () => {
|
||||
}),
|
||||
).toThrow(/metacharacters/u);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra Windows runtime isolation", () => {
|
||||
it.skipIf(process.platform !== "win32").each([
|
||||
{
|
||||
properties:
|
||||
"application.version=12.1.4\napplication.release.name=PUBLIC\n",
|
||||
release: "ghidra_12.1.4_PUBLIC",
|
||||
},
|
||||
{ properties: undefined, release: "renamed-install" },
|
||||
{ properties: "application.version=12.1.4\n", release: "renamed-install" },
|
||||
])(
|
||||
"prepares the release directory through the Windows runtime ($release)",
|
||||
async ({ properties, release }) => {
|
||||
const parent = await createTestTempDirectory("rea-launch-config-");
|
||||
const installRoot = join(parent, "renamed-install");
|
||||
if (properties !== undefined) {
|
||||
await mkdir(join(installRoot, "Ghidra"), { recursive: true });
|
||||
await writeFile(
|
||||
join(installRoot, "Ghidra", "application.properties"),
|
||||
properties,
|
||||
);
|
||||
}
|
||||
const runtime = await createGhidraTestRuntime(parent);
|
||||
runtimes.push(runtime);
|
||||
const spawnProcess = vi.fn(async () => {
|
||||
throw new Error("fixture stops before process creation");
|
||||
});
|
||||
const launcher = new GhidraHeadlessLauncher({
|
||||
environment: process.env,
|
||||
platform: "win32",
|
||||
analyzeHeadlessPath: join(
|
||||
installRoot,
|
||||
"support",
|
||||
"analyzeHeadless.bat",
|
||||
),
|
||||
javaHome: "C:\\Java\\jdk-21",
|
||||
bridgeScriptPath: join(parent, "ReaGhidraBridge.java"),
|
||||
spawnProcess,
|
||||
});
|
||||
const launched = await launcher.launch({
|
||||
runtimeRoot: runtime.path,
|
||||
transport: "unix-socket",
|
||||
endpointPath: join(runtime.path, "bridge.sock"),
|
||||
token: "fixture-token",
|
||||
runId: "d6fcbb66-e829-4ff6-a535-0035aec63139",
|
||||
targetPath: join(parent, "fixture.exe"),
|
||||
targetSha256: "b".repeat(64),
|
||||
providerVersion: "12.1.4",
|
||||
profileDigest: "a".repeat(64),
|
||||
});
|
||||
expect(launched.ok).toBe(false);
|
||||
expect(spawnProcess).toHaveBeenCalledOnce();
|
||||
expect(
|
||||
(
|
||||
await stat(join(runtime.path, "config", "ghidra", release))
|
||||
).isDirectory(),
|
||||
).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"keeps authority in a private descriptor and isolates Ghidra state through the batch launcher",
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
import { rm } from "node:fs/promises";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { inspectAddressContext } from "../../../../src/application/AnalysisContextQueries.js";
|
||||
import { EnhancedTools } from "../../../../src/application/EnhancedTools.js";
|
||||
import { IdaSessionClient } from "../../../../src/ida/IdaSessionClient.js";
|
||||
import { createIdaTarget, RecordingIdaMcp } from "../../../fixtures/idaMcp.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
afterEach(async () => {
|
||||
for (const root of roots.splice(0))
|
||||
await rm(root, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const session = async (cappedReferences = false) => {
|
||||
const { root, target } = await createIdaTarget("arm64");
|
||||
roots.push(root);
|
||||
const producer = new RecordingIdaMcp(target, "headless");
|
||||
if (cappedReferences) {
|
||||
const inner = producer.overrideCall;
|
||||
producer.overrideCall = (name, args) =>
|
||||
name === "xrefs_to"
|
||||
? [
|
||||
{
|
||||
xrefs: [
|
||||
{
|
||||
addr: "0x1004",
|
||||
type: "code",
|
||||
fn: { addr: "0x1000", name: "main", size: "0x20" },
|
||||
},
|
||||
],
|
||||
more: true,
|
||||
},
|
||||
]
|
||||
: inner?.(name, args);
|
||||
}
|
||||
const client = new IdaSessionClient(
|
||||
{
|
||||
command: "fixture",
|
||||
args: [],
|
||||
env: {},
|
||||
mode: "headless",
|
||||
timeoutMs: 1000,
|
||||
workspaceRoot: root,
|
||||
},
|
||||
target,
|
||||
producer,
|
||||
);
|
||||
return { client, target };
|
||||
};
|
||||
|
||||
const MAIN = {
|
||||
found: true,
|
||||
procedure: { address: "0x1000", name: "main" },
|
||||
};
|
||||
|
||||
describe("trace_feature on headless IDA", () => {
|
||||
it("attributes a reference to its containing procedure", async () => {
|
||||
const { client } = await session();
|
||||
try {
|
||||
const result = await new EnhancedTools(client).execute("trace_feature", {
|
||||
query: "a.b",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value).toMatchObject({
|
||||
matches: [{ type: "string", address: "0x3000" }],
|
||||
references: [
|
||||
{
|
||||
target_address: "0x3000",
|
||||
source_address: "0x1004",
|
||||
containing_procedure: MAIN,
|
||||
},
|
||||
],
|
||||
truncated: false,
|
||||
residual_unknowns: [],
|
||||
});
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps an upstream reference cap visible once containment makes the trace run", async () => {
|
||||
const { client } = await session(true);
|
||||
try {
|
||||
const result = await new EnhancedTools(client).execute("trace_feature", {
|
||||
query: "a.b",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value).toMatchObject({
|
||||
references: [{ source_address: "0x1004", containing_procedure: MAIN }],
|
||||
truncated: true,
|
||||
residual_unknowns: [
|
||||
"References to 0x3000 were truncated by the provider; additional references may exist.",
|
||||
],
|
||||
});
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("inspect_address_context on headless IDA", () => {
|
||||
it("resolves the admitted program as the document and reports the containing procedure", async () => {
|
||||
const { client, target } = await session();
|
||||
try {
|
||||
const result = await inspectAddressContext(client, {
|
||||
address: "0x1004",
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value).toMatchObject({
|
||||
address: "0x1004",
|
||||
document: target.path,
|
||||
procedure: { state: "available", value: MAIN },
|
||||
name: { state: "unavailable" },
|
||||
comment: { state: "unavailable" },
|
||||
inline_comment: { state: "unavailable" },
|
||||
bookmarks: { state: "unavailable" },
|
||||
});
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("answers the same way for an explicit admitted document", async () => {
|
||||
const { client, target } = await session();
|
||||
try {
|
||||
const implicit = await inspectAddressContext(client, {
|
||||
address: "0x1004",
|
||||
});
|
||||
const explicit = await inspectAddressContext(client, {
|
||||
address: "0x1004",
|
||||
document: target.path,
|
||||
});
|
||||
|
||||
if (!implicit.ok) throw implicit.error;
|
||||
if (!explicit.ok) throw explicit.error;
|
||||
expect(explicit.value).toEqual(implicit.value);
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,212 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
assertFeatureTrace,
|
||||
findMappedNonFunction,
|
||||
} from "../../../../scripts/lib/ida-feature-trace.mjs";
|
||||
|
||||
const procedure = { address: "0x1000", name: "main" };
|
||||
|
||||
const containing = (found: boolean) =>
|
||||
found
|
||||
? {
|
||||
query_address: "0x1004",
|
||||
found: true,
|
||||
procedure: { address: "0x1000", name: "main" },
|
||||
}
|
||||
: {
|
||||
query_address: "0x3010",
|
||||
found: false,
|
||||
procedure: null,
|
||||
reason: "not_in_procedure",
|
||||
};
|
||||
|
||||
const trace = (
|
||||
matches: readonly { type: string; address: string }[],
|
||||
references: readonly {
|
||||
target_address: string;
|
||||
containing_procedure: unknown;
|
||||
}[],
|
||||
) => ({
|
||||
query: "main",
|
||||
search_mode: "literal",
|
||||
matches,
|
||||
references,
|
||||
truncated: false,
|
||||
residual_unknowns: [],
|
||||
});
|
||||
|
||||
const SELECTED = { type: "procedure", address: "0x1000" };
|
||||
const SUBSTRING = { type: "procedure", address: "0x2000" };
|
||||
const STRING = { type: "string", address: "0x3000" };
|
||||
|
||||
describe("the real IDA lane's feature trace assertions", () => {
|
||||
it("accepts references to every matched address, whoever contains the source", () => {
|
||||
expect(() =>
|
||||
assertFeatureTrace(
|
||||
trace(
|
||||
[SELECTED, SUBSTRING, STRING],
|
||||
[
|
||||
{
|
||||
target_address: "0x1000",
|
||||
containing_procedure: containing(true),
|
||||
},
|
||||
// A substring match such as main_helper, referenced from code.
|
||||
{
|
||||
target_address: "0x2000",
|
||||
containing_procedure: containing(true),
|
||||
},
|
||||
// A string containing the query, referenced from data outside functions.
|
||||
{
|
||||
target_address: "0x3000",
|
||||
containing_procedure: containing(false),
|
||||
},
|
||||
],
|
||||
),
|
||||
procedure,
|
||||
),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("accepts a reference to the selected procedure from data outside functions", () => {
|
||||
expect(() =>
|
||||
assertFeatureTrace(
|
||||
trace(
|
||||
[SELECTED],
|
||||
[
|
||||
{
|
||||
target_address: "0x1000",
|
||||
containing_procedure: containing(false),
|
||||
},
|
||||
],
|
||||
),
|
||||
procedure,
|
||||
),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("rejects a reference whose target is not one of the matches", () => {
|
||||
expect(() =>
|
||||
assertFeatureTrace(
|
||||
trace(
|
||||
[SELECTED],
|
||||
[
|
||||
{
|
||||
target_address: "0x9999",
|
||||
containing_procedure: containing(true),
|
||||
},
|
||||
],
|
||||
),
|
||||
procedure,
|
||||
),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("rejects a trace without the selected procedure's match", () => {
|
||||
expect(() => assertFeatureTrace(trace([STRING], []), procedure)).toThrow();
|
||||
});
|
||||
|
||||
it("rejects a containment answer that is neither found nor a known reason", () => {
|
||||
expect(() =>
|
||||
assertFeatureTrace(
|
||||
trace(
|
||||
[SELECTED],
|
||||
[
|
||||
{
|
||||
target_address: "0x1000",
|
||||
containing_procedure: {
|
||||
query_address: "0x1004",
|
||||
found: false,
|
||||
procedure: null,
|
||||
reason: "unknown",
|
||||
},
|
||||
},
|
||||
],
|
||||
),
|
||||
procedure,
|
||||
),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it("rejects a trace that does not say whether it was truncated", () => {
|
||||
expect(() =>
|
||||
assertFeatureTrace(
|
||||
{ ...trace([SELECTED], []), truncated: undefined },
|
||||
procedure,
|
||||
),
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("the real IDA lane's mapped non-function probe", () => {
|
||||
const inFunction = {
|
||||
query_address: "0x1100",
|
||||
found: true,
|
||||
procedure: { address: "0x1000", name: "main" },
|
||||
};
|
||||
const data = {
|
||||
query_address: "0x3000",
|
||||
found: false,
|
||||
procedure: null,
|
||||
reason: "not_in_procedure",
|
||||
};
|
||||
const resolver =
|
||||
(answers: Readonly<Record<string, unknown>>, asked: string[] = []) =>
|
||||
async (address: string) => {
|
||||
asked.push(address);
|
||||
return answers[address];
|
||||
};
|
||||
|
||||
it("skips a string inside a function chunk and uses the next one", async () => {
|
||||
const asked: string[] = [];
|
||||
|
||||
await expect(
|
||||
findMappedNonFunction(
|
||||
[{ address: "0x1100" }, { address: "0x3000" }],
|
||||
resolver({ "0x1100": inFunction, "0x3000": data }, asked),
|
||||
),
|
||||
).resolves.toBe("0x3000");
|
||||
expect(asked, "strings are tried in order until one qualifies").toEqual([
|
||||
"0x1100",
|
||||
"0x3000",
|
||||
]);
|
||||
});
|
||||
|
||||
it("stops at the first string that qualifies", async () => {
|
||||
const asked: string[] = [];
|
||||
|
||||
await expect(
|
||||
findMappedNonFunction(
|
||||
[{ address: "0x3000" }, { address: "0x3100" }],
|
||||
resolver({ "0x3000": data, "0x3100": data }, asked),
|
||||
),
|
||||
).resolves.toBe("0x3000");
|
||||
expect(asked).toEqual(["0x3000"]);
|
||||
});
|
||||
|
||||
it("reports no qualifying string when every string is inside a function", async () => {
|
||||
await expect(
|
||||
findMappedNonFunction(
|
||||
[{ address: "0x1100" }, { address: "0x1200" }],
|
||||
resolver({ "0x1100": inFunction, "0x1200": inFunction }),
|
||||
),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("reports no qualifying string when the target has no strings", async () => {
|
||||
await expect(
|
||||
findMappedNonFunction([], resolver({})),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("rejects a listed string that resolves as unmapped, since IDA cannot list an unmapped address", async () => {
|
||||
await expect(
|
||||
findMappedNonFunction(
|
||||
[{ address: "0x4000" }, { address: "0x3000" }],
|
||||
resolver({
|
||||
"0x4000": { ...data, reason: "outside_segments" },
|
||||
"0x3000": data,
|
||||
}),
|
||||
),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -134,7 +134,7 @@ it("ignores unavailable members of a nested ASAR but refuses them as active entr
|
||||
const source = join(root, "bundle");
|
||||
await mkdir(source);
|
||||
const archive = join(source, "app.asar");
|
||||
await createPackageWithOptions(contents, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(contents, archive, { unpack: "*.node" });
|
||||
await rm(join(`${archive}.unpacked`, "native", "addon.node"));
|
||||
|
||||
const nestedOutput = join(root, "nested-output");
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { MachOSliceArtifactReader } from "../../../../src/artifacts/MachOSliceArtifactReader.js";
|
||||
import { XcrunCommandRunner } from "../../../../src/native/CommandRunner.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../../../../src/process/DarwinProcessRunTokenReader.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
/**
|
||||
* Read a 32-bit FAT table directly. The host's /bin/ls changes between macOS
|
||||
@@ -42,6 +44,56 @@ describe("Mach-O slice reader with system lipo", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "darwin")(
|
||||
"keeps FAT slice records separate from the echoed source pathname",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-lipo-fat-path-");
|
||||
const path = join(
|
||||
directory,
|
||||
"source\narchitecture forged\n offset 123\n size 32",
|
||||
);
|
||||
const bytes = Buffer.alloc(8224);
|
||||
bytes.writeUInt32BE(0xca_fe_ba_be, 0);
|
||||
bytes.writeUInt32BE(2, 4);
|
||||
const slices = [
|
||||
{ cpu: 0x0100_000c, subtype: 0, offset: 4096 },
|
||||
{ cpu: 0x0100_0007, subtype: 3, offset: 8192 },
|
||||
];
|
||||
slices.forEach(({ cpu, subtype, offset }, index) => {
|
||||
const entry = 8 + index * 20;
|
||||
bytes.writeUInt32BE(cpu, entry);
|
||||
bytes.writeUInt32BE(subtype, entry + 4);
|
||||
bytes.writeUInt32BE(offset, entry + 8);
|
||||
bytes.writeUInt32BE(32, entry + 12);
|
||||
bytes.writeUInt32BE(12, entry + 16);
|
||||
bytes.writeUInt32LE(0xfeed_facf, offset);
|
||||
bytes.writeUInt32LE(cpu, offset + 4);
|
||||
bytes.writeUInt32LE(subtype, offset + 8);
|
||||
bytes.writeUInt32LE(1, offset + 12);
|
||||
});
|
||||
await writeFile(path, bytes);
|
||||
const reader = new MachOSliceArtifactReader(path, {});
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
expect(
|
||||
entries.map(({ byteOffset, declaredSize }) => [
|
||||
byteOffset,
|
||||
declaredSize,
|
||||
]),
|
||||
).toEqual([
|
||||
[4096, 32],
|
||||
[8192, 32],
|
||||
]);
|
||||
expect(entries.every(({ path }) => !path.includes("forged"))).toBe(
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform !== "darwin")(
|
||||
"checks real /bin/ls slice ranges against its FAT table",
|
||||
async () => {
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
type NativeCommandRunner,
|
||||
} from "../../../../src/native/CommandRunner.js";
|
||||
import { err, ok } from "../../../../src/domain/result.js";
|
||||
import { parseLipoArchitectures } from "../../../../src/native/parsers/lipo.js";
|
||||
import { parseLipoOutput } from "../../../../src/native/parsers/lipo.js";
|
||||
import { parseCodeSignature } from "../../../../src/native/parsers/codesign.js";
|
||||
import { prepareProcessOwnershipInspection } from "../../../../src/process/ProcessOwnershipObservation.js";
|
||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
||||
@@ -960,15 +960,17 @@ describe("native macOS provider failures and parsing", () => {
|
||||
});
|
||||
|
||||
it("parses thin and universal lipo fixtures", async () => {
|
||||
expect(
|
||||
parseLipoArchitectures(await fixture("lipo-thin.txt")),
|
||||
).toMatchObject([{ name: "arm64" }]);
|
||||
expect(parseLipoArchitectures(await fixture("lipo-fat.txt"))).toMatchObject(
|
||||
[
|
||||
expect(parseLipoOutput(await fixture("lipo-thin.txt"))).toMatchObject({
|
||||
format: "thin",
|
||||
architectures: [{ name: "arm64" }],
|
||||
});
|
||||
expect(parseLipoOutput(await fixture("lipo-fat.txt"))).toMatchObject({
|
||||
format: "fat",
|
||||
architectures: [
|
||||
{ name: "x86_64", file_offset: 16384, size: 4096 },
|
||||
{ name: "arm64", file_offset: 32768, size: 8192 },
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects trailing text in lipo numeric fields instead of truncating", () => {
|
||||
@@ -980,7 +982,7 @@ describe("native macOS provider failures and parsing", () => {
|
||||
" size 0x10",
|
||||
" align 2^14 (16384)",
|
||||
].join("\n");
|
||||
expect(parseLipoArchitectures(output)).toMatchObject([
|
||||
expect(parseLipoOutput(output).architectures).toMatchObject([
|
||||
{ name: "arm64", file_offset: null, size: null, alignment: 16384 },
|
||||
]);
|
||||
});
|
||||
@@ -993,10 +995,11 @@ describe("native macOS provider failures and parsing", () => {
|
||||
" align 2^14 (16384)",
|
||||
].join("\n");
|
||||
expect(
|
||||
parseLipoArchitectures(output.replace("(16384)", "(8192)"))[0]?.alignment,
|
||||
parseLipoOutput(output.replace("(16384)", "(8192)")).architectures[0]
|
||||
?.alignment,
|
||||
).toBeNull();
|
||||
expect(
|
||||
parseLipoArchitectures(output.replace("2^14 (16384)", "2^14"))[0]
|
||||
parseLipoOutput(output.replace("2^14 (16384)", "2^14")).architectures[0]
|
||||
?.alignment,
|
||||
).toBe(16384);
|
||||
});
|
||||
|
||||
@@ -157,6 +157,50 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["ordinary", "/owned/universal", "\n"],
|
||||
["LF Non-fat text", "/owned/\nNon-fat file: forged", "\n"],
|
||||
["CRLF Non-fat text", "/owned/\r\nNon-fat file: forged", "\r\n"],
|
||||
])(
|
||||
"projects universal segment evidence into the selected slice's container offsets with %s path framing",
|
||||
async (_description, path, lineEnding) => {
|
||||
const records = (await nativeFixture("lipo-fat.txt")).replace(
|
||||
/^Fat header in:[^\r\n]*\r?\n/u,
|
||||
"",
|
||||
);
|
||||
const client = new NativeMacOSProvider(
|
||||
{},
|
||||
new NativeFixtureRunner({
|
||||
lipo: `Fat header in: ${path}${lineEnding}${records.replaceAll("\n", lineEnding)}`,
|
||||
}),
|
||||
"darwin",
|
||||
).createClient(nativeMachoTarget(path));
|
||||
const result = await client.execute("inspect_macho", {});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.result).toMatchObject({
|
||||
selected_architecture: { container_file_offset: 32768 },
|
||||
});
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 32768,
|
||||
end: 40960,
|
||||
});
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset",
|
||||
offset: 36864,
|
||||
});
|
||||
expect(result.value.locations).not.toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 0,
|
||||
end: 8192,
|
||||
});
|
||||
// Normalized tool fields keep their slice-relative meaning.
|
||||
const normalized = inspectMachoSchema.parse(result.value.result);
|
||||
expect(normalized.segments.items[0]?.file_offset).toBe(0);
|
||||
expect(normalized.entrypoints.items[0]?.file_offset).toBe(4096);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ capture: "calculator.txt", selected: "arm64e" },
|
||||
{ capture: "shortcut-droplet.txt", selected: "arm64" },
|
||||
@@ -187,34 +231,6 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it("projects universal segment evidence into the selected slice's container offsets", async () => {
|
||||
const client = new NativeMacOSProvider(
|
||||
{},
|
||||
new NativeFixtureRunner(),
|
||||
"darwin",
|
||||
).createClient(nativeMachoTarget("/owned/universal"));
|
||||
const result = await client.execute("inspect_macho", {});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 32768,
|
||||
end: 40960,
|
||||
});
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset",
|
||||
offset: 36864,
|
||||
});
|
||||
expect(result.value.locations).not.toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 0,
|
||||
end: 8192,
|
||||
});
|
||||
// Normalized tool fields keep their slice-relative meaning.
|
||||
const normalized = inspectMachoSchema.parse(result.value.result);
|
||||
expect(normalized.segments.items[0]?.file_offset).toBe(0);
|
||||
expect(normalized.entrypoints.items[0]?.file_offset).toBe(4096);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
description: "thin",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { expect, it } from "vitest";
|
||||
|
||||
import { parseOtoolLoadCommands } from "../../../../src/native/parsers/otool.js";
|
||||
import { parsePlistJson } from "../../../../src/native/parsers/plist.js";
|
||||
import { parseLipoArchitectures } from "../../../../src/native/parsers/lipo.js";
|
||||
import { parseLipoOutput } from "../../../../src/native/parsers/lipo.js";
|
||||
import { nativeFixture } from "../../../fixtures/nativeCommands.js";
|
||||
|
||||
const toCrlf = (value: string): string => value.replaceAll("\n", "\r\n");
|
||||
@@ -15,7 +15,10 @@ it.each([
|
||||
"retains the reported thin architecture when lipo echoes filename %j",
|
||||
(filename) => {
|
||||
const output = `input file /owned/${filename} is not a fat file\nNon-fat file: /owned/${filename} is architecture: arm64\n`;
|
||||
expect(parseLipoArchitectures(output)).toMatchObject([{ name: "arm64" }]);
|
||||
expect(parseLipoOutput(output)).toMatchObject({
|
||||
format: "thin",
|
||||
architectures: [{ name: "arm64" }],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -38,10 +41,13 @@ it("does not mistake fat slice output for a thin Non-fat file record", () => {
|
||||
" align 2^12 (4096)",
|
||||
"",
|
||||
].join("\n");
|
||||
expect(parseLipoArchitectures(output)).toMatchObject([
|
||||
{ name: "arm64", file_offset: 16384 },
|
||||
{ name: "x86_64", file_offset: 16793600 },
|
||||
]);
|
||||
expect(parseLipoOutput(output)).toMatchObject({
|
||||
format: "fat",
|
||||
architectures: [
|
||||
{ name: "arm64", file_offset: 16384 },
|
||||
{ name: "x86_64", file_offset: 16793600 },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps section blocks separate under CRLF captures", async () => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { DatabaseSync } from "node:sqlite";
|
||||
import { promisify } from "node:util";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { expect, it as nativeTest, onTestFinished } from "vitest";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { SqliteDatabaseProvider } from "../../../src/sqlite/SqliteDatabaseProvider.js";
|
||||
import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
|
||||
import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";
|
||||
@@ -356,6 +357,49 @@ it("does not execute views when selecting rows", async () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("attributes table and column selection failures to their own arguments", async () => {
|
||||
const { database } = await createFixture();
|
||||
const provider = createProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
const projection = async (selection: {
|
||||
table: string;
|
||||
columns?: string[];
|
||||
}) => {
|
||||
const result = await provider.inspect({
|
||||
path: database.path,
|
||||
row_limit: 1,
|
||||
...selection,
|
||||
});
|
||||
if (result.ok) throw new Error("Expected a rejected selection");
|
||||
return projectAnalysisError(result.error);
|
||||
};
|
||||
expect(
|
||||
await projection({ table: "records", columns: ["nope"] }),
|
||||
).toMatchObject({
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["columns"],
|
||||
reason: "invalid_format",
|
||||
message:
|
||||
"Selected column does not exist with that exact name in table records: nope",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(await projection({ table: "absent" })).toMatchObject({
|
||||
details: { issues: [{ path: ["table"] }] },
|
||||
});
|
||||
const selected = await provider.inspect({
|
||||
path: database.path,
|
||||
table: "records",
|
||||
columns: ["id"],
|
||||
row_limit: 1,
|
||||
});
|
||||
if (!selected.ok) throw selected.error;
|
||||
expect(selected.value.result).toMatchObject({ rows: { columns: ["id"] } });
|
||||
});
|
||||
|
||||
it("rejects malformed databases without altering the selected file", async () => {
|
||||
const workspace = await createTestWorkspace("rea-sqlite-invalid-");
|
||||
onTestFinished(() => removeTestWorkspace(workspace.root));
|
||||
|
||||
@@ -1278,3 +1278,102 @@ describe("selector origin forwarding", () => {
|
||||
).toEqual(["provider", "provider", undefined]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reference truncation forwarding", () => {
|
||||
const referenceProvider = (
|
||||
referencesTruncated: boolean | undefined,
|
||||
calls: string[],
|
||||
): AnalysisProvider => {
|
||||
const identity = {
|
||||
id: "fixture",
|
||||
name: "Fixture analysis provider",
|
||||
version: "1",
|
||||
} as const;
|
||||
return {
|
||||
identity: () => identity,
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({
|
||||
profile: createAnalysisProfile(identity, { fixture: true }),
|
||||
}),
|
||||
),
|
||||
capabilities: () => [
|
||||
{
|
||||
provider: identity,
|
||||
operation: "xrefs",
|
||||
available: true,
|
||||
reason: null,
|
||||
effects: {
|
||||
mutatesArtifact: false,
|
||||
launchesProcess: false,
|
||||
mayShowUi: false,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: false,
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
},
|
||||
limitations: [],
|
||||
},
|
||||
],
|
||||
createClient: () => ({
|
||||
execute: (operation) => {
|
||||
calls.push(operation);
|
||||
return Promise.resolve(
|
||||
resultOk(
|
||||
createAnalysisExecution(
|
||||
["0x2000"],
|
||||
identity,
|
||||
referencesTruncated === undefined
|
||||
? {}
|
||||
: { referencesTruncated },
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
close: () => Promise.resolve(resultOk(null)),
|
||||
}),
|
||||
};
|
||||
};
|
||||
const parameters = { address: "0x1000", document: "fixture" };
|
||||
|
||||
it("forwards a truncation on both execution paths and never replays it from the snapshot", async () => {
|
||||
const [first] = await createBinarySessionTargets();
|
||||
const calls: string[] = [];
|
||||
const session = createTestBinarySession(referenceProvider(true, calls));
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
calls.length = 0;
|
||||
|
||||
const direct = await session.execute("xrefs", parameters);
|
||||
const admitted = await session.withAdmittedAnalysis(
|
||||
"trace_feature",
|
||||
undefined,
|
||||
(analysis) => analysis.execute("xrefs", parameters),
|
||||
);
|
||||
|
||||
expect(direct.ok && direct.value.referencesTruncated).toBe(true);
|
||||
if (!admitted.ok) throw admitted.error;
|
||||
expect(admitted.value.ok && admitted.value.value.referencesTruncated).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
calls,
|
||||
"a truncated read is not recorded, so every call reaches the provider",
|
||||
).toEqual(["xrefs", "xrefs"]);
|
||||
});
|
||||
|
||||
it("keeps an explicit complete report out of the way of snapshot replay", async () => {
|
||||
const [first] = await createBinarySessionTargets();
|
||||
const calls: string[] = [];
|
||||
const session = createTestBinarySession(referenceProvider(false, calls));
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
calls.length = 0;
|
||||
|
||||
const live = await session.execute("xrefs", parameters);
|
||||
await session.execute("xrefs", parameters);
|
||||
|
||||
expect(live.ok && live.value.referencesTruncated).toBe(false);
|
||||
expect(calls, "the complete read is recorded and replayed").toEqual([
|
||||
"xrefs",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
FEATURES {
|
||||
STARTADDRESS: default = $8001;
|
||||
}
|
||||
MEMORY {
|
||||
IMAGE: start = %S, size = $10000 - %S, file = %O;
|
||||
}
|
||||
SEGMENTS {
|
||||
CODE: load = IMAGE, type = ro;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
; Source-owned NMOS 6502 fixture: direct call, conditional branch, and arithmetic.
|
||||
.setcpu "6502"
|
||||
.segment "CODE"
|
||||
.export entry, add_three
|
||||
|
||||
entry:
|
||||
lda #7
|
||||
jsr add_three
|
||||
cmp #10
|
||||
bne mismatch
|
||||
lda #42
|
||||
rts
|
||||
mismatch:
|
||||
lda #0
|
||||
rts
|
||||
add_three:
|
||||
clc
|
||||
adc #3
|
||||
rts
|
||||
@@ -29,15 +29,25 @@ const parametersFor = (
|
||||
operation: string,
|
||||
): Readonly<Record<string, JsonValue>> => {
|
||||
if (operation.startsWith("search_")) return { pattern: "a.b" };
|
||||
if (operation === "xrefs") return { address: "0x1000" };
|
||||
if (operation === "xrefs" || operation === "resolve_containing_procedure")
|
||||
return { address: "0x1000" };
|
||||
if (operation.startsWith("list_")) return {};
|
||||
return { procedure: "main" };
|
||||
};
|
||||
|
||||
/** Operations only the headless profile declares. */
|
||||
const HEADLESS_ONLY: ReadonlySet<string> = new Set([
|
||||
"resolve_containing_procedure",
|
||||
"list_documents",
|
||||
]);
|
||||
|
||||
describe.each(["attached", "headless"] as const)(
|
||||
"IDA %s caller-visible contracts",
|
||||
(mode) => {
|
||||
it.each(IDA_OPERATIONS)(
|
||||
const operations = IDA_OPERATIONS.filter(
|
||||
(operation) => mode === "headless" || !HEADLESS_ONLY.has(operation),
|
||||
);
|
||||
it.each(operations)(
|
||||
"declares %s UI effects matching the upstream tools it reaches",
|
||||
async (operation) => {
|
||||
const { root, target } = await createIdaTarget();
|
||||
@@ -69,7 +79,7 @@ describe.each(["attached", "headless"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
it.each(IDA_OPERATIONS)(
|
||||
it.each(operations)(
|
||||
"serializes %s against its named advertised output contract",
|
||||
async (operation) => {
|
||||
const { root, target } = await createIdaTarget();
|
||||
|
||||
@@ -35,6 +35,20 @@ const shellExamples = (content: string): string[] =>
|
||||
);
|
||||
|
||||
describe("onboarding documentation product facts", () => {
|
||||
it.each([
|
||||
["docs/native-investigation.md", "raw-binary.md#nmos-6502"],
|
||||
["docs/ghidra-riscv.md", "raw-binary.md"],
|
||||
])(
|
||||
"routes raw admission guidance in %s to the owning guide",
|
||||
async (path, target) => {
|
||||
const content = await readFile(resolve(path), "utf8");
|
||||
const links = [...content.matchAll(/\]\(([^)\s]+)\)/gu)].map(
|
||||
(match) => match[1],
|
||||
);
|
||||
expect(links, path).toContain(target);
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the installation MCP example aligned with the package registration command", async () => {
|
||||
const content = await readFile(resolve("docs/installation.md"), "utf8");
|
||||
expect(jsonExamples(content)).toContainEqual(
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
@inline(never)
|
||||
func consume(_ value: String) { print(value) }
|
||||
@inline(never)
|
||||
func smallLiteral() { consume("SleepDisabled") }
|
||||
@inline(never)
|
||||
func largeLiteral() { consume("The power setting could not be changed.") }
|
||||
@inline(never)
|
||||
func unicodeLiterals() {
|
||||
consume("café")
|
||||
consume("Résumé of the naïve décor, written twice")
|
||||
}
|
||||
@inline(never)
|
||||
func emptyAndControlLiterals() {
|
||||
consume("")
|
||||
consume("tab\there")
|
||||
}
|
||||
@inline(never)
|
||||
func returnedLiteral() -> String { "Holding awake" }
|
||||
smallLiteral()
|
||||
largeLiteral()
|
||||
unicodeLiterals()
|
||||
emptyAndControlLiterals()
|
||||
print(returnedLiteral(), CommandLine.arguments.count)
|
||||
Vendored
+1
@@ -57,6 +57,7 @@ const modernNames = [
|
||||
"callees",
|
||||
"xrefs_to",
|
||||
"callgraph",
|
||||
"survey_binary",
|
||||
];
|
||||
|
||||
/** Stateful producer fixture at the real connection seam; no module mocking. */
|
||||
|
||||
Vendored
+1
-1
@@ -29,7 +29,7 @@ export const createStrippedAsarAddon = async (
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, file.contents);
|
||||
}
|
||||
await createPackageWithOptions(source, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
await writeFile(
|
||||
join(`${archive}.unpacked`, "node_modules", "btime", "binding.node"),
|
||||
stripped,
|
||||
|
||||
@@ -18,7 +18,10 @@ import {
|
||||
PWNTOOLS_MEMORY_FAILURE_EXIT,
|
||||
PWNTOOLS_PROVIDER_IDENTITY,
|
||||
} from "../../src/native/pwntools/PwntoolsRelease.js";
|
||||
import { cleanupOwnedProcessGroup } from "../../src/process/ProcessOwnership.js";
|
||||
import {
|
||||
cleanupOwnedProcessGroup,
|
||||
type OwnedProcessGroup,
|
||||
} from "../../src/process/ProcessOwnership.js";
|
||||
import { prepareProcessOwnershipInspection } from "../../src/process/ProcessOwnershipObservation.js";
|
||||
import { spawnOwnedProviderProcess } from "../../src/process/ProviderProcess.js";
|
||||
import { PrivateRuntimeRoot } from "../../src/process/PrivateRuntimeRoot.js";
|
||||
@@ -232,12 +235,13 @@ it.runIf(supportedHost).each([
|
||||
const { path, root, environment, basic } = await fixture();
|
||||
let launches = 0;
|
||||
let cleanupAllowed = false;
|
||||
let retainedOwnership: OwnedProcessGroup | undefined;
|
||||
const read = vi.spyOn(artifacts, "readStableArtifact");
|
||||
const provider = new PwntoolsRecordedCrashProvider(
|
||||
environment,
|
||||
async (spawn) => {
|
||||
if (stage === "debugger" && ++launches === 1) return basic(spawn);
|
||||
return changingWorker(
|
||||
const launched = await changingWorker(
|
||||
spawn,
|
||||
join(spawn.cwd ?? "", "resource.failure"),
|
||||
{
|
||||
@@ -247,6 +251,8 @@ it.runIf(supportedHost).each([
|
||||
},
|
||||
() => cleanupAllowed,
|
||||
);
|
||||
retainedOwnership = launched.ownership;
|
||||
return launched;
|
||||
},
|
||||
async () => root,
|
||||
);
|
||||
@@ -261,14 +267,14 @@ it.runIf(supportedHost).each([
|
||||
if (result.ok) throw new Error("Expected unresolved process ownership");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe("cleanup_incomplete");
|
||||
expect(projected).toMatchObject({
|
||||
details: {
|
||||
resources: expect.arrayContaining([
|
||||
expect.stringMatching(/^pid:\d+$/u),
|
||||
expect.stringMatching(/^process-group:\d+$/u),
|
||||
]),
|
||||
},
|
||||
});
|
||||
if (retainedOwnership === undefined)
|
||||
throw new Error("Expected retained process ownership");
|
||||
expect(projected.details?.resources).toEqual([
|
||||
retainedOwnership.runId,
|
||||
root.path,
|
||||
`pid:${retainedOwnership.leaderPid}`,
|
||||
`process-group:${retainedOwnership.processGroupId}`,
|
||||
]);
|
||||
if (stage === "debugger")
|
||||
expect(projected).toMatchObject({
|
||||
details: {
|
||||
|
||||
Reference in New Issue
Block a user