Skip to content

feat(artifacts): inventory Nintendo DS ROM binaries, overlays and file tables offline - #14664

Merged
morluto merged 10 commits into
morluto:mainfrom
mvanhorn:fix/nds-rom-inventory
Nov 26, 2026
Merged

morluto merged 10 commits into
morluto:mainfrom
mvanhorn:fix/nds-rom-inventory

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Nintendo DS cartridge ROMs (.nds) carry an ARM9 and an ARM7 binary, overlay files and a NitroROM filesystem in one file. REA does not recognize the format today, so a .nds file comes back as an unknown blob. To find the CPU binaries, their load addresses, or the files in the ROM's filesystem, an analyst has to unpack it with a separate tool outside REA and loses per-member Evidence.

This adds an offline nds artifact format. inspect-artifact and extract-artifact (and the MCP inspect_artifact / extract_artifact tools) read the cartridge header, the FAT, the FNT directory tree and both overlay tables, report the header facts and list arm9.bin, arm7.bin, each overlay file and each filesystem file as stored byte ranges that can be hashed and extracted. Nothing is decrypted, decompressed or executed. No issue exists for this; it is a format-inspection and ordinary-extraction addition within the supported contribution scope.

Problem and expected behavior

Use case: given game.nds, see its title, game code, unit code, where each CPU binary loads and starts, how many files, directories and overlays it declares, and whether its logo and header checksums hold, then extract arm9.bin or a filesystem file for further analysis.

Observable outcome:

  • The format has no magic number. A file is recognized as nds regardless of filename when the stored logo CRC at 0x15C is 0xCF56, the unit code is 0, 2 or 3, the ARM9 binary starts after the header, and either the logo area or the header checksum at 0x15E agrees with its stored CRC-16/MODBUS value.
  • The root format_metadata (kind: "nds") reports identity, arm9 and arm7 placement, table locations, total_used_rom_size, header_size, declared and computed logo_crc and header_crc, and file, directory and overlay counts.
  • Members are arm9.bin, arm7.bin, overlays/<cpu>/overlay_<id>.bin, data/<path> for files named by the FNT, and fat/<id>.bin for FAT files that no name or overlay reached. Each member carries kind: "nds-entry" metadata with its role and FAT file ID, plus the overlay table row for overlays.
  • Coverage is complete only when both checksums agree, every table was read in full and every range fits in the file. A checksum mismatch, a range past the end of the file, a partial table, a directory loop, an unsafe or repeated name, or a file ID claimed twice leaves coverage unknown with a limitation that names the problem. A range is never clipped; an entry that does not fit is not listed.
  • A header shorter than 0x160 bytes or an unknown unit code is refused rather than read as a container.

Change and scope

  • src/domain/ndsRom.ts owns parsing: header recognition and CRC-16/MODBUS, header facts, table read ranges, the FAT, FNT directory walk and overlay tables, the member list and limitations.
  • src/artifacts/NdsRomArtifactReader.ts reads the header and each table through bounded positional reads and lists members as stored ranges of the ROM through PositionalArtifactReader.
  • Recognition in artifactFormatRecognition.ts (after every format with a leading signature, since DS has none), registration in artifactFormats.ts, nds and nds-entry metadata in artifactFormatMetadata.ts, inventory view, artifact graph, target format and reader type wiring, and a CI scope entry.
  • Fixed bounds: the FAT, FNT and overlay table reads are capped at the largest size the format's 16-bit ID space can describe (61,440 files, 4,096 directories, names of at most 127 bytes). These are format ceilings, not tunable budgets, so they are not REA_ settings. The FNT walk visits each directory once and stops when it would read more bytes than the FNT holds, so its work is bounded by the table it already read. Repeated limitations of one kind are itemized up to 8 times (NDS_LIMITATION_EXAMPLES) and one more line counts the rest; this fixed ceiling keeps the report size independent of a hostile table's entry count without hiding how many problems were found.
  • Docs: new docs/nds-roms.md, a row in docs/reference/supported-targets.md, CLI examples in docs/getting-started/cli.md, the docs index and sidebar, and an NDS entry in the skill references under .agents/skills/reverse-engineer-anything/ and .cursor-plugin/.

