Repository navigation
test(ghidra): verify current MIPS admission and orphan cleanup #2919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bobtoshi
wants to merge
25
commits into
morluto:main
Choose a base branch
from
Bobtoshi:codex/mips1-verification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,345
−2
Open
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 d8630ea
test(ghidra): verify MIPS branch decoding and retain diagnostics
Bobtoshi 5ec1a57
fix(mips)!: reject uninspected GNU ABI attributes
Bobtoshi 102f813
test(mips): isolate native boundary controls from ambient settings
Bobtoshi 05e2366
test(mips): verify cleanup and pin readelf locale
Bobtoshi 0a8f70f
Merge latest upstream and verify MIPS declaration coverage
Bobtoshi e389016
chore: preserve untouched upstream tests after merge
Bobtoshi 2d2f2f8
test(ghidra): refresh MIPS controls and verify orphan cleanup
Bobtoshi 11edd85
fix(verification): sweep the captured Ghidra provider run identities
Bobtoshi 3569da2
chore: merge upstream into MIPS verifier branch
Bobtoshi 7ab92a4
test(ghidra): verify imported MIPS languages and merge upstream
Bobtoshi 6886262
test(ghidra): remove an empty processor context suite
Bobtoshi a830a4a
fix(ghidra): track verifier runs before lazy analysis
Bobtoshi 624b879
fix(ghidra): verify MIPS evidence and preserve cleanup failures
Bobtoshi 779a635
test(ghidra): verify committed MIPS dossier attribution
Bobtoshi 19a9f98
fix(ghidra): bound MIPS readelf verification
Bobtoshi 0a5b082
test(ghidra): bind MIPS dossiers to their ELF fixtures
Bobtoshi 2d1ee37
test(ghidra): retain MIPS readelf verification evidence
Bobtoshi 7494b2b
test(ghidra): retain MIPS source paths and refusal diagnostics
Bobtoshi 99b9126
fix(ghidra): own MIPS verifier CLI refusal commands
Bobtoshi 7d92575
fix(ghidra): recover verified MIPS verifier provider survivors
Bobtoshi dbd04ab
test(ghidra): verify recordless MIPS caveats and cold cleanup
Bobtoshi ffcd4d6
fix(ghidra): own the MIPS verifier MCP transport
Bobtoshi 3596755
fix(ghidra): keep MIPS MCP ownership separate from CLI commands
Bobtoshi 1051072
Qualify MIPS32 boundaries and retain failed verifier ownership
Bobtoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| 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", | ||
|
Bobtoshi marked this conversation as resolved.
Resolved
|
||
| ["-A", gnuPath], | ||
| { env: { PATH: env.PATH, LC_ALL: "C" } }, | ||
|
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 }); | ||
|
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( | ||
|
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" || | ||
|
Bobtoshi marked this conversation as resolved.
Resolved
|
||
| completed.process_lineage.descendants.length !== 0 | ||
|
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), | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.