Homebrew NSP to NSZ - C++

snuffbot1

Well-Known Member
Member
Joined
Aug 21, 2026
Messages
111
Reaction score
92
Trophies
0
Age
60
XP
146
Country
United Kingdom
Here you go, a very small c++ version for converting nsp files to nsz and back again. Source code and exe are in the zip.

Example useage:
Flag Meaning
-C / -D Compress NSP→NSZ or decompress NSZ→NSP
-F Re-pad the PFS0 header to 0x20 alignment
-L zstd long-distance matching
-S / -B Solid stream (default) or block stream
-l N zstd level (default 18)
-s N Block size exponent 14..=32 (default 20)
-o DIR Output directory
-k PATH prod.keys (default ~/.switch/prod.keys)
-x Skip CRC32 check of known keys
-K, -P Accepted for nsz compatibility, no-op


Example compress/decompress nsp

nszrs -C -B -k prod.keys -s 20 -o out/ game.nsp
nszrs -D -F -k prod.keys -o out/ /out/game.nsz
nszrs -C -L -o out/ game.nsp

This is a command line tool, at some point I might make a gui, there's no xci conversion yet and I doubt I'll add it. I just made it for my own personal use but feel free to mod/share or whatever you want. It's called nszrs as I found some rust code version on the net and then converted it to c++ for my own use.
 

Attachments

@snuffbot1
Thank you for your lightweight C++ realization, I like the idea but unfortunately for right now it's very slow.

I tried to test it versus the nszgui by nicoboss, the results with 200 MB NSP file (level 22 blocks and long-distance) are:
  1. His version took 9 seconds to compress with maximum CPU utilization across all cores:

    old_nsz.png
  2. Your version took 31 seconds, three and a half times long and the CPU load average was pretty low:

    new_nsz.png
    Code:
    nszrs.exe -C -L -B -l 22 -k prod.keys test.nsp
Please optimize it if you could. :(
 
Last edited by mathew77,
@snuffbot1
Thank you for your lightweight C++ realization, I like the idea but unfortunately for right now it's very slow.
I tried to test it versus the nszgui by nicoboss, the results with 200 MB NSP file (level 22 blocks and long-distance) are:

1) His version took 9 seconds to compress with maximum CPU utilization across all cores:

View attachment 592261

2) Your version took 31 seconds, three and a half times long and the CPU load average was pretty low:

View attachment 592262
Code:
nszrs.exe -C -L -B -l 22 -k prod.keys test.nsp
Please optimize it if you could. :(
I'm adding xci support just now, I didn't look at nicboss version, but I assume he is starting a few threads so it's using more cpu usage rather that taking longer. I could add that I guess. I've got xcz decompress done and am about 90% though adding xci to xcz, so I'll have a look at multithreading/cpu core use once I'm done with that.
 
  • Like
Reactions: mathew77
@snuffbot1
..and add the ability to verify for hash mismatches (NCA & PFS0, SHA256) right after the compression, too, please!.. :)
I'll think about it, I've just finished xci stuff just now so block and solid compress works. I'll add flags so you can remove update/logo partitions as it's pointless packing an xci with firmware update files included (defeats the point really).

Note to self:
Build windows fancy shmancy GUI with drag and drop support... dropdowns/switches and shit!
Post automatically merged:

@mathew77

Try this command:
nszrs -C -S -l 20 -k prod.keys -o ./ game.nsp # solid

Untitled.png

Untitled.png


That maxed out my cpu and should be faster, I've also added xci > xcz < xci stuff and fixed a few bugs. Report issues and I'll fix them before making a gui. For verification you can use NXfile viewer for now, when I make a gui I'll probably add that as a separate feature from the exe I posted.
 

Attachments

Last edited by snuffbot1,
It's the deal breaker, I need the block compression, only. :) nicoboss maxed out the CPU even with block compression method... It's also has an option to auto-verify the results afterwards.

The problem is, it's python-based, so heavy and cumbersome, I'd like C++ solution more.
 
  • Like
Reactions: digdat0
It's the deal breaker, I need the block compression, only. :) nicoboss maxed out the CPU even with block compression method... It's also has an option to auto-verify the results afterwards.

The problem is, it's python-based, so heavy and cumbersome, I'd like C++ solution more.
Solid produces much smaller files, why do you need block?

EDIT: Verification of nca's flag added. Will post when I finish checking stuff, most stuff is completed now, just some tweaks/bugs to fix...
Untitled.png

Post automatically merged:

@mathew77

Have a look here at ZSTD_c_nbWorkers section:
https://facebook.github.io/zstd/zstd_manual.html

To speed things up, how many workers are set in the python code you are currently using?
 
Last edited by snuffbot1,
  • Like
Reactions: digdat0

Site & Scene News