-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxsr.py
executable file
·59 lines (53 loc) · 1.5 KB
/
xsr.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
import sys
import re
import os
import zlib
outdir = '.'
exts = []
while sys.argv[1][0] == '-':
if sys.argv[1]=='-x':
exts.append(sys.argv[2])
sys.argv = sys.argv[2:]
elif sys.argv[1]=='-o':
outdir = sys.argv[2]
sys.argv = sys.argv[2:]
else:
print("Unknown option")
sys.exit(3)
try:
os.mkdir(outdir)
except:
pass
with open(sys.argv[1], "rb") as f:
def getline():
z = b''
while True:
x = f.read(1)
if x == b'\n':
return z.decode()
z += x
header = getline()
fileCount,_,headerSize = map(int,header.split())
print('files:',fileCount)
files = []
for i in range(fileCount):
offset,size,_,_,_,name = re.split(r'\s+', getline().strip(), maxsplit=5)
offset = int(offset)
size = int(size)
if len(exts):
for x in exts:
if name.lower().endswith(x.lower()):
files.append((offset,size,name))
break
else:
files.append((offset,size,name))
for offset,size,name in files:
f.seek(headerSize+offset)
data = f.read(size)
if name.lower().endswith(".qz"):
name = name[:-3]
data = zlib.decompress(data[4:])
out = os.path.join(outdir, name)
print(out,offset,size)
with open(out,"wb") as g:
g.write(data)