Skip to content

feat(ghidra): admit PS2 Emotion Engine executables through ghidra-emotionengine-reloaded - #6422

Closed
Kendy619 wants to merge 8 commits into
morluto:mainfrom
Kendy619:pr/ghidra-ps2-emotion-engine
Closed

Kendy619 wants to merge 8 commits into
morluto:mainfrom
Kendy619:pr/ghidra-ps2-emotion-engine

Conversation

@Kendy619

Copy link
Copy Markdown

Summary

Every provider refuses PlayStation 2 Emotion Engine executables: MIPS ELF32
files that declare EF_MIPS_MACH_5900 fail with "Machine-specific MIPS
variants … need a separately supported processor profile". This adds a bounded
PS2 profile to the existing Ghidra provider, following the PSP precedent. REA
pins the language of the caller-installed
ghidra-emotionengine-reloaded
extension and fingerprints the extension, but never installs it.

Related: #5240 takes a similar approach for legacy ee-gcc retail executables.
This PR is kept separate so each can be reviewed on its own. The differences
are listed under "Change and scope".

Problem and expected behavior

rea function <PS2 ELF> <name> --provider ghidra fails with
architecture_unsupported. With the extension installed and its r5900.sla
precompiled, CLI and MCP:

  • resolve lane ps2-ee-elf32-exec-r5900-v1;
  • import with ElfLoader / r5900:LE:32:default / default;
  • serve the ordinary inventory, instruction, reference, string and function
    operations.

Without the extension they fail with PS2_EXTENSION_UNAVAILABLE and an
installation remedy.

Change and scope

  • GhidraProcessorExtension.ts: the PSP extension inspection, generalized and
    parameterized by id, label, profile, failure code, required files and an
    optional installed-state check. PSP exports, messages and identity are
    unchanged.

  • GhidraPs2Profile.ts / GhidraPs2Extension.ts: admission and the extension
    spec. Admitted targets run on Linux x64 hosts and are little-endian ELF32
    ET_EXEC, R5900 machine, MIPS III, with only NOREORDER/CPIC hints, and
    either:

    • n32 with the R5900 ABI flags record that PS2SDK emits (ps2dev v2.0.0), or
    • EABI64 (legacy-SDK shape) with that record, or with the record absent
      after every declaration table was inspected.

    Everything else is refused: o32/EABI32/mixed ABIs, PIC/ASE/FP64/NAN2008,
    unknown records, incomplete or carved inspections, and caller language
    overrides.

  • Precompiled SLEIGH requirement. Release archives ship only sources, and
    Ghidra 12.1 SleighLanguage recompiles a missing, wrong-format or stale
    .sla inside the installation. REA refuses an r5900.sla without the
    format-4 header or older than its .slaspec/.sinc sources. Analysis
    therefore never modifies the installation, and the fingerprint stays stable.

  • Wiring:

    • processor dispatcher and analysis profile;
    • provider host check;
    • provider client: expected language at handshake, Evidence limitations;
    • launcher: re-inspection before launch.

    The PS2 limitations are kept short because every response repeats them.

  • tests/conformance/ps2/ fixtures, --ps2 / --ps2-missing-extension modes
    for scripts/verify-real-ghidra-mips.mjs, and docs/ghidra-ps2.md.

Not included: IRX/ERX, relocatable or shared images, ISO and other
containers, runtime overlays, VU microprograms, emulation, non-Linux-x64
hosts, and static recompilation.

Differences from #5240:

  1. This PR admits current PS2SDK n32 homebrew. feat(ghidra): admit PlayStation 2 EE executables through ghidra-emotionengine-reloaded #5240 refuses it because it
    carries an ABI flags record.
  2. It requires a precompiled, fresh r5900.sla instead of letting Ghidra
    write into the installation.
  3. It uses reproducible source-owned fixtures with a real CLI/MCP verifier.

