def decode(self, fs: FileStream): offset = fs.position self.signature = fs.read_string() assert self.signature == UnitySignature.UnityFS self.version = fs.read_sint32() assert self.version != 5 self.unity_web_bundle_version = fs.read_string() self.unity_web_minimum_revision = fs.read_string() self.size = fs.read_uint64() self.compressed_blocks_info_size = fs.read_uint32() self.uncompressed_blocks_info_size = fs.read_uint32() assert self.compressed_blocks_info_size < self.uncompressed_blocks_info_size, vars( self) self.flags = fs.read_uint32() self.header_size = fs.position - offset
def decode_type_tree(self, fs: FileStream): type_index = -1 node_count = fs.read_uint32() char_count = fs.read_uint32() for _ in range(node_count): node = TypeField() node.decode(fs) if type_index >= 0: assert node.index == type_index + 1 self.nodes.append(node) type_index += 1 if char_count > 0: string_offset = fs.position string_size = 0 while string_size + 1 < char_count: offset = fs.position - string_offset position = fs.position self.strings[offset] = fs.read_string() string_size += fs.position - position assert fs.position - string_offset == char_count for node in self.nodes: # type: TypeField node.name = get_caculate_string(offset=node.name_str_offset, strings=self.strings) node.type = get_caculate_string(offset=node.type_str_offset, strings=self.strings) self.name = self.nodes[0].type
def decode(self, fs: FileStream): fs.seek(self.node.offset) header = self.header header.metadata_size = fs.read_sint32() header.file_size = fs.read_sint32() assert self.node.size == header.file_size, '{} != {}'.format( self.node.size, header.file_size) header.version = fs.read_sint32() header.data_offset = fs.read_sint32() header.endianess = fs.read_boolean() fs.read(3) # reserved bytes fs.endian = '>' if header.endianess else '<' self.print(vars(header)) self.version = fs.read_string() self.platform = fs.read_uint32() self.type_tree_enabled = fs.read_boolean() self.print('version={} platform={} type_tree_enabled={}'.format( self.version, self.platform, self.type_tree_enabled)) self.type_trees = [] type_count = fs.read_uint32() self.print('type', type_count) for _ in range(type_count): offset = fs.position type_tree = MetadataTypeTree( type_tree_enabled=self.type_tree_enabled) type_tree.decode(fs) if self.type_tree_enabled: position = fs.position fs.seek(offset) type_data = fs.read(position - offset) with open(type_tree.get_cache_path(auto_create=True), 'wb') as fp: fp.write(type_data) self.type_trees.append(type_tree) self.register_type_tree(type_tree=type_tree) self.print(type_tree) object_count = fs.read_sint32() self.print('object', object_count) for _ in range(object_count): fs.align(4) obj = ObjectInfo() obj.decode(fs) type_tree = self.type_trees[obj.type_id] obj.name = type_tree.name self.objects.append(obj) self.print(vars(obj)) script_type_count = fs.read_sint32() self.print('typeinfo', script_type_count) for _ in range(script_type_count): st = ScriptTypeInfo() st.decode(fs) self.typeinfos.append(st) self.print(vars(st)) external_count = fs.read_sint32() self.print('external', external_count) for _ in range(external_count): ext = ExternalInfo() ext.decode(fs) self.externals.append(ext) self.print(ext) fs.read_string()
def decode(self, fs: FileStream): fs.read_string() self.guid = fs.read(16) self.type = fs.read_sint32() self.path = fs.read_string()
def decode(self, fs: FileStream): self.offset = fs.read_uint64() self.size = fs.read_uint64() self.flags = fs.read_uint32() self.path = fs.read_string()