Not included: secure-area decryption, compressed overlays, NitroARC (NARC) archives inside files, the DSi extended header, and the ARM9 module-parameter footer (not part of arm9.bin).

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the Author readiness and
Author checklist unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ndsRom.ts produces the header facts, table interpretation and member ranges; the reader, inventory graph and inventory view consume them without reparsing raw bytes.
  • Contribution scope fit and linked maintainer decision: format inspection and ordinary extraction of a local file; not applicable (no target execution, injection, mutation, or protection recovery).
  • CLI and MCP/tool-catalog contract: no new tools or parameters. Existing artifact tools recognize one more format value, nds.
  • Provider, bridge, target-format, or platform compatibility: new target format nds, classified as an archive target; existing formats unchanged. Recognition runs after all signature-based formats, so files those formats already claim are unaffected.
  • Evidence, artifact, provenance, or reconstruction contract: new nds and nds-entry metadata shapes; members carry their source ranges and SHA-256.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none committed; authored skill references updated under .agents/skills/reverse-engineer-anything/ and .cursor-plugin/.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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: src/domain/ndsRom.test.ts (CRC-16/MODBUS, recognition by logo CRC and checksum, a wrong logo CRC not claimed, header facts, a header CRC mismatch as a limitation, an unknown unit code refused, member ranges, an empty overlay table, a FAT entry past the file end, a directory loop, an unsafe name listed by file ID, a repeated name, an overlay and a directory claiming the same file ID, two overlays naming one file ID, overlapping directory file ID ranges, table read clamping, bounded itemizing of repeated limitations, directories sharing one subtable), src/artifacts/NdsRomArtifactReader.test.ts (classification as an archive target, hashed inventory, extraction of ARM9, ARM7 and a selected file), src/artifacts/NdsRomArtifactReader.boundaries.test.ts (truncated header, ARM9 past the file, FAT past the file, empty overlay table past the file, partial FNT, overlay with no FAT entry, subdirectory ID below the directory range), and src/application/binary/TargetFormatVocabularies.test.ts. Fixtures are built in src/domain/ndsRom.fixture.ts; the fixture solves the logo area's CRC with zero bytes, so it carries no copy of the boot logo.
  • Base reproduction or other evidence: source-derived. The base revision has no nds format value or reader, so a .nds file is not recognized there. The CLI output below is executed against this branch.
  • User-visible CLI/MCP output (if applicable): executed, rea inspect-artifact game.nds --json on a ROM generated by ndsRomFixture(). Excerpt of the inventory substep's root format_metadata:
{
  "kind": "nds",
  "title": "REA TEST",
  "game_code": "REAE",
  "maker_code": "01",
  "unit_code": 0,
  "unit": "nds",
  "rom_version": 1,
  "arm9": { "rom_offset": 16384, "entry_address": 33556480, "ram_address": 33554432, "size": 256 },
  "arm7": { "rom_offset": 16640, "entry_address": 37224448, "ram_address": 37224448, "size": 128 },
  "fnt": { "offset": 16800, "length": 64 },
  "fat": { "offset": 16864, "length": 24 },
  "arm9_overlay_table": { "offset": 16768, "length": 32 },
  "arm7_overlay_table": { "offset": 0, "length": 0 },
  "total_used_rom_size": 16998,
  "header_size": 16384,
  "logo_crc": { "declared": 53078, "computed": 53078 },
  "header_crc": { "declared": 11432, "computed": 11432 },
  "file_count": 3,
  "directory_count": 2,
  "arm9_overlay_count": 1,
  "arm7_overlay_count": 0
}

Coverage was {"scope":"container-entries","status":"complete"} and the occurrences were:

{"logical_path":"arm7.bin","declared_size":128,"source_location":{"offset":16640,"length":128}}
{"logical_path":"arm9.bin","declared_size":256,"source_location":{"offset":16384,"length":256}}
{"logical_path":"data/data/a.bin","declared_size":8,"source_location":{"offset":16990,"length":8}}
{"logical_path":"data/readme.txt","declared_size":30,"source_location":{"offset":16960,"length":30}}
{"logical_path":"overlays/arm9/overlay_0000.bin","declared_size":64,"source_location":{"offset":16896,"length":64}}

The overlay member's metadata was {"kind":"nds-entry","role":"arm9-overlay","file_id":0,"overlay":{"overlay_id":0,"ram_address":34603008,"ram_size":64,"bss_size":16,"static_init_start":34603040,"static_init_end":34603044,"flags":0}}.

rea extract-artifact game.nds --output-root "$PWD/out" --json wrote all five members with containment_verified: true; data/readme.txt (30 bytes) reads hello from a synthetic DS ROM, and arm9.bin has SHA-256 0240065834f267ff0359380b5888a2835e77f4cb68345b5ee8ec685efcf03d09, matching shasum -a 256 on the written file.

