Hacking libyaz0 - A library for compressing and decompressing Yaz0/1 compression formats.

AboodXD

I hack NSMB games, and other shiz.
OP
Member
Joined
Oct 11, 2014
Messages
2,870
Trophies
1
Location
Not under a rock.
XP
2,857
Country
United Arab Emirates
libyaz0 is a library in Python for decompressing and compressing Yaz0/1 compression formats.
Written in Python 3.

Yaz0 is a compression format used in several games from the N64, GC, Wii, 3DS, Wii U, and now the Switch.

A few of those games:
  • The Legend of Zelda: Ocarina of Time.
  • Super Mario Sunshine.
  • Mario Kart Wii.
  • Super Mario 3D Land.
  • New Super Mario Bros. U.
  • Mario Kart 8.
  • Breath of the Wild.
  • ARMS.
  • Splatoon 2.

I'd say it's a Nintendo-favorite. :>

--------------------------------------------------------------------------------------------

Example of how Yaz0 compressed data can be decompressed:
Code:
from libyaz0 import decompress

# Yaz0 compressed data
data = b"Yaz0\x00\x00\x00\x10\x00\x00\x00\x00\x00" \
          b"\x00\x00\x00\xfbThis \x10\x02a \xf8test!"

# Decompress it
decompressed_data = decompress(data)
Code:
>>> decompressed_data.decode('utf-8')
'This is a test!'

--------------------------------------------------------------------------------------------

Example of how decompressed data can be Yaz0 compressed:
Code:
from libyaz0 import compress

# Decompressed data
data = 'This is a test!'.encode('utf-8')

# Compress it
## unk: the 4-bytes value that will be located at 0x8-0xC of the Yaz0 header
### default is 0x00000000
unk = 0

## level: compression level.
### 0: No compression (Fastest)
### 9: Best compression (Slowest)
#### default is 1
level = 9

compressed_data = compress(data, unk, level)
Code:
>>> compressed_data
b'Yaz0\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\xfbThis \x10\x02a \xf8test!'

--------------------------------------------------------------------------------------------

libyaz0 can also be used to guess the file extension from the decompressed data.

File formats libyaz0 can detect:
  • BNTX (.bntx)
  • BNSH (.bnsh)
  • BFLAN (.bflan)
  • BFLYT (.bflyt)
  • BFLIM (.bflim)
  • GTX (.gtx)
  • SARC (.sarc)
  • Yaz0/SZS (.yaz0)

Code:
from libyaz0 import guessFileExt

# Guess the file extension from the decompressed data
file_extension = guessFileExt(decompressed_data)

--------------------------------------------------------------------------------------------

libyaz0 can also be used as a standalone program. (Download below)

Usage:
  • libyaz0 [option...] input
Options:
  • -o <output>: Output file, if not specified, the output file will have the same name as the intput file
  • -c: Compress (Will try to decompress if not specified)
Compression options:
  • -level <level>: compression level (1-9) (1 is the default)
    0: No compression (Fastest)
    9: Best compression (Slowest)

  • -unk <unk>: the unknown value that will be located at 0x8-0xC (0x00000000 is the default)

--------------------------------------------------------------------------------------------

Download:

You can get libyaz0 using pip:
Code:
pip install libyaz0==0.4

Or you could get the source code from GitHub.
Github.
Standalone program (Windows).

--------------------------------------------------------------------------------------------

Credits:
Written by AboodXD.
Decompression algorithm based on wszst's.
Special thanks to RoadrunnerWMC for helping with looking up matches for the compression algorithm.
 
Last edited by AboodXD,

tunip3

[debugger active]
Banned
Joined
Oct 31, 2016
Messages
1,675
Trophies
0
XP
1,599
Country
United Kingdom
libyaz0 is a library in Python for decompressing and compressing Yaz0/1 compression formats.
Written in Python 3.

Yaz0 is a compression format used in several games from GC, Wii, 3DS, Wii U, and now the Switch.

A few of those games:
  • Super Mario Sunshine.
  • Mario Kart Wii.
  • Super Mario 3D Land.
  • Mario Kart 8.
  • Breath of the Wild.
  • Splatoon 2.

I'd say it's a Nintendo-favorite. :>

--------------------------------------------------------------------------------------------

Example of how Yaz0 compressed data can be decompressed:
Code:
from libyaz0 import decompress

# Yaz0 compressed data
data = b"Yaz0\x00\x00\x00\x10\x00\x00\x00\x00\x00" \
          b"\x00\x00\x00\xfbThis \x10\x02a \xf8test!"

# Decompress it
decompressed_data = decompress(data)
Code:
>>> decompressed_data.decode('utf-8')
'This is a test!'

--------------------------------------------------------------------------------------------

Example of how decompressed data can be Yaz0 compressed:
Code:
from libyaz0 import compress

# Decompressed data
data = 'This is a test!'.encode('utf-8')

# Compress it
## unk: the 4-bytes value that will be located at 0x8-0xC of the Yaz0 header
### default is 0x00000000
unk = 0

## level: compression level.
### 0: No compression (Fastest)
### 9: Best compression (Slowest)
#### default is 1
level = 9

compressed_data = compress(data, unk, level)
Code:
>>> compressed_data
b'Yaz0\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\xfbThis \x10\x02a \xf8test!'

--------------------------------------------------------------------------------------------

libyaz0 can also be used to guess the file extension from the decompressed data.

File formats libyaz0 can detect:
  • BNTX (.bntx)
  • BNSH (.bnsh)
  • BFLAN (.bflan)
  • BFLYT (.bflyt)
  • BFLIM (.bflim)
  • GTX (.gtx)
  • SARC (.sarc)
  • Yaz0/SZS (.yaz0)

Code:
from libyaz0 import guessFileExt

# Guess the file extension from the decompressed data
file_extension = guessFileExt(decompressed_data)

--------------------------------------------------------------------------------------------

libyaz0 can also be used as a standalone program. (Download below)

Usage:
  • libyaz0 [option...] input
Options:
  • -o <output>: Output file, if not specified, the output file will have the same name as the intput file
  • -c: Compress (Will try to decompress if not specified)
Compression options:
  • -level <level>: compression level (1-9) (1 is the default)
    0: No compression (Fastest)
    9: Best compression (Slowest)

  • -unk <unk>: the unknown value that will be located at 0x8-0xC (0x00000000 is the default)

--------------------------------------------------------------------------------------------

Download:

You can get libyaz0 using pip:
Code:
pip install libyaz0

Getting libyaz0 from GitHub is rather recommended because it includes a Cython version of the algorithms, which is much faster.

Github.
Standalone program (Windows).

--------------------------------------------------------------------------------------------

Credits:
Written by AboodXD.
Decompression algorithm based on wszst's.
Special thanks to RoadrunnerWMC for helping with looking up matches for the compression algorithm.
and how would you dump it
 

Alzter

Member
Newcomer
Joined
Apr 4, 2014
Messages
14
Trophies
0
Age
41
XP
125
Country
United States
I try to open the .exe and then it closes. Help? (I'm trying to decrypt a .szs file I found in the rom of Photo Dojo that I believe contains all the graphics...)
 
Last edited by Alzter,

AceTartarSquad

Member
Newcomer
Joined
Jun 11, 2018
Messages
18
Trophies
0
Age
42
XP
158
Country
United States
I try to open the .exe and then it closes. Help? (I'm trying to decrypt a .szs file I found in the rom of Photo Dojo that I believe contains all the graphics...)

You need to double click the python library, and if that doesn't work, try double clicking it twice.
 

Alzter

Member
Newcomer
Joined
Apr 4, 2014
Messages
14
Trophies
0
Age
41
XP
125
Country
United States
I opened a command line at the install location, entered the command and it worked perfectly! Thank you so much!
 
General chit-chat
Help Users
  • KennieDaMeanie @ KennieDaMeanie:
    Everything pre 2015 is just getting so good with emulation now days
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    And theirs like a rip of every media content you could pretty much think of
    Gift
  • SacredMilkOG @ SacredMilkOG:
    True- but I prefer the traditional hardware. They just plain work right... RetroArch and PPSSPP still aren't even perfect. Seems like all of the games I really wanna play have some hiccups still. Silent Hill Origins for instance still has that annoying flashlight bug
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    I prey steamdeck can emulate psp at max speed lol
    Gift
  • SacredMilkOG @ SacredMilkOG:
    Maybe true... but it gets choppy and in some cases they get converted and recompressed too many times.

    Even still, I insist there will always be a difference that matters
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    Guess digital has just sucked me in I'm more the type that collects hardware and want it all on that one device
    +1
    Gift
  • SacredMilkOG @ SacredMilkOG:
    SteamDeck :P it will probably play full speed for sure. My current Android plays them full speed and with tweaks and upscaling. The problems come with the emulation itself
    Gift
  • SacredMilkOG @ SacredMilkOG:
    I feel you
    Gift
  • SacredMilkOG @ SacredMilkOG:
    I want all the physical medias and hardwares... but want to also preserve them by using digital/emulation most of the time.
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    Then again I buy the shit and hardly use them these days too many other services just work
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    Like if switch emulation was shitty I'd probably own a switch by now
    Gift
  • SacredMilkOG @ SacredMilkOG:
    I play all of my PS1 games on my PSP even...

    It's hard though. The whole worls is trying to shift and they're gonna ind that they're missing things eventually. It's gonna be like a digital book burning... they're already trying to make it happen. Then they can resell things that were made years ago again and make all of the money again
    Gift
  • SacredMilkOG @ SacredMilkOG:
    Switch...
    Gift
  • SacredMilkOG @ SacredMilkOG:
    You should at least buy one if you have the means. xD
    Gift
  • SacredMilkOG @ SacredMilkOG:
    Out of an honorable respect of sorts
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    I bet like 60% of steamdeck users will install Win11 just to run YuZu lol
    Gift
  • Gift
  • KennieDaMeanie @ KennieDaMeanie:
    Switch emulator
    Gift
  • SacredMilkOG @ SacredMilkOG:
    Yeahp, just searched it quick xD it's also a japanese citrus fruit too apparently
    Gift
  • Gift
  • KennieDaMeanie @ KennieDaMeanie:
    If I can't easily cfw it I won't buy it lol
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    Too many times in my youth had I bought $60 brand new games and they were shit
    Gift
  • SacredMilkOG @ SacredMilkOG:
    I feel ya... I have a coulple of Falcon 360s' but Xbox is so complicated to modify.

    That's why you play it via other means and buy it if you honestly like it and beat the game.
    Gift
  • SacredMilkOG @ SacredMilkOG:
    Ideally anyway
    Gift
  • KennieDaMeanie @ KennieDaMeanie:
    I almost bought a jtag just for original Xbox games but ended up just buying a $50 broken DVD drive unit the fix was beating the shit out of it tell it opened
    Gift
    KennieDaMeanie @ KennieDaMeanie: I almost bought a jtag just for original Xbox games but ended up just buying a $50 broken DVD...