Files
rea/src/ghidra/GhidraPspProfile.ts
T
Jay-Alexander ElliotGitHubgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>morluto
e4407dbed5 feat(ghidra): admit bounded PSP ELF through installed Allegrex (#1599)
* feat(ghidra): admit bounded PSP ELF through installed Allegrex

Build on merged generic MIPS without weakening its policy. Bind caller-installed processor files into the analysis profile, check them again before launch, force and verify PSP language selection, retain limitations, and extend the public CLI/MCP verifier with source-owned PSP and target-switching checks. Local actual focused Vitest: 102 passed, one existing permission skip. Hosted static and real-provider results are pending.

* fix(ghidra): validate PSPSDK ABI records in PSP admission

* test(ghidra): bind PSP ABI verification to snapshot profiles

* test(ghidra): declare independent PSP ABI reader contract

* test(ghidra): retain the PSP fixture discriminated type

* test(ghidra): contextually type PSP metadata as the MIPS target variant

* test(ghidra): keep carved firmware checks scoped to generic MIPS fixtures

* style(ghidra): format PSP language-override guard

* style(test): format PSP language override regressions

* fix(ghidra): bound PSP extension enumeration before allocation

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-11 19:47:33 +08:00

61 lines
3.0 KiB
TypeScript

import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import { ghidraMipsUnsupportedReason } from "./GhidraMipsProfile.js";
/** Allegrex's ELF machine declaration, not a filename or inferred instruction. */
export const isGhidraPspTarget = (target: BinaryTarget): boolean =>
target.kind === "executable" &&
target.format === "elf" &&
target.architecture === "mips" &&
target.mips !== undefined &&
(target.mips.flags & 0x00ff0000) === 0x00a20000;
/** PSP has its own verified interpretation; generic MIPS rules remain unchanged. */
export const ghidraProcessorUnsupportedReason = (
target: BinaryTarget,
): string | null => {
if (
target.kind !== "executable" ||
target.architecture !== "mips" ||
!isGhidraPspTarget(target)
)
return ghidraMipsUnsupportedReason(target);
const metadata = target.mips;
if (metadata === undefined) return "PSP analysis requires ELF metadata.";
if (metadata.elfClass !== 32 || metadata.byteOrder !== "little")
return "The PSP Allegrex profile requires little-endian ELF32.";
if (metadata.type !== 2)
return "The PSP Allegrex profile supports static ET_EXEC only; PRX, shared and relocatable images require separate verification.";
// PSPSDK emits MIPS-II / Allegrex / EABI32 with NOREORDER. Do not accept
// unknown producer flags or treat this as proof of instruction semantics.
if (metadata.flags !== 0x10a23001)
return "The PSP Allegrex profile requires the verified PSPSDK ELF declaration 0x10a23001; other ISA/ABI/ASE flags are not inferred.";
const abi = metadata.abiFlags;
if (abi === undefined || abi === null)
return "The PSP Allegrex profile requires an inspected separate MIPS ABI flags record; missing declarations are not inferred.";
// PSPDEV v20261001: GNU readelf 2.44 and the 24-byte record agree on
// MIPS II, 32-bit registers, single-precision hard float and flags1=1.
// This is a bounded producer declaration, not a claim about VFPU semantics.
if (
abi.version !== 0 ||
abi.isaLevel !== 2 ||
abi.isaRevision !== 0 ||
abi.gprSize !== 1 ||
abi.cpr1Size !== 1 ||
abi.cpr2Size !== 0 ||
abi.fpAbi !== 2 ||
abi.isaExtension !== 0 ||
abi.ases !== 0 ||
abi.flags1 !== 1 ||
abi.flags2 !== 0
)
return "The separate MIPS ABI flags record does not match the verified PSP MIPS-II/32-bit/single-float declaration; other versions, register modes and extension flags require separate verification.";
return null;
};
/** Propagated with every PSP observation, including successful decompilation. */
export const GHIDRA_PSP_LIMITATIONS = [
"PSP/Allegrex analysis uses the caller-installed ghidra-allegrex extension. ELF declarations and selected instruction checks are not proof of runtime semantics.",
"ghidra-allegrex does not model VFPU prefix effects completely in decompiled output. Verify vector behavior independently; pseudocode is not an execution oracle.",
"This PSP profile covers static ELF32 ET_EXEC only. PRX relocations, PBP/ISO containers, live overlays and PSP emulation are outside this verified lane.",
] as const;