Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5df5571
feat(ghidra): admit verified recordless MIPS I o32 executables
Bobtoshi Oct 13, 2026
d8630ea
test(ghidra): verify MIPS branch decoding and retain diagnostics
Bobtoshi Oct 13, 2026
5ec1a57
fix(mips)!: reject uninspected GNU ABI attributes
Bobtoshi Oct 13, 2026
102f813
test(mips): isolate native boundary controls from ambient settings
Bobtoshi Oct 13, 2026
05e2366
test(mips): verify cleanup and pin readelf locale
Bobtoshi Oct 13, 2026
0a8f70f
Merge latest upstream and verify MIPS declaration coverage
Bobtoshi Oct 14, 2026
e389016
chore: preserve untouched upstream tests after merge
Bobtoshi Oct 14, 2026
2d2f2f8
test(ghidra): refresh MIPS controls and verify orphan cleanup
Bobtoshi Nov 6, 2026
11edd85
fix(verification): sweep the captured Ghidra provider run identities
Bobtoshi Nov 6, 2026
3569da2
chore: merge upstream into MIPS verifier branch
Bobtoshi Nov 8, 2026
7ab92a4
test(ghidra): verify imported MIPS languages and merge upstream
Bobtoshi Nov 10, 2026
6886262
test(ghidra): remove an empty processor context suite
Bobtoshi Nov 10, 2026
a830a4a
fix(ghidra): track verifier runs before lazy analysis
Bobtoshi Nov 11, 2026
624b879
fix(ghidra): verify MIPS evidence and preserve cleanup failures
Bobtoshi Nov 11, 2026
779a635
test(ghidra): verify committed MIPS dossier attribution
Bobtoshi Nov 13, 2026
19a9f98
fix(ghidra): bound MIPS readelf verification
Bobtoshi Nov 13, 2026
0a5b082
test(ghidra): bind MIPS dossiers to their ELF fixtures
Bobtoshi Nov 13, 2026
2d1ee37
test(ghidra): retain MIPS readelf verification evidence
Bobtoshi Nov 13, 2026
7494b2b
test(ghidra): retain MIPS source paths and refusal diagnostics
Bobtoshi Nov 13, 2026
99b9126
fix(ghidra): own MIPS verifier CLI refusal commands
Bobtoshi Nov 13, 2026
7d92575
fix(ghidra): recover verified MIPS verifier provider survivors
Bobtoshi Nov 13, 2026
dbd04ab
test(ghidra): verify recordless MIPS caveats and cold cleanup
Bobtoshi Nov 13, 2026
ffcd4d6
fix(ghidra): own the MIPS verifier MCP transport
Bobtoshi Nov 13, 2026
3596755
fix(ghidra): keep MIPS MCP ownership separate from CLI commands
Bobtoshi Nov 13, 2026
1051072
Qualify MIPS32 boundaries and retain failed verifier ownership
Bobtoshi Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/ghidra-mips.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ PSP/Allegrex has a [separate static-ELF profile](ghidra-psp.md) tracked in

## Admission boundary

MIPS I remains unsupported. The generic Ghidra MIPS processor's immediate load
assignment does not establish MIPS I load-delay behavior; correctly decoding a
small integer fixture does not verify its decompiler/dataflow semantics.

The ELF metadata reader refuses typed `SHT_GNU_ATTRIBUTES` sections before
provider selection. GNU MIPS ABI attributes can declare floating-point storage
that differs from MIPS ABI-flags records. Until this declaration source is parsed
and reconciled, its presence must not be treated as recordless absence. Section
names and attacker-controlled section sizes do not bypass that refusal.

After building, `node scripts/verify-real-ghidra-mips-boundaries.mjs` checks both
byte orders through production CLI/MCP. GNU readelf independently decodes the
soft-float attribute fixture; MIPS I and uninspected GNU attributes are refused,
while a recordless MIPS32 control still produces a real Ghidra dossier and exact
loaded bytes. Supply existing Ghidra/Java and GNU readelf (`REA_READELF`). Source
hashes are checked after inspection, and no target is executed.