#5240 also admits an unspecified-ABI header. This PR does not, because no
producer evidence for that shape was available.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra target admission
    (ghidraProcessorUnsupportedReason), then analysis-profile resolution.
  • Contribution scope fit and linked maintainer decision: static decompilation
    of a new processor family through an existing provider. No maintainer
    decision yet; feedback welcome.
  • CLI and MCP/tool-catalog contract: unchanged, apart from newly admitted
    targets and the new failure code PS2_EXTENSION_UNAVAILABLE.
  • Provider, bridge, target-format, or platform compatibility: Ghidra only,
    Linux x64 only; bridge unchanged. Generic MIPS, PSP and IOP (R3000)
    headers keep their lanes or refusals.
  • Evidence, artifact, provenance, or reconstruction contract:
    • new profile parameters: mips_support_lane, ps2_abi_declaration,
      ps2_extension, and the pinned loader, language and compiler;
    • five PS2 limitations, plus one for a recordless EABI64 header.
  • Target selection, authority, upstream behavior, and cleanup details: not
    applicable (static import; ephemeral project as before).
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code. Note: for .mdebug targets,
    the caller-installed extension's STABS analyzer runs its bundled
    stdump, as installed Ghidra code. This is documented and can be
    disabled with REA_GHIDRA_DISABLED_ANALYZERS.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/filesystem/ghidraPs2Extension.test.ts;
    • tests/conformance/ghidra/ps2-checks.test.ts;
    • tests/conformance/ghidra/mips-checks.mjs, which now accepts a null ABI
      record.
  • Base reproduction or other evidence: on the base revision, both PS2
    fixtures are refused as machine-specific MIPS variants.
  • Real provider, both fixtures (PS2SDK n32 e312d08b…, legacy EABI64
    dcc503da…):
    • observed r5900:LE:32:default / default;
    • exact bytes and mnemonics of li, paddw, pcpyld, three-operand
      mult and vadd.xyzw;
    • caller, call-site xref, global xref, and the marker string together with
      its EE RAM mirrors;
    • snapshot reopen, A-B-A target switch and CLI Evidence;
    • process lineage verified with no descendants.
  • Caller-owned retail executables (outside the suite; no game data in the
    repository). This was 11 EE executables from 7 discs: 6 USA titles from
    2003–2006 and one modified disc.
    • All 11 declare the legacy-SDK EABI64 shape (0x20924000/0x20924001)
      with no record and are admitted.
    • All 7 boot executables analyze as r5900:LE:32:default and their entry
      functions decompile. They have 4,183–28,022 procedures each.
    • One title built with Metrowerks CodeWarrior has all 4,183 function names
      recovered from its symbol table; its runtime overlay sections stay outside
      the image, as documented.
    • Two tasks hit REA's general 10 MiB MCP response budget rather than a
      profile limit: a 28k-function string list, and the load image of the
      CodeWarrior title with 56,477 relocations. A separate issue will propose
      smaller responses.
    • For one title, God Hand, the boot ELF SHA-256 equals the public
      god-hand-decomp record. With that project's function list as
      REA_GHIDRA_SEED_FILE seeds:
      • all 10,122 decomp function starts are found, and 2,922/2,922 names sit
        at the exact address;
      • call sites match raw jal decoding (902/902 on the most-called
        function);
      • the callees of 19 functions with matched C equal that C (85/85).
  • Remaining proof gaps:
    • carved PS2 images and non-EABI64 retail header shapes not observed;
    • only Ghidra 12.1.3 with extension v2.1.38;
    • no CI lane with the extension;
    • reopening a snapshot re-runs auto-analysis (about 150 s for a 2.8 MB
      .text).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

All on this branch, rebased onto main 47353e494; the branch also merges cleanly with b7f8bbb49, whose 5 newer commits touch no PS2, Ghidra, ELF or MIPS files. Environment: WSL2 Ubuntu
24.04 (Linux x64), Node 24.18, Temurin JDK 21, Ghidra 12.1.3.

  • npm ci && npm run build:cached — passed.
  • npm run check — passed (lint 0 errors, module boundaries, architecture guards).
  • npm run test:focused -- <34 Ghidra extension/conformance/provider test files> — 945 passed, 1 skipped.
  • node scripts/verify-real-ghidra-mips.mjs --ps2 — passed (256 s).
  • node scripts/verify-real-ghidra-mips.mjs --ps2-missing-extension — passed.
  • node scripts/verify-real-ghidra-mips.mjs --psp (ghidra-allegrex v21.4, PSPDEV v20261001) — passed (186 s); --psp-missing-extension — passed.
  • npm run docs:check / npm run verify:test-discovery — passed (re-run for the docs update).
  • Generic MIPS verifier (Clang/LLD 18.1.3), on the pre-rebase branch with the EE
    and Allegrex extensions installed — passed for 6 fixtures. The generic
    MIPS32r2 control is still observed as MIPS:LE:32:default, and the
    IOP-shaped R3000 ELF is still refused.
  • Full npm run check:pr on the pre-rebase branch: 18 tests in 10 files
    failed. All of them are outside Ghidra/MIPS/PSP/PS2 and fail identically, or
    flakily, on unmodified main in this environment (Kuna, WindowsHandleClose,
    ciStaticArtifacts, runtime URL mapping, mutation workflow, symlink race).

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Ghidra 12.1.3, Temurin JDK 21,
    Linux x64 (WSL2). Windows and macOS hosts are refused for this profile.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: same model as PSP. The
    extension is identified by content, not signed or sandboxed. The .sla
    freshness rule keeps analysis from writing into the installation.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Move the bounded, read-only fingerprinting of a caller-installed Ghidra
