mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
Add bounded offline DWARF compilation-unit inspection with source provenance, explicit coverage, caller-selected controls and shared ELF compression framing. Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning) Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
207 lines
5.8 KiB
TypeScript
207 lines
5.8 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
|
|
import { parseEvidence } from "../../src/domain/evidence.js";
|
|
import { pythonPycFixture } from "../../src/python/PythonPyc.fixture.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../support/cli/cliFixture.js";
|
|
|
|
const fileCommands = [
|
|
"inspect-sqlite-database",
|
|
"inspect-python-pyc",
|
|
"inspect-apk-signature",
|
|
"inspect-packet-capture",
|
|
"decode-signal-recording",
|
|
"inspect-model-artifact",
|
|
"inspect-elf-notes",
|
|
"inspect-dwarf-units",
|
|
"inspect-elf-debug-link",
|
|
"inspect-native-initializers",
|
|
"inspect-elf-unwind-ranges",
|
|
"inspect-kernel-module",
|
|
"inspect-elf-dependencies",
|
|
"inspect-kernel-build-config",
|
|
"inspect-byte-entropy",
|
|
"inspect-pe-resources",
|
|
"inspect-pe-certificates",
|
|
"inspect-native-exports",
|
|
"inspect-binary-layout",
|
|
"inspect-recorded-crash",
|
|
"inspect-go-binary",
|
|
"inspect-rust-binary",
|
|
"inspect-gpu-code-objects",
|
|
"inspect-il2cpp-metadata",
|
|
"inspect-native-data-type",
|
|
] as const;
|
|
|
|
cliTest(
|
|
"rejects empty file selections before they can become the working directory",
|
|
async ({ cli }) => {
|
|
const cwd = await createTestTempDirectory("rea-empty-local-path-");
|
|
const selections = [
|
|
...fileCommands.map((command) => ({
|
|
arguments: [command, ""],
|
|
field: "path",
|
|
})),
|
|
{ arguments: ["decompile-all", "", "--output", "out"], field: "path" },
|
|
{ arguments: ["observe-native-calls", "", "{}"], field: "path" },
|
|
{ arguments: ["inspect-evm-interface", "", "hex"], field: "path" },
|
|
{
|
|
arguments: ["inspect-web-network-capture", "", "har"],
|
|
field: "capturePath",
|
|
},
|
|
];
|
|
for (const selection of selections) {
|
|
const result = await cli.run({
|
|
arguments: [...selection.arguments, "--json"],
|
|
cwd,
|
|
});
|
|
expect(result.exitCode, selection.arguments[0]).toBe(1);
|
|
expect(result.json, selection.arguments[0]).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
fieldErrors: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
path: selection.field,
|
|
code: "too_small",
|
|
missing: false,
|
|
}),
|
|
]),
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"rejects empty auxiliary selections and output destinations before reading inputs",
|
|
async ({ cli }) => {
|
|
const cwd = await createTestTempDirectory("rea-empty-auxiliary-path-");
|
|
const selections = [
|
|
{
|
|
arguments: ["inspect-elf-debug-link", "unread", "--candidate-path", ""],
|
|
field: "candidatePath",
|
|
},
|
|
{
|
|
arguments: ["inspect-il2cpp-metadata", "unread", "--binary", ""],
|
|
field: "binary",
|
|
},
|
|
{
|
|
arguments: ["inspect-il2cpp-metadata", "unread", "--ghidra-seeds", ""],
|
|
field: "ghidraSeeds",
|
|
},
|
|
{
|
|
arguments: [
|
|
"inspect-web-network-capture",
|
|
"unread",
|
|
"har",
|
|
"--protobuf-schema",
|
|
"",
|
|
],
|
|
field: "protobufSchema",
|
|
},
|
|
{
|
|
arguments: ["decompile-all", "unread", "--output", ""],
|
|
field: "output",
|
|
},
|
|
{ arguments: ["capture-process", ""], field: "scenario" },
|
|
{
|
|
arguments: ["compare-process-captures", "", "unread"],
|
|
field: "left",
|
|
},
|
|
{
|
|
arguments: ["compare-process-captures", "unread", ""],
|
|
field: "right",
|
|
},
|
|
{
|
|
arguments: ["compare-process-captures", "unread", "unread", ""],
|
|
field: "traceSpec",
|
|
},
|
|
{
|
|
arguments: ["export-desktop-application", "", "unread"],
|
|
field: "capture",
|
|
},
|
|
{
|
|
arguments: ["export-desktop-application", "unread", ""],
|
|
field: "directory",
|
|
},
|
|
{
|
|
arguments: [
|
|
"export-desktop-application",
|
|
"unread",
|
|
"output",
|
|
"--task",
|
|
"",
|
|
],
|
|
field: "task.0",
|
|
},
|
|
{
|
|
arguments: ["describe-desktop-application-task", ""],
|
|
field: "capture",
|
|
},
|
|
{
|
|
arguments: ["inspect-desktop-application-state", ""],
|
|
field: "capture",
|
|
},
|
|
{
|
|
arguments: [
|
|
"capture-desktop-application",
|
|
"--executable",
|
|
"notes",
|
|
"--output",
|
|
"unread",
|
|
"--package-file",
|
|
"",
|
|
],
|
|
field: "packageFile",
|
|
},
|
|
{ arguments: ["environment-export", "unread", ""], field: "directory" },
|
|
{
|
|
arguments: [
|
|
"environment-export",
|
|
"unread",
|
|
"output",
|
|
"--package-tarball",
|
|
"",
|
|
],
|
|
field: "packageTarball",
|
|
},
|
|
];
|
|
for (const selection of selections) {
|
|
const result = await cli.run({
|
|
arguments: [...selection.arguments, "--json"],
|
|
cwd,
|
|
});
|
|
expect(result.exitCode, selection.field).toBe(1);
|
|
expect(result.json, selection.field).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
fieldErrors: expect.arrayContaining([
|
|
expect.objectContaining({ path: selection.field, code: "too_small" }),
|
|
]),
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"still inspects an explicit relative file with its exact digest",
|
|
async ({ cli }) => {
|
|
const cwd = await createTestTempDirectory("rea-relative-local-path-");
|
|
const bytes = pythonPycFixture();
|
|
const path = join(cwd, "selected.pyc");
|
|
await writeFile(path, bytes);
|
|
const result = await cli.run({
|
|
arguments: ["inspect-python-pyc", "./selected.pyc", "--json"],
|
|
cwd,
|
|
});
|
|
expect(result.exitCode, result.stderr).toBe(0);
|
|
expect(parseEvidence(result.json)).toMatchObject({
|
|
operation: "inspect_python_pyc",
|
|
subject: {
|
|
local_path: path,
|
|
identity: { sha256: createHash("sha256").update(bytes).digest("hex") },
|
|
},
|
|
});
|
|
},
|
|
);
|