Skip to content

feat(ghidra): admit 32-bit big-endian PowerPC ELF - #1747

Merged
morluto merged 6 commits into
morluto:mainfrom
arielfikru:feat/ghidra-powerpc
Oct 13, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
arielfikru:feat/ghidra-powerpc

Conversation

@arielfikru

Copy link
Copy Markdown
Contributor

Summary

Milestone 1 of #1741: 32-bit big-endian PowerPC ELF executables can reach REA's normal Ghidra workflow. Before this change EM_PPC was "unsupported ELF architecture", so no PowerPC target could be opened.

Opened as a draft while #1741 waits for maintainer input on direction; happy to reshape it.

Problem and expected behavior

A legally obtained PowerPC ELF (embedded/firmware code, or reconstruction work on PowerPC programs) should give functions, instructions, pseudocode, references and Evidence through the existing tools, with the same admission discipline as the MIPS lane.

One PowerPC-specific trap shapes the design: for a plain EM_PPC header with e_flags 0, Ghidra 12.1.4's ELF loader picks PowerPC:BE:32:e500:default. e500 is the Book-E/SPE variant without the classic FPU, so it misreads 750-family code, and nothing in the header distinguishes the two. Observed headless import of the fixture:

INFO  Using Loader: Executable and Linking Format (ELF) (ProgramLoader)
INFO  Using Language/Compiler: PowerPC:BE:32:e500:default (ProgramLoader)

Change and scope

  • Domain: powerpc joins BINARY_ARCHITECTURES. EM_PPC (20) resolves to an ELF target that carries PowerPcElfMetadata (class, byte order, e_type, raw e_flags), mirroring how MIPS keeps its header facts. EM_PPC64 (21) is not mapped to this family. ElfHeaderArchitecture = "mips" | "powerpc" replaces the Exclude<…, "mips"> spellings.
  • Ghidra admission (src/ghidra/GhidraPowerPcProfile.ts): ELF32, big endian, ET_EXEC. ELF64, little endian, relocatable/shared objects and EF_PPC_EMB are refused with a specific reason. Other e_flags bits only declare relocation conventions.
  • Bound language: the profile commits language_id: "PowerPC:BE:32:default", compiler_spec_id: "default", language_selection: "admitted-lane-v1", plus powerpc_elf header facts and powerpc_support_lane: "elf32-be-exec-generic-v1". The client reads that back (ghidraProfileLaneLanguage) and uses the existing launcher/handshake path: -processor … -cspec … on import and expectedLanguageId checked against the bridge's reported language. A caller's REA_GHIDRA_LANGUAGE_ID still wins (configured-v1, admitted against the installed catalog as before), e.g. PowerPC:BE:32:e500 for real e500 code.
  • Other adapters: Hopper and IDA refuse PowerPC explicitly; Windows Ghidra P0 is unchanged.

Not included: GameCube/Wii DOL, Gekko/Broadway paired singles, PPC64, little-endian PowerPC, REL/RSO, VLE. Unlike the MIPS lane there is no carved-section case, because PowerPC admission reads no section-borne ABI record.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ELF header parsing in src/domain/binaryTarget.ts; lane admission in src/ghidra/GhidraPowerPcProfile.ts.
  • CLI and MCP/tool-catalog contract: no new tools or options. The architecture enum in target/Evidence/snapshot schemas gains "powerpc".
  • Provider, bridge, target-format, or platform compatibility: Ghidra (Linux/macOS) gains the lane; Hopper, IDA and Windows Ghidra P0 refuse PowerPC. No bridge changes.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence and snapshots preserve powerpc; profile-bound snapshots are invalidated when header facts change.
  • Process execution, authorization, cleanup, or containment impact: none. The fixture is never executed.
  • Generated metadata, package, or installation impact: none committed; docs:check passes.

Evidence and regression coverage

  • Tests added or updated:
    • src/domain/binaryTarget.powerpc.test.ts: header facts for both byte orders, ELF64 flag offset, EM_PPC64 not recognized.
    • src/ghidra/GhidraPowerPcProfile.test.ts: bound language and admitted-lane-v1, configured language replaces it (real temporary catalog), header flags change the profile digest, refusals (ELF64, little endian, ET_REL, ET_DYN, EF_PPC_EMB), Windows P0, Hopper/IDA refusal.
    • tests/composition/analysis-sessions/powerpc-identity.test.ts: identity through Evidence, snapshot and open_binary schema.
    • tests/conformance/ghidra/ppc-checks.test.ts: GNU readelf parser against real 2.47 output; rejects wrong class/order/machine/type/flags, ambiguous fields, an e500 loaded language, and wrong probe bytes/immediate/destination.
  • Base reproduction or other evidence: on the base revision the fixture fails with unsupported ELF architecture; a direct analyzeHeadless -import picks e500 (log above).
  • User-visible CLI/MCP output: open_binary on the fixture returns architecture: "powerpc"; inspect_native_load_image reports language_id: "PowerPC:BE:32:default".
  • Remaining proof gaps: Linux host not run; floating-point and paired-single semantics not exercised; only Clang/LLD-produced ELF tested.

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

