Home

Awesome

nsZip

Work in progress file format for compressed Nintendo Switch games and a tool to compress/decompress them.

Please note that nsZip currently only supports the depreciated NSZP but not the new homebrew compatible NSZ file format so I highly recommend to use https://github.com/nicoboss/nsz instead.

NSZ file format:

Header:

OffsetSizeDescription
0x000x05XOR-Encrypted magic ("nsZip")
0x050x05Random key to decrypt the magic
0x0A0x01Version (for now 0x00)
0x0B0x01nsZip Type

Type 0:

OffsetSizeDescription
0x0C0x01Compression algorithm
0x0DFile size - 0x1DFull compressed file
File size - 0x100x10 (first half)SHA256 of everything above

Type 1:

OffsetSizeDescription
0x0C0x05bs = Decompressed Block Size
0x110x04Amount of Blocks
0x15 + x * y0x01Compression algorithm
0x16 + x * yy - 1cbs = Compressed Block Size
0x15 + (x+1) * ysum(cbs)Concatenated compressed blocks
File size - 0x100x10 (first half)SHA256 header XOR SHA256 compressed

y = ceil(log2(bs)/8) + 1

Note: The compressed block isn't allowed to be larger than the decompressed data - please use compression algorithm 0x00 (None) in that case or cbs might overflow!

Type 2:

OffsetSizeDescription
0x0C0x04Amount of Blocks
0x100x01s = Size of size parameters
0x11 + x * y0x01Compression algorithm
0x12 + x * ysbs = Decompressed Block Size
0x12 + x * y + sscbs = Compressed Block Size
0x12 + (x+1) * ysum(cbs)Concatenated compressed blocks
File size - 0x100x10 (first half)SHA256 header XOR SHA256 compressed

y = 2 * s + 1

Compression algorithms:

ValueAlgorithmRecommended Parameters
0x00NoneNone - Just use memcpy
0x01ZstandardCompressionLevel = 19
0x02lzmaDic=1536, WordS=273, cLevel=9