fix(firmware): accept the verified Binwalk and Unblob release lines (#844)

* fix(firmware): accept the verified Binwalk and Unblob release lines

Exact --version equality rejected every build except Binwalk 3.1.0 and
Unblob 26.6.4, then stored that constant as the observed engine version.
Admit the 3.1 and 26.6 lines, keep the audited build as verified, and
report the banner that actually ran.

* chore(docs): regenerate skill metadata after firmware contract text

docs:check failed because SKILL.md lagged the Binwalk/Unblob release-line
tool descriptions.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-07 12:19:28 +08:00
committed by GitHub
co-authored by Cursor Agent
parent 3f1a77f68e
commit bef4321afb
15 changed files with 249 additions and 32 deletions
+22 -14
View File
@@ -24,10 +24,10 @@ import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
import { publishFirmwareExtraction } from "./FirmwarePublication.js";
import {
FIRMWARE_LIMITS,
FIRMWARE_RELEASES,
BINWALK_PROVIDER_IDENTITY,
UNBLOB_PROVIDER_IDENTITY,
} from "./FirmwareRelease.js";
import { admitFirmwareVersion } from "./FirmwareVersion.js";
import {
resolveFirmwareCommand,
runFirmwareCommand,
@@ -143,21 +143,22 @@ export class FirmwareProvider implements FirmwareAnalysisPort {
});
const versionRun = await run(["--version"]);
const version = versionRun.stdout.text.trim();
const expected = FIRMWARE_RELEASES[engineName].version;
if (
versionRun.stdout.bytes > 1024 ||
(engineName === "binwalk"
? version !== `binwalk ${expected}`
: version !== expected)
)
if (versionRun.stdout.bytes > 1024)
throw new AnalysisCapabilityUnavailableError(
engineName,
request.operation,
`Unsupported tool version ${version}; this adapter is verified against ${expected}`,
`Tool version banner is ${String(versionRun.stdout.bytes)} bytes; expected a short ${engineName} version line.`,
);
const admitted = admitFirmwareVersion(engineName, version);
if (admitted.status === "unsupported" || admitted.status === "unresolved")
throw new AnalysisCapabilityUnavailableError(
engineName,
request.operation,
admitted.message,
);
const engine = {
name: engineName,
version: expected,
version: admitted.version,
executable_path: command.command,
executable_sha256: command.sha256,
source_revision: null,
@@ -259,16 +260,23 @@ export class FirmwareProvider implements FirmwareAnalysisPort {
});
raw = { report, execution: processRun, version_execution: versionRun };
}
const catalog =
engineName === "binwalk"
? BINWALK_PROVIDER_IDENTITY
: UNBLOB_PROVIDER_IDENTITY;
outcome = ok(
createAnalysisExecution(
result,
engineName === "binwalk"
? BINWALK_PROVIDER_IDENTITY
: UNBLOB_PROVIDER_IDENTITY,
{ ...catalog, version: admitted.version },
{
subject: target.subject,
rawResult: raw,
limitations,
limitations: [
...limitations,
...(admitted.status === "compatible"
? [admitted.limitation]
: []),
],
locations: [
{
kind: "file-offset-range",
+1 -1
View File
@@ -12,7 +12,7 @@ export const FIRMWARE_RELEASES = {
},
} as const;
/** Catalog identities; Evidence uses the version observed from the executed tool. */
/** Catalog identity for the verified Binwalk release. Evidence replaces version with the observed banner. */
export const BINWALK_PROVIDER_IDENTITY = {
id: "binwalk",
name: "Binwalk",
+50
View File
@@ -0,0 +1,50 @@
import { describe, expect, it } from "vitest";
import { admitFirmwareVersion } from "./FirmwareVersion.js";
describe("firmware release lines", () => {
it("accepts the verified banners without an extra limitation", () => {
expect(admitFirmwareVersion("binwalk", "binwalk 3.1.0")).toEqual({
status: "verified",
version: "3.1.0",
});
expect(admitFirmwareVersion("unblob", "26.6.4")).toEqual({
status: "verified",
version: "26.6.4",
});
});
it.each([
["binwalk", "binwalk 3.1.2", "3.1.2"],
["binwalk", "binwalk 3.1.0-1", "3.1.0-1"],
["unblob", "26.6.5", "26.6.5"],
] as const)(
"accepts %s %s on the verified line",
(engine, banner, version) => {
const admitted = admitFirmwareVersion(engine, banner);
expect(admitted).toMatchObject({ status: "compatible", version });
if (admitted.status !== "compatible")
throw new Error("expected a compatible release");
expect(admitted.limitation).toContain(version);
expect(admitted.limitation).toContain(
engine === "binwalk" ? "3.1.0" : "26.6.4",
);
},
);
it.each([
["binwalk", "binwalk 3.2.0", "Binwalk 3.1.x"],
["binwalk", "unsupported", "Binwalk 3.1.x"],
["binwalk", "3.1.2", "Binwalk 3.1.x"],
["unblob", "26.7.0", "Unblob 26.6.x"],
["unblob", "unblob 26.6.4", "Unblob 26.6.x"],
["unblob", "", "missing"],
] as const)("rejects %s banner %j", (engine, banner, detail) => {
const admitted = admitFirmwareVersion(engine, banner);
expect(
admitted.status === "verified" || admitted.status === "compatible",
).toBe(false);
if (admitted.status === "verified" || admitted.status === "compatible")
throw new Error("expected a rejected banner");
expect(admitted.message).toContain(detail);
});
});
+116
View File
@@ -0,0 +1,116 @@
import { FIRMWARE_RELEASES } from "./FirmwareRelease.js";
/** Caller-supplied firmware engine selected by the operation. */
export type FirmwareEngineName = keyof typeof FIRMWARE_RELEASES;
interface ReleaseNumber {
readonly major: number;
readonly minor: number;
readonly patch: number;
readonly suffix: string;
readonly token: string;
}
const TOKEN = /^(\d+)\.(\d+)\.(\d+)([-+][0-9A-Za-z.-]+)?$/u;
const parseToken = (token: string): ReleaseNumber | undefined => {
const match = TOKEN.exec(token);
if (match === null) return undefined;
const major = Number(match[1]);
const minor = Number(match[2]);
const patch = Number(match[3]);
if (![major, minor, patch].every((part) => Number.isSafeInteger(part)))
return undefined;
const suffix = match[4] ?? "";
return { major, minor, patch, suffix, token };
};
const verifiedRelease = (engine: FirmwareEngineName): ReleaseNumber => {
const parsed = parseToken(FIRMWARE_RELEASES[engine].version);
if (parsed === undefined || parsed.suffix !== "")
throw new Error(
`FIRMWARE_RELEASES.${engine}.version is not a release number`,
);
return parsed;
};
/** Caller-facing engine name. */
export const firmwareEngineLabel = (engine: FirmwareEngineName): string => {
switch (engine) {
case "binwalk":
return "Binwalk";
case "unblob":
return "Unblob";
default: {
const unreachable: never = engine;
return unreachable;
}
}
};
/** Release line accepted for one engine, such as `Binwalk 3.1.x`. */
export const firmwareReleaseLine = (engine: FirmwareEngineName): string => {
const verified = verifiedRelease(engine);
return `${firmwareEngineLabel(engine)} ${String(verified.major)}.${String(verified.minor)}.x`;
};
/** Admission of one observed `--version` banner. */
export type FirmwareVersionAdmission =
| { readonly status: "verified"; readonly version: string }
| {
readonly status: "compatible";
readonly version: string;
readonly limitation: string;
}
| { readonly status: "unsupported"; readonly message: string }
| { readonly status: "unresolved"; readonly message: string };
/**
* Classify a `--version` banner against the audited release line.
* Binwalk prints `binwalk <version>`; Unblob prints the version alone.
*/
export const admitFirmwareVersion = (
engine: FirmwareEngineName,
banner: string,
): FirmwareVersionAdmission => {
const token = versionToken(engine, banner);
const parsed = token === undefined ? undefined : parseToken(token);
const verified = verifiedRelease(engine);
const accepted = `accepted releases are ${firmwareReleaseLine(engine)} (verified with ${verified.token})`;
if (parsed === undefined)
return {
status: "unresolved",
message: `Unsupported tool version ${banner.length === 0 ? "missing" : banner}; ${accepted}.`,
};
if (parsed.major !== verified.major || parsed.minor !== verified.minor)
return {
status: "unsupported",
message: `Unsupported tool version ${banner}; ${accepted}.`,
};
if (parsed.token === verified.token)
return { status: "verified", version: parsed.token };
const line = `${String(verified.major)}.${String(verified.minor)}.x`;
return {
status: "compatible",
version: parsed.token,
limitation: `This session uses ${firmwareEngineLabel(engine)} ${parsed.token}. The report parser is verified against ${verified.token}; other ${line} builds are accepted and the observed version is reported.`,
};
};
const versionToken = (
engine: FirmwareEngineName,
banner: string,
): string | undefined => {
switch (engine) {
case "binwalk":
return banner.startsWith("binwalk ")
? banner.slice("binwalk ".length)
: undefined;
case "unblob":
return banner;
default: {
const unreachable: never = engine;
return unreachable;
}
}
};