Skip to content

Instantly share code, notes, and snippets.

@ChainSwordCS
Last active August 29, 2026 00:39
Show Gist options
  • Select an option

  • Save ChainSwordCS/95700185135d2711c867a34a61a8659a to your computer and use it in GitHub Desktop.

Select an option

Save ChainSwordCS/95700185135d2711c867a34a61a8659a to your computer and use it in GitHub Desktop.
simple script to fix the header of a .nro.lz4 file, so you can decompress it with standard tools
#!/usr/bin/env python3
# nro-lz4-fixup.py
# simple script to fix the header of a .nro.lz4 file,
# so you can decompress it with standard tools (namely, lz4, the cli utility)
# doesn't work on all .nro.lz4 files. idk why. something stupid i'm sure. ymmv
# License: MIT
import os
import sys
from struct import pack
# argument: .nro.lz4 file
with open(sys.argv[1], 'rb') as file:
infile_bytes = file.read()
l = len(sys.argv[1])
filename = (sys.argv[1][0:l-8]) + '_' + (sys.argv[1][l-8:l])
with open(filename, 'wb') as out:
# Legacy format lz4 magic
out.write(b'\x02\x21\x4C\x18')
# write size of compressed content
compressed_size = len(infile_bytes)-4
out.write(pack('<L', compressed_size))
# copy compressed content
out.write(infile_bytes[4:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment