Repository navigation
feat(artifacts): inventory Nintendo Switch NSO and NRO executables offline - #14655
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The reviewed changes appear safe to merge, with no new actionable findings. SummaryAdds offline NSO/NRO recognition, segment extraction, hashes, header metadata, and NRO asset ranges.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Local file] --> B[Recognize NSO or NRO]
B --> C[Parse headers and declared ranges]
C --> D{Compressed segment?}
D -->|Yes| E[Check allowance and decode LZ4]
D -->|No| F[Read stored range]
E --> G[Inventory bytes, hashes and limitations]
F --> G
G --> H[Extract selected entries through owned streams]
Reviews (9) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
…fline Detection uses the bytes: NSO0 at the start of the file, or NRO0 at offset 0x10. Inventory records the module id, flags, and MOD0 offset, lists the text, rodata, and data segments, and for an NRO adds the ASET icon, NACP, and RomFS when that trailer is present. Compressed NSO segments are raw LZ4 blocks decoded under artifact_limits.expanded_bytes, with the stored size and the decoded size both reserved before allocation, and hash_status is match, mismatch, not-checked, or unavailable. Truncated, over-budget, and invalid-LZ4 entries stay listed while their bytes are refused, and a positional reader can stream those decoded bytes instead of the stored file range.
b835595 to
6e8549d
Compare
# Conflicts: # .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md # .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md # docs/reference/limits-and-recovery.md
- Remove the duplicate NSO decoded-only budget pre-check in #prepareNso so #admitStoredInput owns all compressed-segment admission and reports an accurate required_value covering both stored and decoded bytes. - Use testWaitDeadline() in SwitchExecutableArtifactReader.boundaries.test.ts instead of a hardcoded 2_000 ms timeout. - Reuse tests/fixtures/lz4LiteralBlock.ts in switchExecutable.fixture.ts.
# Conflicts: # docs/getting-started/cli.md # docs/reference/limits-and-recovery.md # src/artifacts/artifactFormats.ts # src/domain/artifactFormatRecognition.ts
Summary
Nintendo Switch homebrew and modding work starts from NSO modules (
main,subsdk*,sdk) and NRO homebrew executables. REA does not recognize either format today, soinspect-artifactonmain.nsorefuses it as an unsupported binary format. To get the module id that pairs a build with crash logs and patches, or to load the decompressed text segment into a disassembler at the right offset, an analyst has to decode the header and the LZ4 segments with a separate tool and loses per-segment Evidence.This adds offline
nsoandnroartifact formats.inspect-artifactandextract-artifact(and the MCPinspect_artifact/extract_artifacttools) report the header facts, list the text, rodata and data segments with file and memory offsets, decompress LZ4 segments in memory to hash and extract the loaded bytes, compare them with the header's SHA-256 values, and for NRO list the icon, NACP and RomFS ranges from theASETtrailer. Nothing is run, patched or disassembled. 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
main.nso, see its module id, flags, MOD0 offset and the three segments with their memory offsets and hash status, then extracttext.binas the decompressed code. Given an NRO, see the same header facts plus the asset ranges.Observable outcome:
NSO0is recognized asnso, and a file withNRO0at offset0x10asnro, regardless of filename.format_metadataof kindswitch-executable:format,version,flags,unknown_flags,module_id(lowercase hex),bss_size, theembedded,dynstranddynsymextents,mod0_offset,mod0_present(NRO only),image_size(NRO only) andasset_section.text.bin,rodata.bin,data.bin,assets/icon.jpg,assets/control.nacp,assets/romfs.bin) with kindswitch-executable-entrymetadata: role, file and memory offsets, stored size,compressed,declared_sha256,observed_sha256andhash_status(match,mismatch,not-checked,unavailable).artifact_limits.expanded_bytesallowance stays listed withhash_status: "unavailable", coverage becomesunknown, and opening it is refused. The other entries are still inventoried and extractable.0x100bytes (NSO) or0x80bytes (NRO), an NSO segment that overlaps the header, or an NRO segment past the declared image size refuses the file as malformed.Change and scope
src/domain/switchExecutable.tsowns parsing: magic checks, NSO and NRO header fields, segment and asset extents, truncation and overlap checks, theASETheader and MOD0 offset reads.src/artifacts/SwitchExecutableArtifactReader.tsreads headers through bounded positional reads, decodes compressed NSO segments within the expansion allowance, hashes loaded bytes, and serves each entry either as a stored range or from the decoded segment.PositionalArtifactReadergains a protectedentrySourcehook so a subclass can serve bytes that are not one stored carrier range (here a decoded segment). The base reader still owns the stream lifecycle, cancellation and the declared-size check. The default returnsundefined, so existing readers are unchanged.artifactFormats.ts, recognition inartifactFormatRecognition.ts,switch-executableandswitch-executable-entryschemas inpackageAndGameMetadata.tsandartifactFormatMetadata.ts, andnso/nrowiring intargetFormats.ts,artifactGraph.ts,artifactInventoryView.tsandArtifactReader.ts.artifact_limits.expanded_bytesparameter (default derived from the file size byartifactExpansionBudgetBytes), and its refusal reports that parameter throughartifactReaderLimitFailure. No new fixed ceiling is added. The header sizes (0x100,0x80,0x38forASET) are format facts, and the 64 KiBREAD_CHUNK_BYTESis a streaming read granularity, not an admission limit.docs/switch-executables.md, a row indocs/reference/supported-targets.md, NSO added to theexpanded_bytesreader list indocs/reference/limits-and-recovery.md, CLI examples indocs/getting-started/cli.md, the docs sidebar,docs/README.md, and a Switch entry in the skill references under.agents/skills/reverse-engineer-anything/and.cursor-plugin/.src/artifacts/inventory/scanReader.ts: when a reader refuses entry content withArtifactEntryContentUnavailableand the entry already lists the same limitation, the occurrence no longer records it twice. NSO segments that are truncated or over the expansion allowance hit this, and so do ISO 9660 fragmented and interleaved files on main today (an interleaved entry listed "ISO 9660 interleaved file units are listed but not read; the file's bytes were not established." twice). Hash status and traversal recording are unchanged.Not included: KIP1, NSP, XCI and NCA containers, NACP or RomFS decoding, symbol or relocation parsing from
dynsym/dynstr, and disassembly.Follow the contribution scope. Not applicable: this reads a local file and does not add target execution, injection, mutation or protection recovery.
Contract and boundary impact
switchExecutable.tsproduces the header and extent facts at recognition and inventory; the reader, inventory graph and inventory view consume them without reparsing raw bytes.nsoandnro.nsoandnro; existing formats unchanged. ThePositionalArtifactReaderhook defaults to the previous behavior.switch-executableandswitch-executable-entrymetadata shapes. Declared header hashes and REA-computed hashes are separate fields.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; 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.
Evidence and regression coverage
src/domain/switchExecutable.test.ts(magic checks, NSO and NRO header parsing, overlap and image-size refusals,ASETparsing, MOD0 offsets),src/artifacts/SwitchExecutableArtifactReader.test.tsand.boundaries.test.ts(compressed and stored segments, hash match, mismatch and unchecked hashes, unknown flag bits, truncated segments, invalid LZ4, the expansion allowance, NRO with and without assets, truncated assets, trailing bytes, cancellation while streaming), andTargetFormatVocabularies.test.ts.SwitchExecutableArtifactReader.boundaries.test.tsandIso9660ArtifactReader.test.tsalso assert that a refused occurrence carries its limitation once; both failed before thescanReader.tschange. Fixtures are built insrc/domain/switchExecutable.fixture.ts.upstream/mainhas nonsoornroformat value, so these files fall through to the unsupported-format refusal. The behavior below is executed on this branch.rea inspect-artifact main.nso --jsonon an NSO generated withbuildNso(): compressed text and data, stored rodata, all three hash checks on). Excerpt of the root andtext.binoccurrences:{ "logical_path": ".", "artifact_format": "nso", "declared_size": 326, "format_metadata": { "kind": "switch-executable", "format": "nso", "version": 0, "flags": 61, "unknown_flags": 0, "module_id": "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff", "bss_size": 64, "mod0_offset": 16, "mod0_present": null, "embedded": { "offset": 0, "size": 0 }, "dynstr": { "offset": 0, "size": 0 }, "dynsym": { "offset": 0, "size": 0 }, "image_size": null, "asset_section": null }, "limitations": [] }{ "logical_path": "text.bin", "declared_size": 32, "compressed_size": 34, "executable": true, "source_location": { "offset": 256, "length": 34 }, "format_metadata": { "kind": "switch-executable-entry", "role": "text", "file_offset": 256, "memory_offset": 0, "file_size": 34, "compressed": true, "declared_sha256": "2a1a6382f2a0327f878edb59cd507994618b285acf49f05196f60f41ce9d7ea4", "observed_sha256": "2a1a6382f2a0327f878edb59cd507994618b285acf49f05196f60f41ce9d7ea4", "hash_status": "match" } }rea extract-artifact main.nso --output-root out --jsonwrotetext.bin(32 bytes, SHA-2562a1a6382..., starting with the branch andMOD0at 0x10),rodata.bin(22 bytes) anddata.bin(13 bytes, decompressed from 14 stored bytes) withcontainment_verified: true.On an NRO generated with
buildNro()and an icon, NACP and RomFS, coverage iscomplete, the root reports"image_size": 178, "asset_section": {"offset": 178, "version": 0}, "mod0_offset": 128, "mod0_present": true, and the assets are listed asassets/icon.jpg,assets/control.nacpandassets/romfs.binwithhash_status: "not-checked".Limitations and refusals from the same run:
buildNso({ corruptHash: 1 })): coverageunknown,rodata.binkeeps its bytes with"hash_status": "mismatch"and the limitation "rodata segment SHA-256 6f8c15f4d6321cf32b44501ec62e18a91383e7e1c8cad1dc8b38e82c6c90eaa2 does not match the header's 908c15f4d6321cf32b44501ec62e18a91383e7e1c8cad1dc8b38e82c6c90eaa2".data.binis listed with"observed_sha256": null, "hash_status": "unavailable"and the limitation "data segment is truncated: it declares 13 stored bytes at offset 310 but the file has 319 bytes";text.binandrodata.binstill reportmatch.extract-artifacton that file refuses with"detail": "Inventoried source bytes are unavailable for data.bin".--artifact-limits '{"expanded_bytes":20}'onmain.nso):text.binisunavailablewith "text segment decompresses to 32 bytes, over the remaining artifact_limits.expanded_bytes budget of 20", anddata.binisunavailablewith "data segment allocates 14 stored bytes and 13 decoded bytes, over the remaining artifact_limits.expanded_bytes budget of 20". The storedrodata.binstill hashes and extracts.NSO0followed by 5 bytes):{ "code": "unsupported_target", "message": "Malformed nso target for inspect_artifact at .../short.nso: NSO is malformed: NSO header is truncated: 9 of 256 bytes", "details": { "failure_kind": "malformed", "format": "nso" } }For boundary fixes, identify the applicable boundary regressions and lifecycle regressions covered by the evidence above, and explain relevant gaps. Applicable: malformed input (short headers, overlap, truncated segments, invalid LZ4), capacity (expansion allowance refusal with the named parameter), and cancellation while streaming a decoded segment through the new
entrySourcehook.For evidence-bearing changes:
Demo
Rendered walkthrough of the CLI inspect output above (simulated terminal, values taken from a real run on generated fixtures).
rea-switch-demo.mp4
Validation performed
npm run test:local -- src/domain/switchExecutable.test.ts src/artifacts/SwitchExecutableArtifactReader.test.ts src/artifacts/SwitchExecutableArtifactReader.boundaries.test.ts src/application/binary/TargetFormatVocabularies.test.ts: 4 files, 84 tests passednpm run test:localover every*.test.tsfile undersrc/artifactsplussrc/domain/artifactFormatRecognition.test.tsandsrc/domain/artifactGraph.test.ts(covers the otherPositionalArtifactReadersubclasses): 96 files passed, 2165 tests passed, 19 skippednpm run check:fast: typecheck and lint passed (turbo cache hit), architecture guards passed across 3135 source filesnpm run docs:check: passed, includingreadmeConsistency.test.ts(8 tests)npm run format:check: all matched files use the correct formatnpm run compile, thennode scripts/rea.mjs inspect-artifactandextract-artifacton generated NSO and NRO fixtures: output as shown abovescanReader.tschange:npm run test:localon 13 files (Switch, ISO 9660,scanReader,ArtifactGraphConstruction,ArtifactInventoryFinalization, Android OTA and Asar tests): 201 tests passed;npm run check:fast,npm run docs:check,npm run format:checkandnpm run verify:advertised-schemaspassedinspect-artifacton a truncated NSO and an interleaved ISO before and after the change: the repeated limitation string appears once after itCompatibility, safety, and release
nsoandnro.Number.MAX_SAFE_INTEGERis refused. LZ4 output is bounded by the declared segment size, and the stored and decoded buffers are charged toartifact_limits.expanded_bytesbefore they are allocated.AI was used for assistance.
Author readiness
Human owner: @mvanhorn
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.