From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Format:NRO" |
|---|
| claim | "elf2nro writes each of the first three PT_LOAD segments at file offset p_vaddr with a page-rounded size, then overwrites bytes 0x10-0x7F with the 0x70-byte NRO header (so the first segment must leave that room), sets size to the sum of the rounded sizes, flags bit 0 for --alignedheader, copies the GNU build id (max 0x20 bytes) and, when --icon, --nacp or --romfs is given, appends an ASET header (0x38 bytes) plus icon, NACP and RomFS at file_off. With --romfsdir as the only asset option the function returns before the ASET header is written (the early-exit test does not look at romfsdir), so no assets are embedded." |
|---|
| scope | | level | "tool" |
|---|
| applies_to | "switch-tools elf2nro" |
|---|
| observed_in | |
|---|
|
|---|
| data | | trigger | "elf2nro <elf> <nro> [--icon= --nacp= --romfs= --romfsdir= --alignedheader]" |
|---|
| effect | "NRO file" |
|---|
| condition | "Header fields: version 0 at 0x14, size at 0x18 = running total of page-aligned segment sizes, flags at 0x1C (bit 0 = AlignedHeader), segment file offset = p_vaddr, segment size = (p_filesz+0xFFF)&~0xFFF. bss size: the 4th loop pass (i==3) does not advance past the third PT_LOAD, so it reads the SAME phdr as the data segment: bss = ((p_memsz - rounded p_filesz) + 0xFFF) & ~0xFFF if p_memsz exceeds the rounded file size, else 0. So three PT_LOAD headers are enough (the error text 'expected 3 loadable phdrs and a bss' only fires when fewer than three exist). Asset offsets in the ASET header are relative to the ASET header itself (first asset at 0x38) and are laid out icon, nacp, romfs; --romfs and --romfsdir are mutually exclusive; with --romfsdir plus --icon or --nacp the RomFS is built by build_romfs_by_path_into_file at file_off+tmp_off. The ELF must be AArch64 (e_machine check). Read: whole elf2nro.c; not read: the elf64.h/romfs.c helpers." |
|---|
| function | "main" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "NroStart/NroHeader/AssetHeader structs and main(): header written after fseek to sizeof(nro_start)=0x10, flags = aligned_header << 0, ASET offsets start at sizeof(asset_hdr) and are written at file_off + offset" |
|---|
| repo | "switchbrew/switch-tools" |
|---|
| commit | "22756068dd0ed6ff9734c59cb4f99ebd3f62555b" |
|---|
| path | "src/elf2nro.c" |
|---|
| lines | "11-45, 73-132, 161-186, 213-227, 234-302" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "elf2nro output layout" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-19T12:50:38.698Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T13:17:08.128Z" |
|---|
| result | "confirmed" |
|---|
| method | "Re-read the corrected claim against the whole of switch-tools src/elf2nro.c at 2275606 (307 lines): ASET only when icon/nacp/romfs given, bss from the third PT_LOAD." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T13:10:41.650Z" |
|---|
| summary | "Read all of src/elf2nro.c at 22756068: (1) the ASET header is written only when --icon, --nacp or --romfs is given; the early return tests icon_path, nacp_path and romfs_path but not romfs_dir_path…" |
|---|
| changed | |
|---|
|
|
|---|