Limitation example: on a copy whose FAT entry for file 2 was changed to end past the file, inspect-artifact returned coverage {"scope":"container-entries","status":"unknown"}, did not list data/data/a.bin, and added the limitation "DS FAT entry 2 spans 16990-17254, outside the 16998-byte file; file 2 is not listed."

Refusal example: a copy cut to 256 bytes and a copy with unit code 7 both exited 1 with "code":"target_unavailable", "message":"Cannot open artifact: unsupported binary format." and "constraint":"file_format_rejected".

  • Remaining proof gaps: tested against synthetic ROMs built from the GBATEK header and NitroROM descriptions. No commercial or homebrew ROM was used. The MCP tools were not exercised directly in this run; they share the inventory and extraction path the CLI uses.

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

Not a boundary fix. The new reader's boundary tests cover truncated input, ranges and tables past the end of the file, and malformed table references. Cancellation is handled by the shared positional reader and is not separately tested for this format.

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.

Demo

Rendered walkthrough of the CLI inspect output above (simulated terminal, values taken from a real run on generated fixtures).

demo

rea-nds-demo.mp4

Validation performed

  • npm run test:local -- src/application/binary/TargetFormatVocabularies.test.ts src/artifacts/NdsRomArtifactReader.boundaries.test.ts src/artifacts/NdsRomArtifactReader.test.ts src/domain/ndsRom.test.ts: 4 files, 83 tests passed
  • npm run check:fast (typecheck, lint, architecture guards): passed, "Architecture guards passed across 3135 source files."
  • npm run docs:check: passed, including tests/conformance/readmeConsistency.test.ts (8 tests)
  • npm run format:check: "All matched files use the correct format."
  • npm run compile, then node scripts/rea.mjs inspect-artifact and extract-artifact on generated ROMs: output as shown above

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; offline parsing only, run on macOS.
  • Package or release metadata impact: one new format value, nds.
  • Security, privacy, process, or containment review: reads a local file only and extracts through the existing contained extraction path. FNT names are target-derived and untrusted; a name with /, \, .. or non-ASCII bytes, or a repeated name, is reported and its file is listed under fat/<id>.bin instead. Table reads are capped at the format's ID-space ceilings before allocation, directory loops are walked once, and the number of itemized limitations is bounded.

AI was used for assistance.

Author readiness

Human owner: @mvanhorn

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

…e tables offline

Recognition now claims a Nintendo DS ROM from the cartridge header:
stored logo CRC 0xCF56, unit code 0, 2, or 3, an ARM9 offset after the
header, and a matching logo-area or header CRC. Inspection records those
header facts on the root and lists arm9.bin, arm7.bin,
overlays/<cpu>/overlay_<id>.bin, FNT-named data/<path> files, and
unnamed fat/<id>.bin files as stored byte ranges. A checksum mismatch, a
partial table, or a range past the end of the file leaves coverage
unknown. Secure-area encryption, compressed overlays, and NitroARC
archives stay undecoded, and the format is registered for inventory,
extraction, and the docs.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T05:27:42.221625Z
We couldn’t complete this review. Comment @codex review to try again.
ee56229 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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed changes appear safe to merge; no new actionable issue was established.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no new actionable issue was established.

Summary

Adds offline Nintendo DS ROM inspection and extraction through the existing artifact workflows.

  • REA can inspect and extract the files inside Nintendo DS ROMs.
  • NDS comparisons distinguish code placement changes from file layout changes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Local ROM] --> B[Header recognition]
  B --> C[Bounded header and table reads]
  C --> D[Parse facts, member ranges, and limitations]
  D --> E[Check paths and aggregate member bytes]
  E --> F[Shared positional reader]
  F --> G[Hashed inventory and metadata]
  G --> H[Comparison]
  G --> I[Contained extraction]
Loading

Reviews (10) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread src/domain/ndsRom.ts Resolved
Comment thread src/artifacts/artifactFormats.ts Resolved
Comment thread src/domain/ndsRom.ts Resolved
Comment thread src/domain/artifactFormatMetadata.ts Resolved
Comment thread src/domain/ndsRom.ts Resolved
Comment thread src/domain/ndsRom.ts Resolved
Comment thread docs/guides/firmware/nds-roms.md Resolved
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request labels Nov 26, 2026
Comment thread src/domain/artifactFormatMetadata.ts Resolved
@morluto
morluto enabled auto-merge (squash) November 26, 2026 18:13
# Conflicts:
#	.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md
#	.cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md
#	docs/getting-started/cli.md
@morluto
morluto merged commit 51b3671 into morluto:main Nov 26, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants