Files
reverse-engineering-anything/tests/boundary/mcp/openBinaryUnrecognizedFormat.test.ts
T
morluto 35d0d013c1 fix(artifacts): report an unrecognized file's leading bytes and working fallbacks (#16508)
* fix(artifacts): report an unrecognized file's leading bytes and working fallbacks

A file no format route recognizes was refused with only the raw-binary
load as recovery, which suits headerless machine code but not data
containers. The refusal now reports the file size and first 16 bytes,
names inspect_byte_entropy and inspect_yara_matches, which accept any
file, and keeps raw-binary for machine code. The REA skill gains a
workflow for continuing analysis when no route recognizes a file.

* docs(development): require recovery fallbacks to fit and accept the refused input

* docs(skill): describe entropy ranges as places to inspect, not content labels
2026-12-04 00:02:34 +00:00

43 lines
1.9 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("reports an unrecognized file's leading bytes and the tools that accept any file", async () => {
const root = await createTestTempDirectory("rea-open-unrecognized-");
const path = join(root, "image.bin");
const content = "plain text, not an executable\n";
await writeFile(path, content);
const { call } = await connectLocalToolsMcp();
for (const name of ["open_binary", "inspect_artifact"]) {
const refused = parseMcpToolError(await call(name, { path }));
expect(refused.error, name).toMatchObject({
details: {
path,
constraint: "file_format_rejected",
file_bytes: content.length,
leading_bytes: Buffer.from(content.slice(0, 16)).toString("hex"),
},
remediation: {
action:
'No supported format recognizes this file; details.leading_bytes holds its first bytes in hex. inspect_byte_entropy accepts any file and reports its SHA-256 and entropy, and inspect_yara_matches scans it with caller-supplied rules. Open it with format "raw-binary", architecture and entry_point only when it is headerless machine code, such as a firmware or memory image.',
},
});
}
// The named fallback accepts the file the format routes refused.
const entropy = await call("inspect_byte_entropy", { path });
expect(entropy.isError, JSON.stringify(entropy.content)).not.toBe(true);
const raw = await call("open_binary", {
path,
format: "raw-binary",
architecture: "arm",
entry_point: "0x0",
});
expect(raw.isError, JSON.stringify(raw.content)).not.toBe(true);
});