Skip to content

feat(ghidra): admit raw 8051 images - #15057

Merged
morluto merged 3 commits into
morluto:mainfrom
petrochen:feat/raw-8051
Nov 29, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
petrochen:feat/raw-8051

Conversation

@petrochen

@petrochen petrochen commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Admit headerless Intel 8051 (MCS-51) images as raw-binary with architecture: "8051", analyzed by Ghidra with 8051:BE:16:default. Before this change, open_binary and the CLI refused 8051 at the architecture enum, and an ELF carrier with EM_8051 was refused as an unsupported ELF architecture, so 8051 firmware could not be analyzed through REA at all even though Ghidra ships the language.

Problem and expected behavior

Use case: static analysis of a banked Keil C51 firmware image (32 × 64 KiB banks). Expected outcome: each 64 KiB bank opens as a raw 8051 image, decompiles through the existing Ghidra lane, and keeps the same Evidence, profile and load-image guarantees as the 6502 and m68k raw lanes.

Change and scope

  • 8051 joins BINARY_ARCHITECTURES and RAW_ONLY_ARCHITECTURES (header detection never yields it).
  • Raw admission treats it like 6502: byte-aligned entry, whole mapping within 0x0000..0xffff.
  • ghidraRawBinaryLanguage maps it to 8051:BE:16:default, compiler spec default, default space CODE. The language's INTMEM/SFR/BITS blocks remain uninitialized observations, as with 6502 zero page.
  • Hopper (raw-only), IDA (unsupported), Kuna (null) and Windows Ghidra P0 keep refusing it, matching m68k.
  • Docs: docs/providers/raw-binary.md gains an 8051 section; the skill reference lists the family and notes that bank-switch thunks and Keil ?C?CCASE switch arms are not followed by auto-analysis, so their targets must be supplied through the existing REA_GHIDRA_SEED_FILE.

Not included: bank/overlay modelling, cross-bank call resolution, automatic seed derivation, the 80251/80390/MX51/CIP-51 variants, and a source-owned verify:ghidra:8051 lane.

Contribution scope: not applicable (new raw family on the existing Ghidra lane; no new provider, execution, injection, mutation or protection recovery).

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/binaryTargetTypes.ts / src/domain/rawBinary.ts (family set and admission), consumed by GhidraRawBinaryLanguage, provider architecture tables and the CLI/MCP schemas generated from the enum.
  • Contribution scope fit and linked maintainer decision: not applicable, see above.
  • CLI and MCP/tool-catalog contract: --architecture / architecture enum gains 8051; the raw-binary refusal text lists it. CLI help goldens updated.
  • Provider, bridge, target-format, or platform compatibility: Ghidra only, POSIX. No bridge change.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence subjects accept architecture: "8051" only for raw-binary, like 6502/m68k (evidenceSubject.test.ts now derives that rule from RAW_ONLY_ARCHITECTURES).
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: none committed; .cursor-plugin skill copy regenerated with scripts/generate-cursor-plugin-skill.mjs.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • 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:

    • rawBinary.test.ts: the 16-bit admission block runs for 6502 and 8051; 8051 joins the base-address refusal cases. The admission grid digest changed only because the refusal text now lists 8051: substituting the previous list back into the grid reproduces the previous digest ccc75843….
    • GhidraRawProfileDigest.test.ts: 8051 binds 8051:BE:16:default / default, and joins the legacy raw-load commitments.
    • GhidraProvider.behavior.test.ts: the admitted-family refusal names 8051; raw 8051 binds 8051:BE:16:default outside Windows and Windows Ghidra P0 refuses it.
    • GhidraRawBinaryLoadImage.test.ts: the 8051 language binding returns default space CODE, and load-image attestation accepts CODE and reports ram as a mismatch (replacing CODE with ram in the binding fails three tests).
    • rawBinaryMcp.test.ts: opens a 4-byte 8051 image (LJMP 0x0003; RET) through MCP.
    • liveBinaryTargetSummary.test.ts, evidenceSubject.test.ts, CLI parity help goldens.
  • Base reproduction: on main, open_binary with architecture: "8051" is rejected by the schema enum; an EM_8051 ELF carrier fails with unsupported ELF architecture.

  • User-visible CLI/MCP output (real Ghidra 12.2, JDK 25, macOS arm64, one 64 KiB bank of a 2 MiB Keil C51 image):

    $ rea inspect bank03.bin --target-format raw-binary --architecture 8051 --entry-point 0x0 --provider ghidra --json
    language_id 8051:BE:16:default, segments CODE 0x0-0x10000 + INTMEM/SFR/BITS, procedure_count 42
    
    $ REA_GHIDRA_SEED_FILE=bank03.seeds rea decompile bank03.bin <switch-arm address> ...
    Seed outcome: 1494 functions created, 1 already present, 0 failed
    decompiled a switch-arm handler (seeded function) to C pseudocode
    

    decompile-all completed on 17 banks of the same image (1,400–2,300 functions each). Without seeds, auto-analysis from the reset vector finds 42 functions in a bank, which is why the docs point to REA_GHIDRA_SEED_FILE.

  • Remaining proof gaps: no source-owned 8051 fixture or verify:ghidra:8051 lane; Linux and Windows not exercised; load-image verification was exercised only through the real-provider runs above.

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 check:test (typecheck, lint, format:check, knip, metadata:check, test:run), macOS arm64, Node 24.22.1 — 58,381 passed, 651 skipped, 5 failed in 4 files. The same 5 tests fail on unmodified main in this environment (reran them with the change stashed): tests/acceptance/artifactExtractionLimitations.test.ts, tests/boundary/providers/desktopTaskReaderTemporaryFiles.test.ts, tests/boundary/providers/hopper/hopperBridgeReconnect.test.ts, and both cases in tests/boundary/mcp/signalRecordingMcp.test.ts.
  • npm run test:focused on the 8 touched test files — 637 passed, 2 skipped.
  • npm run check:fast — typecheck and lint pass; architecture guards pass across 3322 source files.
  • npm run format:check (oxfmt) — all files use the correct format.
  • npm run docs:check — pass (Cursor plugin skill copy regenerated).
  • npm run verify:advertised-schemas — pass after regenerating the open_binary summary (only its input-schema digest changed).
  • Merged onto current origin/main (25 commits newer) in a scratch worktree: no conflicts; check:fast, format:check, docs:check and verify:advertised-schemas pass; every test file that names a raw family (14 files, 893 tests) passes; a real Ghidra 12.2 decompile of a seeded 8051 bank still succeeds.
  • Real provider: Ghidra 12.2 + JDK 25 on macOS arm64 — inspect, decompile and decompile-all on raw 8051 banks as shown above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The architecture enum only gains a value; refusal text for unknown families now also lists 8051.
  • Real Hopper/Ghidra, browser, or OS coverage: Ghidra 12.2 + JDK 25 on macOS arm64 (manual, above). Hopper/IDA/Kuna refusals covered by unit tables only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new process, network or write paths; same immutable snapshot import as other raw lanes.

