def contents(self): if hasattr(self, '_m_contents'): return self._m_contents if hasattr(self, '_m_contents') else None io = self._root._io _pos = io.pos() io.seek(self.offset) self._debug['_m_contents']['start'] = io.pos() _on = self.name if _on == u"SECTORS": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Sectors(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"TEXTURE1": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Texture12(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"VERTEXES": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Vertexes(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"BLOCKMAP": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Blockmap(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"PNAMES": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Pnames(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"TEXTURE2": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Texture12(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"THINGS": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Things(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"LINEDEFS": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Linedefs(_io__raw__m_contents, self, self._root) self._m_contents._read() elif _on == u"SIDEDEFS": self._raw__m_contents = io.read_bytes(self.size) _io__raw__m_contents = KaitaiStream( BytesIO(self._raw__m_contents)) self._m_contents = DoomWad.Sidedefs(_io__raw__m_contents, self, self._root) self._m_contents._read() else: self._m_contents = io.read_bytes(self.size) self._debug['_m_contents']['end'] = io.pos() io.seek(_pos) return self._m_contents if hasattr(self, '_m_contents') else None
def _read(self): self._debug['type']['start'] = self._io.pos() self.type = KaitaiStream.resolve_enum(BtrfsStream.Attribute, self._io.read_u2le()) self._debug['type']['end'] = self._io.pos() self._debug['length']['start'] = self._io.pos() self.length = self._io.read_u2le() self._debug['length']['end'] = self._io.pos() self._debug['value']['start'] = self._io.pos() _on = self.type if _on == BtrfsStream.Attribute.ctransid: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.size: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.clone_uuid: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.Uuid( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.file_offset: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.otime: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.Timespec( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.uid: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.atime: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.Timespec( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.ctime: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.Timespec( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.uuid: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.Uuid( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.clone_len: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.xattr_name: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.String( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.clone_ctransid: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.mode: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.mtime: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.Timespec( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.path_link: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.String( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.rdev: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.path_to: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.String( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.path: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.String( _io__raw_value, self, self._root) self.value._read() elif _on == BtrfsStream.Attribute.clone_offset: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.gid: self.value = self._io.read_u8le() elif _on == BtrfsStream.Attribute.clone_path: self._raw_value = self._io.read_bytes(self.length) _io__raw_value = KaitaiStream(BytesIO(self._raw_value)) self.value = BtrfsStream.SendCommand.String( _io__raw_value, self, self._root) self.value._read() else: self.value = self._io.read_bytes(self.length) self._debug['value']['end'] = self._io.pos()
def _read(self): self.entries_count = self._io.read_u4le() self.entries_size = self._io.read_u4le() self._raw_entries = self._io.read_bytes(self.entries_size) io = KaitaiStream(BytesIO(self._raw_entries)) self.entries = self._root.FileEntries(io, self, self._root)
def _read(self): self._debug['code']['start'] = self._io.pos() self.code = self._io.read_bytes(4) self._debug['code']['end'] = self._io.pos() if not self.code == b"\x01\x00\x00\x00": raise kaitaistruct.ValidationNotEqualError( b"\x01\x00\x00\x00", self.code, self._io, u"/types/list_with_header/seq/0") self._debug['header_size']['start'] = self._io.pos() self.header_size = self._io.read_u4le() self._debug['header_size']['end'] = self._io.pos() self._debug['library_id_stamp']['start'] = self._io.pos() self.library_id_stamp = self._io.read_u4le() self._debug['library_id_stamp']['end'] = self._io.pos() self._debug['header']['start'] = self._io.pos() _on = self._parent.code if _on == RenderwareBinaryStream.Sections.geometry: self._raw_header = self._io.read_bytes(self.header_size) _io__raw_header = KaitaiStream(BytesIO(self._raw_header)) self.header = RenderwareBinaryStream.StructGeometry( _io__raw_header, self, self._root) self.header._read() elif _on == RenderwareBinaryStream.Sections.texture_dictionary: self._raw_header = self._io.read_bytes(self.header_size) _io__raw_header = KaitaiStream(BytesIO(self._raw_header)) self.header = RenderwareBinaryStream.StructTextureDictionary( _io__raw_header, self, self._root) self.header._read() elif _on == RenderwareBinaryStream.Sections.geometry_list: self._raw_header = self._io.read_bytes(self.header_size) _io__raw_header = KaitaiStream(BytesIO(self._raw_header)) self.header = RenderwareBinaryStream.StructGeometryList( _io__raw_header, self, self._root) self.header._read() elif _on == RenderwareBinaryStream.Sections.clump: self._raw_header = self._io.read_bytes(self.header_size) _io__raw_header = KaitaiStream(BytesIO(self._raw_header)) self.header = RenderwareBinaryStream.StructClump( _io__raw_header, self, self._root) self.header._read() elif _on == RenderwareBinaryStream.Sections.frame_list: self._raw_header = self._io.read_bytes(self.header_size) _io__raw_header = KaitaiStream(BytesIO(self._raw_header)) self.header = RenderwareBinaryStream.StructFrameList( _io__raw_header, self, self._root) self.header._read() else: self.header = self._io.read_bytes(self.header_size) self._debug['header']['end'] = self._io.pos() self._debug['entries']['start'] = self._io.pos() self.entries = [] i = 0 while not self._io.is_eof(): if not 'arr' in self._debug['entries']: self._debug['entries']['arr'] = [] self._debug['entries']['arr'].append({'start': self._io.pos()}) _t_entries = RenderwareBinaryStream(self._io) _t_entries._read() self.entries.append(_t_entries) self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() i += 1 self._debug['entries']['end'] = self._io.pos()
def _read(self): self._raw_dir = self._io.read_bytes(self.dir_size) _io__raw_dir = KaitaiStream(BytesIO(self._raw_dir)) self.dir = Dune2Pak.Files(_io__raw_dir, self, self._root)
def _read(self): self.len = self._io.read_u1() if self.len > 0: self._raw_body = self._io.read_bytes((self.len - 1)) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.DirEntryBody(io, self, self._root)
def calculate_route(): file = request.files['file'] data = Gif(KaitaiStream(BytesIO(file.read()))) capacity = count_available_storage(data) return {"capacity": capacity}
def _read(self): self.id_tag = CryptString(u"ID", self._io) self.refine_base = CryptString(u"ID", self._io) self.name_id = CryptString(u"ID", self._io) self.desc_id = CryptString(u"ID", self._io) self.refine_id = CryptString(u"ID", self._io) self.beast_effect_id = CryptString(u"ID", self._io) self.prerequisites = [None] * (2) for i in range(2): self.prerequisites[i] = CryptString(u"ID", self._io) self.next_skill = CryptString(u"ID", self._io) self.sprites = [None] * (4) for i in range(4): self.sprites[i] = CryptString(u"NONE", self._io) self.stats = StatsTuple(self._io) self.class_params = StatsTuple(self._io) self.skill_params = StatsTuple(self._io) self.refine_stats = StatsTuple(self._io) self._raw__raw_num_id = self._io.read_bytes(4) self._raw_num_id = KaitaiStream.process_xor_many( self._raw__raw_num_id, b"\x23\x3A\xA5\xC6") io = KaitaiStream(BytesIO(self._raw_num_id)) self.num_id = Encrypted(u"xoru4", io) self._raw__raw_sort_id = self._io.read_bytes(4) self._raw_sort_id = KaitaiStream.process_xor_many( self._raw__raw_sort_id, b"\xAC\xF8\xDB\x8D") io = KaitaiStream(BytesIO(self._raw_sort_id)) self.sort_id = Encrypted(u"xoru4", io) self._raw__raw_icon_id = self._io.read_bytes(4) self._raw_icon_id = KaitaiStream.process_xor_many( self._raw__raw_icon_id, b"\x73\x21\xDF\xC6") io = KaitaiStream(BytesIO(self._raw_icon_id)) self.icon_id = Encrypted(u"xoru4", io) self._raw__raw_wep_equip = self._io.read_bytes(4) self._raw_wep_equip = KaitaiStream.process_xor_many( self._raw__raw_wep_equip, b"\x28\x98\xB9\x35") io = KaitaiStream(BytesIO(self._raw_wep_equip)) self.wep_equip = Encrypted(u"xoru4", io) self._raw__raw_mov_equip = self._io.read_bytes(4) self._raw_mov_equip = KaitaiStream.process_xor_many( self._raw__raw_mov_equip, b"\xEB\x18\x28\xAB") io = KaitaiStream(BytesIO(self._raw_mov_equip)) self.mov_equip = Encrypted(u"xoru4", io) self._raw__raw_sp_cost = self._io.read_bytes(4) self._raw_sp_cost = KaitaiStream.process_xor_many( self._raw__raw_sp_cost, b"\x69\xF6\x31\xC0") io = KaitaiStream(BytesIO(self._raw_sp_cost)) self.sp_cost = Encrypted(u"xoru4", io) self._raw__raw_category = self._io.read_bytes(1) self._raw_category = KaitaiStream.process_xor_many( self._raw__raw_category, b"\xBC") io = KaitaiStream(BytesIO(self._raw_category)) self.category = Encrypted(u"xoru1", io) self._raw__raw_tome_class = self._io.read_bytes(1) self._raw_tome_class = KaitaiStream.process_xor_many( self._raw__raw_tome_class, b"\xF1") io = KaitaiStream(BytesIO(self._raw_tome_class)) self.tome_class = MagicElement(io) self._raw__raw_exclusive = self._io.read_bytes(1) self._raw_exclusive = KaitaiStream.process_xor_many( self._raw__raw_exclusive, b"\xCC") io = KaitaiStream(BytesIO(self._raw_exclusive)) self.exclusive = Xorb1(io) self._raw__raw_enemy_only = self._io.read_bytes(1) self._raw_enemy_only = KaitaiStream.process_xor_many( self._raw__raw_enemy_only, b"\x4F") io = KaitaiStream(BytesIO(self._raw_enemy_only)) self.enemy_only = Xorb1(io) self._raw__raw_range = self._io.read_bytes(1) self._raw_range = KaitaiStream.process_xor_many( self._raw__raw_range, b"\x56") io = KaitaiStream(BytesIO(self._raw_range)) self.range = Encrypted(u"xoru1", io) self._raw__raw_might = self._io.read_bytes(1) self._raw_might = KaitaiStream.process_xor_many( self._raw__raw_might, b"\xD2") io = KaitaiStream(BytesIO(self._raw_might)) self.might = Encrypted(u"xoru1", io) self._raw__raw_cooldown_count = self._io.read_bytes(1) self._raw_cooldown_count = KaitaiStream.process_xor_many( self._raw__raw_cooldown_count, b"\x56") io = KaitaiStream(BytesIO(self._raw_cooldown_count)) self.cooldown_count = Encrypted(u"xors1", io) self._raw__raw_assist_cd = self._io.read_bytes(1) self._raw_assist_cd = KaitaiStream.process_xor_many( self._raw__raw_assist_cd, b"\xF2") io = KaitaiStream(BytesIO(self._raw_assist_cd)) self.assist_cd = Xorb1(io) self._raw__raw_healing = self._io.read_bytes(1) self._raw_healing = KaitaiStream.process_xor_many( self._raw__raw_healing, b"\x95") io = KaitaiStream(BytesIO(self._raw_healing)) self.healing = Xorb1(io) self._raw__raw_skill_range = self._io.read_bytes(1) self._raw_skill_range = KaitaiStream.process_xor_many( self._raw__raw_skill_range, b"\x09") io = KaitaiStream(BytesIO(self._raw_skill_range)) self.skill_range = Encrypted(u"xoru1", io) self._raw__raw_score = self._io.read_bytes(2) self._raw_score = KaitaiStream.process_xor_many( self._raw__raw_score, b"\x32\xA2") io = KaitaiStream(BytesIO(self._raw_score)) self.score = Encrypted(u"xoru2", io) self._raw__raw_promotion_tier = self._io.read_bytes(1) self._raw_promotion_tier = KaitaiStream.process_xor_many( self._raw__raw_promotion_tier, b"\xE0") io = KaitaiStream(BytesIO(self._raw_promotion_tier)) self.promotion_tier = Encrypted(u"xoru1", io) self._raw__raw_promotion_rarity = self._io.read_bytes(1) self._raw_promotion_rarity = KaitaiStream.process_xor_many( self._raw__raw_promotion_rarity, b"\x75") io = KaitaiStream(BytesIO(self._raw_promotion_rarity)) self.promotion_rarity = Encrypted(u"xoru1", io) self._raw__raw_refined = self._io.read_bytes(1) self._raw_refined = KaitaiStream.process_xor_many( self._raw__raw_refined, b"\x02") io = KaitaiStream(BytesIO(self._raw_refined)) self.refined = Xorb1(io) self._raw__raw_refine_sort_id = self._io.read_bytes(1) self._raw_refine_sort_id = KaitaiStream.process_xor_many( self._raw__raw_refine_sort_id, b"\xFC") io = KaitaiStream(BytesIO(self._raw_refine_sort_id)) self.refine_sort_id = Encrypted(u"xoru1", io) self._raw__raw_wep_effective = self._io.read_bytes(4) self._raw_wep_effective = KaitaiStream.process_xor_many( self._raw__raw_wep_effective, b"\x43\x3D\xBE\x23") io = KaitaiStream(BytesIO(self._raw_wep_effective)) self.wep_effective = Encrypted(u"xoru4", io) self._raw__raw_mov_effective = self._io.read_bytes(4) self._raw_mov_effective = KaitaiStream.process_xor_many( self._raw__raw_mov_effective, b"\xEB\xDA\x3F\x82") io = KaitaiStream(BytesIO(self._raw_mov_effective)) self.mov_effective = Encrypted(u"xoru4", io) self._raw__raw_wep_shield = self._io.read_bytes(4) self._raw_wep_shield = KaitaiStream.process_xor_many( self._raw__raw_wep_shield, b"\x43\xB7\xBA\xAA") io = KaitaiStream(BytesIO(self._raw_wep_shield)) self.wep_shield = Encrypted(u"xoru4", io) self._raw__raw_mov_shield = self._io.read_bytes(4) self._raw_mov_shield = KaitaiStream.process_xor_many( self._raw__raw_mov_shield, b"\x5B\xF2\xBE\x0E") io = KaitaiStream(BytesIO(self._raw_mov_shield)) self.mov_shield = Encrypted(u"xoru4", io) self._raw__raw_wep_weakness = self._io.read_bytes(4) self._raw_wep_weakness = KaitaiStream.process_xor_many( self._raw__raw_wep_weakness, b"\xAF\x02\x5A\x00") io = KaitaiStream(BytesIO(self._raw_wep_weakness)) self.wep_weakness = Encrypted(u"xoru4", io) self._raw__raw_mov_weakness = self._io.read_bytes(4) self._raw_mov_weakness = KaitaiStream.process_xor_many( self._raw__raw_mov_weakness, b"\x19\xB8\x69\xB2") io = KaitaiStream(BytesIO(self._raw_mov_weakness)) self.mov_weakness = Encrypted(u"xoru4", io) self._raw__raw_wep_adaptive = self._io.read_bytes(4) self._raw_wep_adaptive = KaitaiStream.process_xor_many( self._raw__raw_wep_adaptive, b"\x29\x26\x4E\x49") io = KaitaiStream(BytesIO(self._raw_wep_adaptive)) self.wep_adaptive = Encrypted(u"xoru4", io) self._raw__raw_mov_adaptive = self._io.read_bytes(4) self._raw_mov_adaptive = KaitaiStream.process_xor_many( self._raw__raw_mov_adaptive, b"\x2E\xEF\x6C\xEE") io = KaitaiStream(BytesIO(self._raw_mov_adaptive)) self.mov_adaptive = Encrypted(u"xoru4", io) self._raw__raw_timing_id = self._io.read_bytes(4) self._raw_timing_id = KaitaiStream.process_xor_many( self._raw__raw_timing_id, b"\x48\x66\x77\x9C") io = KaitaiStream(BytesIO(self._raw_timing_id)) self.timing_id = Encrypted(u"xoru4", io) self._raw__raw_ability_id = self._io.read_bytes(4) self._raw_ability_id = KaitaiStream.process_xor_many( self._raw__raw_ability_id, b"\x25\x73\xB0\x72") io = KaitaiStream(BytesIO(self._raw_ability_id)) self.ability_id = Encrypted(u"xoru4", io) self._raw__raw_limit1_id = self._io.read_bytes(4) self._raw_limit1_id = KaitaiStream.process_xor_many( self._raw__raw_limit1_id, b"\x32\xB8\xBD\x0E") io = KaitaiStream(BytesIO(self._raw_limit1_id)) self.limit1_id = Encrypted(u"xoru4", io) self._raw_limit1_params = [None] * (2) self.limit1_params = [None] * (2) for i in range(2): self._raw__raw_limit1_params[i] = self._io.read_bytes(2) self._raw_limit1_params = KaitaiStream.process_xor_many( self._raw__raw_limit1_params, b"\x90\xA5") io = KaitaiStream(BytesIO(self._raw_limit1_params[i])) self.limit1_params[i] = Encrypted(u"xors2", io) self._raw__raw_limit2_id = self._io.read_bytes(4) self._raw_limit2_id = KaitaiStream.process_xor_many( self._raw__raw_limit2_id, b"\x32\xB8\xBD\x0E") io = KaitaiStream(BytesIO(self._raw_limit2_id)) self.limit2_id = Encrypted(u"xoru4", io) self._raw_limit2_params = [None] * (2) self.limit2_params = [None] * (2) for i in range(2): self._raw__raw_limit2_params[i] = self._io.read_bytes(2) self._raw_limit2_params = KaitaiStream.process_xor_many( self._raw__raw_limit2_params, b"\x90\xA5") io = KaitaiStream(BytesIO(self._raw_limit2_params[i])) self.limit2_params[i] = Encrypted(u"xors2", io) self._raw__raw_target_wep = self._io.read_bytes(4) self._raw_target_wep = KaitaiStream.process_xor_many( self._raw__raw_target_wep, b"\xD7\xC9\x9F\x40") io = KaitaiStream(BytesIO(self._raw_target_wep)) self.target_wep = Encrypted(u"xoru4", io) self._raw__raw_target_mov = self._io.read_bytes(4) self._raw_target_mov = KaitaiStream.process_xor_many( self._raw__raw_target_mov, b"\x22\xD1\x64\x6C") io = KaitaiStream(BytesIO(self._raw_target_mov)) self.target_mov = Encrypted(u"xoru4", io) self.passive_next = CryptString(u"ID", self._io) self._raw__raw_timestamp = self._io.read_bytes(8) self._raw_timestamp = KaitaiStream.process_xor_many( self._raw__raw_timestamp, b"\x51\x9F\xFE\x3B\xF9\x39\x3F\xED") io = KaitaiStream(BytesIO(self._raw_timestamp)) self.timestamp = Encrypted(u"xors8", io) self._raw__raw_unknown1 = self._io.read_bytes(1) self._raw_unknown1 = KaitaiStream.process_xor_many( self._raw__raw_unknown1, b"\x10") io = KaitaiStream(BytesIO(self._raw_unknown1)) self.unknown1 = Encrypted(u"xoru1", io) self._raw__raw_min_lv = self._io.read_bytes(1) self._raw_min_lv = KaitaiStream.process_xor_many( self._raw__raw_min_lv, b"\x90") io = KaitaiStream(BytesIO(self._raw_min_lv)) self.min_lv = Encrypted(u"xoru1", io) self._raw__raw_max_lv = self._io.read_bytes(1) self._raw_max_lv = KaitaiStream.process_xor_many( self._raw__raw_max_lv, b"\x24") io = KaitaiStream(BytesIO(self._raw_max_lv)) self.max_lv = Encrypted(u"xoru1", io) self._raw__raw_unknown2 = self._io.read_bytes(1) self._raw_unknown2 = KaitaiStream.process_xor_many( self._raw__raw_unknown2, b"\x19") io = KaitaiStream(BytesIO(self._raw_unknown2)) self.unknown2 = Encrypted(u"xoru1", io) self._raw__raw_unknown3 = self._io.read_bytes(1) self._raw_unknown3 = KaitaiStream.process_xor_many( self._raw__raw_unknown3, b"\xBD") io = KaitaiStream(BytesIO(self._raw_unknown3)) self.unknown3 = Encrypted(u"xoru1", io) self.padding = self._io.read_bytes(3) self.id_tag2 = CryptString(u"ID", self._io) self.next_seal = CryptString(u"ID", self._io) self.prev_seal = CryptString(u"ID", self._io) self._raw__raw_ss_coin = self._io.read_bytes(2) self._raw_ss_coin = KaitaiStream.process_xor_many( self._raw__raw_ss_coin, b"\x40\xC5") io = KaitaiStream(BytesIO(self._raw_ss_coin)) self.ss_coin = Encrypted(u"xoru2", io) self._raw__raw_ss_badge_type = self._io.read_bytes(2) self._raw_ss_badge_type = KaitaiStream.process_xor_many( self._raw__raw_ss_badge_type, b"\x0F\xD5") io = KaitaiStream(BytesIO(self._raw_ss_badge_type)) self.ss_badge_type = BadgeColor(io) self._raw__raw_ss_badge = self._io.read_bytes(2) self._raw_ss_badge = KaitaiStream.process_xor_many( self._raw__raw_ss_badge, b"\xEC\x8C") io = KaitaiStream(BytesIO(self._raw_ss_badge)) self.ss_badge = Encrypted(u"xoru2", io) self._raw__raw_ss_great_badge = self._io.read_bytes(2) self._raw_ss_great_badge = KaitaiStream.process_xor_many( self._raw__raw_ss_great_badge, b"\xFF\xCC") io = KaitaiStream(BytesIO(self._raw_ss_great_badge)) self.ss_great_badge = Encrypted(u"xoru2", io)
def _read(self): self._raw__raw_buf1 = self._io.read_bytes(5) self._raw_buf1 = KaitaiStream.process_rotate_left( self._raw__raw_buf1, 3, 1) _io__raw_buf1 = KaitaiStream(BytesIO(self._raw_buf1)) self.buf1 = ProcessToUser.JustStr(_io__raw_buf1, self, self._root)
def _read(self): self.form_type = self._io.read_u4le() self._raw_subchunks_slot = self._io.read_bytes_full() _io__raw_subchunks_slot = KaitaiStream(BytesIO(self._raw_subchunks_slot)) self.subchunks_slot = Riff.ParentChunkData.Slot(_io__raw_subchunks_slot, self, self._root)
def _read(self): self._debug['chunk_id']['start'] = self._io.pos() self.chunk_id = KaitaiStream.resolve_enum(MagicavoxelVox.ChunkType, self._io.read_u4be()) self._debug['chunk_id']['end'] = self._io.pos() self._debug['num_bytes_of_chunk_content']['start'] = self._io.pos() self.num_bytes_of_chunk_content = self._io.read_u4le() self._debug['num_bytes_of_chunk_content']['end'] = self._io.pos() self._debug['num_bytes_of_children_chunks'][ 'start'] = self._io.pos() self.num_bytes_of_children_chunks = self._io.read_u4le() self._debug['num_bytes_of_children_chunks']['end'] = self._io.pos() if self.num_bytes_of_chunk_content != 0: self._debug['chunk_content']['start'] = self._io.pos() _on = self.chunk_id if _on == MagicavoxelVox.ChunkType.size: self._raw_chunk_content = self._io.read_bytes( self.num_bytes_of_chunk_content) _io__raw_chunk_content = KaitaiStream( BytesIO(self._raw_chunk_content)) self.chunk_content = MagicavoxelVox.Size( _io__raw_chunk_content, self, self._root) self.chunk_content._read() elif _on == MagicavoxelVox.ChunkType.matt: self._raw_chunk_content = self._io.read_bytes( self.num_bytes_of_chunk_content) _io__raw_chunk_content = KaitaiStream( BytesIO(self._raw_chunk_content)) self.chunk_content = MagicavoxelVox.Matt( _io__raw_chunk_content, self, self._root) self.chunk_content._read() elif _on == MagicavoxelVox.ChunkType.rgba: self._raw_chunk_content = self._io.read_bytes( self.num_bytes_of_chunk_content) _io__raw_chunk_content = KaitaiStream( BytesIO(self._raw_chunk_content)) self.chunk_content = MagicavoxelVox.Rgba( _io__raw_chunk_content, self, self._root) self.chunk_content._read() elif _on == MagicavoxelVox.ChunkType.xyzi: self._raw_chunk_content = self._io.read_bytes( self.num_bytes_of_chunk_content) _io__raw_chunk_content = KaitaiStream( BytesIO(self._raw_chunk_content)) self.chunk_content = MagicavoxelVox.Xyzi( _io__raw_chunk_content, self, self._root) self.chunk_content._read() elif _on == MagicavoxelVox.ChunkType.pack: self._raw_chunk_content = self._io.read_bytes( self.num_bytes_of_chunk_content) _io__raw_chunk_content = KaitaiStream( BytesIO(self._raw_chunk_content)) self.chunk_content = MagicavoxelVox.Pack( _io__raw_chunk_content, self, self._root) self.chunk_content._read() else: self.chunk_content = self._io.read_bytes( self.num_bytes_of_chunk_content) self._debug['chunk_content']['end'] = self._io.pos() if self.num_bytes_of_children_chunks != 0: self._debug['children_chunks']['start'] = self._io.pos() self.children_chunks = [] i = 0 while not self._io.is_eof(): if not 'arr' in self._debug['children_chunks']: self._debug['children_chunks']['arr'] = [] self._debug['children_chunks']['arr'].append( {'start': self._io.pos()}) _t_children_chunks = MagicavoxelVox.Chunk( self._io, self, self._root) _t_children_chunks._read() self.children_chunks.append(_t_children_chunks) self._debug['children_chunks']['arr'][ len(self.children_chunks) - 1]['end'] = self._io.pos() i += 1 self._debug['children_chunks']['end'] = self._io.pos()
times = {} cases = ['test_cell', 'test_col_fixed'] for k in cases: times[k] = [] # https://www.peterbe.com/plog/how-to-do-performance-micro-benchmarks-in-python for i in progressbar(range(num_iterations), "Running benchmark: ", 40): choice = cases[random.randint(0, 1)] k = None row_0 = None t0 = time.time() with open('./sample.bin', 'rb') as f: if choice == 'test_cell': k = TestCell(KaitaiStream(f)) row_0 = k.table.table_rows[0].entries elif choice == 'test_col_fixed': k = TestColFixed(KaitaiStream(f)) row_0_type = k.table.table_rows[0] row_0 = N_COLUMN_REPS * [row_0_type.a, row_0_type.b, row_0_type.c, row_0_type.d] t1 = time.time() assert len(k.table.table_rows) == 65536, 'len(k.table.table_rows) = {} must be {}'.format(len(k.table.table_rows), 65536) if row_0 != N_COLUMN_REPS * [0x7a46, 0x86b97d9c, 0.842150092124939, 0.5340359913176319]: breakpoint() assert row_0 == N_COLUMN_REPS * [0x7a46, 0x86b97d9c, 0.842150092124939, 0.5340359913176319], 'row_0 = {} does not match'.format(row_0) times[choice].append((t1 - t0) * 1000) stats = [ ('MEDIAN', lambda numbers: statistics.median(numbers)),
def _read(self): self._debug['len']['start'] = self._io.pos() self.len = self._io.read_u4be() self._debug['len']['end'] = self._io.pos() self._debug['type']['start'] = self._io.pos() self.type = (self._io.read_bytes(4)).decode(u"UTF-8") self._debug['type']['end'] = self._io.pos() self._debug['body']['start'] = self._io.pos() _on = self.type if _on == u"iTXt": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.InternationalTextChunk( _io__raw_body, self, self._root) self.body._read() elif _on == u"gAMA": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.GamaChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"tIME": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.TimeChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"PLTE": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.PlteChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"bKGD": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.BkgdChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"pHYs": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.PhysChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"tEXt": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.TextChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"cHRM": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.ChrmChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"sRGB": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.SrgbChunk(_io__raw_body, self, self._root) self.body._read() elif _on == u"zTXt": self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.CompressedTextChunk( _io__raw_body, self, self._root) self.body._read() else: self.body = self._io.read_bytes(self.len) self._debug['body']['end'] = self._io.pos() self._debug['crc']['start'] = self._io.pos() self.crc = self._io.read_bytes(4) self._debug['crc']['end'] = self._io.pos()
def _read(self): self.len_index = self._io.read_u4be() self._raw_index_entries = self._io.read_bytes(self.len_index) _io__raw_index_entries = KaitaiStream(BytesIO(self._raw_index_entries)) self.index_entries = MozillaMar.IndexEntries(_io__raw_index_entries, self, self._root)
def _read(self): self.len_orig = self._io.read_u2le() self.str = (self._io.read_bytes(self.len_mod)).decode(u"UTF-8") self._raw_rest = self._io.read_bytes(3) _io__raw_rest = KaitaiStream(BytesIO(self._raw_rest)) self.rest = Expr2.Tuple(_io__raw_rest, self, self._root)
def convert(gif_filename, BGR2RGB=True): """converts an image specified by its filename gif_filename to a numpy image if BGR2RGB is True (default) there will also be a color conversion from BGR to RGB""" if not os.path.isfile(gif_filename): raise IOError("File does not exist") frames = [] frames_specs = [] image_specs = {} gifread = open(gif_filename, "rb") raw = gifread.read() gifread.close() # print(len(raw)) image_specs["Length"] = len(raw) data = Gif(KaitaiStream(BytesIO(raw))) # print("Header", data.hdr.magic, data.hdr.version) image_specs["Header"] = str(data.hdr.magic).replace( "b'", "").strip("'") + " " + str(data.hdr.version) lsd = data.logical_screen_descriptor image_width = lsd.screen_width image_height = lsd.screen_height # print("Color table size", repr(lsd.color_table_size), "Has color table", lsd.has_color_table, "Image width", image_width, "image height", image_height, "Flags", lsd.flags, "Background color", lsd.bg_color_index, "Pixel aspect ratio", lsd.pixel_aspect_ratio) image_specs["Color table size"] = lsd.color_table_size image_specs["Color table existing"] = lsd.has_color_table image_specs["Image Size"] = image_width, image_height image_specs["Flags"] = lsd.flags image_specs["Background Color"] = lsd.bg_color_index image_specs["Pixel Aspect Ratio"] = lsd.pixel_aspect_ratio # print("Color table length", len(data.global_color_table.entries)) image_specs["Color table length"] = len(data.global_color_table.entries) gcte = data.global_color_table.entries color_table = [] for i in range(len(gcte)): color_table.append((gcte[i].red, gcte[i].green, gcte[i].blue)) # print("Color table values", color_table) image_specs["Color table values"] = color_table # print(len(data.blocks)) image_specs["Data Blocks count"] = len(data.blocks) frames = [] exts = [] first_frame = True for i in range(len(data.blocks)): # print("Block_type", data.blocks[i].block_type, "block_count:", i) if data.blocks[i].block_type == Gif.BlockType.local_image_descriptor: imgdata = data.blocks[i].body.image_data left = data.blocks[i].body.left top = data.blocks[i].body.top width = data.blocks[i].body.width height = data.blocks[i].body.height flags = data.blocks[i].body.flags has_color_table = data.blocks[i].body.has_color_table if has_color_table: local_color_table = data.blocks[i].body.local_color_table lzw_min = imgdata.lzw_min_code_size if exts == []: exts.append({}) exts[-1]["left"] = left exts[-1]["top"] = top exts[-1]["width"] = width exts[-1]["height"] = height exts[-1]["flags1"] = flags exts[-1]["has_color_table"] = has_color_table if has_color_table: exts[-1]["local_color_table"] = local_color_table exts[-1]["lzw_min"] = lzw_min all_bytes = b"" alle = 0 for j in range(len(imgdata.subblocks.entries)): # print(imgdata.subblocks.entries[i].num_bytes, sep=" ", end=", ") block_len = imgdata.subblocks.entries[j].num_bytes alle = alle + block_len # print(len(imgdata.subblocks.entries[i].bytes), repr(imgdata.subblocks.entries[i].bytes)) all_bytes = all_bytes + imgdata.subblocks.entries[j].bytes # print("alle", alle) # print(len(all_bytes)) # print("single frame attr at block no.:", i, left, top, width, height, flags, has_color_table, lzw_min) # if has_color_table: # print(local_color_table) uncompressed = lzw_decompress(all_bytes, lzw_min) np_len = len(uncompressed) # print("Uncompressed image: type/length, image_data[:100]", type(uncompressed), np_len, uncompressed[:100]) if len(color_table[0]) == 1: np_image = np.zeros((np_len), dtype=np.uint8) channels = 1 elif len(color_table[0]) == 2: np_image = np.zeros((np_len * 2), dtype=np.uint8) channels = 2 elif len(color_table[0]) == 3: np_image = np.zeros((np_len * 3), dtype=np.uint8) channels = 3 elif len(color_table[0]) == 4: np_image = np.zeros((np_len * 4), dtype=np.uint8) channels = 4 if has_color_table: np_image = np.array( [local_color_table[byt] for byt in uncompressed]) else: np_image = np.array([color_table[byt] for byt in uncompressed]) # print("image_height, image_width, channels", image_height, image_width, channels) np_image = np.reshape(np_image, (height, width, channels)) # print(np_image.shape, np_image[329-height,329-width,0]) if BGR2RGB: if channels == 3 or channels == 4: np_image = cvtColor(np_image) else: np_image = np_image.astype(np.uint8) else: np_image = np_image.astype(np.uint8) if first_frame: first_frame = False frame1 = np_image.copy() else: old_frame = frames[-1].copy() if has_color_table: if BGR2RGB: transp_idx = local_color_table[ exts[-1]['transparent_idx']][::-1] # RGB -> BGR else: transp_idx = local_color_table[ exts[-1]['transparent_idx']] # RGB -> RGB else: if BGR2RGB: transp_idx = color_table[ exts[-1]['transparent_idx']][::-1] # RGB -> BGR else: transp_idx = color_table[ exts[-1]['transparent_idx']] # RGB -> RGB transp_idx = np.array(transp_idx) # cv2.imshow("old_frame", old_frame) new_frame = paste(frame1.copy(), np_image, exts[-1]['left'], exts[-1]['top']) # cv2.imshow("new_frame", new_frame) f = np.all((new_frame == transp_idx), axis=-1) flattened_image = np.reshape( new_frame, (new_frame.shape[0] * new_frame.shape[1], channels)) old_flattened_image = np.reshape( old_frame, (old_frame.shape[0] * old_frame.shape[1], channels)) f = np.reshape(f, (old_frame.shape[0] * old_frame.shape[1], 1)) np_image = np.array([ old_flattened_image[i] if j else flattened_image[i] for i, j in enumerate(f) ]) np_image = np.reshape( np_image, (old_frame.shape[0], old_frame.shape[1], channels)) # cv2.imshow("last_frame", np_image) # cv2.waitKey() frames.append(np_image) elif data.blocks[i].block_type == Gif.BlockType.extension: label = data.blocks[i].body.label # print("label of extension", label) if label == Gif.ExtensionLabel.graphic_control: body = data.blocks[i].body.body # print("body, label of extension", body, label) block_size = data.blocks[i].body.body.block_size flags = data.blocks[i].body.body.flags delay_time = data.blocks[i].body.body.delay_time transparent_idx = data.blocks[i].body.body.transparent_idx terminator = data.blocks[i].body.body.terminator frame_count = len(frames) ext_dict = { "block_size": block_size, "flags": flags, "delay_time": delay_time, "transparent_idx": transparent_idx, "terminator": terminator } exts.append(ext_dict) # print(i, "block_size, flags, delay_time, transparent_idx, terminator", block_size, flags, delay_time, transparent_idx, terminator) elif label == Gif.ExtensionLabel.application: application_id = data.blocks[i].body.body.application_id subblocks = data.blocks[i].body.body.subblocks image_specs["application_id"] = application_id.bytes for k in range(len(subblocks)): image_specs["application_subblocks" + str(k)] = subblocks[k].bytes elif label == Gif.ExtensionLabel.comment: subblocks = data.blocks[i].body.body image_specs["comment"] = b"".join( [b.bytes for b in subblocks.entries]) else: # data.blocks[i].block_type == Gif.BlockType.end_of_file pass return frames, exts, image_specs
def _read(self): self._raw_envelope = self._io.read_bytes(6) _io__raw_envelope = KaitaiStream(BytesIO(self._raw_envelope)) self.envelope = EosExceptionBytes.Data(_io__raw_envelope, self, self._root)
def _read(self): self.len32 = self._io.read_u4be() self.atom_type = KaitaiStream.resolve_enum(QuicktimeMov.AtomType, self._io.read_u4be()) if self.len32 == 1: self.len64 = self._io.read_u8be() _on = self.atom_type if _on == QuicktimeMov.AtomType.moof: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.tkhd: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.TkhdBody(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.stbl: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.traf: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.minf: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.trak: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.moov: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.mdia: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.dinf: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.AtomList(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.mvhd: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.MvhdBody(_io__raw_body, self, self._root) elif _on == QuicktimeMov.AtomType.ftyp: self._raw_body = self._io.read_bytes(self.len) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = QuicktimeMov.FtypBody(_io__raw_body, self, self._root) else: self.body = self._io.read_bytes(self.len)
def _read(self): self._debug['name']['start'] = self._io.pos() self.name = (self._io.read_bytes(4)).decode(u"ASCII") self._debug['name']['end'] = self._io.pos() self._debug['size']['start'] = self._io.pos() self.size = self._io.read_u4le() self._debug['size']['end'] = self._io.pos() self._debug['body']['start'] = self._io.pos() _on = self.name if _on == u"SLBR": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionStartingResource( _io__raw_body, self, self._root) self.body._read() elif _on == u"ERAX": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionEra(_io__raw_body, self, self._root) self.body._read() elif _on == u"OWNR": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionOwnr(_io__raw_body, self, self._root) self.body._read() elif _on == u"ERA ": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionEra(_io__raw_body, self, self._root) self.body._read() elif _on == u"SGLD": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionStartingResource( _io__raw_body, self, self._root) self.body._read() elif _on == u"VER ": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionVer(_io__raw_body, self, self._root) self.body._read() elif _on == u"SOIL": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionStartingResource( _io__raw_body, self, self._root) self.body._read() elif _on == u"UNIT": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionUnit(_io__raw_body, self, self._root) self.body._read() elif _on == u"DIM ": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionDim(_io__raw_body, self, self._root) self.body._read() elif _on == u"TYPE": self._raw_body = self._io.read_bytes(self.size) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = Warcraft2Pud.SectionType(_io__raw_body, self, self._root) self.body._read() else: self.body = self._io.read_bytes(self.size) self._debug['body']['end'] = self._io.pos()
def _read(self): self._raw_hdr = self._io.read_bytes(128) _io__raw_hdr = KaitaiStream(BytesIO(self._raw_hdr)) self.hdr = Pcx.Header(_io__raw_hdr, self, self._root)
def __init__(self, raw_client_hello): self._client_hello = tls_client_hello.TlsClientHello( KaitaiStream(io.BytesIO(raw_client_hello)))
def _read(self): self.size = self._io.read_u2le() self._raw_body = self._io.read_bytes((self.size - 2)) _io__raw_body = KaitaiStream(BytesIO(self._raw_body)) self.body = S3m.PatternCells(_io__raw_body, self, self._root)
def parse(hcdBin): if isinstance(hcdBin, (bytes, bytearray)): iO = BytesIO(hcdBin) return BluetoothHcd(BluetoothVendorsIds.Vendor.cypress_semiconductor, KaitaiStream(iO))
def _read(self): self.left_child_page = self._io.read_u4be() self.len_payload = vlq_base128_be.VlqBase128Be(self._io) self._raw_payload = self._io.read_bytes(self.len_payload.value) _io__raw_payload = KaitaiStream(BytesIO(self._raw_payload)) self.payload = Sqlite3.CellPayload(_io__raw_payload, self, self._root)
def _read(self): self.string_magic = self._io.ensure_fixed_contents(b"\x73") self.length = self._io.read_u4le() self._raw_items = self._io.read_bytes(self.length) io = KaitaiStream(BytesIO(self._raw_items)) self.items = self._root.OpArgs(io, self, self._root)
def __init__(self, raw_client_hello: bytes): """Create a TLS ClientHello object from raw bytes.""" self.raw_bytes = raw_client_hello self._client_hello = tls_client_hello.TlsClientHello( KaitaiStream(io.BytesIO(raw_client_hello)))
def _read(self): self._raw_header = self._io.read_bytes(self.header_size) io = KaitaiStream(BytesIO(self._raw_header)) self.header = self._root.Header(io, self, self._root) self.data = self._io.read_bytes(self.header.data_size)
def _read(self): self._debug['len']['start'] = self._io.pos() self.len = self._root.LenSubpacket(self._io, self, self._root) self.len._read() self._debug['len']['end'] = self._io.pos() self._debug['subpacket_type']['start'] = self._io.pos() self.subpacket_type = KaitaiStream.resolve_enum(self._root.SubpacketTypes, self._io.read_u1()) self._debug['subpacket_type']['end'] = self._io.pos() self._debug['content']['start'] = self._io.pos() _on = self.subpacket_type if _on == self._root.SubpacketTypes.preferred_key_server: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.PreferredKeyServer(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.issuer: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.Issuer(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.revocable: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.Revocable(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.signature_target: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.SignatureTarget(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.regular_expression: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.RegularExpression(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.exportable_certification: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.ExportableCertification(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.reason_for_revocation: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.ReasonForRevocation(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.key_server_preferences: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.KeyServerPreferences(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.signature_creation_time: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.SignatureCreationTime(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.preferred_hash_algorithms: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.PreferredHashAlgorithms(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.trust_signature: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.TrustSignature(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.key_expiration_time: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.KeyExpirationTime(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.key_flags: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.KeyFlags(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.signature_expiration_time: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.SignatureExpirationTime(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.features: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.Features(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.signers_user_id: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.SignersUserId(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.notation_data: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.NotationData(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.revocation_key: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.RevocationKey(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.preferred_compression_algorithms: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.PreferredCompressionAlgorithms(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.policy_uri: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.PolicyUri(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.primary_user_id: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.PrimaryUserId(_io__raw_content, self, self._root) self.content._read() elif _on == self._root.SubpacketTypes.embedded_signature: self._raw_content = self._io.read_bytes((self.len.len - 1)) _io__raw_content = KaitaiStream(BytesIO(self._raw_content)) self.content = self._root.EmbeddedSignature(_io__raw_content, self, self._root) self.content._read() else: self.content = self._io.read_bytes((self.len.len - 1)) self._debug['content']['end'] = self._io.pos()
Gbr0.Gbr0Object.Type.producer: parse_object_producer, Gbr0.Gbr0Object.Type.tile_data: parse_object_tile_data, Gbr0.Gbr0Object.Type.tile_settings: parse_object_tile_settings, Gbr0.Gbr0Object.Type.tile_export: parse_object_tile_export, Gbr0.Gbr0Object.Type.tile_import: parse_object_tile_import, Gbr0.Gbr0Object.Type.palettes: parse_object_palettes, Gbr0.Gbr0Object.Type.tile_pal: parse_object_tile_pal, Gbr0.Gbr0Object.Type.deleted: parse_object_deleted, } def dump_gbr_file(file): print(gbr0.magic) for gbr_object in gbr0.objects: print('Type: %s, ID: %d' % (gbr_object.object_type, gbr_object.object_id)) print('Size: %d' % gbr_object.record_length) body_parsers[gbr_object.object_type](gbr_object.body) print('') if __name__ == '__main__': files = [ '8x8.gbr', 'alpha.gbr', 'digits.gbr', 'shaded_alpha.gbr', 'shadow.gbr' ] for filename in files: with open('test/%s' % filename, 'rb') as fin: gbr0 = Gbr0(KaitaiStream(fin)) dump_gbr_file(gbr0) print('---' * 10)
def gse_parse(file, outfile, matype_crib=int(0x4200), stream=False, tcp_hijack=False, tcp_hijack_ips=None, reliable=True): with open(outfile, 'wb') as pcap_file: io = KaitaiStream(open(file, 'rb')) pcap_writer = Writer() pcap_writer.create_header(pcap_file) bbframe_count = 1 pkt_count = 0 eof_count = 0 while True: try: # we record the last io position for kaitai so we can recover from EOF errors in streaming mode last_pos = io.pos() # prints the first BBframe we find at the current IO position # this throws EOF if there's no bytes left in the file current_bbframe = PureBb(io, matype_crib=matype_crib).bbframe if eof_count > 0: print("new frames found, continuing...") eof_count = 0 except EOFError: if not stream: # if we're reading from a static file EOFError is sufficient reason to stop break elif eof_count == 0: pass # otherwise we will wait progressively longer whenever there isn't data in the streamed file elif eof_count % 10000 == 0: time.sleep(1) elif eof_count > 1000000: time.sleep(10) elif eof_count > 1000600: # after an hour of no fresh bytes (plus a little bit more), gsextract will exit and clean up buffers # this normally means something has broken in the satellite hardware side print( "No new data received for at least 1 hour. Exiting gsextract." ) eof_count += 1 io.seek(last_pos) continue except: # we want to maximize recovery in the case of stream parsing errors so we will just keep trying continue bbframe_count += 1 # record stats on corrupt BBframes and then move to the next frame if hasattr(current_bbframe, 'corrupt_data'): counters['broken_bbframes'] += 1 print("BBFrame", bbframe_count, " contains corrupt data, (MA2:", current_bbframe.bbheader.matype_2, ") attempting to recover") else: # for valid BBFrames # next extract gse packets from the bbframe and try to make them into IP payloads gse_packets = get_gse_from_bbdata(current_bbframe.data_field) raw_packets = parse_gse_packet_array(gse_packets, bbframe_count, reliable=reliable) # if we get any IP packets, write them to a pcap file if len(raw_packets) > 0: pcap_writer.write(raw_packets, pcap_file) pkt_count += len(raw_packets) # print some progress stats if pkt_count % 10000 == 0: print(pkt_count, "packets parsed") print(counters) # Clean up any lingering fragments when GSExtract closes # these would be partially filled buffers from end of recording raw_packets = parse_gse_packet_array([], 0, cleanup=True, reliable=reliable) if len(raw_packets) > 0: pcap_writer.write(raw_packets, pcap_file) # Print some basic stats before finishing print(counters)