Skip to content

feat(ghidra): admit verified MIPS16 shared ELF images - #1991

Merged
N0zoM1z0 merged 2 commits into
mainfrom
feat/1851-mips16-shared-elf
Oct 11, 2026
Merged

N0zoM1z0 merged 2 commits into
mainfrom
feat/1851-mips16-shared-elf

Conversation

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Summary

REA can analyze unchanged ELF32 o32 MIPS32r2 MIPS16 shared images when their complete source declarations fit a verified Ghidra load profile. Mixed MIPS32/MIPS16 instructions retain their per-address decoder context.

Fixes #1851

Problem and expected behavior

The standard MIPS lane refuses ET_DYN and compressed encodings, preventing native investigation of shared ELF artifacts. Admission must establish the source load, relocation and mode semantics rather than edit headers or infer compatibility from the architecture name.

Change and scope

  • Extend the existing source metadata reader to examine complete program/section declarations and stream dynamic REL records in 64 KiB chunks. Preserve unknown ABI declarations and partial-table reasons.
  • Admit the separate ELF32 ET_DYN/o32/MIPS32r2/MIPS16 profile with uniquely mapped load ranges, R_MIPS_NONE and symbol-index-zero R_MIPS_REL32. Refuse symbol-bearing REL32, extra section relocation tables, RELA/PLT, other relocation types and incomplete declarations.
  • Pin the endian-matched generic MIPS32 language and default compiler specification. Preserve matching caller overrides and explicitly refuse incompatible choices.
  • Expose Ghidra's per-address ISA_MODE separately from the program-wide mode label, preserving null when no context value is available.
  • Add source-owned GNU controls and an optional real CLI/MCP verifier covering both byte orders, mixed modes, declared/absent ABI records and relocation refusals.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application ELF source inspection owns declaration coverage; the Ghidra adapter owns admission, language selection and decoder interpretation.
  • CLI and MCP/tool-catalog contract: existing operations remain unchanged; native instruction results gain optional decoder_context, e.g. [{"register":"ISA_MODE","value":"1","source":"ghidra-program-context"}]. A null value preserves unavailable context; omitted fields remain valid for older captures/providers.
  • Provider, bridge, target-format, or platform compatibility: the bounded profile applies to Ghidra on Linux/macOS. Existing ET_EXEC/ET_REL, other providers and Windows P0 retain their admission boundaries.
  • Evidence, artifact, provenance, or reconstruction contract: preserve original bytes/digests, ABI facts and relocation declarations. Profiles commit the shared-load and context policy; addresses remain analysis coordinates. Loaded-image relocation bytes/status and external-binding limitations remain visible.
  • Process execution, authorization, cleanup, or containment impact: existing owned ephemeral Ghidra lifecycle; no target execution, byte modification or GUI authority. The verifier checks process cleanup and source digests.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: one optional verify:ghidra:mips-shared package script; ignored catalogs regenerate from contracts. No binary, generated catalog or dependency changes. Tools are caller-supplied.

Evidence and regression coverage

  • Tests added or updated: endian-aware source declaration parsing, late relocation records, malformed/duplicate/incomplete tables, overlapping mappings, extra section relocations, cancellation identity, missing declarations, configured-language preservation and profile/session mismatch.
  • Base reproduction or other evidence: main's provider admission refuses the original unchanged shared image. On the patch, real CLI/MCP analysis of that image recovered 412 procedures, selected instruction/pseudocode evidence and a retained Evidence export, with unchanged source digest. Independent source/load comparison verified 169 nonzero relocation/GOT words; unresolved external entries remain unknown.
  • Real negative control: Ghidra 12.1.4 normalizes a symbol-bearing MIPS16 REL32 function pointer to an even address in both byte orders. The profile refuses that shape instead of silently repairing its mode tag.
  • User-visible CLI/MCP output: mode retains default; compressed instructions report ISA_MODE 1, while the standard-mode control preserves an observed null. Source-owned local pointer tags survive relocation; snapshot round trips preserve decoder context.
  • Remaining proof gaps: compressed floating-point behavioral conformance, other relocation families, external GOT resolution, other Ghidra versions, macOS real execution, and other native providers were not verified.

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

  • npm run test:focused -- eight relevant source/boundary files — 152 passed after main integration, including existing MIPS ABI and WASM diagnostics.
  • npm run verify:ghidra:mips-shared — eight real public CLI/MCP controls passed using Ghidra 12.1.4, JDK 21 and GNU cross-binutils 2.40 on Linux x64. Covered four positive and four refused controls, CLI/MCP parity, source symbols/instruction bytes, local pointer tags, snapshot restore, service responsiveness and zero surviving owned descendants.
  • Original-artifact public CLI/MCP replay — passed with advertised schemas, instruction/pseudocode/export parity and unchanged source bytes.
  • The eight-control run used one CPU, peaked at approximately 1.50 GiB, and recorded zero memory-limit, OOM or OOM-kill events.
  • npm run check:fast and npm run docs:check — passed on the integrated head. npm run check:ci passed the full static gate before the main sync; CI validates the final published head.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; additive result field and narrowly expanded admission.
  • Real Hopper/Ghidra, browser, or OS coverage: genuine Linux x64 Ghidra 12.1.4; other providers/platforms unverified for the new lane.
  • Package or release metadata impact: optional developer verifier script only; no installer or runtime dependency additions.
  • Security, privacy, process, or containment review: source-file identity and bytes are preserved; temporary read-only analysis uses existing process ownership and cleanup. Source bounds and complete declaration coverage are checked before admission.

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.

N0zoM1z0 and others added 2 commits October 11, 2026 23:35
Inspect source load and relocation declarations before admitting the bounded
ELF32 o32 MIPS32r2 MIPS16 lane. Pin the endian-matched language and report
per-address decoder context without changing the caller-selected bytes.

Refuse symbol-relative and additional section relocations whose semantics
are outside this verified lane. Add real public CLI/MCP source controls.

Refs #1851

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: Kaoru0822 <[email protected]>
Preserve the merged WASM format guidance and existing MIPS ABI coverage.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: Kaoru0822 <[email protected]>
@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 ✅ Completed 2026-10-11T23:43:10.879520Z 303a7fa PR opened
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 303a7fa50d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +153 to +157
relocationSections.push({
type,
offset: u32(contents.value, position + 16),
size: u32(contents.value, position + 20),
entrySize: u32(contents.value, position + 36),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate relocation section virtual addresses

For an ET_DYN whose SHT_REL entry has the same file offset and size as DT_REL but a conflicting sh_addr, this projection drops sh_addr (at section-header offset 12), so checkSections incorrectly marks the declarations complete and the image can enter the verified shared-image lane. Capture the section address and require it to match the dynamic table address so contradictory source declarations are refused.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

@N0zoM1z0
N0zoM1z0 merged commit e9fe643 into main Oct 11, 2026
31 checks passed
@N0zoM1z0
N0zoM1z0 deleted the feat/1851-mips16-shared-elf branch October 11, 2026 23:50
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
@morluto morluto added area: tests Test suite and verification 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

area: tests Test suite and verification ci:full enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Verify and admit MIPS16 shared ELF images in the native analysis lane

2 participants