-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtractUnityWeb.py
More file actions
executable file
·68 lines (65 loc) · 2.05 KB
/
ExtractUnityWeb.py
File metadata and controls
executable file
·68 lines (65 loc) · 2.05 KB
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
import sys
import os
import gzip
import struct
def gunzip(in_name, out_name):
with gzip.open(in_name, mode='rb') as f:
data = f.read()
with open(out_name, 'wb') as f:
f.write(data)
def extract(filepath):
f = open(filepath, 'rb')
# Read header
magic = f.read(16)
if magic != b'UnityWebData1.0\x00':
print("[-] Invalid header: " + repr(magic))
return
header_length = struct.unpack('<I', f.read(4))[0]
print("[+] Header length: " + hex(header_length))
offset = 16 + 4
# Extract files
while offset < header_length:
packet = struct.unpack('<III', f.read(12))
data_offset, data_length, path_length = packet
path = f.read(path_length).decode()
print("- {0} ({1} bytes)".format(path, data_length))
try:
os.makedirs('UnityWebData/' + os.path.dirname(path))
except:
pass
whereami = f.tell()
with open('UnityWebData/' + path, 'wb') as fout:
f.seek(data_offset)
data = f.read(data_length)
fout.write(data)
f.seek(whereami)
# Next file
offset += 12 + path_length
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: {0} run.data.unityweb\n".format(sys.argv[0]))
print("This script extracts all files from UnityWeb data file. "
"The target filename is generally named `run.data.unityweb`.")
exit(1)
# Gunzip
created = False
filepath = sys.argv[1] + '.raw'
try:
gunzip(sys.argv[1], filepath)
print("[+] Decompressed " + sys.argv[1])
created = True
except:
with open(sys.argv[1], 'rb') as f:
magic = f.read(16)
if magic == b'UnityWebData1.0\x00':
print("[+] You specified decompressed file")
filepath = sys.argv[1]
else:
print("[-] Invalid header: " + repr(magic))
exit(1)
# Extract
extract(filepath)
print("[+] Exiting...")
# Remove temp file
if created:
os.remove(filepath)