Host: macOS 26 arm64, Node 24.18.0, npm 11.16.0, Ghidra 12.1.4, OpenJDK 21, Homebrew clang/LLD 23.1.3, GNU readelf 2.47.

  • npm run check:fast: passed
  • npm run verify:test-discovery: "Discovered all 817 test files exactly once."
  • npm run test:changed: 379 files, 4296 passed, 7 skipped
  • npm run docs:check: passed
  • GHIDRA_INSTALL_DIR=… REA_PPC_CLANG=… REA_PPC_READELF=… npm run verify:ghidra:ppc: passed (effective_language: "PowerPC:BE:32:default", 3 procedures, process lineage verified)
  • npm run verify:ghidra:mips on this branch: passed for both byte orders (shared ELF parsing and language plumbing unchanged for MIPS)

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Previously rejected targets are now admitted; no existing target changes interpretation.
  • Real Hopper/Ghidra, browser, or OS coverage: real Ghidra 12.1.4 on macOS arm64 for the PowerPC and MIPS lanes; Linux not run; Hopper/IDA only via refusal unit tests.
  • Package or release metadata impact: new verify:ghidra:ppc script; no package contents change.
  • Security, privacy, process, or containment review: the fixture is source-owned and compiled locally; no third-party or commercial binaries; nothing is executed.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.

Refs #1741

Recognize EM_PPC as a provider-neutral `powerpc` family that keeps its ELF
class, byte order, type and flags, and admit ELF32 big-endian ET_EXEC through
a bounded Ghidra lane. ELF64, little-endian, relocatable/shared objects and
EF_PPC_EMB are refused with a specific reason; Hopper and IDA do not gain
PowerPC support, and Windows Ghidra P0 is unchanged.

Ghidra's ELF loader selects PowerPC:BE:32:e500:default for a plain EM_PPC
header, which misreads 750-family code. The lane binds
PowerPC:BE:32:default/default in the profile (language_selection
"admitted-lane-v1"), imports with it and checks the reported language. A
language set through REA_GHIDRA_LANGUAGE_ID still replaces the lane default.

Add a source-owned fixture, fixed-encoding probe, GNU readelf cross-check and
the optional `verify:ghidra:ppc` real-provider lane, plus docs/ghidra-ppc.md.

Refs morluto#1741
@arielfikru
arielfikru marked this pull request as ready for review October 11, 2026 07:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-11T07:25:02.235928Z 80f93ce Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

Adds bounded support for 32-bit big-endian PowerPC ELF executables through Ghidra.

  • REA recognizes EM_PPC files as PowerPC targets.
  • Ghidra analyzes admitted PowerPC ELF files with an explicit language.
  • Operators can verify PowerPC analysis with a source-built Ghidra fixture.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[ELF header] --> B[PowerPC target and header facts]
  B --> C{Ghidra admission}
  C -->|Unsupported class, order, type, or embedded flag| D[Refuse target]
  C -->|Admitted| E[Resolve analysis profile]
  F[Caller language choice] --> E
  E --> G[Import with committed language]
  G --> H[Check reported language]
  H --> I[Analysis, Evidence, and snapshots]
Loading

Reviews (6) · Last reviewed commit: "Merge branch 'main' into feat/ghidra-pow..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraAnalysisProfile.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

The shared default language owner also enforced the restricted MIPS/RISC-V override rule on the newly added PowerPC fallback. Commit 43557da exempts PowerPC from that restriction, preserving explicit caller language/compiler selections for installed-catalog validation while retaining the generic fallback and client readback. MIPS and RISC-V restrictions remain enforced. Source inspection and git diff --check completed; touched files were formatted. Tests, builds, lint, checks, CI reruns, and performance measurements were not run at the explicit user request. Real Ghidra PowerPC behavior remains unverified.

@morluto morluto added enhancement New feature or request area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: domain Domain logic, errors, and pure functions area: providers Provider and capability discovery, including provider proposal triage P2: medium Medium priority issue labels Oct 13, 2026
@morluto
morluto merged commit c86b09a into morluto:main Oct 13, 2026
1 check passed
@morluto morluto mentioned this pull request Oct 14, 2026
3 tasks done
@morluto morluto mentioned this pull request Oct 26, 2026
3 tasks done
@morluto morluto added the provider: ghidra Analysis provider / engine: ghidra label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: providers Provider and capability discovery, including provider proposal triage enhancement New feature or request P2: medium Medium priority issue provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants