nsz


Namensz JSON
Version 4.6.1 PyPI version JSON
download
home_pagehttps://github.com/nicoboss/nsz
SummaryNSZ - Homebrew compatible NSP/XCI compressor/decompressor
upload_time2023-12-18 18:27:12
maintainerNico Bosshard
docs_urlNone
authorNico Bosshard
requires_python>=3.6
license
keywords nsz xcz ncz nsp xci nca switch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NSZ
A compression/decompresson script (with optional GUI) that allows user to compress/decompress Nintendo Switch ROMs loselessly, thanks to [zstd](https://github.com/facebook/zstd) compression algorithm. The compressed file can be installed directly with supported NSW Homebrew Title Installers.

## Legal
- This project does NOT incorporate any copyrighted material such as cryptographic keys. All keys must be provided by the user.
- This project does NOT circumvent any technological protection measures. The NSZ file format purposely keeps all technological protection measures in place by not decrypting the most crucial parts.
- This project shall only be used for legally purchased games.
- This project is MIT licensed. Check [LICENSE](https://github.com/nicoboss/nsz/blob/master/LICENSE) for more information.

## Installation:
There are several ways the install the script. You can find details on installation for all of them below.\
\
**You need to have a hactool compatible keys file in a suitable directory to use the script**.\
The keys file must be located as `prod.keys` file in `%USERPROFILE%/.switch/`(Windows)/`$HOME/.switch/`(UNIX) or `keys.txt` in the working directory.\
\
It can be dumped using Lockpick_RCM.

### Windows Builds
You can also use the Windows binaries. They do not require any external libraries to be installed and can be run without installing anything. You can find the binaries in the [release](https://github.com/nicoboss/nsz/releases/) page.

**Methods listed below requires you to have Python 3.6+ and pip3 installed.**

### PIP Package
Use the following command to install the console-only version:\
`pip3 install --upgrade nsz`

Use the following command to install the GUI version:\
`pip3 install --upgrade nsz[gui]`

### Android
1. Install "Pydroid 3" and the "Pydroid repository plugin" from the Play Store
2. Open "Pydroid 3" and navigate to "Pip"
3. Enter "nsz" and unselect "use prebuild" then press install
4. Navigate to "Terminal" to use the "nsz" command
5. The first time it will tell you where to copy your prod.keys which you should do using the "cp" command
6. Use any command line arguments you want like "nsz -D file.nsz" to decompress your game

### Running from source
The tool can also be run by cloning the repository, installing the requirements and then executing nsz using `python3 nsz.py`

Use the following command to install the console-only versions requirements:\
`pip3 install -r requirements.txt`

Use the following command to install the GUI versions requirements:\
`pip3 install -r requirements-gui.txt`

## Usage
```
nsz.py --help
usage: nsz.py [-h] [-C] [-D] [-l LEVEL] [-L] [-B] [-S] [-s BS] [-V] [-Q] [-K]
              [-F] [-p] [-P] [-t THREADS] [-m MULTI] [-o [OUTPUT]] [-w] [-r]
              [--rm-source] [-i] [--depth DEPTH] [-x]
              [--extractregex EXTRACTREGEX] [--titlekeys] [--undupe]
              [--undupe-dryrun] [--undupe-rename] [--undupe-hardlink]
              [--undupe-prioritylist UNDUPE_PRIORITYLIST]
              [--undupe-whitelist UNDUPE_WHITELIST]
              [--undupe-blacklist UNDUPE_BLACKLIST] [--undupe-old-versions]
              [-c CREATE]
              [file ...]

positional arguments:
  file

options:
  -h, --help            show this help message and exit
  -C                    Compress NSP/XCI
  -D                    Decompress NSZ/XCZ/NCZ
  -l LEVEL, --level LEVEL
                        Compression Level: Trade-off between compression speed
                        and compression ratio. Default: 18, Max: 22
  -L, --long            Enables zStandard long distance mode for even better
                        compression
  -B, --block           Use block compression option. This mode allows highly
                        multi-threaded compression/decompression with random
                        read access allowing compressed games to be played
                        without decompression in the future however this comes
                        with a slightly lower compression ratio cost. This is
                        the default option for XCZ.
  -S, --solid           Use solid compression option. Slightly higher
                        compression ratio but won't allow for random read
                        access. File compressed this way will never be
                        mountable (have to be installed or decompressed first
                        to run). This is the default option for NSZ.
  -s BS, --bs BS        Block Size for random read access 2^x while x between
                        14 and 32. Default: 20 => 1 MB
  -V, --verify          Verifies files after compression raising an unhandled
                        exception on hash mismatch and verify existing NSP and
                        NSZ files when given as parameter. Requires --keep
                        when used during compression.
  -Q, --quick-verify    Same as --verify but skips the NSP SHA256 hash
                        verification and only verifies NCA hashes. Does not
                        require --keep when used during compression.
  -K, --keep            Keep all useless files and partitions during
                        compression to allow bit-identical recreation
  -F, --fix-padding     Fixes PFS0 padding to match the nxdumptool/no-intro
                        standard. Incompatible with --verify so --quick-verify
                        will be used instead.
  -p, --parseCnmt       Extract TitleId/Version from Cnmt if this information
                        cannot be obtained from the filename. Required for
                        skipping/overwriting existing files and --rm-old-
                        version to work properly if some not every file is
                        named properly. Supported filenames:
                        *TitleID*[vVersion]*
  -P, --alwaysParseCnmt
                        Always extract TitleId/Version from Cnmt and never
                        trust filenames
  -t THREADS, --threads THREADS
                        Number of threads to compress with. Numbers < 1
                        corresponds to the number of logical CPU cores for
                        block compression and 3 for solid compression
  -m MULTI, --multi MULTI
                        Executes multiple compression tasks in parallel. Take
                        a look at available RAM especially if compression
                        level is over 18.
  -o [OUTPUT], --output [OUTPUT]
                        Directory to save the output NSZ files
  -w, --overwrite       Continues even if there already is a file with the
                        same name or title id inside the output directory
  -r, --rm-old-version  Removes older versions if found
  --rm-source           Deletes source file/s after compressing/decompressing.
                        It's recommended to only use this in combination with
                        --verify
  -i, --info            Show info about title or file
  --depth DEPTH         Max depth for file info and extraction
  -x, --extract         Extract a NSP/XCI/NSZ/XCZ/NSPZ
  --extractregex EXTRACTREGEX
                        Regex specifying which files inside the container
                        should be extracted. Example: "^.*\.(cert|tik)$"
  --titlekeys           Extracts titlekeys from your NSP/NSZ files and adds
                        missing keys to ./titlekeys.txt and JSON files inside
                        ./titledb/ (obtainable from
                        https://github.com/blawar/titledb). Titlekeys can be
                        used to unlock updates using NUT OG (OG fork
                        obtainable from https://github.com/plato79/nut). There
                        is currently no publicly known way of optioning NSX
                        files. To MitM: Apply disable_ca_verification &
                        disable_browser_ca_verification patches, use your
                        device's nx_tls_client_cert.pfx (Password: switch,
                        Install to OS and import for Fiddler or import into
                        Charles/OWASP ZAP). Use it for aauth-
                        lp1.ndas.srv.nintendo.net:443, dauth-
                        lp1.ndas.srv.nintendo.net:443 and
                        app-b01-lp1.npns.srv.nintendo.net:443. Try with your
                        WiiU first as there you won't get banned if you mess
                        up.
  --undupe              Deleted all duplicates (games with same ID and
                        Version). The Files folder will get parsed in order so
                        the later in the argument list the more likely the
                        file is to be deleted
  --undupe-dryrun       Shows what files would get deleted using --undupe
  --undupe-rename       Renames files to minimal standard:
                        [TitleId][vVersion].nsz
  --undupe-hardlink     Hardlinks files to minimal standard:
                        [TitleId][vVersion].nsz
  --undupe-prioritylist UNDUPE_PRIORITYLIST
                        Regex specifying which dublicate deletion should be
                        prioritized before following the normal deletion
                        order. Example: "^.*\.(nsp|xci)$"
  --undupe-whitelist UNDUPE_WHITELIST
                        Regex specifying which dublicates should under no
                        circumstances be deleted. Example: "^.*\.(nsz|xcz)$"
  --undupe-blacklist UNDUPE_BLACKLIST
                        Regex specifying which files should always be deleted
                        - even if they are not even a dublicate! Be careful!
                        Example: "^.*\.(nsp|xci)$"
  --undupe-old-versions
                        Removes every old version as long there is a newer one
                        of the same titleID.
  -c CREATE, --create CREATE
                        Inverse of --extract. Repacks files/folders to an NSP.
                        Example: --create out.nsp .\in
```

## Few Usage Examples
* To compress all files in a folder: `nsz -C /path/to/folder/with/roms/`
* To compress all files in a folder and verifying integrity of compressed files: `nsz --verify -C /path/to/folder/with/roms/`
* To compress all files in a folder with 8 threads and outputting resulting files to a new directory: `nsz --threads 8 --output /path/to/out/dir/ -C /path/to/folder/with/roms/`
* To compress all files in a folder with level 22 compression level: `nsz --level 22 -C /path/to/folder/with/roms/`
* To decompress all files in a folder: `nsz -D /path/to/folder/with/roms/`

To view all the possible flags and a description on what each flag, check the [Usage](https://github.com/nicoboss/nsz#usage) section.

## File Format Details

### NSZ
NSZ files are functionally identical to NSP files. Their sole purpose to alert the user that it contains compressed NCZ files. NCZ files can be mixed with NCA files in the same container.

As an alternative to this tool NSC_Builder also supports compressing NSP to NSZ, and decompressing NSZ to NSP. NSC_Builder can be downloaded at https://github.com/julesontheroad/NSC_BUILDER

### XCZ
XCZ files are functionally identical to XCI files. Their sole purpose to alert the user that it contains compressed NCZ files. NCZ files can be mixed with NCA files in the same container.

### NCZ
These are compressed NCA files. The NCA's are decrypted, and then compressed using zStandard.

The first 0x4000 bytes of an NCZ file is exactly the same as the original NCA (and still encrypted). This applies even if the first section doesn't start at 0x4000.

At 0x4000, there is the variable sized NCZ Header. It contains a list of sections which tell the decompressor how to re-encrypt the NCA data after decompression. It can also contain an optional block compression header allowing random read access.

All of the information in the header can be derived from the original NCA + Ticket, however it is provided pre-parsed to make decompression as easy as possible for third parties.

Directly after the NCZ header, the zStandard stream begins and ends at EOF. The stream is decompressed to offset 0x4000. If block compression is used the stream is splitted into independent blocks and can be decompressed as shown in https://github.com/nicoboss/nsz/blob/master/nsz/BlockDecompressorReader.py. CompressedBlockSizeList[blockID] must not exceed decompressedBlockSize. If smaller the block must be decompressed. If equal the block is stored in plain text.

```python
class Section:
	def __init__(self, f):
		self.magic = f.read(8) # b'NCZSECTN'
		self.offset = f.readInt64()
		self.size = f.readInt64()
		self.cryptoType = f.readInt64()
		f.readInt64() # padding
		self.cryptoKey = f.read(16)
		self.cryptoCounter = f.read(16)

class Block:
	def __init__(self, f):
		self.magic = f.read(8) # b'NCZBLOCK'
		self.version = f.readInt8()
		self.type = f.readInt8()
		self.unused = f.readInt8()
		self.blockSizeExponent = f.readInt8()
		self.numberOfBlocks = f.readInt32()
		self.decompressedSize = f.readInt64()
		self.compressedBlockSizeList = []
		for i in range(self.numberOfBlocks):
			self.compressedBlockSizeList.append(f.readInt32())

nspf.seek(0x4000)
sectionCount = nspf.readInt64()
for i in range(sectionCount):
	sections.append(Section(nspf))

if blockCompression:
	BlockHeader = Block(nspf)
```

## References
NSZ pip package: https://pypi.org/project/nsz/  
Forum thread: https://gbatemp.net/threads/nsz-homebrew-compatible-nsp-xci-compressor-decompressor.550556/

## Credits
SciresM for his hardware crypto functions; the blazing install speeds (50 MB/sec +) achieved here would not be possible without this.

Thanks to our contributors: nicoboss, blawar, plato79, eXhumer, Taorni, anthonyu, teknoraver, KWottrich, gabest11, siddhartha77, alucryd, seiya-git, drizzt, 16BitWonder, 2weak2live, thatch, maki-chan, pR0Ps

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nicoboss/nsz",
    "name": "nsz",
    "maintainer": "Nico Bosshard",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "nico@bosshome.ch",
    "keywords": "nsz,xcz,ncz,nsp,xci,nca,Switch",
    "author": "Nico Bosshard",
    "author_email": "nico@bosshome.ch",
    "download_url": "https://files.pythonhosted.org/packages/5f/ec/83f85c0ba48227db5b2b9501dd75b8ea1ed9d44f72c6fa52e19d6b85a5ad/nsz-4.6.1.tar.gz",
    "platform": null,
    "description": "# NSZ\r\nA compression/decompresson script (with optional GUI) that allows user to compress/decompress Nintendo Switch ROMs loselessly, thanks to [zstd](https://github.com/facebook/zstd) compression algorithm. The compressed file can be installed directly with supported NSW Homebrew Title Installers.\r\n\r\n## Legal\r\n- This project does NOT incorporate any copyrighted material such as cryptographic keys. All keys must be provided by the user.\r\n- This project does NOT circumvent any technological protection measures. The NSZ file format purposely keeps all technological protection measures in place by not decrypting the most crucial parts.\r\n- This project shall only be used for legally purchased games.\r\n- This project is MIT licensed. Check [LICENSE](https://github.com/nicoboss/nsz/blob/master/LICENSE) for more information.\r\n\r\n## Installation:\r\nThere are several ways the install the script. You can find details on installation for all of them below.\\\r\n\\\r\n**You need to have a hactool compatible keys file in a suitable directory to use the script**.\\\r\nThe keys file must be located as `prod.keys` file in `%USERPROFILE%/.switch/`(Windows)/`$HOME/.switch/`(UNIX) or `keys.txt` in the working directory.\\\r\n\\\r\nIt can be dumped using Lockpick_RCM.\r\n\r\n### Windows Builds\r\nYou can also use the Windows binaries. They do not require any external libraries to be installed and can be run without installing anything. You can find the binaries in the [release](https://github.com/nicoboss/nsz/releases/) page.\r\n\r\n**Methods listed below requires you to have Python 3.6+ and pip3 installed.**\r\n\r\n### PIP Package\r\nUse the following command to install the console-only version:\\\r\n`pip3 install --upgrade nsz`\r\n\r\nUse the following command to install the GUI version:\\\r\n`pip3 install --upgrade nsz[gui]`\r\n\r\n### Android\r\n1. Install \"Pydroid 3\" and the \"Pydroid repository plugin\" from the Play Store\r\n2. Open \"Pydroid 3\" and navigate to \"Pip\"\r\n3. Enter \"nsz\" and unselect \"use prebuild\" then press install\r\n4. Navigate to \"Terminal\" to use the \"nsz\" command\r\n5. The first time it will tell you where to copy your prod.keys which you should do using the \"cp\" command\r\n6. Use any command line arguments you want like \"nsz -D file.nsz\" to decompress your game\r\n\r\n### Running from source\r\nThe tool can also be run by cloning the repository, installing the requirements and then executing nsz using `python3 nsz.py`\r\n\r\nUse the following command to install the console-only versions requirements:\\\r\n`pip3 install -r requirements.txt`\r\n\r\nUse the following command to install the GUI versions requirements:\\\r\n`pip3 install -r requirements-gui.txt`\r\n\r\n## Usage\r\n```\r\nnsz.py --help\r\nusage: nsz.py [-h] [-C] [-D] [-l LEVEL] [-L] [-B] [-S] [-s BS] [-V] [-Q] [-K]\r\n              [-F] [-p] [-P] [-t THREADS] [-m MULTI] [-o [OUTPUT]] [-w] [-r]\r\n              [--rm-source] [-i] [--depth DEPTH] [-x]\r\n              [--extractregex EXTRACTREGEX] [--titlekeys] [--undupe]\r\n              [--undupe-dryrun] [--undupe-rename] [--undupe-hardlink]\r\n              [--undupe-prioritylist UNDUPE_PRIORITYLIST]\r\n              [--undupe-whitelist UNDUPE_WHITELIST]\r\n              [--undupe-blacklist UNDUPE_BLACKLIST] [--undupe-old-versions]\r\n              [-c CREATE]\r\n              [file ...]\r\n\r\npositional arguments:\r\n  file\r\n\r\noptions:\r\n  -h, --help            show this help message and exit\r\n  -C                    Compress NSP/XCI\r\n  -D                    Decompress NSZ/XCZ/NCZ\r\n  -l LEVEL, --level LEVEL\r\n                        Compression Level: Trade-off between compression speed\r\n                        and compression ratio. Default: 18, Max: 22\r\n  -L, --long            Enables zStandard long distance mode for even better\r\n                        compression\r\n  -B, --block           Use block compression option. This mode allows highly\r\n                        multi-threaded compression/decompression with random\r\n                        read access allowing compressed games to be played\r\n                        without decompression in the future however this comes\r\n                        with a slightly lower compression ratio cost. This is\r\n                        the default option for XCZ.\r\n  -S, --solid           Use solid compression option. Slightly higher\r\n                        compression ratio but won't allow for random read\r\n                        access. File compressed this way will never be\r\n                        mountable (have to be installed or decompressed first\r\n                        to run). This is the default option for NSZ.\r\n  -s BS, --bs BS        Block Size for random read access 2^x while x between\r\n                        14 and 32. Default: 20 => 1 MB\r\n  -V, --verify          Verifies files after compression raising an unhandled\r\n                        exception on hash mismatch and verify existing NSP and\r\n                        NSZ files when given as parameter. Requires --keep\r\n                        when used during compression.\r\n  -Q, --quick-verify    Same as --verify but skips the NSP SHA256 hash\r\n                        verification and only verifies NCA hashes. Does not\r\n                        require --keep when used during compression.\r\n  -K, --keep            Keep all useless files and partitions during\r\n                        compression to allow bit-identical recreation\r\n  -F, --fix-padding     Fixes PFS0 padding to match the nxdumptool/no-intro\r\n                        standard. Incompatible with --verify so --quick-verify\r\n                        will be used instead.\r\n  -p, --parseCnmt       Extract TitleId/Version from Cnmt if this information\r\n                        cannot be obtained from the filename. Required for\r\n                        skipping/overwriting existing files and --rm-old-\r\n                        version to work properly if some not every file is\r\n                        named properly. Supported filenames:\r\n                        *TitleID*[vVersion]*\r\n  -P, --alwaysParseCnmt\r\n                        Always extract TitleId/Version from Cnmt and never\r\n                        trust filenames\r\n  -t THREADS, --threads THREADS\r\n                        Number of threads to compress with. Numbers < 1\r\n                        corresponds to the number of logical CPU cores for\r\n                        block compression and 3 for solid compression\r\n  -m MULTI, --multi MULTI\r\n                        Executes multiple compression tasks in parallel. Take\r\n                        a look at available RAM especially if compression\r\n                        level is over 18.\r\n  -o [OUTPUT], --output [OUTPUT]\r\n                        Directory to save the output NSZ files\r\n  -w, --overwrite       Continues even if there already is a file with the\r\n                        same name or title id inside the output directory\r\n  -r, --rm-old-version  Removes older versions if found\r\n  --rm-source           Deletes source file/s after compressing/decompressing.\r\n                        It's recommended to only use this in combination with\r\n                        --verify\r\n  -i, --info            Show info about title or file\r\n  --depth DEPTH         Max depth for file info and extraction\r\n  -x, --extract         Extract a NSP/XCI/NSZ/XCZ/NSPZ\r\n  --extractregex EXTRACTREGEX\r\n                        Regex specifying which files inside the container\r\n                        should be extracted. Example: \"^.*\\.(cert|tik)$\"\r\n  --titlekeys           Extracts titlekeys from your NSP/NSZ files and adds\r\n                        missing keys to ./titlekeys.txt and JSON files inside\r\n                        ./titledb/ (obtainable from\r\n                        https://github.com/blawar/titledb). Titlekeys can be\r\n                        used to unlock updates using NUT OG (OG fork\r\n                        obtainable from https://github.com/plato79/nut). There\r\n                        is currently no publicly known way of optioning NSX\r\n                        files. To MitM: Apply disable_ca_verification &\r\n                        disable_browser_ca_verification patches, use your\r\n                        device's nx_tls_client_cert.pfx (Password: switch,\r\n                        Install to OS and import for Fiddler or import into\r\n                        Charles/OWASP ZAP). Use it for aauth-\r\n                        lp1.ndas.srv.nintendo.net:443, dauth-\r\n                        lp1.ndas.srv.nintendo.net:443 and\r\n                        app-b01-lp1.npns.srv.nintendo.net:443. Try with your\r\n                        WiiU first as there you won't get banned if you mess\r\n                        up.\r\n  --undupe              Deleted all duplicates (games with same ID and\r\n                        Version). The Files folder will get parsed in order so\r\n                        the later in the argument list the more likely the\r\n                        file is to be deleted\r\n  --undupe-dryrun       Shows what files would get deleted using --undupe\r\n  --undupe-rename       Renames files to minimal standard:\r\n                        [TitleId][vVersion].nsz\r\n  --undupe-hardlink     Hardlinks files to minimal standard:\r\n                        [TitleId][vVersion].nsz\r\n  --undupe-prioritylist UNDUPE_PRIORITYLIST\r\n                        Regex specifying which dublicate deletion should be\r\n                        prioritized before following the normal deletion\r\n                        order. Example: \"^.*\\.(nsp|xci)$\"\r\n  --undupe-whitelist UNDUPE_WHITELIST\r\n                        Regex specifying which dublicates should under no\r\n                        circumstances be deleted. Example: \"^.*\\.(nsz|xcz)$\"\r\n  --undupe-blacklist UNDUPE_BLACKLIST\r\n                        Regex specifying which files should always be deleted\r\n                        - even if they are not even a dublicate! Be careful!\r\n                        Example: \"^.*\\.(nsp|xci)$\"\r\n  --undupe-old-versions\r\n                        Removes every old version as long there is a newer one\r\n                        of the same titleID.\r\n  -c CREATE, --create CREATE\r\n                        Inverse of --extract. Repacks files/folders to an NSP.\r\n                        Example: --create out.nsp .\\in\r\n```\r\n\r\n## Few Usage Examples\r\n* To compress all files in a folder: `nsz -C /path/to/folder/with/roms/`\r\n* To compress all files in a folder and verifying integrity of compressed files: `nsz --verify -C /path/to/folder/with/roms/`\r\n* To compress all files in a folder with 8 threads and outputting resulting files to a new directory: `nsz --threads 8 --output /path/to/out/dir/ -C /path/to/folder/with/roms/`\r\n* To compress all files in a folder with level 22 compression level: `nsz --level 22 -C /path/to/folder/with/roms/`\r\n* To decompress all files in a folder: `nsz -D /path/to/folder/with/roms/`\r\n\r\nTo view all the possible flags and a description on what each flag, check the [Usage](https://github.com/nicoboss/nsz#usage) section.\r\n\r\n## File Format Details\r\n\r\n### NSZ\r\nNSZ files are functionally identical to NSP files. Their sole purpose to alert the user that it contains compressed NCZ files. NCZ files can be mixed with NCA files in the same container.\r\n\r\nAs an alternative to this tool NSC_Builder also supports compressing NSP to NSZ, and decompressing NSZ to NSP. NSC_Builder can be downloaded at https://github.com/julesontheroad/NSC_BUILDER\r\n\r\n### XCZ\r\nXCZ files are functionally identical to XCI files. Their sole purpose to alert the user that it contains compressed NCZ files. NCZ files can be mixed with NCA files in the same container.\r\n\r\n### NCZ\r\nThese are compressed NCA files. The NCA's are decrypted, and then compressed using zStandard.\r\n\r\nThe first 0x4000 bytes of an NCZ file is exactly the same as the original NCA (and still encrypted). This applies even if the first section doesn't start at 0x4000.\r\n\r\nAt 0x4000, there is the variable sized NCZ Header. It contains a list of sections which tell the decompressor how to re-encrypt the NCA data after decompression. It can also contain an optional block compression header allowing random read access.\r\n\r\nAll of the information in the header can be derived from the original NCA + Ticket, however it is provided pre-parsed to make decompression as easy as possible for third parties.\r\n\r\nDirectly after the NCZ header, the zStandard stream begins and ends at EOF. The stream is decompressed to offset 0x4000. If block compression is used the stream is splitted into independent blocks and can be decompressed as shown in https://github.com/nicoboss/nsz/blob/master/nsz/BlockDecompressorReader.py. CompressedBlockSizeList[blockID] must not exceed decompressedBlockSize. If smaller the block must be decompressed. If equal the block is stored in plain text.\r\n\r\n```python\r\nclass Section:\r\n\tdef __init__(self, f):\r\n\t\tself.magic = f.read(8) # b'NCZSECTN'\r\n\t\tself.offset = f.readInt64()\r\n\t\tself.size = f.readInt64()\r\n\t\tself.cryptoType = f.readInt64()\r\n\t\tf.readInt64() # padding\r\n\t\tself.cryptoKey = f.read(16)\r\n\t\tself.cryptoCounter = f.read(16)\r\n\r\nclass Block:\r\n\tdef __init__(self, f):\r\n\t\tself.magic = f.read(8) # b'NCZBLOCK'\r\n\t\tself.version = f.readInt8()\r\n\t\tself.type = f.readInt8()\r\n\t\tself.unused = f.readInt8()\r\n\t\tself.blockSizeExponent = f.readInt8()\r\n\t\tself.numberOfBlocks = f.readInt32()\r\n\t\tself.decompressedSize = f.readInt64()\r\n\t\tself.compressedBlockSizeList = []\r\n\t\tfor i in range(self.numberOfBlocks):\r\n\t\t\tself.compressedBlockSizeList.append(f.readInt32())\r\n\r\nnspf.seek(0x4000)\r\nsectionCount = nspf.readInt64()\r\nfor i in range(sectionCount):\r\n\tsections.append(Section(nspf))\r\n\r\nif blockCompression:\r\n\tBlockHeader = Block(nspf)\r\n```\r\n\r\n## References\r\nNSZ pip package: https://pypi.org/project/nsz/  \r\nForum thread: https://gbatemp.net/threads/nsz-homebrew-compatible-nsp-xci-compressor-decompressor.550556/\r\n\r\n## Credits\r\nSciresM for his hardware crypto functions; the blazing install speeds (50 MB/sec +) achieved here would not be possible without this.\r\n\r\nThanks to our contributors: nicoboss, blawar, plato79, eXhumer, Taorni, anthonyu, teknoraver, KWottrich, gabest11, siddhartha77, alucryd, seiya-git, drizzt, 16BitWonder, 2weak2live, thatch, maki-chan, pR0Ps\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "NSZ - Homebrew compatible NSP/XCI compressor/decompressor",
    "version": "4.6.1",
    "project_urls": {
        "Homepage": "https://github.com/nicoboss/nsz"
    },
    "split_keywords": [
        "nsz",
        "xcz",
        "ncz",
        "nsp",
        "xci",
        "nca",
        "switch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abe7d75bd01d5d402e03cda549cb3a441d3db96fae921a1d0a3b16462d4fa6f4",
                "md5": "585b2114e60125ac6c7c04c86a8b6b02",
                "sha256": "3b65c3ccc5620d713b7d862191f2f657f1b019ec6173e95ddf274c4e196a714d"
            },
            "downloads": -1,
            "filename": "nsz-4.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "585b2114e60125ac6c7c04c86a8b6b02",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 1216149,
            "upload_time": "2023-12-18T18:27:09",
            "upload_time_iso_8601": "2023-12-18T18:27:09.518851Z",
            "url": "https://files.pythonhosted.org/packages/ab/e7/d75bd01d5d402e03cda549cb3a441d3db96fae921a1d0a3b16462d4fa6f4/nsz-4.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5fec83f85c0ba48227db5b2b9501dd75b8ea1ed9d44f72c6fa52e19d6b85a5ad",
                "md5": "7aab61f38933aa826c40061c66ba441b",
                "sha256": "456e3b33ff1fa9455376768dad588046a4530c8c1c87416607e6ba7221e6ba3f"
            },
            "downloads": -1,
            "filename": "nsz-4.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7aab61f38933aa826c40061c66ba441b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 1190995,
            "upload_time": "2023-12-18T18:27:12",
            "upload_time_iso_8601": "2023-12-18T18:27:12.246399Z",
            "url": "https://files.pythonhosted.org/packages/5f/ec/83f85c0ba48227db5b2b9501dd75b8ea1ed9d44f72c6fa52e19d6b85a5ad/nsz-4.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-18 18:27:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nicoboss",
    "github_project": "nsz",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "nsz"
}
        
Elapsed time: 0.16231s