nsZip is a tool to compress/decompress Nintendo Switch games using the here specified NSZ file format
Branch: master
Clone or download
Latest commit b4e1487 Feb 14, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Crypto Code cleanup to always use a { } block even for a single line to impr… Jan 24, 2019
LibHac First working version! Jan 30, 2019
LibHacControl Implemented XCI compression, fixed a decompression bug and save the d… Jan 31, 2019
LibHacExtensions Finished implementing splitted NDV0 trimming Feb 14, 2019
Properties Version 1.0.0-rc.14 Jan 31, 2019
.gitattributes Initial commit Jan 23, 2019
.gitignore Initial commit Jan 23, 2019
App.config Version 1.0.0 Feb 1, 2019
CompressFolder.cs Version 1.0.1: Added BlockSizeComboBox, CompressionLevelLabel and let… Feb 2, 2019
DecompressFolder.cs Implemented XCI compression, fixed a decompression bug and save the d… Jan 31, 2019
EncryptNCA.cs Added support for NCA3 fragment trimming using NCA referencing and fi… Jan 31, 2019
Frontend.Designer.cs Version 1.1.0 Feb 14, 2019
Frontend.cs Finished implementing splitted NDV0 trimming Feb 14, 2019
Frontend.resx Version 1.0.0 Feb 1, 2019
LICENSE Version 1.0.0 Feb 1, 2019
Program.cs Initial commit Jan 23, 2019
README.md Improved the NSZ file format specifications Jan 27, 2019
Utils.cs Code cleanup to always use a { } block even for a single line to impr… Jan 24, 2019
nsZip.csproj Version 1.1.0 Feb 14, 2019
nsZip.ico Version 1.0.0-rc.14 Jan 31, 2019
nsZip.psd Version 1.0.0-rc.14 Jan 31, 2019
nsZip.sln Initial commit Jan 23, 2019
packages.config Version 1.0.1: Added BlockSizeComboBox, CompressionLevelLabel and let… Feb 2, 2019

README.md

nsZip

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

NSZ file format:

Header:

Offset Size Description
0x00 0x05 XOR-Encrypted magic ("nsZip")
0x05 0x05 Random key to decrypt the magic
0x0A 0x01 Version (for now 0x00)
0x0B 0x01 nsZip Type

Type 0:

Offset Size Description
0x0C 0x01 Compression algorithm
0x0D File size - 0x1D Full compressed file
File size - 0x10 0x10 (first half) SHA256 of everything above

Type 1:

Offset Size Description
0x0C 0x05 bs = Decompressed Block Size
0x11 0x04 Amount of Blocks
0x15 + x * y 0x01 Compression algorithm
0x16 + x * y y - 1 cbs = Compressed Block Size
0x15 + (x+1) * y sum(cbs) Concatenated compressed blocks
File size - 0x10 0x10 (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:

Offset Size Description
0x0C 0x04 Amount of Blocks
0x10 0x01 s = Size of size parameters
0x11 + x * y 0x01 Compression algorithm
0x12 + x * y s bs = Decompressed Block Size
0x12 + x * y + s s cbs = Compressed Block Size
0x12 + (x+1) * y sum(cbs) Concatenated compressed blocks
File size - 0x10 0x10 (first half) SHA256 header XOR SHA256 compressed

y = 2 * s + 1

Compression algorithms:

Value Algorithm Recommended Parameters
0x00 None None - Just use memcpy
0x01 Zstandard CompressionLevel = 19
0x02 lzma Dic=1536, WordS=273, cLevel=9