feat(native): admit raw binaries with caller-supplied architecture and entry (#1868)
* feat(native): admit raw binaries with caller-supplied architecture and entry * fix(native): honor raw-binary preparation and entry identity * fix(ghidra): stream raw snapshot attestation with cancellation * fix(native): preserve and validate raw lifecycle entries --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { executableFormatHintSchema } from "./dosCom.js";
|
||||
import {
|
||||
admitRawBinary,
|
||||
parseRawBinaryEntryPoint,
|
||||
rawBinarySelectionError,
|
||||
validateRawBinaryLength,
|
||||
} from "./rawBinary.js";
|
||||
|
||||
describe("headerless format hints", () => {
|
||||
it("admits dos-com and raw-binary names only", () => {
|
||||
expect(executableFormatHintSchema.safeParse("dos-com").success).toBe(true);
|
||||
expect(executableFormatHintSchema.safeParse("raw-binary").success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(executableFormatHintSchema.safeParse("raw").success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("raw-binary entry addresses", () => {
|
||||
it("canonicalizes equivalent hex spellings without dropping the source", () => {
|
||||
const parsed = parseRawBinaryEntryPoint("0x08000000");
|
||||
expect(parsed).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
source: "0x08000000",
|
||||
canonical: "0x8000000",
|
||||
value: 0x8000000n,
|
||||
},
|
||||
});
|
||||
});
|
||||
it.each(["8000000", "0x", "0xgg", "0X8000000", ""])(
|
||||
"rejects malformed entry %s",
|
||||
(value) => {
|
||||
expect(parseRawBinaryEntryPoint(value).ok).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("raw-binary admission", () => {
|
||||
it("admits a little-endian ARM image mapped at the caller entry", () => {
|
||||
expect(
|
||||
admitRawBinary({
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
fileBytes: 4,
|
||||
}),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x8000000",
|
||||
},
|
||||
});
|
||||
});
|
||||
it("rejects an empty file", () => {
|
||||
expect(validateRawBinaryLength(0).ok).toBe(false);
|
||||
expect(
|
||||
admitRawBinary({
|
||||
architecture: "x86",
|
||||
entryPoint: "0x1000",
|
||||
fileBytes: 0,
|
||||
}).ok,
|
||||
).toBe(false);
|
||||
});
|
||||
it("rejects a 32-bit mapping that exceeds the architecture width", () => {
|
||||
const result = admitRawBinary({
|
||||
architecture: "arm",
|
||||
entryPoint: "0xfffffffc",
|
||||
fileBytes: 8,
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected overflow rejection");
|
||||
expect(result.error).toContain("arm address width");
|
||||
});
|
||||
it("allows a 64-bit mapping that would overflow 32-bit ARM", () => {
|
||||
expect(
|
||||
admitRawBinary({
|
||||
architecture: "arm64",
|
||||
entryPoint: "0xfffffffc",
|
||||
fileBytes: 8,
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
});
|
||||
it.each(["arm", "arm64"])(
|
||||
"rejects unaligned %s entries before provider selection",
|
||||
(architecture) => {
|
||||
for (const entryPoint of ["0x8000001", "0x8000002", "0x8000003"]) {
|
||||
expect(
|
||||
admitRawBinary({ architecture, entryPoint, fileBytes: 4 }),
|
||||
).toEqual({
|
||||
ok: false,
|
||||
error: `raw-binary ${architecture} entry_point ${entryPoint} must be 4-byte aligned`,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
it.each(["x86", "x86_64"])(
|
||||
"admits byte-aligned %s entries",
|
||||
(architecture) => {
|
||||
const admitted = admitRawBinary({
|
||||
architecture,
|
||||
entryPoint: "0x1001",
|
||||
fileBytes: 1,
|
||||
});
|
||||
if (!admitted.ok) throw new Error(admitted.error);
|
||||
expect(admitted.value.entryPoint).toBe("0x1001");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("raw-binary selection pairing", () => {
|
||||
it("requires architecture and entry with format=raw-binary", () => {
|
||||
expect(rawBinarySelectionError({ format: "raw-binary" })).toBe(
|
||||
"format=raw-binary requires architecture and entry_point",
|
||||
);
|
||||
expect(
|
||||
rawBinarySelectionError({
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
it("rejects architecture or entry without format=raw-binary", () => {
|
||||
expect(
|
||||
rawBinarySelectionError({ architecture: "arm", entryPoint: "0x1" }),
|
||||
).toBe("architecture and entry_point apply only with format=raw-binary");
|
||||
expect(
|
||||
rawBinarySelectionError({ format: "dos-com", architecture: "x86" }),
|
||||
).toBe("architecture and entry_point apply only with format=raw-binary");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user