-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
59 lines (46 loc) · 1.48 KB
/
main.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
from pyvz2rijndael import RijndaelCBC
import base64
import zlib
import struct
import sys
import os
import json
import hashlib
key = "65bd1b2305f46eb2806b935aab7630bb"
tool = RijndaelCBC(key=key, block_size=24)
magic = 0xDEADFED4
def decode(data: bytes):
step1 = base64.b64decode(data)[2:]
step2 = tool.decrypt(step1)[8:]
step3 = zlib.decompress(step2)
return step3
def encode(data: bytes):
step1 = struct.pack("<I", magic) + struct.pack("<I", len(data)) + zlib.compress(data)
step2 = tool.encrypt(step1)
step3 = base64.b64encode(b"\x10\0" + step2)
return step3
def process_translation(input_file, output_dir):
# Reading input file
with open(input_file, "rb") as f:
translation = f.read()
# Generating pvz2_l.txt
pvz2_content = encode(translation)
with open(os.path.join(output_dir, "pvz2_l.txt"), "wb") as f:
f.write(pvz2_content)
# Generating content to file_lists.txt
h = hashlib.md5(translation).hexdigest()
d = {
"File": {
"Name": "pvz2_l.txt",
"Hash": h
}
}
# Generating file_list.txt
file_list_content = encode(json.dumps(d).encode())
with open(os.path.join(output_dir, "file_list.txt"), "wb") as f:
f.write(file_list_content)
if __name__ == '__main__':
raw_file = sys.argv[1] # path to raw lawnstrings file
out_dir = sys.argv[2] # path to output directory
os.makedirs(out_dir, exist_ok=True)
process_translation(raw_file, out_dir)