processor extension out of the PSP module into GhidraProcessorExtension,
parameterized by directory id, refusal label, profile name, failure code,
required files and an optional installed-state check. The PSP wrappers keep
their exports, refusal messages and PSP_EXTENSION_UNAVAILABLE code; the
existing PSP boundary tests pass unmodified.

The inspection now also retains each file's whole-millisecond mtime and
first eight bytes for specification-owned checks; neither enters the
content identity.
…tionengine-reloaded

Add a bounded PS2 profile to the existing Ghidra provider, following the PSP
precedent. The R5900 machine declaration (EF_MIPS_MACH_5900) selects it;
filenames and entry addresses do not. Admission is limited to Linux x64 and
little-endian ELF32 ET_EXEC MIPS III images declaring either:

- n32 with the R5900 ABI flags record that ps2dev v2.0.0 PS2SDK emits, or
- EABI64, the legacy-SDK header shape, with that record or with an
  inspected absence of every ABI declaration.

Other ABIs, PIC/ASE/FP64/NAN2008 bits, unknown records, incomplete
inspections and caller language overrides are refused before extension
discovery. Generic MIPS, PSP and IOP headers keep their lanes.

The import pins ElfLoader, r5900:LE:32:default and the default compiler
specification, and the session handshake checks the observed language. The
caller-installed extension is fingerprinted at profile resolution and again
before launch; missing or incompatible installations fail with
PS2_EXTENSION_UNAVAILABLE. Release archives ship only SLEIGH sources and
Ghidra recompiles a missing, wrong-format or stale r5900.sla inside the
installation, so REA requires a precompiled format-4 file that is not older
than its .slaspec/.sinc sources.

Evidence carries the support lane, ABI declaration, extension identity and
limitations for MMI/VU0 decompilation, the single R5900 calling convention
and the extension's synthetic memory blocks and RAM mirrors.
Add source-owned PS2 fixtures under tests/conformance/ps2: a standard
PS2SDK n32 executable and a freestanding EABI64 control linked without an
ABI flags record. Neither is executed and neither contains game data.

scripts/verify-real-ghidra-mips.mjs gains --ps2 and
--ps2-missing-extension. GNU readelf/objdump independently supply the
header, raw ABI record, symbols and probe encodings. Public MCP and CLI
must report the observed ElfLoader/r5900 language, known functions, a
direct call, the leaf's caller and call-site xref, exact bytes and
mnemonics for ADDIU, MMI PADDW/PCPYLD, R5900 MULT and VU0 VADD.xyzw, a
global word, the marker string (allowing EE RAM mirrors), Evidence
limitations, snapshot reopening, an A-B-A target switch and verified
process cleanup. Without the extension both adapters must return
PS2_EXTENSION_UNAVAILABLE.

expectedMipsElfProfile now accepts an inspected ABI-record absence.
Describe the admission boundary, the bring-your-own extension with its
required precompiled r5900.sla, the public CLI/MCP use, Evidence and
limitations, and the real verification lane and its tested versions.
Map the build directory out of debug information at compile and link time.
PS2SDK libraries are LTO objects whose link-time units otherwise record the
build directory, so the verifier's temporary workspace changed the fixture
digest on every run. Two builds in different directories are now
byte-identical with ps2dev v2.0.0.
Every PS2 observation repeats the profile limitations, so their length is
paid on each MCP call. In a God Hand investigation each callers/callees
response was about 5.6 KB, of which the PS2 text was 1.1 KB. State each
fact once and briefly and drop the language ID, which Evidence already
carries as a profile parameter: 1110 -> 753 bytes per response, same
facts, same phrases checked by the tests and the real verifier.

Validation: ghidraPs2Extension, ps2-checks and psp-checks tests (96
passed); check:fast; real verify-real-ghidra-mips.mjs --ps2 passed.
Report the out-of-suite run on 11 EE executables from 7 caller-owned discs.
All declare the legacy-SDK EABI64 shape, are admitted and analyse as
r5900:LE:32:default, including a Metrowerks CodeWarrior build whose symbol
table names every function. Two tasks hit REA's general MCP response budget
rather than a profile limit. Replace the statement that no commercial
executable was verified.
@morluto

morluto commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thanks for documenting the differences from #5240. Both proposals affect the same PS2 profile and extension owner, with different ABI admission and verification evidence. Please coordinate on one integration path so the supported declarations and retained real-provider coverage are reviewed together. Both remain open while the scope is settled.

@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks for the PS2 profile and for documenting the differences from #5240. Closing this as a duplicate: both proposals own the same Emotion Engine profile and extension, #5240 is the one still being updated, and this draft has conflicted with main since the coordination request on October 26. Please bring any ABI admission or verification evidence that #5240 lacks to that PR.

@morluto morluto closed this Nov 15, 2026
@morluto morluto added enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants