-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_patch.py
40 lines (37 loc) · 1.1 KB
/
create_patch.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
# -*- coding: utf-8 -*-
import csv, sys, time, zlib
from struct import pack, unpack
def main():
rep = list()
source = open(sys.argv[1], "r", encoding="utf-8-sig")
reader = csv.reader(source)
for row in reader:
i = int(row[0])
rep.append((i, int(row[1], 16), row[3]))
source.close()
with open("patch.bin.tmp", "wb") as tmp:
tmp.write(pack("<L", len(rep)))
for i, o, t in rep:
if ((1 <= i and i < 53909) or i >= 57045):
tmp.write(pack("<L", o))
t = t.encode("gbk", errors="ignore") + b"\0"
tmp.write(pack("<H", len(t)))
tmp.write(t)
else:
tmp.write(pack("<L", o))
t = b""
tmp.write(pack("<H", len(t)))
tmp.write(t)
data = b""
with open("patch.bin.tmp", "rb") as tmp:
data = tmp.read()
target = open("patch.dat", "wb")
target.write(pack("<L", 0)) # compressed signature
target.write(pack("<L", int(time.time())))
target.write(pack("<L", len(data)))
comp_data = zlib.compress(data)
target.write(pack("<L", len(comp_data)))
target.write(comp_data)
target.close()
if __name__ == "__main__":
main()