-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_files.py
42 lines (35 loc) · 1.17 KB
/
extract_files.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
import os
import xml.etree.ElementTree as ET
from lib.paths import PACK, DATA
from lib.crypt import decrypt, extract
from zipfile import ZipFile
import io
def main():
os.makedirs(DATA, exist_ok=True)
# 1. update index.xml in pack
index_fp = os.path.join(DATA, "index.xml")
decrypt(os.path.join(PACK, "index"), index_fp)
# fix index.xml ending
with open(index_fp, "r+") as f:
end = f.seek(0, 2)
f.seek(end - 16)
data = f.read(16)
f.truncate(end - (16 - len(data.rstrip("\x00"))))
if data[:2] == b"PK":
with ZipFile(io.BytesIO(dec), 'r') as zip:
data = zip.open("index").read()
with open(index_fp, "wb") as f:
f.write(data)
# parse index.xml
tree = ET.parse(index_fp)
root = tree.getroot()
for item in root:
src = os.path.join(PACK, *item.get("pack").split("/"))
dst = os.path.join(DATA, *item.get("original").split("\\"))
dsize = os.path.getsize(dst) if os.path.exists(dst) else -1
if dsize == int(item.get("size")):
continue
print(dst)
extract(src, dst, item)
if __name__ == "__main__":
main()