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
10
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.
+733
−0
Open
Changes from 2 commits
Commits
Show all changes
10 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 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
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,181 @@ | ||
| #!/usr/bin/env node | ||
| import assert from "node:assert/strict"; | ||
| import { execFile } from "node:child_process"; | ||
| import { createHash } from "node:crypto"; | ||
| import { mkdtemp, readFile, 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 } from "./lib/mcp-verifier-results.mjs"; | ||
| import { functionDossierSchema } from "../dist/domain/hopperValues.js"; | ||
| import { parseEvidence } from "../dist/domain/evidence.js"; | ||
| import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; | ||
|
|
||
| // Static inspection only. No MIPS compiler, acquisition or target execution. | ||
| if (!process.env.GHIDRA_INSTALL_DIR || !process.env.JAVA_HOME) | ||
| throw new Error("Supply GHIDRA_INSTALL_DIR and JAVA_HOME."); | ||
| const execute = promisify(execFile); | ||
| const root = await mkdtemp(join(tmpdir(), "rea-ghidra-mips1-")); | ||
| const reports = []; | ||
| try { | ||
| for (const byteOrder of ["little", "big"]) { | ||
| const fixture = await buildMips1Fixture(root, byteOrder); | ||
| const { stdout: headers } = await execute( | ||
| process.env.REA_READELF ?? "readelf", | ||
| ["-h", "-s", fixture.path], | ||
| ); | ||
| assert.match(headers, /ELF32/u); | ||
| assert.match(headers, /0x1001.*o32.*mips1/u); | ||
| assert.match(headers, /00401000.*rea_mips1_entry/u); | ||
| const transport = new StdioClientTransport({ | ||
| command: process.execPath, | ||
| args: [fileURLToPath(new URL("./rea.mjs", import.meta.url)), "mcp"], | ||
| env: { | ||
| ...process.env, | ||
| REA_ANALYSIS_PROVIDER: "ghidra", | ||
| REA_LOG_LEVEL: "silent", | ||
| TMPDIR: root, | ||
| }, | ||
| stderr: "inherit", | ||
| }); | ||
| const client = new Client({ name: "rea-mips1-verifier", version: "1" }); | ||
| const call = async (name, args = {}) => | ||
| requireMcpOperationResult( | ||
| await client.callTool({ name, arguments: args }, { timeout: 240_000 }), | ||
| name, | ||
| ); | ||
| try { | ||
| await client.connect(transport); | ||
| const selected = await call("open_binary", { | ||
| path: fixture.path, | ||
| provider_id: "ghidra", | ||
| }); | ||
| assert.equal(selected.sha256, fixture.sha256); | ||
| const image = await call("inspect_native_load_image"); | ||
| assert.equal( | ||
| image.observations.language_id, | ||
| `MIPS:${byteOrder === "little" ? "LE" : "BE"}:32:default`, | ||
| ); | ||
| const first = await call("inspect_native_instruction", { | ||
| address: fixture.entry, | ||
| }); | ||
| const delay = await call("inspect_native_instruction", { | ||
| address: "0x401008", | ||
| }); | ||
| const branch = await call("inspect_native_instruction", { | ||
| address: "0x401004", | ||
| }); | ||
| assert.equal(first.status, "decoded"); | ||
| assert.match(first.mnemonic, /^addiu$/iu); | ||
| assert.match(delay.mnemonic, /^_?sll$/iu); | ||
| assert.equal(branch.status, "decoded"); | ||
| assert.match(branch.mnemonic, /^beq$/iu); | ||
| assert.equal(branch.flow.kind, "jump"); | ||
| assert.equal(branch.flow.conditional, true); | ||
| assert.deepEqual(branch.flow.direct_destinations, ["0x401010"]); | ||
| const loaded = await call("read_bytes", { | ||
| address: fixture.entry, | ||
| length: 24, | ||
| }); | ||
| assert.equal(loaded.returned_bytes, 24); | ||
| const bytes = Buffer.from(loaded.bytes_hex, "hex"); | ||
| const words = Array.from({ length: 6 }, (_, index) => | ||
| byteOrder === "little" | ||
| ? bytes.readUInt32LE(index * 4) | ||
| : bytes.readUInt32BE(index * 4), | ||
| ); | ||
| assert.deepEqual(words, fixture.words); | ||
| const dossier = functionDossierSchema.parse( | ||
| await call("analyze_function", { procedure: fixture.entry }), | ||
| ); | ||
| assert.ok(dossier.pseudocode.trim().length > 0); | ||
| assert.ok(dossier.assembly.some((line) => /sll/iu.test(line))); | ||
|
|
||
| const snapshotPath = join(root, `snapshot-${byteOrder}.json`); | ||
| await call("close_binary", { snapshot_path: snapshotPath }); | ||
| const snapshot = parseAnalysisSnapshot( | ||
| JSON.parse(await readFile(snapshotPath, "utf8")), | ||
| ); | ||
| assert.ok( | ||
| snapshot.evidence_bundle.records.some((record) => | ||
| parseEvidence(record).limitations.some((text) => | ||
| /Floating-point ABI behavior remains unverified/u.test(text), | ||
| ), | ||
| ), | ||
| ); | ||
| assert.equal( | ||
| snapshot.binding.analysis_profile.parameters.mips_support_lane, | ||
| "elf32-exec-mips1-recordless-pinned-v1", | ||
| ); | ||
| await call("open_binary", { | ||
| path: fixture.path, | ||
| provider_id: "ghidra", | ||
| snapshot_path: snapshotPath, | ||
| }); | ||
| const replay = await call("analyze_function", { | ||
| procedure: fixture.entry, | ||
| }); | ||
| assert.deepEqual(replay, dossier); | ||
| await call("close_binary"); | ||
| if (byteOrder === "little") { | ||
| const { stdout } = await execute( | ||
| process.execPath, | ||
| [ | ||
| fileURLToPath(new URL("./rea.mjs", import.meta.url)), | ||
| "function", | ||
| fixture.path, | ||
| fixture.entry, | ||
| "--provider", | ||
| "ghidra", | ||
| "--full-output", | ||
| "--json", | ||
| ], | ||
| { env: process.env, timeout: 240_000, maxBuffer: 32 * 1024 ** 2 }, | ||
| ); | ||
| const envelope = JSON.parse(stdout); | ||
| assert.equal(envelope.ok, true); | ||
| const cliEvidence = parseEvidence(envelope.data); | ||
| assert.equal(cliEvidence.subject?.digest.sha256, fixture.sha256); | ||
| const cliDossier = functionDossierSchema.parse( | ||
| cliEvidence.normalized_result, | ||
| ); | ||
| assert.equal(cliDossier.pseudocode, dossier.pseudocode); | ||
| } | ||
| assert.equal( | ||
| createHash("sha256") | ||
| .update(await readFile(fixture.path)) | ||
| .digest("hex"), | ||
| fixture.sha256, | ||
| ); | ||
| reports.push({ | ||
| byte_order: byteOrder, | ||
| sha256: fixture.sha256, | ||
| language: image.observations.language_id, | ||
| source_unchanged: true, | ||
| loaded_bytes: true, | ||
| cli: byteOrder === "little" ? "verified" : "not-run", | ||
| instruction_decode: true, | ||
| conditional_branch_destination: true, | ||
| expected_delay_slot_instruction_decoded: true, | ||
| delay_slot_relationship: "not-exposed-by-instruction-contract", | ||
| dossier: true, | ||
| snapshot_replay: true, | ||
| fp_semantics: "unverified", | ||
| target_executed: false, | ||
| }); | ||
| } finally { | ||
| try { | ||
| await client.close(); | ||
| } finally { | ||
| await transport.close(); | ||
| } | ||
| } | ||
| } | ||
| console.log(JSON.stringify({ status: "passed", reports }, null, 2)); | ||
| } finally { | ||
| await rm(root, { recursive: true, force: true }); | ||
| } | ||
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.