Files
rea/src/ghidra/GhidraRawBinaryLoadImage.test.ts
T
Matt Van Hornandmorluto 7c207c7951 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>
2026-10-12 00:06:29 +08:00

99 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { attestGhidraRawBinaryLoadImage } from "./GhidraLoadImageValues.js";
import { fixtureRawBinaryLoadImage } from "./GhidraRawBinaryLoadImage.fixture.js";
import { ghidraRawBinaryLanguage } from "./GhidraRawBinaryLanguage.js";
describe("raw-binary Ghidra language binding", () => {
it("maps the four admitted families to little-endian generic languages", () => {
expect(ghidraRawBinaryLanguage("x86")).toEqual({
languageId: "x86:LE:32:default",
compilerSpecId: "default",
});
expect(ghidraRawBinaryLanguage("x86_64")).toEqual({
languageId: "x86:LE:64:default",
compilerSpecId: "default",
});
expect(ghidraRawBinaryLanguage("arm")).toEqual({
languageId: "ARM:LE:32:v7",
compilerSpecId: "default",
});
expect(ghidraRawBinaryLanguage("arm64")).toEqual({
languageId: "AARCH64:LE:64:v8A",
compilerSpecId: "default",
});
});
});
describe("raw-binary independent load-image checks", () => {
it("verifies mapped bytes at the caller-supplied entry", () => {
const f = fixtureRawBinaryLoadImage();
const result = attestGhidraRawBinaryLoadImage(
f.snapshot,
f.target,
f.observation,
);
expect(result).toMatchObject({
ok: true,
value: {
status: "verified",
format: "raw-binary",
architecture: "arm",
language_id: "ARM:LE:32:v7",
base_address: "0x8000000",
file_bytes: 4,
entry: { address: "0x8000000", file_offset: 0 },
},
});
});
it("retains mismatch evidence for a drifted language", () => {
const f = fixtureRawBinaryLoadImage();
f.observation.language_id = "x86:LE:32:default";
const result = attestGhidraRawBinaryLoadImage(
f.snapshot,
f.target,
f.observation,
);
expect(result).toMatchObject({
ok: true,
value: { status: "mismatch", observations: f.observation },
});
});
it("preserves additional language entries while requiring the caller entry", () => {
const f = fixtureRawBinaryLoadImage();
f.observation.entry_points = ["0x0", f.target.entryPoint, "0xffff0000"];
expect(
attestGhidraRawBinaryLoadImage(f.snapshot, f.target, f.observation),
).toMatchObject({
ok: true,
value: { status: "verified", observations: f.observation },
});
f.observation.entry_points = ["0x0", "0xffff0000"];
expect(
attestGhidraRawBinaryLoadImage(f.snapshot, f.target, f.observation),
).toMatchObject({
ok: true,
value: {
status: "mismatch",
checks: expect.arrayContaining([
expect.objectContaining({
name: "entry_point",
matched: false,
observed: null,
}),
]),
},
});
});
it("rejects stale snapshot identity", () => {
const f = fixtureRawBinaryLoadImage();
expect(
attestGhidraRawBinaryLoadImage(
f.snapshot,
{ ...f.target, sha256: "f".repeat(64) },
f.observation,
).ok,
).toBe(false);
});
});