Skip to content

Instantly share code, notes, and snippets.

@kjy00302
Created January 17, 2024 19:42
Show Gist options
  • Save kjy00302/679b6652c8a0cbd6d6822d8e19d5b140 to your computer and use it in GitHub Desktop.
Save kjy00302/679b6652c8a0cbd6d6822d8e19d5b140 to your computer and use it in GitHub Desktop.
PoC masterdata unpacker/repacker for Yohane the Parhelion - NUMAZU in the MIRAGE
import msgpack
import glob
import json
import pathlib
out_file = open('masterdata_repacked', 'wb')
jsons = [pathlib.Path(i) for i in glob.glob("unpacked/*.json")]
header = {}
buf = bytearray()
i = 0
for json_path in jsons:
name = json_path.stem
with open(json_path, 'r') as f:
data = msgpack.packb(json.load(f))
size = len(data)
header[name] = [i, size]
i += size
buf += data
out_file.write(msgpack.packb(header))
out_file.write(buf)
import lz4.block
import msgpack
import json
import os
def unlz4_hook(code, data):
if code == 99:
size = int.from_bytes(data[1:5], 'big')
return msgpack.unpackb(lz4.block.decompress(data[5:], size))
return msgpack.ExtType(code, data)
with open('masterdata', 'rb') as f:
unpacker = msgpack.Unpacker(f, ext_hook=unlz4_hook)
info = unpacker.unpack()
os.makedirs('unpacked', exist_ok=True)
for name, (offset, size) in info.items():
with open(f'unpacked/{name}.json', 'w') as g:
data = unpacker.read_bytes(size)
json.dump(msgpack.unpackb(data, ext_hook=unlz4_hook), g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment