-
Notifications
You must be signed in to change notification settings - Fork 12
/
genMhfKey.py
73 lines (57 loc) · 1.63 KB
/
genMhfKey.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import zlib
import sys
import hashlib
from multiprocessing import Pool
def sha256(file):
with open(file.filename, 'rb') as fp:
s = fp.read()
h = hashlib.sha256()
h.update(s)
return h.hexdigest().upper()
def crc32(file):
with open(file.filename, '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.filename) * 10000000) + 116444736000000000).to_bytes(8, 'big')
def fileinfo(file):
if target == '51':
filehash = sha256(file)
else:
filehash = crc32(file)
return filehash, filetime(file), file.filename, file.size
class MhfFile:
def __init__(self, _filename, _size):
self.filename = _filename
self.size = _size
target = ''
if len(sys.argv) == 2:
target = sys.argv[1]
else:
target = '00'
if target == '51':
print('Targeting PS3, using SHA256')
else:
print('Targeting PC, using CRC32')
key = set()
files = set()
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
files.add(MhfFile(fn, fs))
with Pool() as pool:
infos = pool.map(fileinfo, files)
for crc, filetime, filename, size in infos:
dfn = filename.replace('/', '\\')[7:]
key.add(f'{crc},{filetime[4:8].hex().upper()},{filetime[0:4].hex().upper()},{dfn},{size},0\n')
with open(f'key{target}.txt', 'w') as fp:
fp.write(''.join(key))