Author readiness

Human owner: @petrochen

  • 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.

Author checklist (completed by the PR author before requesting review)

  • 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.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

🤖 Generated with Claude Code

Add 8051 as a raw-only architecture: byte-aligned entry, mapping within
0x0000..0xffff, analyzed by Ghidra with 8051:BE:16:default in the CODE
space. Hopper, IDA, Kuna and Windows Ghidra P0 keep refusing it.

Document the lane, including that bank-switch thunks and Keil ?C?CCASE
switch arms are not followed by auto-analysis and need
REA_GHIDRA_SEED_FILE entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed changes appear safe to merge, with no blocking findings.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge, with no blocking findings.

Summary

Adds raw 8051 analysis through Ghidra’s 8051:BE:16:default language and CODE space.

  • Callers can open raw 8051 images with Ghidra.

Reviews (3) · Last reviewed commit: "test(ghidra): pin the 8051 CODE binding ..." · Reviewed by Greptile

@morluto
morluto marked this pull request as ready for review November 28, 2026 21:11
@morluto
morluto enabled auto-merge (squash) November 28, 2026 21:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T22:29:23.303218Z cb4371d New commits
ℹ️ 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.

The architecture enum gained 8051, so the committed input schema digest
for open_binary changed. Regenerated with
`npm run verify:advertised-schemas -- --update-summary`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
auto-merge was automatically disabled November 28, 2026 21:59

Head branch was pushed to by a user without write access

- Assert the 8051 language binding (8051:BE:16:default, CODE) and that
  load-image attestation requires the CODE default space; replacing CODE
  with ram now fails three tests.
- Assert that Windows Ghidra P0 refuses raw 8051.
- Derive the raw-binary architecture refusal from BINARY_ARCHITECTURES
  with Intl.ListFormat; the wording, and so the admission grid digest,
  is unchanged.
- Docs: list the memory blocks Ghidra really creates for 8051 (no
  external RAM block), explain bank addressing for paged banks and the
  entry-decode requirement, state when the seed file is read, and add
  8051 to the n64 guide's family list. Fix a duplicated "and" in the
  generic-language limitation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto enabled auto-merge (squash) November 29, 2026 18:04
@morluto
morluto merged commit 6f36de3 into morluto:main Nov 29, 2026
57 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants