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
test(ghidra): refresh MIPS controls and verify orphan cleanup
  • Loading branch information
Bobtoshi committed Nov 6, 2026
commit 2d2f2f85dba86987cc9c52f2c1cde40f455fd561
20 changes: 7 additions & 13 deletions docs/ghidra-mips.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ 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.

GNU MIPS attributes are parsed and reconciled by the upstream metadata reader.
A valid program ABI record cannot establish admission when section declaration
coverage is incomplete; a conflicting declaration may be hidden by a partial
header. GNU soft-float attributes without an ABI record are also refused.

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 unsupported GNU soft-float declarations 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.
soft-float attribute fixture; declared-o32 MIPS I and unsupported GNU soft-float
inputs are refused, while recordless MIPS I and MIPS32 controls produce real
Ghidra dossiers and exact loaded bytes. These observations do not establish
MIPS I instruction-subset or load-delay correctness. Supply existing Ghidra/Java
and GNU readelf (`REA_READELF`). Source hashes are checked after inspection,
and no target is executed. Cleanup checks both process lineage and an independent
run-token sweep, so reparenting cannot hide an owned survivor.

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.
Expand Down
3 changes: 2 additions & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"scripts/verify/termux/browser.mjs",
"scripts/verify-real-ghidra-noreturn.mjs",
"scripts/verify-real-ghidra-mips-boundaries.mjs",
"scripts/run-exact-tests.mjs",
"scripts/verify-real-ghidra-decompiler-failure.mjs",
"scripts/verify-real-ghidra-decompile-timeout.mjs",
"tests/processOwnershipRunner.ts"
],
"project": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.mjs"],
Expand Down
14 changes: 14 additions & 0 deletions scripts/lib/verifier-token-cleanup.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {
ProcessCleanupResult,
ProcessOwnershipHost,
} from "../../src/process/ProcessOwnership.js";
import type { VerifierRunStart } from "./verifier-run.mjs";

/** Capture the prelaunch identities used by the canonical, PPID-independent sweep. */
export function prepareVerifierTokenCleanup(
run: VerifierRunStart,
suppliedHost?: ProcessOwnershipHost,
): Promise<{
verify(): Promise<ProcessCleanupResult>;
close(): Promise<void>;
}>;
34 changes: 34 additions & 0 deletions scripts/lib/verifier-token-cleanup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { verifyNoTokenOwnedProcesses } from "../../dist/process/ProcessOwnership.js";
import { ProcessOwnershipEvidenceOwner } from "../../dist/process/ProcessOwnershipEvidence.js";
import { createSystemProcessOwnershipHost } from "../../dist/process/ProcessOwnershipObservation.js";

/** Capture the prelaunch identities used by the canonical, PPID-independent sweep. */
export async function prepareVerifierTokenCleanup(run, suppliedHost) {
const host = suppliedHost ?? createSystemProcessOwnershipHost();
try {
await host.prepare?.();
const baseline = await host.captureBaseline?.();
if (baseline === undefined)
throw new Error("Verifier process ownership baseline is unavailable");
const launcher = (await host.listProcesses()).find(
({ pid }) => pid === run.verifier_pid,
);
if (launcher === undefined)
throw new Error("Verifier launcher is absent from the process snapshot");
const relation = {
leaderPid: run.verifier_pid,
processGroupId: launcher.processGroupId,
evidenceOwner: new ProcessOwnershipEvidenceOwner(),
};
return {
verify: () =>
verifyNoTokenOwnedProcesses(run.run_id, host, baseline, relation),
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
close: async () => {
await host.close?.();
},
};
} catch (cause) {
await host.close?.();
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
throw cause;
}
}
70 changes: 51 additions & 19 deletions scripts/verify-real-ghidra-mips-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
requireMcpOperationResult,
requireMcpToolError,
} from "./lib/mcp-verifier-results.mjs";
import { prepareVerifierTokenCleanup } from "./lib/verifier-token-cleanup.mjs";
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
import { functionDossierSchema } from "../dist/domain/hopperValues.js";
import { functionDossierSchema } from "../dist/domain/native/functionDossier.js";

// Static source-owned controls. Never execute an ELF or acquire a toolchain.
if (!["darwin", "linux"].includes(process.platform))
Expand Down Expand Up @@ -48,6 +49,7 @@ for (const setting of ["GHIDRA_HEADLESS_MAXMEM", "GHIDRA_MAXMEM"]) {
}
const reports = [];
let primaryFailure;
const cleanup = await prepareVerifierTokenCleanup(run);
try {
for (const byteOrder of ["little", "big"]) {
const original = await buildMips1Fixture(root, byteOrder);
Expand All @@ -64,6 +66,10 @@ try {
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 recordlessMips1 = Buffer.from(initial);
u32(recordlessMips1, 36, 0x1);
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
const recordlessMips1Path = join(root, `recordless-mips1-${byteOrder}.elf`);
await writeFile(recordlessMips1Path, recordlessMips1);
const gnu = Buffer.alloc(0x1200);
legacy.copy(gnu);
u32(gnu, 68, gnu.length);
Expand Down Expand Up @@ -101,7 +107,10 @@ try {
try {
await client.connect(transport);
for (const [path, pattern] of [
[original.path, /MIPS I.*load-delay semantics/u],
[
original.path,
/requires EF_MIPS_ARCH_32R2 for headers that declare an ABI/u,
],
[gnuPath, /GNU floating-point ABI attribute/u],
]) {
const error = requireMcpToolError(
Expand Down Expand Up @@ -133,33 +142,45 @@ try {
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");
for (const [path, expected] of [
[legacyPath, legacy],
[recordlessMips1Path, recordlessMips1],
]) {
await call("open_binary", { path, provider_id: "ghidra" });
const dossier = functionDossierSchema.parse(
await call("analyze_function", {
procedure: original.entry,
detail: "complete",
}),
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
);
assert.ok(dossier.pseudocode.length > 0);
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
const loaded = await call("read_bytes", {
address: original.entry,
length: 24,
});
assert.equal(
loaded.bytes_hex,
expected.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);
assert.deepEqual(await readFile(recordlessMips1Path), recordlessMips1);
reports.push({
byte_order: byteOrder,
mips1: "refused by CLI and MCP",
declared_o32_mips1: "refused by CLI and MCP",
recordless_mips1:
"real Ghidra dossier and exact loaded bytes; instruction subset/load-delay semantics unverified",
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),
recordless_mips1: digest(recordlessMips1),
},
source_unchanged: true,
target_executed: false,
Expand All @@ -175,13 +196,20 @@ try {
} catch (cause) {
primaryFailure = cause;
}
let tokenCleanup;
try {
tokenCleanup = await cleanup.verify();
} finally {
await cleanup.close();
}
const completed = await completeVerifierRun(run);
if (
!tokenCleanup.cleaned ||
completed.process_lineage.status !== "verified" ||
Comment thread
Bobtoshi marked this conversation as resolved.
Resolved
completed.process_lineage.descendants.length !== 0
)
throw new Error(
`Cleanup unverified; retained diagnostic workspace: ${root}`,
`Cleanup unverified (${JSON.stringify(tokenCleanup)}); retained diagnostic workspace: ${root}`,
{ cause: primaryFailure },
);
if (primaryFailure !== undefined)
Expand All @@ -191,5 +219,9 @@ if (primaryFailure !== undefined)
);
await rm(root, { recursive: true, force: true });
console.log(
JSON.stringify({ ...completed, status: "passed", reports }, null, 2),
JSON.stringify(
{ ...completed, token_cleanup: tokenCleanup, status: "passed", reports },
null,
2,
),
);
19 changes: 0 additions & 19 deletions src/ghidra/GhidraMipsProfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { GhidraProvider } from "./GhidraProvider.js";
import {
ghidraMipsProfileMismatchReason,
ghidraMipsProfileParameters,
ghidraMipsLanguageOverride,
ghidraPinnedMipsLanguage,
} from "./GhidraMipsProfile.js";
import { ghidraProfileInstallationHost as host } from "./GhidraInstallation.fixture.js";
import { GHIDRA_SESSION_CAPABILITIES } from "./GhidraSessionValues.js";
Expand Down Expand Up @@ -101,23 +99,6 @@ 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 a saved project's MIPS metadata without claiming a fresh-import lane", () => {
const little = target();
Expand Down
6 changes: 2 additions & 4 deletions src/ghidra/GhidraMipsProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,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.";
if (arch !== MIPS_ARCH_1 && arch !== MIPS_ARCH_32 && arch !== MIPS_ARCH_32R2)
return "This Ghidra MIPS lane requires EF_MIPS_ARCH_32R2, or a recordless legacy EF_MIPS_ARCH_1 (MIPS-I) or EF_MIPS_ARCH_32 header; other ISA revisions need separate verification.";
const recordlessShape =
(metadata.flags & 0x0000f000) === 0 &&
(metadata.flags & 0x20) === 0 &&
Expand Down
40 changes: 0 additions & 40 deletions tests/boundary/filesystem/mipsAbiFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,46 +213,6 @@ const inspectedTarget = (
});

for (const little of [true, false]) {
it(`refuses PT-backed admission when the final GNU section header is partial (${little ? "LE" : "BE"})`, async () => {
const original = fixture(little);
const bytes = Buffer.concat([original, Buffer.alloc(24)]);
const u32 = (value: number, offset: number) =>
little
? bytes.writeUInt32LE(value, offset)
: bytes.writeUInt32BE(value, offset);
const u16 = (value: number, offset: number) =>
little
? bytes.writeUInt16LE(value, offset)
: bytes.writeUInt16BE(value, offset);
// PT_MIPS_ABIFLAGS is valid; the partial section prefix still declares a
// conflicting soft-float payload, but full section coverage is unproved.
u32(original.length, 32);
u16(1, 48);
u32(0x6ffffff5, original.length + 4);
u32(abiOffset + 24, original.length + 16);
u32(16, original.length + 20);
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 path = await writeFixture(bytes);
const result = await parseBinaryTarget(path);
assert.ok(result.ok);
assert.ok(
result.value.kind === "executable" &&
result.value.format === "elf" &&
result.value.architecture === "mips",
);
assert.equal(result.value.mips.abiFlags?.fpAbi, 5);
assert.match(
ghidraMipsUnsupportedReason(result.value) ?? "",
/ABI declaration inspection is incomplete/u,
);
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
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.