-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathassetbundle.py
139 lines (107 loc) · 5.67 KB
/
assetbundle.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
from pkg_resources import parse_version
from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO
from enum import Enum
from lz4process import Lz4process
if parse_version(ks_version) < parse_version('0.7'):
raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))
class Assetbundle(KaitaiStruct):
class CompressionMethod(Enum):
lzma = 1
lz4 = 2
lz4hc = 3
lzham = 4
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.archive_storage_header = self._root.ArchiveStorageHeader(self._io, self, self._root)
self.archive_storage_body = self._root.ArchiveStorageBody(self._io, self, self._root)
class ArchiveStorageHeader(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.header = self._root.ArchiveStorageHeader.Header(self._io, self, self._root)
self._raw__raw_blocks_info = self._io.read_bytes(self.header.compressed_size)
_process = Lz4process(self.header.uncompressed_size)
self._raw_blocks_info = _process.decode(self._raw__raw_blocks_info)
io = KaitaiStream(BytesIO(self._raw_blocks_info))
self.blocks_info = self._root.ArchiveStorageHeader.BlocksInfo(io, self, self._root)
class Header(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.signature = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8")
self.format = self._io.read_u4be()
self.unity_major_version = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8")
self.unity_minor_version = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8")
self.file_size = self._io.read_s8be()
self.compressed_size = self._io.read_u4be()
self.uncompressed_size = self._io.read_u4be()
self.flags = self._io.read_u4be()
class BlocksInfo(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.guid = self._io.read_bytes(16)
self.blocks_size = self._io.read_s4be()
self.blocks = [None] * (self.blocks_size)
for i in range(self.blocks_size):
self.blocks[i] = self._root.ArchiveStorageHeader.StorageBlock(self._io, self, self._root)
self.directory_info_size = self._io.read_u4be()
self.directory_infos = [None] * (self.directory_info_size)
for i in range(self.directory_info_size):
self.directory_infos[i] = self._root.ArchiveStorageHeader.DirectoryInfo(self._io, self, self._root)
class StorageBlock(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.uncompressed_size = self._io.read_u4be()
self.compressed_size = self._io.read_u4be()
self.flags = self._io.read_u2be()
class DirectoryInfo(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.offset = self._io.read_u8be()
self.size = self._io.read_u8be()
self.flags = self._io.read_u4be()
self.path = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8")
class ArchiveStorageBody(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.blocks = [None] * (self._parent.archive_storage_header.blocks_info.blocks_size)
for i in range(self._parent.archive_storage_header.blocks_info.blocks_size):
self.blocks[i] = self._root.ArchiveStorageBody.CompressedBlock(i, self._io, self, self._root)
class CompressedBlock(KaitaiStruct):
def __init__(self, i, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self.i = i
self._read()
def _read(self):
self._raw_uncompressed_data = self._io.read_bytes(self._parent._parent.archive_storage_header.blocks_info.blocks[self.i].compressed_size)
_process = Lz4process(self._parent._parent.archive_storage_header.blocks_info.blocks[self.i].uncompressed_size)
self.uncompressed_data = _process.decode(self._raw_uncompressed_data)