Skip to content

Instantly share code, notes, and snippets.

@sekaiwish
Last active April 19, 2025 03:30
Show Gist options
  • Save sekaiwish/604296de5e6c6506331b8291062c1e78 to your computer and use it in GitHub Desktop.
Save sekaiwish/604296de5e6c6506331b8291062c1e78 to your computer and use it in GitHub Desktop.
Generate MHFUP keyfile
import os
import zlib
def crc32(file):
with open(file, 'rb') as fp:
h = 0
while True:
s = fp.read(65536)
if not s:
break
h = zlib.crc32(s, h)
return "%08X" % (h & 0xFFFFFFFF)
def filetime(file):
return int((os.path.getmtime(file) * 10000000) + 116444736000000000).to_bytes(8, 'big')
key = str()
for r, _, f in os.walk('mhfdat', topdown=False):
for name in f:
fn = os.path.join(r, name)
fs = os.stat(fn).st_size
if fs == 0:
continue
dfn = fn.replace('/', '\\')[7:]
ftb = filetime(os.path.join(r, name))
key += f'{crc32(fn)},{ftb[4:8].hex().upper()},{ftb[0:4].hex().upper()},{dfn},{fs},0\n'
with open('key.txt', 'w') as fp:
fp.write(key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment