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

Discussion in 'Switch - Exploits, Custom Firmwares & Soft Mods' started by AboodXD, Nov 22, 2017.

  1. AboodXD
    OP

    AboodXD I hack NSMB games, and other shiz.

    Member
    10
    Oct 11, 2014
    United Arab Emirates
    Not under a rock.
    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, Dec 31, 2017
  2. DSpider

    DSpider GBAtemp Advanced Fan

    Member
    6
    Mar 14, 2015
    Romania
    Cool. But the game files are still encrypted after decompressing them, right?
     
    Last edited by DSpider, Nov 22, 2017
  3. tunip3

    tunip3 [debugger active]

    Banned
    7
    Oct 31, 2016
    United Kingdom
    and how would you dump it
     
  4. AboodXD
    OP

    AboodXD I hack NSMB games, and other shiz.

    Member
    10
    Oct 11, 2014
    United Arab Emirates
    Not under a rock.
    Not as far as I know.
    Yaz0 files? From the game files. They usually end with .szs.
     
  5. tunip3

    tunip3 [debugger active]

    Banned
    7
    Oct 31, 2016
    United Kingdom
    but how do you dump the games
     
  6. AboodXD
    OP

    AboodXD I hack NSMB games, and other shiz.

    Member
    10
    Oct 11, 2014
    United Arab Emirates
    Not under a rock.
    You can find dumps online.
     
  7. AboodXD
    OP

    AboodXD I hack NSMB games, and other shiz.

    Member
    10
    Oct 11, 2014
    United Arab Emirates
    Not under a rock.
    Just released v0.3 which fixes a major bug where the uncompressed data size is not saved correctly when compressing.

    You can get it using pip:
    Code:
    pip install libyaz0==0.3.1
    Or you could get the source code from Github.

    Updated the standalone program (Windows) as well.
     
    Last edited by AboodXD, Nov 25, 2017
  8. AboodXD
    OP

    AboodXD I hack NSMB games, and other shiz.

    Member
    10
    Oct 11, 2014
    United Arab Emirates
    Not under a rock.
    Just released v0.4 which allows for faster compressing and decompressing.

    You can get it using pip:
    Code:
    pip install libyaz0==0.4
    Or you could get the source code from Github.

    Updated the standalone program (Windows) as well.
     
  9. Alzter

    Alzter Member

    Newcomer
    1
    Apr 4, 2014
    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, Jul 2, 2018
  10. AceTartarSquad

    AceTartarSquad Member

    Newcomer
    2
    Jun 11, 2018
    United States
    You need to double click the python library, and if that doesn't work, try double clicking it twice.
     
  11. Alzter

    Alzter Member

    Newcomer
    1
    Apr 4, 2014
    United States
    I opened a command line at the install location, entered the command and it worked perfectly! Thank you so much!
     
  12. AboodXD
    OP

    AboodXD I hack NSMB games, and other shiz.

    Member
    10
    Oct 11, 2014
    United Arab Emirates
    Not under a rock.
    You're welcome; but I recommend you to use SARC Tool instead. ;)
     
  13. Alzter

    Alzter Member

    Newcomer
    1
    Apr 4, 2014
    United States
Loading...