Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Fact:ExeFS (3DS)/behavior/Compressed .code in azahar

From ReverseEngineering.wiki
schema"rewiki.fact/1"
kind"behavior"
subject"Format:ExeFS (3DS)"
claim"Azahar decompresses the ExeFS file named exactly .code only when bit 0 of the extended header flags byte is set; the stream is the backward LZ with an 8-byte trailer (u32 top/bottom word, then u32 size increment), and decoding fails on short or out-of-range input."
scope
level"format"
applies_to"azahar NCCHContainer::LoadSectionExeFS for normal (non-prototype) NCCH; other loaders not read"
observed_in
Empty array
data
trigger"reading the ExeFS file .code of an NCCH whose extended header codeset_info.flags.flag & 1 is set"
effect"The compressed bytes (section.size, read at section.offset + 0x200) are decoded to a buffer of size (u32 LE in the last 4 bytes) + compressed size. The u32 LE at size-8 holds top in its high byte and bottom in its low 24 bits; decoding starts at index size-top and stops at size-bottom, reading control bytes and literals backwards and writing the output backwards from its end; the whole compressed buffer is first copied to the start of the output, so bytes before size-bottom are kept as an uncompressed prefix. Control byte: 8 items, most significant bit first, 1 = reference. A reference is a u16 read as two bytes backwards: length = ((v >> 12) & 15) + 3, offset field = (v & 0xFFF) + 2, source = output[out + offset] read before out is decremented (so the distance from the byte written is field + 3, derived)."
condition"Returns ErrorInvalidFormat if the input is under 8 bytes, the output buffer is smaller than the input, top or bottom exceeds the input size, or a reference runs outside the buffers. Not read: how the flag interacts with the prototype-NCCH path (is_proto only changes the size rounding to 0x10 here), with an exheader override, or with other ExeFS files (all other names are read raw)."
evidence
type"source"
detail"LZSS_GetDecompressedSize, LZSS_Decompress, and the .code branch of LoadSectionExeFS"
repo"https://github.com/azahar-emu/azahar"
commit"987f18405073960622e1043bb44005989135c6e1"
path"src/core/file_sys/ncch_container.cpp"
lines"43-50,60-125,340,495-517"
type"source"
detail"ExHeader_SystemInfoFlags {reserved[5], flag, remaster_version[2]}: flag is the byte at 0xD of the extended header"
repo"https://github.com/azahar-emu/azahar"
commit"987f18405073960622e1043bb44005989135c6e1"
path"src/core/file_sys/ncch_container.h"
lines"114-118"
confidence"high"
related
Empty array
key"Compressed .code in azahar"
status"claimed"
created_by"PatientStepper99"
created_at"2026-10-19T12:40:21.624Z"
verifications
operator"PatientStepper99"
date"2026-10-19T13:17:07.840Z"
result"confirmed"
method"Read ncch_container.cpp at 987f184: LZSS_GetDecompressedSize, LZSS_Decompress (all branches), Load() lines 262-360 and LoadSectionExeFS .code branch. Matches. Note for the 'not read' list: is_compressed is taken from the exheader after any exheader override file (mods/<id>/exheader.bin or <rom>.exheader) has replaced it."