Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(mips)!: reject uninspected GNU ABI attributes
Preserve the MIPS I refusal until load-delay semantics are verified. Decode
typed GNU attribute presence before making recordless ABI assumptions, and
exercise both refusal paths plus existing MIPS32 controls through CLI/MCP.

BREAKING CHANGE: ELF32 MIPS inputs with SHT_GNU_ATTRIBUTES are refused until
those ABI declarations are parsed and reconciled. Preserve the original
input and use a tool that understands its declared ABI; stripping metadata
does not establish compatible semantics.
  • Loading branch information
Bobtoshi committed Oct 13, 2026
commit 5ec1a57a297fa81e14a405a49ebc374e0d4627d1
36 changes: 17 additions & 19 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 Expand Up @@ -44,25 +61,6 @@ establish the recordless admission, and an `EF_MIPS_ARCH_32` header that
_declares_ an ABI is refused rather than relabeled, because the declared-ABI
lane is verified for `EF_MIPS_ARCH_32R2` headers only.

A third admission covers recordless MIPS I ELF32 `ET_EXEC` images whose header
explicitly declares o32, with complete ABI-record inspection and no ASE,
machine-specific, n32, 32-bit-on-64-bit, FP64 or NaN2008 declarations. Both byte
orders use the pinned `MIPS:<LE|BE>:32:default` language, checked after import.
The header's o32 declaration is retained as a fact; floating-point storage remains
unverified and is reported in Evidence limitations. ABI-record-bearing MIPS I,
MIPS II/III, relocatable/shared MIPS I and unspecified-ABI MIPS I remain outside
this increment. This does not widen the existing Windows P0 boundary.

Run `node scripts/verify-real-ghidra-mips1.mjs` after building, with the existing
Ghidra/Java installation and `REA_READELF` when GNU readelf is not on PATH.
The source-owned integer fixture is encoded directly from its declared MIPS I
instructions; no cross compiler is required. GNU readelf independently checks
its header and symbol. The verifier checks both byte orders through production
MCP, exact loaded words, instruction/delay-slot decoding, dossier output, retained
FP uncertainty, source immutability and snapshot replay; it also checks the LE
fixture through the production CLI. Real macOS arm64/Ghidra 12.1.4 was exercised;
Linux, Windows and a real firmware corpus were not.

Explicit `EF_MIPS_FP64` and `EF_MIPS_NAN2008` declarations are refused. Their
absence is insufficient: Clang can emit identical `e_flags` for FP32, FP64 and
soft-float targets. Target resolution also reads the 24-byte ABI flags record
Expand Down
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts/verify/fridaBindingsCompatibility.ts",
"scripts/verify/termux/browser.mjs",
"scripts/verify-real-ghidra-noreturn.mjs",
"scripts/verify-real-ghidra-mips1.mjs",
"scripts/verify-real-ghidra-mips-boundaries.mjs",
"tests/processOwnershipRunner.ts"
],
"project": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.mjs"],
Expand Down
160 changes: 160 additions & 0 deletions scripts/verify-real-ghidra-mips-boundaries.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/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 { 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 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));
const reports = [];
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],
);
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: {
...process.env,
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
REA_ANALYSIS_PROVIDER: "ghidra",
REA_LOG_LEVEL: "silent",
TMPDIR: root,
},
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: process.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();
}
}
}
console.log(JSON.stringify({ status: "passed", reports }, null, 2));
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
} finally {
await rm(root, { recursive: true, force: true });
}
Loading