-
Notifications
You must be signed in to change notification settings - Fork 8
/
dump.py
71 lines (55 loc) · 1.75 KB
/
dump.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
import sys
import json
import base64
import struct
def xor(message, key):
return hex(message ^ key)
def dump(path):
try:
config = json.load(open(path, "r"))["object"]
data = config["areaNotify"]["areaCode"]
if config["areaNotify"]["areaType"] != 1:
print("I cannnot deal with type 2 or 3.")
sys.exit(1)
luac = base64.b64decode(data)
except:
luac = open(path, "rb").read()
if b"sb_1184180438" in luac:
start = luac.find(0x38) + 14
end = luac.rfind(0xA3)
luac = luac[start:end + 1]
with open("temp_dump.luac", "wb") as f:
f.write(luac)
file = open("temp_dump.luac", "rb")
data = []
while True:
temp = file.read(1)
if not temp:
break
else:
if (ord(temp) <= 15):
data.append(("0x0" + hex(ord(temp))[2:])[2:])
else:
data.append((hex(ord(temp))[2:]))
data.reverse()
for key, value in enumerate(data):
if key == 0:
pass
else:
data[key] = xor(int(value, 16), int(data[key - 1], 16))
for key, value in enumerate(data):
data[key] = xor(int(value, 16), 0xA3)
data.reverse()
with open("result.luac", "wb") as file:
for item in data:
pack = struct.pack("B", int(item, 16))
file.write(pack)
else:
open("result.luac", "wb").write(luac)
print("Done! result.luac")
def help():
print("dump.py <bin or json path>")
if len(sys.argv) != 2:
help()
else:
dump(sys.argv[1])