ELF `EM_MIPS` is retained as the provider-neutral `mips` family. The target also
retains class, byte order, `e_type`, raw `e_flags`, and inspected ABI declarations.
Recognition does not mean every provider or MIPS variant is supported. Existing
Expand Down
1 change: 1 addition & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts/verify/fridaBindingsCompatibility.ts",
"scripts/verify/termux/browser.mjs",
"scripts/verify-real-ghidra-noreturn.mjs",
"scripts/verify-real-ghidra-mips-boundaries.mjs",
"tests/processOwnershipRunner.ts"
],
"project": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.mjs"],
Expand Down
191 changes: 191 additions & 0 deletions scripts/verify-real-ghidra-mips-boundaries.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/usr/bin/env node
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdtemp, readFile, writeFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { buildMips1Fixture } from "../tests/conformance/ghidra/mips1-fixture.mjs";
import {
requireMcpOperationResult,
requireMcpToolError,
} from "./lib/mcp-verifier-results.mjs";
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
import { functionDossierSchema } from "../dist/domain/hopperValues.js";

// Static source-owned controls. Never execute an ELF or acquire a toolchain.
if (!process.env.GHIDRA_INSTALL_DIR || !process.env.JAVA_HOME)
throw new Error(
"Supply GHIDRA_INSTALL_DIR and JAVA_HOME for the MIPS32 positive control.",
);
const execute = promisify(execFile);
const run = createVerifierRun();
const root = await mkdtemp(join(tmpdir(), "rea-mips-boundaries-"));
const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
const cli = fileURLToPath(new URL("./rea.mjs", import.meta.url));
// Only declared tool prerequisites and resource settings reach REA children.
// Ambient REA seeds, analyzer controls and session settings cannot alter controls.
const env = {
PATH: process.env.PATH ?? "/usr/bin:/bin",
TMPDIR: root,
REA_ANALYSIS_PROVIDER: "ghidra",
REA_LOG_LEVEL: "silent",
REA_PROCESS_RUN_ID: run.run_id,
GHIDRA_INSTALL_DIR: process.env.GHIDRA_INSTALL_DIR,
JAVA_HOME: process.env.JAVA_HOME,
HOPPER_LAUNCHER_PATH: "/rea-unconfigured-deep-provider/hopper",
};
for (const setting of ["GHIDRA_HEADLESS_MAXMEM", "GHIDRA_MAXMEM"]) {
if (process.env[setting] !== undefined) env[setting] = process.env[setting];
}
const reports = [];
let primaryFailure;
try {
for (const byteOrder of ["little", "big"]) {
const original = await buildMips1Fixture(root, byteOrder);
const initial = await readFile(original.path);
const legacy = Buffer.from(initial);
const u32 = (bytes, offset, value) =>
byteOrder === "little"
? bytes.writeUInt32LE(value, offset)
: bytes.writeUInt32BE(value, offset);
const u16 = (bytes, offset, value) =>
byteOrder === "little"
? bytes.writeUInt16LE(value, offset)
: bytes.writeUInt16BE(value, offset);
u32(legacy, 36, 0x50000001); // Existing recordless MIPS32 lane.
const legacyPath = join(root, `legacy-${byteOrder}.elf`);
await writeFile(legacyPath, legacy);
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
const gnu = Buffer.alloc(0x1200);
legacy.copy(gnu);
u32(gnu, 68, gnu.length);
u32(gnu, 72, gnu.length);
u16(gnu, 48, 6);
u32(gnu, 0x1188 + 4, 0x6ffffff5);
u32(gnu, 0x1188 + 16, 0x11d0);
u32(gnu, 0x1188 + 20, 16);
gnu[0x11d0] = 0x41;
u32(gnu, 0x11d1, 15);
gnu.write("gnu\0", 0x11d5, "ascii");
gnu[0x11d9] = 1;
u32(gnu, 0x11da, 7);
gnu[0x11de] = 4; // Tag_GNU_MIPS_ABI_FP
gnu[0x11df] = 3; // Soft float.
const gnuPath = join(root, `gnu-fp-${byteOrder}.elf`);
await writeFile(gnuPath, gnu);
const { stdout: attributes } = await execute(
process.env.REA_READELF ?? "readelf",
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
["-A", gnuPath],
{ env: { PATH: env.PATH, LC_ALL: "C" } },
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
);
assert.match(attributes, /Tag_GNU_MIPS_ABI_FP.*Soft float/iu);
const transport = new StdioClientTransport({
command: process.execPath,
args: [cli, "mcp"],
env,
stderr: "inherit",
});
const client = new Client({ name: "rea-mips-boundaries", version: "1" });
const invoke = (name, args = {}) =>
client.callTool({ name, arguments: args }, { timeout: 240_000 });
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
const call = async (name, args = {}) =>
requireMcpOperationResult(await invoke(name, args), name);
try {
await client.connect(transport);
for (const [path, pattern] of [
[original.path, /MIPS I.*load-delay semantics/u],
[gnuPath, /SHT_GNU_ATTRIBUTES.*uninspected/u],
]) {
const error = requireMcpToolError(
await invoke("open_binary", { path, provider_id: "ghidra" }),
);
assert.match(JSON.stringify(error), pattern);
let stdout;
try {
await execute(
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
process.execPath,
[
cli,
"function",
path,
original.entry,
"--provider",
"ghidra",
"--full-output",
"--json",
],
{ env, timeout: 240_000 },
);
assert.fail("CLI admitted an unsupported MIPS declaration");
} catch (cause) {
assert.equal(cause.code, 1);
stdout = cause.stdout;
}
const reply = JSON.parse(stdout);
assert.equal(reply.ok, false);
assert.match(JSON.stringify(reply), pattern);
}
await call("open_binary", { path: legacyPath, provider_id: "ghidra" });
const dossier = functionDossierSchema.parse(
await call("analyze_function", { procedure: original.entry }),
);
assert.ok(dossier.pseudocode.length > 0);
const loaded = await call("read_bytes", {
address: original.entry,
length: 24,
});
assert.equal(
loaded.bytes_hex,
legacy.subarray(0x1000, 0x1018).toString("hex"),
);
await call("close_binary");
assert.deepEqual(await readFile(original.path), initial);
assert.deepEqual(await readFile(gnuPath), gnu);
assert.deepEqual(await readFile(legacyPath), legacy);
reports.push({
byte_order: byteOrder,
mips1: "refused by CLI and MCP",
gnu_fp_attributes:
"independently decoded soft-float declaration; refused by CLI and MCP",
existing_mips32_control: "real Ghidra dossier and exact loaded bytes",
hashes: {
mips1: digest(initial),
gnu: digest(gnu),
legacy: digest(legacy),
},
source_unchanged: true,
target_executed: false,
});
} finally {
try {
await client.close();
} finally {
await transport.close();
}
}
}
} catch (cause) {
primaryFailure = cause;
}
const completed = await completeVerifierRun(run);
if (
completed.process_lineage.status !== "verified" ||
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
completed.process_lineage.descendants.length !== 0
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
)
throw new Error(
`Cleanup unverified; retained diagnostic workspace: ${root}`,
{ cause: primaryFailure },
);
if (primaryFailure !== undefined)
throw new Error(
`MIPS boundary verification failed; retained workspace: ${root}`,
{ cause: primaryFailure },
);
await rm(root, { recursive: true, force: true });
console.log(
JSON.stringify({ ...completed, status: "passed", reports }, null, 2),
);
4 changes: 4 additions & 0 deletions src/application/MipsElfMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export const readMipsElfMetadata = async (
checkCancelled();
const position = i * table.entrySize;
const type = u32(contents.value, position + table.typeOffset);
if (table.optional && type === 0x6ffffff5)
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
return err(
`MIPS SHT_GNU_ATTRIBUTES at section index ${i} is uninspected; its GNU ABI declarations cannot be treated as absent. GNU MIPS attribute parsing requires separate verification.`,
);
if (metadata.type === 3 && table.optional && (type === 4 || type === 9))
relocationSections.push({
type,
Expand Down
18 changes: 18 additions & 0 deletions src/ghidra/GhidraMipsProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IdaProvider } from "../ida/IdaProvider.js";
import { GhidraProvider } from "./GhidraProvider.js";
import {
ghidraMipsProfileParameters,
ghidraMipsLanguageOverride,
ghidraPinnedMipsLanguage,
} from "./GhidraMipsProfile.js";
import type { GhidraInstallationHost } from "./GhidraInstallation.js";
Expand Down Expand Up @@ -80,6 +81,23 @@ const abi = (
};
const softFloat = abi({ cpr1Size: 0, fpAbi: 3 });

it.each([
["little", 0x1001],
["big", 0x1001],
["little", 0x1801],
["big", 0x1801],
] as const)(
"refuses MIPS I load-delay semantics independently of an explicit o32 declaration (%s, %i)",
(byteOrder, flags) => {
const provider = new GhidraProvider(config, silentLogger, {}, host);
const value = target({ flags, byteOrder, abiFlags: null });
const support = provider.inspectTargetSupport(value);
expect(support).toMatchObject({ status: "unsupported" });
expect(JSON.stringify(support)).toContain("load-delay semantics");
expect(ghidraMipsLanguageOverride(value)).toBeUndefined();
},
);

describe("bounded Ghidra MIPS admission", () => {
it("binds endian and flags without widening Windows P0", async () => {
const ghidra = new GhidraProvider(config, silentLogger, {}, host);
Expand Down
2 changes: 2 additions & 0 deletions src/ghidra/GhidraMipsProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const ghidraMipsUnsupportedReason = (
if ((metadata.flags & 0x00ff0000) !== 0)
return "Machine-specific MIPS variants, including PSP Allegrex, need a separately supported processor profile.";
const arch = metadata.flags & 0xf0000000;
if (arch === 0)
return "MIPS I remains unsupported: the generic Ghidra MIPS processor does not establish MIPS I load-delay semantics; instruction decoding alone cannot verify decompiler/dataflow correctness.";
if (arch !== 0x70000000 && arch !== 0x50000000)
return "This Ghidra MIPS lane requires EF_MIPS_ARCH_32R2 or a recordless legacy EF_MIPS_ARCH_32 header; other ISA revisions need separate verification.";
const recordlessShape =
Expand Down
34 changes: 34 additions & 0 deletions tests/boundary/filesystem/mipsAbiFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ const target = (mips: MipsElfMetadata) => ({
});

for (const little of [true, false]) {
it(`refuses typed GNU attributes before inferring an ABI (${little ? "LE" : "BE"})`, async () => {
const bytes = fixture(little);
const u32 = (value: number, offset: number) =>
little
? bytes.writeUInt32LE(value, offset)
: bytes.writeUInt32BE(value, offset);
// Keep the independently declared FPXX program record; add a conflicting
// legacy GNU soft-float attribute. Type, not section name, owns discovery.
u32(0x6ffffff5, 172);
u32(abiOffset + 24, 184);
u32(16, 188);
bytes[abiOffset + 24] = 0x41;
u32(15, abiOffset + 25);
bytes.write("gnu\0", abiOffset + 29, "ascii");
bytes[abiOffset + 33] = 1;
u32(7, abiOffset + 34);
bytes[abiOffset + 38] = 4;
bytes[abiOffset + 39] = 3;
const result = await inspect(bytes, little);
assert.equal(result.ok, false);
if (result.ok) throw new Error("Expected uninspected attribute refusal");
assert.match(
result.error,
/SHT_GNU_ATTRIBUTES.*cannot be treated as absent/u,
);
// Refusal does not allocate from an untrusted attribute-section size.
u32(0xffffffff, 188);
const oversized = await inspect(bytes, little);
assert.equal(oversized.ok, false);
const path = await writeFixture(bytes);
const resolved = await parseBinaryTarget(path);
assert.equal(resolved.ok, false);
assert.deepEqual(await readFile(path), bytes);
});
it(`reads a remote ABI record through both ELF tables (${little ? "LE" : "BE"})`, async () => {
const bytes = fixture(little);
const result = await inspect(bytes, little);
Expand Down
Loading