Created
May 6, 2024 11:42
-
-
Save GaryOderNichts/09f08637276d3eece20ab70beeb87ce7 to your computer and use it in GitHub Desktop.
Script to decompress .cx files found in Pokemon Rumble U
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zlib | |
import sys | |
import struct | |
""" | |
.cx file header (0x14 in size): | |
word[0] 0xe0000000 -> Magic, only the 0x0e is checked | |
word[1] little endian value, uncompressed size | |
word[2] 0x624d414c -> "bMAL" Magic | |
word[3] little endian value, compressed size | |
word[4] little endian crc32 | |
""" | |
with open(sys.argv[1], "rb") as inf: | |
with open(sys.argv[2], "wb") as outf: | |
(magic0, decompressed_size, magic1, compressed_size, crc) = struct.unpack("<4sI4sII", inf.read(0x14)) | |
if magic0[0] != 0xe0 or magic1 != b"bMAL": | |
raise Exception("Invalid magic values") | |
compressed = inf.read() | |
if len(compressed) != compressed_size: | |
raise Exception("Invalid compressed size") | |
decompressed = zlib.decompress(compressed) | |
if len(decompressed) != decompressed_size: | |
raise Exception("Invalid decompressed size") | |
if zlib.crc32(decompressed) != crc: | |
raise Exception("Checksum doesn't match") | |
outf.write(decompressed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment